Piecewise analyticity of optimal cost functions and optimal feedback