[optimization] Calculate best initial condition for loops

In order to not impact the code too much, we'll simply calculate the correct values of k here so that execution will simply pass through the existing do loops once and be finished.