I am working on the following problem: Find the derivative of $f(x)=\displaystyle \int_{x}^{0}\displaystyle\frac{\cos xt}{t}dt$.
The answer I am supposed to get is $\displaystyle \frac{1}{x}\left[1-2\cos(x^2)\right]$.
To get there, the first thing I did, of course, was switch the limits of integration as such: $f(x) = \displaystyle \int_{x}^{0} \frac{\cos xt}{t} dt = -\int_{0}^{x}\frac{\cos xt}{t} dt$.
Then, I tried a couple of different avenues: first, I tried straight up integration by parts, with $\displaystyle u = \frac{1}{t}$, $\displaystyle dv=\cos xt$, and end up with $\displaystyle \left[ \frac{-\sin(xt)}{xt}\right]_{0}^{x} + \frac{1}{x}\int_{0}^{x}\frac{\sin(xt)}{t^{2}}dt$, which doesn't get me any closer to a solution.
choosing instead $u = \cos xt$ introduces natural logaritms that cause me to need more integration by parts, and eventually, I get that $\displaystyle \int_{0}^{x}\frac{\cos xt}{t}dt = \left[\ln t \cos (xt)\right]_{0}^{x}$, which is a problem, because $\ln t$ is not defined at $t=0$ (nor does the limit exist there, if I wrote it properly as an improper integral). So, I'm at an impasse.
If someone could please tell me how in the world they managed to get $\displaystyle \frac{1}{x}\left[1-2\cos(x^2)\right]$ out of this, I'd be most grateful. I'm sure it is something very simple, yet extremely clever.
Thank you in advance (this was a question on a GRE practice test, fyi).

You are not looking for $f$, but for $f'(x)$. So, we want to know
$$ f'(x)=\frac{d}{dx}\int_{x}^{0}\frac{\cos(xt)}{t}dt $$
We can differentiate under the sign of the integral, given that the integrand and it's partial derivative in relation to $x$ are continuous (see http://en.wikipedia.org/wiki/Differentiation_under_the_integral_sign). So, $$ f'(x)=-\frac{\cos(x^2)}{x}+\int_{x}^{0}\frac{\partial}{\partial x}\frac{\cos(xt)}{t}dt =-\frac{\cos(x^2)}{x}+\int_{x}^{0}-\sin(xt)dt = \\ -\frac{\cos(x^2)}{x}+ [\frac{\cos(xt)}{x}]_{x}^{0}=\frac{1}{x}-2\frac{\cos(x^2)}{x} $$