Second-order optimality schemes for nonsmooth functions