We consider a simple direct-style IR:
Translating the applyf function into this IR yields:
fun applyf (f, n) = fun lp_i i = let bi = i < n in if bi then fun lp_j j = let bj = j < n in if bj then let foo = f (i, j) in let j' = j + 1 in lp_j j' else () in let bar = lp_j = 0 in let i' = i + 1 in lp_i i' else () in lp_i 0
But, that's a little verbose for an example, so we'll work with the following:
fun applyf (f, n) = fun lp_i i = if i < n then fun lp_j j = if j < n then let foo = f (i, j) in lp_j (j + 1) else () in let bar = lp_j = 0 in lp_i (i + 1) else () in lp_i 0
Note that we once again have a non-tail call to lp_j requiring it to be in a separate cluster.