Adjoint formulation and constraint handling for gradient-based optimization of compositional reservoir flow