Cosmic-ray spectra of primary protons and high altitude muons deconvolved from observed atmospheric gamma rays