Photochemistry in Terrestrial Exoplanet Atmospheres III: Photochemistry and Thermochemistry in Thick Atmospheres on Super Earths and Mini Neptunes