A second-order optimality condition with first- and second-order complementarity associated with global convergence of algorithms