Proof (Rolle's theorem)
By the extreme value theorem, there exists $y,Y\in[a,b]$ such that $m=f(y)\leq f(x)\leq f(Y)=M$ for all $x\in[a,b]$.
If $m=M$ then $f(x)$ is a constant function so just pick $c$ to be anything in $[a,b]$.
Otherwise either $M>f(a)=f(b)$, or $m<f(a)=f(b)$. Suppose $M>f(a)$, then $Y\in(a,b)$. We want to show that $f'(Y)=0$.
Consider the left and right limits. First let $h_n\searrow 0$. Then $$ \frac{f(Y+h_n) - f(Y)}{h_n} \leq 0 \implies f'(Y) = \lim_{n\to 0}\frac{f(Y+h_n) - f(Y)}{h_n} \leq 0. $$ But for $h_n\nearrow 0$, we have $$ \frac{f(Y+h_n) - f(Y)}{h_n} \geq 0 \implies f'(Y) = \lim_{n\to 0}\frac{f(Y+h_n) - f(Y)}{h_n} \geq 0 $$ so $f'(Y) = 0$.
For $m<f(a)$ apply a similar argument to show $y\in(a,b)$ and $f'(y)=0$.