Optimal Errors and Phase Transitions in High-Dimensional Generalized Linear Models