Pick $a\in \Bbb R$, Then from $P(a,x-a)$,
$$\tag1f(x)\ge f(a)+(x-a)f(f(a)).$$
The line given by the expression on the right passes through $(a,f(a))$, thus showing that $f$ is convex.
Then $f$ is also continuous.
By swapping $x\leftrightarrow a$, also $f(a)\ge f(x)-(x-a)f(f(x))$, so that for the difference quotient either $f(f(a))\le \frac{f(x)-f(a)}{x-a}\le f(f(x))$ or $f(f(a))\ge \frac{f(x)-f(a)}{x-a}\ge f(f(x))$. By continuity of $f\circ f$ and squeeze theorem, $f$ is differentiable and
$$ \tag2f'(x)=f(f(x)).$$
By induction, all higher derivatives exist ($f$ is smooth) and can be expressed as sums of products of iterates of $f$.
For example,
$$f''(x)=f'(x)f'(f(x))=f(f(x))f(f(f(x))) $$
and
$$f''(x) = f''(x)f(f(f(x))) + f'(x)^2f''(f(x))
= f(f(x))f(f(f(x)))^2 + f(f(x))^2f(f(f(x)))f(f(f(f(x)))).$$
Suppose $f$ is constant, so $f(x)=f(0)\ne0$ for all $x$. Then $0=f'(x)=f(f(x))=f(0)\ne 0$, contradiction.
We conclude that $f$ is not constant.
Non-constant convex implies not bounded from above.
Let $a,b\in\Bbb R$ with $f(a)=f(b)$.
For $c\in\{a,b\}$, $t\mapsto f(c+t)$ is a solution to the ODE $y(0)=f(a)$, $y'(t)=f(y(t))$.
By convexity, $f$ is Lipschitz on every bounded interval. Then by Picard-Lindelöf, this ODE has a unique global solution. This implies that $f(a+t)=f(b+t)$ for all $t$. As a periodic continuos function would be bounded, we conclude that we cannot have $a\ne b$.
Hence $f$ is injective.
Suppose $f$ is not bounded from below. Then by continuity, $f$ is onto and we can find $a$ with $f(f(a))=0$. Then by convexity, $f$ has a global minimum at $a$, contradicting unboundedness. We conclude that $f$ is bounded from below.
Let $s=\inf f$.
Then either $f(a)=s$ for some $a\in\Bbb R$, or $\lim_{x\to a}f(x)=s$ for some $a\in\{-\infty,\infty\}$. In the first case, $f(s)=f(f(a))=f'(a)=0$, and in the other cases, simiularly $f(s)=\lim_{x\to s}f(x)=\lim_{x\to a}f(f(x))=\lim_{x\to a}f'(x)=0$.
Hence
$$ \tag3f(s)=0.$$
Then $s\ne0$ as $f(0)\ne 0$.
As also $s\le f(s)=0$, we have
$$ \tag4s<0.$$
Now $f\circ f= f'$ is non-decreasing and bounded from below by $s$. Hence $\lim_{x\to-\infty} f'(x)=t$ for some $t$ with $s\le t\le 0$.
Suppose $t<0$. Then $f(x)\to\infty$ as $x\to-\infty$ while at the same time $f(f(x))\to s$. We conclude $\lim_{x\to\infty}f(x)=s$.
If on the other hand $t=0$, then necessarily $\lim_{x\to-\infty}f(x)=s$.
Thus
$$ \tag5\lim_{x\to\infty}f(x)=s\quad\text{or}\quad\lim_{x\to-\infty}f(x)=s.$$