Mollified derivatives and second-order optimality conditions