Evaluate $$\int_0^\infty \frac{\cos x}{(x^2+1)^2} \, dx \tag{1}$$
It's just setting this one up that's the hardest part. Finding the right contour is what is most tricky to me. My first move is to note that the above integrand is even. So it suffices to instead calculate
$$\frac{1}{2} \int_{-\infty}^\infty \frac{\cos x}{(x^2+1)^2} \, dx \tag{2}$$
Now, I will construct a semicircular arc consisting of the real interval from $-R$ to $R$ for $R>0$ and the arc $\gamma$ given by the top half of the circle $|z|=R$. Call this contour $C_R$. This is the trickiest step. From here, can I directly write $(2)$ as
$$\frac{1}{2} \int_{C_R} \frac{\cos z}{(z^2+1)^2} \, dz \hspace{0.3cm} ? \tag{3}$$
If so, then from here I observe that $z= \pm i$ are each poles of order $2$ and by Cauchy's limit formula for residues, I can find the appropriate residues and then ultimately evaluate $(3)$ via the residue theorem.
Hence, my post begs the question is the substitution from $(2)$ to $(3)$ valid? If not, what steps do I need to take instead?