Notice that, if $f(x)$ is a solution, then $-f(x)$ is also a solution.
Let $P(x,y)$ denotes the assertion.
$P(0,0)$ implies $f(f(0)^2)=0$ . Now if $f(0)=0$ , $P(x,0)$ implies $f(x)=0$ for all $x \in \mathbb{R} $. So, assume $f(0) \neq 0$.
Claim 1: If $f(x)=0$, then $ x=1$
Proof: Assume the contrary. So, $P(x, \frac{x}{x-1})$ implies $f(0)=0$. Contradiction!
So, $f(0)^2=1 \Rightarrow f(0)=1$ or $-1$. WLOG, $f(0)=-1$.
Claim 2: $f(k)=k-1$ for all $k \in \mathbb{Z}$
Proof: $P(x,1) \Rightarrow f(x+1)=f(x)+1$ . Then Induction!
Claim 3: If $a \in R_f$, then $f(a)=a-1$ where $R_f$ denotes the RANGE of $f$. Also, $f(2x)=2f(x)+1$
Proof: $P(x,0) \Rightarrow f(-f(x))=-f(x)-1 \Rightarrow f(f(x))=f(x)-1$ and the other one follows from $P(x,2)$
Claim 4: $f(x)+f(-x)=-2$ and $f(-x)=-f(x+2)$
Proof: $P(x,-1) \Rightarrow f(-x)=f(x)-1+f(-2f(x)) = f(x)+2f(-f(x)) = f(x)-2f(x)-2 = -f(x)-2 = -f(x+2)$
Claim 5: $f(x+y)=f(x)+f(y)+1$
Proof: $f(x)=-f(2-x)$. Then, $f(f(x)f(y))=f(f(2-x)f(2-y)) \Rightarrow f(xy)-f(x+y)=f(xy-2x-2y+4)-f(4-x-y) \Rightarrow f(p)=f(p-2s+4)-f(4-s)+f(s) \Rightarrow f(p)=f(p-2s)+f(2s)+1$ where $p=xy$ and $s=x+y$ and $s^2 \ge 4p$. So, all $x,y$ satisfying $(\frac{y}{2})^2 \ge 4 (x+y)$ or $x+y \le 0$ satisfies $f(x+y)=f(x)+f(y)+1$. Plugging $-x,-y$ into this equation also satisfies the equation. So we can say that, this equation holds for all real $x,y$.
Claim 6: $f(x)f(y)+x+y-xy=1$
Proof: $0=f(f(x)f(y))+f(x+y)-f(xy) =...=f(f(x)f(y)+x+y-xy)$. The result follows.
Putting $y=0$ on claim 6 gives us the result.
So, all such functions are $f(x)=0 , f(x) = x-1 , f(x)=1-x$