Misallocation of Capital in a Model of Endogenous Financial Intermediation and Insurance