The Chandra COSMOS Legacy Survey: Energy Spectrum of the Cosmic X-Ray Background and Constraints on Undetected Populations