Asymptotics of Non-Convex Generalized Linear Models in High-Dimensions: A proof of the replica formula