I need to compute the following integral: $$ m=2(1-z^2)\int^\pi_0\frac{g(\theta,x)}{z^2-2z\cos\theta+1}d\theta $$ where $$ g(\theta,x)= \begin{cases} \frac{1}{2\pi}\frac{\sin(\theta/2)}{\sqrt{\sin^2(\theta/2)-x^2}} \ \ \mathrm{if} \ \ \cos(\theta)\leq1-2x^2 \\ 0 \ \ \mathrm{else} \end{cases} $$ I (think I) know the answer is $$ m=\sqrt{\frac{z^2-2z+1}{z^2-2z(1-2x^2)+1}} $$ but I need to make my proof more rigorous as it just stands on intuition for the moment... I have used the residue theorem, considering that the density $g(\theta)$ is an analytic measure on the domain of integration and that the denominator has simple zeros at $e^{\pm i\theta_0}=z$. Taking that $$ \mathrm{Res}\left[\frac{g(\theta,x)}{z^2-2z\cos\theta+1},\theta_0\right]=\frac{g(\theta_0,x)}{(z^2-2z\cos\theta+1)'} $$ directly yields the right answer, if I consider a contour so that the residue is multiplied by $2\pi i$ and not just $\pi i$.
Clearly this is not rigorous as I don't even know what domain of integration would allow me to use the residue theorem as such. Besides, I don't know to which extent my reasoning is wrong due to the discontinuity in $g$. Any help would be much appreciated! Thanks