Integral over fraction of trigonometric functions I would like to calculate the following integral
$$
I_1(A,B,C) = \int_0^{2\pi} \frac{d\phi}{1 + A \cos\phi + B \sin\phi + C},
$$
and if possible also
$$
I_2(A,B,C,D,E) = \int_0^{2\pi} d\phi \frac{D \cos\phi + E \sin\phi }{1 + A \cos\phi + B \sin\phi + C}.
$$
Mathematica gives the following analytic expression 
$$
\frac{-2\text{ArcTanh}\Big(\frac{B + (1- A+C)\tan(x/2)}{\sqrt{A^2+B^2-(1+C)^2}}\Big)}{\sqrt{A^2+B^2-(1+C)^2}},
$$
for the primitive function of $I_1$. However, when using it to evaluate the definite integral, it yields zero, whereas a numerical integration shows that it is not zero. 
 A: By making the simplifications observed in the comments, we can rewrite the first integral as some fixed real multiple of
$$\int_0^{2 \pi} \frac{d\phi}{1 + M \sin \phi},$$
where $M = \frac{\sqrt{A^2 + B^2}}{C + 1}$. Henceforth assume $|M| < 1$, so that the denominator is always positive, avoiding singularities.
Integrating formally gives that
$$\int \frac{d\phi}{1 + M \sin \phi} = \frac{2}{\sqrt{1 - M^2}} \arctan \left(\frac{\tan \frac{\phi}{2} + M}{\sqrt{M^2 - 1}}\right),$$
but we can see that this expression is not defined at $\phi$ for which $\frac{\phi}{2}$ is a singularity of $\tan$, that is, where $\phi = (2 k + 1) \pi$, $k \in \Bbb Z$, so the antiderivative can only be used to evaluate definite integrals of the integrand on intervals not containing odd multiples of $\pi$. One can certainly write down an antiderivative of the integrand continuous on all of $[0, 2 \pi]$, but it's easier to use the symmetry of $\sin$ to write the definite integral as
$$\int_{- \pi}^{\pi} \frac{d\phi}{1 + M \sin \phi} .$$ In particular, the interior of the domain of integration contains no singularities of $\tan \frac{\phi}{2}$, so we can conclude that the value of this integral is
$$\lim_{\phi \nearrow \pi} \left[\frac{2}{\sqrt{1 - M^2}} \arctan \left(\frac{\tan \frac{\phi}{2} + M}{\sqrt{M^2 - 1}}\right) \right] - \lim_{\phi \searrow -\pi} \left[\frac{2}{\sqrt{1 - M^2}} \arctan \left(\frac{\tan \frac{\phi}{2} + M}{\sqrt{M^2 - 1}}\right) \right] = \frac{2 \pi}{\sqrt{1 - M^2}}.$$
As for the second integral, applying the same formal simplifications as before leaves us with (some real multiple of) the integral
$$\int_0^{2 \pi} \frac{D \cos \phi + E \sin \phi}{1 + M \sin \phi} d\phi .$$
We can split the integral as 
$$D \int_0^{2 \pi} \frac{\cos \phi \,d\phi}{1 + M \sin \phi} d\phi + E \int_0^{2 \pi} \frac{\sin \phi \,d\phi}{1 + M \sin \phi} d\phi ,$$
and the obvious substitution leads to the vanishing of the first integral. We can then proceed similarly as before and express our remaining integral as a sum of two limits, yielding (if I managed this correctly)
$$\int_0^{2 \pi} \frac{\sin \phi \,d\phi}{1 + M \sin \phi} = \frac{2 \pi}{M} \left(1 - \frac{1}{\sqrt{1 - M^2}} \right) .$$
