  We study the inclusive production of J/psi and psi(2S) mesons originating
from the decays of bottom-flavored hadrons produced in p anti-p collisions at
the Fermilab Tevatron and in pp collisions at the CERN LHC. We work at
next-to-leading order in the general-mass variable-flavor-number scheme
(GM-VFNS) implemented with nonperturbative fragmentation functions fitted to
e^+e^- data of inclusive b-hadron production exploiting their universality. The
three-momentum distributions of the charmonia used were extracted from B-decay
data in the framework of nonrelativistic-QCD factorization. Comparing the
theoretical predictions thus obtained with transverse-momentum distributions
measured by the CDF II, ALICE, ATLAS, CMS, and LHCb Collaborations, we find
excellent overall agreement as for both absolute normalization and lineshape,
which provides a nontrivial test of the GM-VFNS over wide ranges of
center-of-mass energy, transverse momentum, and rapidity.
