Inverse Fast Fourier Transform Hard Way
Effectively Xsize is allows the sampling frequency to be set.

If you just used 2*pi*0*n+Xphase(1) as the argument of $\cos(\cdot)$ or $\sin(\cdot)$ then you'd just get $\cos({\tt Xphase(1)})$ or $\sin({\tt Xphase(1)})$ for all terms... because then the 2*pi*0*n terms would be an integer multiple of 2*pi.



EDIT
With respect to the Xsize terms at the end:


  s0=Xmag(1)*cos(2*pi*0*n/Xsize+Xphase(1))/Xsize;


Check out the definition of the inverse DFT, particularly equation 2:
$$
x_n = \frac{1}{N} \sum_{k=0}^{N-1} X_k e^{i2\pi k n / N}
$$
for your code, N = XSize.