Finding $\int e^{-\sin^2x}{(\cos x -3 x \sin(x)+2 x \sin^3(x))}dx$ 
I need to find $$\int e^{-\sin^2x}{(\cos x -3 x \sin(x)+2 x
 \sin^3(x))}dx$$ .
I know that $$\int e^{g(x)}{(f(x)g'(x)+f'(x))}dx = e^{g(x)}f(x)$$.

But I cannot find cannot $f(x)$ in the above expression.It seems really difficult to guess what $f(x)$ could be.Any other faster methods?How do I get $f(x)$ ?

The integral is of the form 
\begin{equation*}
\int e^{-\sin ^{2}x}\left( \cos x-3x\sin x+2x\sin ^{3}x\right) dx=\int
e^{g(x)}h(x)dx.
\end{equation*} 
The presence of the exponential function in the integrand function recalls
the well-known formula 
\begin{equation*}
\int e^{g(x)}\left( f^{\prime }(x)+g^{\prime }(x)f(x)\right)
dx=f(x)e^{g(x)}+C
\end{equation*} 
with $g(x)=-\sin ^{2}x.$ So we are done if we find a function $f(x)$ such
that 
\begin{eqnarray*}
h(x) &=&\left( \cos x-3x\sin x+2x\sin ^{3}x\right)  \\
&=&f^{\prime }(x)+g^{\prime }(x)f(x) \\
&=&f^{\prime }(x)+\left( -2\sin x\cos x\right) f(x).
\end{eqnarray*} 
In what follows, I will show step by step that $f(x)=x\cos x,$ and therefore 
\begin{equation*}
\int e^{-\sin ^{2}x}\left( \cos x-3x\sin x+2x\sin ^{3}x\right) dx=x\cos
xe^{-\sin ^{2}x}+C.
\end{equation*} 
The unique thing which is given in the statement is $g(x)=-\sin ^{2}x.$ So,
the first thing we start with is to look for $g^{\prime }(x)=-2\sin x\cos x$
inside what would be $f^{\prime }(x)+g^{\prime }(x)f(x),$ that is, inside 
\begin{equation*}
\cos x-3x\sin x+2x\sin ^{3}x.
\end{equation*} 
Since $g^{\prime }(x)=-2\sin x\cos x$ is a product of two trigonometric
functions and the first two terms do not contain any product of two trig
functions, then if it is possible to find $g^{\prime }(x)$ inside $h(x)$ then
it is inside its third term $2x\sin ^{3}x.$ Another matter is : to get $ 
\cos x$ inside $\sin ^{n}x$ we need the relation $\sin ^{2}x=1-\cos ^{2}x.$
Now, it is easy to see that 
\begin{eqnarray*}
2x\sin ^{3}x &=&2x\sin x\sin ^{2}x \\
&=&2x\sin x(1-\cos ^{2}x) \\
&=&2x\sin x-2x\sin x\cos ^{2}x \\
&=&2x\sin x+(-2\sin x\cos x)(x\cos x) \\
&=&2x\sin x+g^{\prime }(x)(x\cos x).
\end{eqnarray*} 
Then 
\begin{eqnarray*}
h(x) &=&\cos x-3x\sin x+2x\sin ^{3}x \\
&=&\cos x-3x\sin x+2x\sin x+g^{\prime }(x)(x\cos x) \\
&=&\cos x-x\sin x+g^{\prime }(x)(x\cos x).
\end{eqnarray*} 
Now we add and subtract $(x\cos x)^{\prime },$ to get 
\begin{equation*}
h(x)=(x\cos x)^{\prime }+g^{\prime }(x)(x\cos x)+\cos x-x\sin x-(x\cos
x)^{\prime }
\end{equation*} 
But $(x\cos x)^{\prime }=\cos x-x\sin x,$ so 
\begin{equation*}
h(x)=(x\cos x)^{\prime }+g^{\prime }(x)(x\cos x).
\end{equation*} 
Therefore, it suffices to take $f(x)=x\cos x.
\color{red} 
\blacksquare $
