First- and second-order optimality conditions for piecewise smooth objective functions. (2nd September 2016)