Nonsmooth Implicit Differentiation for Machine-Learning and Optimization