Integration problem with maximum function inside integral

Hello. I have two questions, I'll be extremely cheerful if anyone can provide an answer.

I have got two equations as follows

(1)

(2)

where w' is not the derivative of w, but just describing another value of w.

He says: Let , then he evaluates the equation (2) at (so he gets r*U=....)

Then combines this with (1), (Because (1) and the (2) evaluated at are equal) to solve for :

to get:

Now my problem is: how does he actually gets that final equation? Because I cannot manage to evaluate (2) at because that maximum function in the integral really confuses me. Moreover, I don't understand how he merges two integrals with different intervals.

Okay this was the first question.

Second one is, he differentiates the equation (2) to get

I can't manage to get this either. I get all my problems come down to that integral with a maximum function in it.

Okay, I hope I could describe it well enough.

Cheers

Burak