Help with identity in complex contour I am dealing with an integral in the complex plane, in particular I want to transform
$$
\int_{0}^{2\pi} \frac{d\phi}{\sqrt{1+b^2 -2b \cos \phi}}
$$
into another integral near the branch cuts for the principal branch. Here $0<b<1$.
I got so far as to show that if I introduce $z= e^{i\phi}$, then I have the integral
$$
-i\int_C \frac{dz}{z\sqrt{1+ b^2 - b(z +1/z)}}
$$
$C$ is the unit circle ran counterclockwise.
I showed also that the function (taking the principal branch of the square root) $\sqrt{z(z-b)(1-bz)}$ is continuous on $C$. The thing to do seems to substitute this as the denominator above and work it out (I know what the final answer should look like), I have no problems doing that. 
My problem is that I do not see why is it possible to substitute this for the denominator, it seems to me that one would have to prove that these functions agree on $C$:
$$
z\sqrt{1+ b^2 - b(z +1/z)}|_C = \sqrt{z(z-b)(1-bz)}|_C  \quad .....(1)
$$
This might be a very stupid question, but I haven't found a way to do it. 
Is there a simple way to see that this is the case indeed? I strongly suspect there is, but I am sure I am missing something.
EDIT: I actually just realised that the identity (1) above is not true, by plugging $z=-1$ into it. So my question now would be how to convert the original integral on $\phi$ into:
$$ \int_C  \frac{dz}{\sqrt{z(b-z)(1-bz)}}$$
Where we take the principal branch of the square root.
I thought I was in the right track, now I am not so sure any more. 
 A: Consider the following contour integral:
$$\oint_C \frac{dz}{\sqrt{z} \sqrt{(b-z)(b z-1)}} $$
where $C=C_1+C_2$, $C_1$ is the unit circle in the counterclockwise direction, $C_2$ a dogbone contour in a clockwise direction around the points $z=b$ and $z=0$.  Note that you cannot put the square roots together.
The dogbone piece $C_2$ is necessary for excluding the branch points $z=0$ and $z=b$ from the integral so that we may apply Cauchy's theorem.
Note that
$$\oint_{C_1} \frac{dz}{\sqrt{z} \sqrt{(b-z)(b z-1)}} = i \int_0^{2 \pi} \frac{d\phi}{\sqrt{1+b^2-2 b \cos{\phi}}}$$
As for $C_2$, we need to deal with the square root so that we define a single-valued function inside $C$.  Note that
$$z^{-1/2} = e^{-(1/2) \log{z}}$$
such that $\arg{z} \in [-\pi,\pi)$.  This definition is a result of the original branch cut of this factor being $(-\infty,0]$.  Further define
$$(b-z)^{-1/2} = e^{-(1/2) \log{(b-z)}}$$
such that $\arg{(b-z)} \in [0,2\pi)$.  This definition is a result of the original branch cut of this factor being $[1,\infty)$. 
To summarize, on the lines above and below the real axis, $z=x \in [0,1]$ and therefore $\arg{z} = 0$.  On the line above the real axis, however, $\arg{(b-z)} = 2 \pi$.  Therefore above the real axis,  $z^{-1/2} (b-z)^{-1/2} =  x^{-1/2} (b-x)^{-1/2} e^{-i \pi}$  Below the real axis,  $z^{-1/2} (b-z)^{-1/2} =  x^{-1/2} (b-x)^{-1/2}$ because there, $\arg{(b-z)} = 0$.  
Note also that $\arg{(b z-1)} = -\pi$ throughout $C$.
Further, it should be clear that the integrals about the small circular arcs of radius $\epsilon$ around the branch points vanish as $\epsilon^{1/2}$.
Therefore, by Cauchy's theorem, we have
$$\oint_{C_1} \frac{dz}{\sqrt{z} \sqrt{(b-z)(b z-1)}} + \oint_{C_2} \frac{dz}{\sqrt{z} \sqrt{(b-z)(b z-1)}}= 0 $$
so that
$$ i \int_0^{2 \pi} \frac{d\phi}{\sqrt{1+b^2-2 b \cos{\phi}}} -i 2 \int_0^b \frac{dx}{\sqrt{x (b-x) (1-b x)}} = 0$$
or
$$\int_0^{2 \pi} \frac{d\phi}{\sqrt{1+b^2-2 b \cos{\phi}}} = 2 \int_0^b \frac{dx}{\sqrt{x (b-x) (1-b x)}}$$
To get this latter integral into a more familiar form, sub $x=b t^2$ to get
$$4 \int_0^1 \frac{dt}{\sqrt{(1-t^2)(1-b^2 t^2)}} = 4 K(b)$$
where $K$ is the complete elliptic integral of the first kind.
