https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
--- Comment #5 from Steve Ellcey <sje at gcc dot gnu.org> --- If we did not truncate ret on each loop iteration then ret could get large enough to overflow the maximum integer value before we truncate it at the end, leading to undefined results. But if we truncate ret on each loop iteration then ret will not overflow and the result is defined.