The llvm code below can be executed using: USE: llvm.invoker "resource:extra/llvm/insertion.bc" install-bc 100 [ drop 1000 random ] map >int-array [ 100 insertion-sort ] keep define void @insertion-sort([0 x i32]* %a, i32 %len) { entry: br label %j_for j_for: %j = phi i32 [1, %entry], [%j_next, %i_while_end] %j_index = getelementptr [0 x i32]* %a, i32 0, i32 %j %j_key = volatile load i32* %j_index br label %i_while i_while: %i_plus_one = phi i32 [%j, %j_for], [%i, %i_while_iter] %i_plus_one_index = phi i32* [%j_index, %j_for], [%i_index, %i_while_iter] %i = sub i32 %i_plus_one, 1 %i_bounds = icmp sge i32 %i, 0 br i1 %i_bounds, label %i_while_cont, label %i_while_end i_while_cont: %i_index = getelementptr [0 x i32]* %a, i32 0, i32 %i %i_key = volatile load i32* %i_index %key_gt = icmp sgt i32 %i_key, %j_key br i1 %key_gt, label %i_while_iter, label %i_while_end i_while_iter: volatile store i32 %i_key, i32* %i_plus_one_index br label %i_while i_while_end: volatile store i32 %j_key, i32* %i_plus_one_index %j_next = add i32 %j, 1 %cond = icmp slt i32 %j_next, %len br i1 %cond, label %j_for, label %return return: ret void }