Constrained optimal control for nonlinear multi-input safety-critical systems with time-varying safety constraints