  We perform a fit to measurements of the cosmic ray spectrum and of the depth
of shower maximum in the energy range between $10^{15}$~eV and $10^{18}$~eV. We
consider a Galactic component that is a mixture of five representative nuclear
species (H, He, N, Si and Fe), for which we adopt rigidity dependent broken
power-law spectra, and we allow for an extragalactic component which becomes
strongly suppressed for decreasing energies. The relative abundances of the
Galactic components at $10^{15}$~eV are taken to be comparable to those
determined by direct measurements at $10^{13}$~eV. The main features of the
spectrum and of the composition are reproduced in these scenarios. The spectral
knee results from the break of the H spectrum at $E_{\rm k}\simeq 3\times
10^{15}$~eV, although it is broaden by the comparable contribution from He
which has a break at about $6\times 10^{15}$~eV. The low-energy ankle at
$E_{\rm la}\simeq 2\times 10^{16}$~eV is associated to the strong suppression
of the H and He Galactic components and the increasing relative contribution of
the heavier ones, but the observed hardening of the spectrum at this energy
turns out to result from the growing contribution of the extragalactic
component. The second-knee at $E_{\rm sk}\simeq 26 E_{\rm k}\simeq 8\times
10^{16}$~eV is associated with the steepening of the Galactic Fe component. The
transition to the regime in which the total cosmic ray flux is dominated by the
extragalactic component takes place at an energy of about $10^{17}$~eV. The
parameters of the fit depend on the hadronic model that is used to interpret
the $X_{\rm max}$ measurements as well as on the specific $X_{\rm max}$ dataset
that is considered in the fit. The impact of the possible existence of a
maximum rigidity cutoff in the Galactic components is also discussed.
