Functional Retiming: A New Approach to Sequential Synthesis and Optimization