Finding $ \max \mathrm{rk} \, A'(0)$ among all $A\in C^1(\mathbb{R}, M_n)$ with $ \mathrm{rk} A(t) \leq r$ From the admission test for Normale di Pisa:

Let $0<r<n$ be integers and let $M_n$ be the space of real valued matrices. The problem is to find:
  $$
\max \mathrm{rk} \, A'(0)
$$
  among all the $A \in C^1(\mathbb{R}, M_n)$ meeting the condition $ \mathrm{rk} A(t) \leq r$

I have some ideas. For example, if the matrix $A(t)$ is diagonal for each $t$, than the above maximum should be $r$, thanks to some easy continuity arguments. The same arguments work for the triangular case. I don't know how to generalize this in the general case: does observing that any matrix can be put in triangular form help?
Thanks in advance for any answers!
 A: The maximum possible rank of $A'(0)$ is $\min\{n,2r\}$.
We may assume without loss of generality that the leading principal $r\times r$ submatrix of $A(0)$ is $I_r$. Let
$$
A(t)=\pmatrix{X_{r\times r}&Y_{r\times(n-r)}\\ Z_{(n-r)\times r}&W_{(n-r)\times(n-r)}}.
$$
Now suppose $t$ is small. Since $X(0)=I_r$ is nonsingular, $X(t)$ is also nonsingular. Therefore the first $r$ rows of $A$ are linearly independent. Yet, the rank of $A$ is $r$. Hence the last $n-r$ rows of $A$ are linear combinations of the first $r$ rows, i.e. $\pmatrix{Z&W}=\pmatrix{CX&CY}$ for some $C\in\mathbb R^{(n-r)\times r}$. Solving $Z=CX$ for $C$, we see that $C=ZX^{-1}$ is differentiable. It follows that
\begin{aligned}
\operatorname{rank}(A')
&=\operatorname{rank}\pmatrix{X'&Y'\\ C'X+CX'&C'Y+CY'}\\
&=\operatorname{rank}\left(\pmatrix{I_r&0\\ -C'&I_{n-r}}\pmatrix{X'&Y'\\ C'X+CX'&C'Y+CY'}\right)\\
&=\operatorname{rank}\pmatrix{X'&Y'\\ C'X&C'Y}\\
&\le\operatorname{rank}\pmatrix{X'&Y'}+\operatorname{rank}\pmatrix{C'X&C'Y}\\
&\le r+\operatorname{rank}\left(C'\pmatrix{X&Y}\right)\\
&\le r+\operatorname{rank}(C')\\
&=r+\min\{n-r,\,r\}\\
&=\min\{n,2r\}.
\end{aligned}
It remains to show that the upper bound $\min\{n,2r\}$ is attainable. When $n\ge 2r$, consider
$$
A(t)=\pmatrix{e^tI_r&I_r&0\\ e^{2t}I_r&e^tI_r&0\\ 0&0&0},
\ A'(0)=\pmatrix{I_r&0&0\\ 2I_r&I_r&0\\ 0&0&0}.
$$
When $n<2r$, consider
$$
A(t)=\pmatrix{e^tI_{2r-n}&0&0\\ 0&e^tI_{n-r}&I_{n-r}\\ 0&e^{2t}I_{n-r}&e^tI_{n-r}},
\ A'(0)=\pmatrix{I_{2r-n}&0&0\\ 0&I_{n-r}&0\\ 0&2I_{n-r}&I_{n-r}}.
$$
