extension Rolle's theorem for limit values Rolle's theorem states that:
If a real-valued function $f$ is continuous on a proper closed interval $[a, b]$, differentiable on the open interval $(a, b)$, and $f (a) = f (b)$, then there exists at least one $c$ in the open interval $(a, b)$ such that ${\displaystyle f'(c)=0}$.
Exercise:
Show that Rolle's theorem is true in case $f$ is defined and differentiable in the open interval  ] $a, b\left[\right.$, and $\lim\limits_{x\to a^+}f(x)=\lim\limits_{x\to b^-}f(x)$. Note that $a$ could be $-\infty$ and $b$ could be $+\infty$. Furthermore the two limits could also be infinite.
My attempt:
Let choose $a_1, b_1$ so that $a<a_1<b_1<b$. Now we have the following cases:
$f(a_1)=f(b_1)$,  $f(a_1)<f(b_1)$ or  $f(a_1)>f(b_1)$.
When $f(a_1)=f(b_1)$ we can directly apply Rolle's theorem on $]a_1,b_1[$ so $ \exists c \in ]a_1,b_1[$ such that $f′(c)=0$.
If $f(a_1)<f(b_1)$ then there is a real number $z$ such that $f(a_1)<z<f(b_1)$ and by the intermediate value theorem we have $a_2 \in ]a_1,b_1[$ which $f(a_2)=z$. Now, again we can apply Rolle's theorem to the restriction of $f$ to $[a_2,b_1]$.
The case when $f(a_1)>f(b_1)$ can be done similarly.
My question: Is this proof correct or I am missing something?
Thank you in advance.
 A: As mentioned in comments, let us first handle the case when $$\lim_{x\to a^+} f(x) =\lim_{x\to b^-} f(x) \in\mathbb {R} $$ (meaning these limits are finite). We can define a function $g:[a, b] \to\mathbb {R} $ as $$g(x) =f(x) \, \forall x\in(a, b) $$ and $$g(a) =\lim_{x\to a^+} f(x), g(b) =\lim_{x\to b^-} f(x) $$ One can check that $g'(x) =f'(x) $ for all $x\in(a, b) $ and that $g$ satisfies all conditions for applicability of Rolle's theorem on $[a, b] $ and our job is done by applying Rolle's theorem on $g$.

Let me also say a few words about your approach. You can ensure that there are numbers $a_1,b_1 $ in $(a, b) $ such that $f(a_1)=f(b_1)$ and there is no need to consider further cases.
The proof below is simple if you try to picture the graph of $f$ and use intermediate value theorem.
If $f$ is constant on $(a, b) $ then $f'$ is zero on whole of $(a, b) $. Otherwise $f$ takes at least two distinct values on $(a, b) $ and then one of these values must be different from the given equal limits $$\lim _{x\to a^+} f(x) =\lim _{x\to b^-} f(x) =L\, \text {(say)} $$ Thus we have a $d\in(a, b) $ with $f(d) \neq L$.
Let $k$ be a real number between $f(d) $ and $L$ (for clarity let $L<k<f(d) $ and the case $L>k>f(d) $ is similar). Choosing $\epsilon =k-L>0$ in definition of limit we can see that we have an interval of type $(a, a+h_1)$ where the values of $f$ are less than $k$ (write details explicitly using definition of limit as applied to $\lim_{x\to a^+} f(x) =L$ for your benefit).
Similarly there is an interval of type $(b-h_2,b)$ where the values of $f$ are less than $k$. Let $p\in(a, a+h_1),q\in(b-h_2,b)$ such that $a<p<d<q<b$. Then we have $$f(p) <k<f(d), f(d) >k> f(q) $$ and hence by applying intermediate value theorem in $[p, d] $ and $[d, q] $ we find $a_1\in(p,d),b_2\in(d,q)$ such that $f(a_1)=f(b_1)=k$. And now apply Rolle's theorem on $f$ on $[a_1,b_1]$.

The case when $L$ is infinite can't be handled by defining $g$ as in first part of this answer and that's where the second part comes into picture and one can see that this proof works fine (we need to choose $k$ between $f(d) $ and $\pm\infty $).
