Find all functions $f: \mathbb{R} \rightarrow \mathbb{R}$ such that

$$
f(x+y f(x+y))=y^{2}+f(x) f(y)
$$

for all $x, y \in \mathbb{R}$.
Note that the function $f(x)=0$ for all $x$ does not satisfy the condition. Therefore, there is an $a$ such that $f(a) \neq 0$. Substitute $x=a$ and $y=0$, which gives $f(a)=f(a) f(0)$, so $f(0)=1$. Now substitute $x=1$ and $y=-1$, which gives $f(1-f(0))=1+f(1) f(-1)$. Since $f(0)=1$, this becomes $1=1+f(1) f(-1)$, so $f(1)=0$ or $f(-1)=0$. We will consider these two cases separately.

First, assume that $f(1)=0$. Substitute $x=t$ and $y=1-t$, and then $x=1-t$ and $y=t$, which gives the two equations

$$
\begin{aligned}
f(t) & =(1-t)^{2}+f(t) f(1-t) \\
f(1-t) & =t^{2}+f(t) f(1-t)
\end{aligned}
$$

Subtracting these equations gives $f(t)-f(1-t)=(1-t)^{2}-t^{2}=1-2 t$, so $f(1-t)=f(t)+2 t-1$. Substituting this into the first of the above two equations gives

$$
f(t)=(1-t)^{2}+f(t)^{2}+(2 t-1) f(t)
$$

which can be rewritten as

$$
f(t)^{2}+(2 t-2) f(t)+(1-t)^{2}=0
$$

or $(f(t)-(1-t))^{2}=0$. We conclude that $f(t)=1-t$. Checking this function in the original functional equation gives on the left $1-(x+y(1-x-y))=1-\left(x+y-x y-y^{2}\right)=1-x-y+x y+y^{2}$ and on the right $y^{2}+(1-x)(1-y)=y^{2}+1-x-y+x y$ and that is the same, so the function satisfies the equation.

Now assume $f(-1)=0$. Substitute $x=t$ and $y=-1-t$, and then $x=-1-t$ and $y=t$, which gives the two equations

$$
\begin{aligned}
f(t) & =(-1-t)^{2}+f(t) f(-1-t), \\
f(-1-t) & =t^{2}+f(t) f(-1-t)
\end{aligned}
$$

Subtracting these equations gives $f(t)-f(-1-t)=(-1-t)^{2}-t^{2}=1+2 t$, so $f(-1-t)=f(t)-2 t-1$. Substituting this into the first of the above two equations gives

$$
f(t)=(-1-t)^{2}+f(t)^{2}+(-2 t-1) f(t)
$$

which can be rewritten as

$$
f(t)^{2}-(2 t+2) f(t)+(t+1)^{2}=0
$$

or $(f(t)-(t+1))^{2}=0$. We conclude that $f(t)=t+1$. Checking this function in the original functional equation gives on the left $x+y(x+y+1)+1=x+x y+y^{2}+y+1$ and on the right $y^{2}+(x+1)(y+1)=y^{2}+x y+x+y+1$ and that is the same, so the function satisfies the equation.

We conclude that there are exactly two solutions: $f(x)=1-x$ for all $x$ and $f(x)=x+1$ for all $x$.