When a fori_loop specialized on trip count is to be evaluated, it's
preferable to generate a scan rather than a while_loop because the
former is reverse-mode differentiable while the latter is not. Otherwise
they're essentially the same; in particular, no extensive inputs/outputs
arise unless reverse-mode autodiff is applied.
Also fixes#2412.