i have no idea with the part under red line
The path of the light ray is given by an equation y = y(x). The time taken for the ray to travel along the path is given in infinitesimal terms by $\displaystyle dT = \frac{\sqrt{1+y'^2}\,dx}{c(x)}$ ("time = distance/speed"). Integrate that to get $\displaystyle T = \int_{x_1}^{x_2}\frac{\sqrt{1+y'^2}}{c(x)}\,dx.$ The E–L equation tells you that the extremal path is given by $\displaystyle 0 = \frac d{dx}\Bigl(\frac\partial{\partial y'}\Bigl(\frac{\sqrt{1+y'^2}}{c(x)}\Bigr)\Bigr) = \frac d{dx}\Bigl(\frac{y'}{c(x)\sqrt{1+y'^2}}\Bigr)$. In other words, $\displaystyle \frac{y'}{c(x)\sqrt{1+y'^2}}$ is a constant, which for convenience we can call $\displaystyle k^{-1}.$
Then $\displaystyle ky' = c(x)\sqrt{1+y'^2}$. Square both sides, solve for $\displaystyle y'^2$ and take the square root again, to get $\displaystyle y' = \frac{c(x)}{\sqrt{k^2-c^2(x)}}.$ Integrate that to get $\displaystyle y_2 - y_1 = \int_{x_1}^{x_2}\frac{c(x)}{\sqrt{k^2-c^2(x)}}\,dx.$
The last part is straightforward calculus.