Geometric analysis of gaits and optimal control for three-link kinematic swimmers