Chemistry of atmospheres formed during accretion of the Earth and other terrestrial planets