Differentiable Safe Controller Design through Control Barrier Functions