Second-order optimality conditions for problems with $C^1$ data