Ab initio temperature dependence of the thermal expansion of diamond and the frequency shift of optical phonons