  The sub-Saturn ($\sim$4--8$R_{\oplus}$) occurrence rate rises with orbital
period out to at least $\sim$300 days. In this work we adopt and test the
hypothesis that the decrease in their occurrence towards the star is a result
of atmospheric mass loss, which can transform sub-Saturns into sub-Neptunes
($\lesssim$4$R_{\oplus}$) more efficiently at shorter periods. We show that
under the mass loss hypothesis, the sub-Saturn occurrence rate can be leveraged
to infer their underlying core mass function, and by extension that of gas
giants. We determine that lognormal core mass functions peaked near
$\sim$10--20$M_{\oplus}$ are compatible with the sub-Saturn period
distribution, the distribution of observationally-inferred sub-Saturn cores,
and gas accretion theories. Our theory predicts that close-in sub-Saturns
should be $\sim$50\% less common and $\sim$30\% more massive around rapidly
rotating stars; this should be directly testable for stars younger than
$\lesssim$500 Myr. We also predict that the sub-Jovian desert becomes less
pronounced and opens up at smaller orbital periods around M stars compared to
solar-type stars ($\sim$0.7 days vs.~$\sim$3 days). We demonstrate that
exceptionally low-density sub-Saturns, "Super-Puffs", can survive intense
hydrodynamic escape to the present day if they are born with even larger
atmospheres than they currently harbor; in this picture, Kepler 223 d began
with an envelope $\sim$1.5$\times$ the mass of its core and is currently losing
its envelope at a rate $\sim$2$\times 10^{-3}M_{\oplus}~\mathrm{Myr}^{-1}$. If
the predictions from our theory are confirmed by observations, the core mass
function we predict can also serve to constrain core formation theories of
gas-rich planets.
