In this work, we optimally control the upright gait of a three-dimensional symmetric bipedal walking model with flat feet. The whole walking cycle is assumed to occur during a fixed time span while the time span for each of the cycle phases is variable and part of the optimization. The implemented flat foot model allows to distinguish forefoot and heel contact such that a half walking cycle consists of five different phases. A fixed number of discrete time nodes in combination with a variable time interval length assure that the discretized problem is differentiable even though the particular time of establishing or releasing the contact between the foot and the ground is variable. Moreover, the perfectly plastic contact model prevents penetration of the ground. The optimal control problem is solved by our structure preserving discrete mechanics and optimal control for constrained systems (DMOCC) approach where the considered cost function is physiologically motivated and the obtained results are analyzed with regard to the gait of humans walking on a horizontal and an inclined plane.