Rewrite some loops to avoid -Wunsafe-loop-optimizations warnings.
For example, loops of the form: "for (i = 0; i < 1 + max_value; ++i) ..." or "for (i = 0; i <= max_value; ++i) ..." are possibly infinite loops, theoretically speaking (even if practically, they aren't). So, compiler cannot optimize those loops. When possible, I rewrote such loops to be finite even theoretically. Cherry-picked from aomedia/master: 4e69284b Change-Id: Ied47a24833b689c0ec011f8645cf1c01856f7c59