Subdifferentials of nonsmooth functions and second order optimality conditions