Design optimization and space minimization considering timing and code size via retiming and unfolding