#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ stable_grail_merge_left(int **, int, int, int);
int /*<<< orphan*/ stable_grail_merge_without_buffer(int **, int, int);
int /*<<< orphan*/ stable_grail_smart_merge_with_buffer(int **, int *, int *,
                                                        int, int);
int /*<<< orphan*/ stable_grail_smart_merge_without_buffer(int **, int *, int *,
                                                           int);
int /*<<< orphan*/ stable_grail_swap_n(int **, int **, int);
void stable_grail_merge_buffers_left(int **keys, int **midkey, int **arr,
                                     int nblock, int lblock, int havebuf,
                                     int nblock2, int llast) {
  int l, prest, lrest, frest, pidx, cidx, fnext, plast;
  if (nblock == 0) {
    l = nblock2 * lblock;
    if (havebuf) {
      stable_grail_merge_left(arr, l, llast, -lblock);
    } else {
      stable_grail_merge_without_buffer(arr, l, llast);
    }
    return;
  }
  lrest = lblock;
  frest = (*(*(keys)) - *(*(midkey))) < 0 ? 0 : 1;
  pidx = lblock;
  for (cidx = 1; cidx < nblock; cidx++, pidx += lblock) {
    prest = pidx - lrest;
    fnext = (*(*(keys + cidx)) - *(*(midkey))) < 0 ? 0 : 1;
    if (fnext == frest) {
      if (havebuf) {
        stable_grail_swap_n(arr + prest - lblock, arr + prest, lrest);
      }
      prest = pidx;
      lrest = lblock;
    } else {
      if (havebuf) {
        stable_grail_smart_merge_with_buffer(arr + prest, &lrest, &frest,
                                             lblock, lblock);
      } else {
        stable_grail_smart_merge_without_buffer(arr + prest, &lrest, &frest,
                                                lblock);
      }
    }
  }
  prest = pidx - lrest;
  if (llast) {
    plast = pidx + lblock * nblock2;
    if (frest) {
      if (havebuf) {
        stable_grail_swap_n(arr + prest - lblock, arr + prest, lrest);
      }
      prest = pidx;
      lrest = lblock * nblock2;
      frest = 0;
    } else {
      lrest += lblock * nblock2;
    }
    if (havebuf) {
      stable_grail_merge_left(arr + prest, lrest, llast, -lblock);
    } else {
      stable_grail_merge_without_buffer(arr + prest, lrest, llast);
    }
  } else {
    if (havebuf) {
      stable_grail_swap_n(arr + prest, arr + (prest - lblock), lrest);
    }
  }
}


x86 assembly (clang, -O0):
<stable_grail_merge_buffers_left>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11c0 <stable_grail_merge_buffers_left+0x70>
mov    0x10(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11ac <stable_grail_merge_buffers_left+0x5c>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    0x18(%rbp),%edx
xor    %ecx,%ecx
sub    -0x20(%rbp),%ecx
call   1040 <stable_grail_merge_left@plt>
jmp    11bb <stable_grail_merge_buffers_left+0x6b>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    0x18(%rbp),%edx
call   1070 <stable_grail_merge_without_buffer@plt>
jmp    141b <stable_grail_merge_buffers_left+0x2cb>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
sub    (%rax),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1300 <stable_grail_merge_buffers_left+0x1b0>
mov    -0x38(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
sub    (%rax),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    128e <stable_grail_merge_buffers_left+0x13e>
cmpl   $0x0,-0x24(%rbp)
je     127d <stable_grail_merge_buffers_left+0x12d>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
movslq -0x20(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x30(%rbp),%edx
call   1030 <stable_grail_swap_n@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    12e4 <stable_grail_merge_buffers_left+0x194>
cmpl   $0x0,-0x24(%rbp)
je     12c0 <stable_grail_merge_buffers_left+0x170>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1060 <stable_grail_smart_merge_with_buffer@plt>
jmp    12df <stable_grail_merge_buffers_left+0x18f>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%ecx
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1050 <stable_grail_smart_merge_without_buffer@plt>
jmp    12e4 <stable_grail_merge_buffers_left+0x194>
jmp    12e9 <stable_grail_merge_buffers_left+0x199>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    11f5 <stable_grail_merge_buffers_left+0xa5>
mov    -0x38(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,0x18(%rbp)
je     13e2 <stable_grail_merge_buffers_left+0x292>
mov    -0x38(%rbp),%eax
mov    -0x20(%rbp),%ecx
imul   0x10(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1388 <stable_grail_merge_buffers_left+0x238>
cmpl   $0x0,-0x24(%rbp)
je     136c <stable_grail_merge_buffers_left+0x21c>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
movslq -0x20(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x30(%rbp),%edx
call   1030 <stable_grail_swap_n@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
imul   0x10(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
jmp    1395 <stable_grail_merge_buffers_left+0x245>
mov    -0x20(%rbp),%eax
imul   0x10(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     13c3 <stable_grail_merge_buffers_left+0x273>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%esi
mov    0x18(%rbp),%edx
xor    %ecx,%ecx
sub    -0x20(%rbp),%ecx
call   1040 <stable_grail_merge_left@plt>
jmp    13dd <stable_grail_merge_buffers_left+0x28d>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%esi
mov    0x18(%rbp),%edx
call   1070 <stable_grail_merge_without_buffer@plt>
jmp    141b <stable_grail_merge_buffers_left+0x2cb>
cmpl   $0x0,-0x24(%rbp)
je     1416 <stable_grail_merge_buffers_left+0x2c6>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%eax
sub    -0x20(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x30(%rbp),%edx
call   1030 <stable_grail_swap_n@plt>
jmp    141b <stable_grail_merge_buffers_left+0x2cb>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stable_grail_merge_buffers_left>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,%r13d
mov    %rdx,%r14
mov    0x78(%rsp),%r12d
mov    0x70(%rsp),%ebp
test   %ecx,%ecx
je     128f <stable_grail_merge_buffers_left+0x13f>
mov    %r13d,0x4(%rsp)
mov    (%rdi),%rax
mov    (%rax),%edx
mov    (%rsi),%r8
xor    %eax,%eax
cmp    (%r8),%edx
setge  %al
mov    %eax,0x8(%rsp)
mov    %r13d,%edx
mov    %r13d,%r15d
cmp    $0x2,%ecx
mov    %r9d,0xc(%rsp)
jl     12cb <stable_grail_merge_buffers_left+0x17b>
mov    %ebp,0x20(%rsp)
mov    %r12d,0x24(%rsp)
movslq %r13d,%r12
mov    %ecx,%ecx
add    $0xfffffffffffffffe,%rcx
mov    %rcx,0x30(%rsp)
shl    $0x3,%r12
lea    0x0(%r13,%r13,1),%r15d
xor    %ebp,%ebp
mov    %r14,0x28(%rsp)
mov    %r13d,%edx
mov    %rsi,0x18(%rsp)
mov    %rdi,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rdi,%rbp,8),%rcx
mov    (%rcx),%ecx
xor    %ebx,%ebx
cmp    (%r8),%ecx
setge  %bl
cmp    %ebx,%eax
jne    1230 <stable_grail_merge_buffers_left+0xe0>
test   %r9d,%r9d
je     1220 <stable_grail_merge_buffers_left+0xd0>
movslq %edx,%rax
shl    $0x3,%rax
lea    (%r14,%r12,1),%rsi
sub    %rax,%rsi
mov    %r14,%rdi
sub    %rax,%rdi
call   1030 <stable_grail_swap_n@plt>
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    0xc(%rsp),%r9d
mov    %r13d,0x4(%rsp)
jmp    126e <stable_grail_merge_buffers_left+0x11e>
nopw   0x0(%rax,%rax,1)
movslq %edx,%rax
shl    $0x3,%rax
lea    (%r14,%r12,1),%rdi
sub    %rax,%rdi
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r13d,%ecx
test   %r9d,%r9d
je     125a <stable_grail_merge_buffers_left+0x10a>
mov    %r13d,%r8d
call   1060 <stable_grail_smart_merge_with_buffer@plt>
jmp    125f <stable_grail_merge_buffers_left+0x10f>
call   1050 <stable_grail_smart_merge_without_buffer@plt>
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    0xc(%rsp),%r9d
mov    0x4(%rsp),%edx
cmp    %rbp,0x30(%rsp)
je     12bd <stable_grail_merge_buffers_left+0x16d>
mov    (%rsi),%r8
mov    0x8(%rsp),%eax
add    $0x1,%rbp
add    %r12,%r14
add    %r13d,%r15d
jmp    11e0 <stable_grail_merge_buffers_left+0x90>
imul   %r13d,%ebp
test   %r9d,%r9d
je     132c <stable_grail_merge_buffers_left+0x1dc>
neg    %r13d
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <stable_grail_merge_left@plt>
mov    0x24(%rsp),%r12d
mov    0x28(%rsp),%r14
mov    0x20(%rsp),%ebp
mov    %r15d,%eax
sub    %edx,%eax
test   %r12d,%r12d
je     1310 <stable_grail_merge_buffers_left+0x1c0>
imul   %r13d,%ebp
cmpl   $0x0,0x8(%rsp)
je     1347 <stable_grail_merge_buffers_left+0x1f7>
test   %r9d,%r9d
je     1302 <stable_grail_merge_buffers_left+0x1b2>
cltq
lea    (%r14,%rax,8),%rsi
movslq %r13d,%rax
shl    $0x3,%rax
mov    %rsi,%rdi
sub    %rax,%rdi
call   1030 <stable_grail_swap_n@plt>
mov    0xc(%rsp),%r9d
mov    %ebp,0x4(%rsp)
movl   $0x0,0x8(%rsp)
jmp    1350 <stable_grail_merge_buffers_left+0x200>
test   %r9d,%r9d
je     1378 <stable_grail_merge_buffers_left+0x228>
movslq %eax,%rcx
lea    (%r14,%rcx,8),%rdi
sub    %r13d,%eax
cltq
lea    (%r14,%rax,8),%rsi
call   1030 <stable_grail_swap_n@plt>
jmp    1378 <stable_grail_merge_buffers_left+0x228>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <stable_grail_merge_without_buffer@plt>
add    %edx,%ebp
mov    %ebp,0x4(%rsp)
mov    %eax,%r15d
movslq %r15d,%rax
lea    (%r14,%rax,8),%rdi
test   %r9d,%r9d
je     136e <stable_grail_merge_buffers_left+0x21e>
neg    %r13d
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
call   1040 <stable_grail_merge_left@plt>
jmp    1378 <stable_grail_merge_buffers_left+0x228>
mov    %ebp,%esi
mov    %r12d,%edx
call   1070 <stable_grail_merge_without_buffer@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @stable_grail_merge_buffers_left(i32** %0, i32** %1, i32** %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i32**
%10 = alloca i32**
%11 = alloca i32**
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
store i32** %0, i32*** %9
store i32** %1, i32*** %10
store i32** %2, i32*** %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%25 = load i32, i32* %12
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %46
27: ; preds = %8
%28 = load i32, i32* %15
%29 = load i32, i32* %13
%30 = mul nsw i32 %28, %29
store i32 %30, i32* %17
%31 = load i32, i32* %14
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %27
%34 = load i32**, i32*** %11
%35 = load i32, i32* %17
%36 = load i32, i32* %16
%37 = load i32, i32* %13
%38 = sub nsw i32 0, %37
%39 = call i32 @stable_grail_merge_left(i32** %34, i32 %35, i32 %36, i32 %38)
br label %45
40: ; preds = %27
%41 = load i32**, i32*** %11
%42 = load i32, i32* %17
%43 = load i32, i32* %16
%44 = call i32 @stable_grail_merge_without_buffer(i32** %41, i32 %42, i32 %43)
br label %45
45: ; preds = %40, %33
br label %212
46: ; preds = %8
%47 = load i32, i32* %13
store i32 %47, i32* %19
%48 = load i32**, i32*** %9
%49 = load i32*, i32** %48
%50 = load i32, i32* %49
%51 = load i32**, i32*** %10
%52 = load i32*, i32** %51
%53 = load i32, i32* %52
%54 = sub nsw i32 %50, %53
%55 = icmp slt i32 %54, 0
%56 = zext i1 %55 to i64
%57 = select i1 %55, i32 0, i32 1
store i32 %57, i32* %20
%58 = load i32, i32* %13
store i32 %58, i32* %21
store i32 1, i32* %22
br label %59
59: ; preds = %124, %46
%60 = load i32, i32* %22
%61 = load i32, i32* %12
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %130
63: ; preds = %59
%64 = load i32, i32* %21
%65 = load i32, i32* %19
%66 = sub nsw i32 %64, %65
store i32 %66, i32* %18
%67 = load i32**, i32*** %9
%68 = load i32, i32* %22
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32*, i32** %67, i64 %69
%71 = load i32*, i32** %70
%72 = load i32, i32* %71
%73 = load i32**, i32*** %10
%74 = load i32*, i32** %73
%75 = load i32, i32* %74
%76 = sub nsw i32 %72, %75
%77 = icmp slt i32 %76, 0
%78 = zext i1 %77 to i64
%79 = select i1 %77, i32 0, i32 1
store i32 %79, i32* %23
%80 = load i32, i32* %23
%81 = load i32, i32* %20
%82 = icmp eq i32 %80, %81
br i1 %82, label %83, label %104
83: ; preds = %63
%84 = load i32, i32* %14
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %101
86: ; preds = %83
%87 = load i32**, i32*** %11
%88 = load i32, i32* %18
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32*, i32** %87, i64 %89
%91 = load i32, i32* %13
%92 = sext i32 %91 to i64
%93 = sub i64 0, %92
%94 = getelementptr inbounds i32*, i32** %90, i64 %93
%95 = load i32**, i32*** %11
%96 = load i32, i32* %18
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32*, i32** %95, i64 %97
%99 = load i32, i32* %19
%100 = call i32 @stable_grail_swap_n(i32** %94, i32** %98, i32 %99)
br label %101
101: ; preds = %86, %83
%102 = load i32, i32* %21
store i32 %102, i32* %18
%103 = load i32, i32* %13
store i32 %103, i32* %19
br label %123
104: ; preds = %63
%105 = load i32, i32* %14
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %115
107: ; preds = %104
%108 = load i32**, i32*** %11
%109 = load i32, i32* %18
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i32*, i32** %108, i64 %110
%112 = load i32, i32* %13
%113 = load i32, i32* %13
%114 = call i32 @stable_grail_smart_merge_with_buffer(i32** %111, i32* %19, i32* %20, i32 %112, i32 %113)
br label %122
115: ; preds = %104
%116 = load i32**, i32*** %11
%117 = load i32, i32* %18
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i32*, i32** %116, i64 %118
%120 = load i32, i32* %13
%121 = call i32 @stable_grail_smart_merge_without_buffer(i32** %119, i32* %19, i32* %20, i32 %120)
br label %122
122: ; preds = %115, %107
br label %123
123: ; preds = %122, %101
br label %124
124: ; preds = %123
%125 = load i32, i32* %22
%126 = add nsw i32 %125, 1
store i32 %126, i32* %22
%127 = load i32, i32* %13
%128 = load i32, i32* %21
%129 = add nsw i32 %128, %127
store i32 %129, i32* %21
br label %59
130: ; preds = %59
%131 = load i32, i32* %21
%132 = load i32, i32* %19
%133 = sub nsw i32 %131, %132
store i32 %133, i32* %18
%134 = load i32, i32* %16
%135 = icmp ne i32 %134, 0
br i1 %135, label %136, label %195
136: ; preds = %130
%137 = load i32, i32* %21
%138 = load i32, i32* %13
%139 = load i32, i32* %15
%140 = mul nsw i32 %138, %139
%141 = add nsw i32 %137, %140
store i32 %141, i32* %24
%142 = load i32, i32* %20
%143 = icmp ne i32 %142, 0
br i1 %143, label %144, label %167
144: ; preds = %136
%145 = load i32, i32* %14
%146 = icmp ne i32 %145, 0
br i1 %146, label %147, label %162
147: ; preds = %144
%148 = load i32**, i32*** %11
%149 = load i32, i32* %18
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i32*, i32** %148, i64 %150
%152 = load i32, i32* %13
%153 = sext i32 %152 to i64
%154 = sub i64 0, %153
%155 = getelementptr inbounds i32*, i32** %151, i64 %154
%156 = load i32**, i32*** %11
%157 = load i32, i32* %18
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i32*, i32** %156, i64 %158
%160 = load i32, i32* %19
%161 = call i32 @stable_grail_swap_n(i32** %155, i32** %159, i32 %160)
br label %162
162: ; preds = %147, %144
%163 = load i32, i32* %21
store i32 %163, i32* %18
%164 = load i32, i32* %13
%165 = load i32, i32* %15
%166 = mul nsw i32 %164, %165
store i32 %166, i32* %19
store i32 0, i32* %20
br label %173
167: ; preds = %136
%168 = load i32, i32* %13
%169 = load i32, i32* %15
%170 = mul nsw i32 %168, %169
%171 = load i32, i32* %19
%172 = add nsw i32 %171, %170
store i32 %172, i32* %19
br label %173
173: ; preds = %167, %162
%174 = load i32, i32* %14
%175 = icmp ne i32 %174, 0
br i1 %175, label %176, label %186
176: ; preds = %173
%177 = load i32**, i32*** %11
%178 = load i32, i32* %18
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i32*, i32** %177, i64 %179
%181 = load i32, i32* %19
%182 = load i32, i32* %16
%183 = load i32, i32* %13
%184 = sub nsw i32 0, %183
%185 = call i32 @stable_grail_merge_left(i32** %180, i32 %181, i32 %182, i32 %184)
br label %194
186: ; preds = %173
%187 = load i32**, i32*** %11
%188 = load i32, i32* %18
%189 = sext i32 %188 to i64
%190 = getelementptr inbounds i32*, i32** %187, i64 %189
%191 = load i32, i32* %19
%192 = load i32, i32* %16
%193 = call i32 @stable_grail_merge_without_buffer(i32** %190, i32 %191, i32 %192)
br label %194
194: ; preds = %186, %176
br label %212
195: ; preds = %130
%196 = load i32, i32* %14
%197 = icmp ne i32 %196, 0
br i1 %197, label %198, label %211
198: ; preds = %195
%199 = load i32**, i32*** %11
%200 = load i32, i32* %18
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds i32*, i32** %199, i64 %201
%203 = load i32**, i32*** %11
%204 = load i32, i32* %18
%205 = load i32, i32* %13
%206 = sub nsw i32 %204, %205
%207 = sext i32 %206 to i64
%208 = getelementptr inbounds i32*, i32** %203, i64 %207
%209 = load i32, i32* %19
%210 = call i32 @stable_grail_swap_n(i32** %202, i32** %208, i32 %209)
br label %211
211: ; preds = %198, %195
br label %212
212: ; preds = %45, %211, %194
ret void
}

LLVM IR (-O2):
define void @stable_grail_merge_buffers_left(i32** nocapture %0, i32** nocapture %1, i32** %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i32
%11 = bitcast i32* %9 to i8*
%12 = bitcast i32* %10 to i8*
%13 = icmp eq i32 %3, 0
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = mul nsw i32 %6, %4
%16 = icmp eq i32 %5, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = sub nsw i32 0, %4
%19 = tail call i32 @stable_grail_merge_left(i32** %2, i32 %15, i32 %7, i32 %18)
br label %112
20: ; preds = %14
%21 = tail call i32 @stable_grail_merge_without_buffer(i32** %2, i32 %15, i32 %7)
br label %112
22: ; preds = %8
store i32 %4, i32* %9
%23 = load i32*, i32** %0
%24 = load i32, i32* %23
%25 = load i32*, i32** %1
%26 = load i32, i32* %25
%27 = icmp sge i32 %24, %26
%28 = zext i1 %27 to i32
store i32 %28, i32* %10
%29 = icmp sgt i32 %3, 1
br i1 %29, label %30, label %71
30: ; preds = %22
%31 = icmp eq i32 %5, 0
%32 = sext i32 %4 to i64
%33 = sub nsw i64 0, %32
%34 = zext i32 %3 to i64
br label %35
35: ; preds = %68, %30
%36 = phi i32 [ %28, %30 ], [ %70, %68 ]
%37 = phi i32* [ %25, %30 ], [ %69, %68 ]
%38 = phi i32 [ %4, %30 ], [ %67, %68 ]
%39 = phi i64 [ 1, %30 ], [ %64, %68 ]
%40 = phi i32 [ %4, %30 ], [ %65, %68 ]
%41 = sub nsw i32 %40, %38
%42 = getelementptr inbounds i32*, i32** %0, i64 %39
%43 = load i32*, i32** %42
%44 = load i32, i32* %43
%45 = load i32, i32* %37
%46 = icmp sge i32 %44, %45
%47 = zext i1 %46 to i32
%48 = icmp eq i32 %36, %47
br i1 %48, label %49, label %56
49: ; preds = %35
br i1 %31, label %55, label %50
50: ; preds = %49
%51 = sext i32 %41 to i64
%52 = getelementptr inbounds i32*, i32** %2, i64 %51
%53 = getelementptr inbounds i32*, i32** %52, i64 %33
%54 = call i32 @stable_grail_swap_n(i32** %53, i32** %52, i32 %38)
br label %55
55: ; preds = %50, %49
store i32 %4, i32* %9
br label %63
56: ; preds = %35
%57 = sext i32 %41 to i64
%58 = getelementptr inbounds i32*, i32** %2, i64 %57
br i1 %31, label %61, label %59
59: ; preds = %56
%60 = call i32 @stable_grail_smart_merge_with_buffer(i32** %58, i32* %9, i32* %10, i32 %4, i32 %4)
br label %63
61: ; preds = %56
%62 = call i32 @stable_grail_smart_merge_without_buffer(i32** %58, i32* %9, i32* %10, i32 %4)
br label %63
63: ; preds = %55, %61, %59
%64 = add nuw nsw i64 %39, 1
%65 = add nsw i32 %40, %4
%66 = icmp eq i64 %64, %34
%67 = load i32, i32* %9
br i1 %66, label %71, label %68
68: ; preds = %63
%69 = load i32*, i32** %1
%70 = load i32, i32* %10
br label %35
71: ; preds = %63, %22
%72 = phi i32 [ %4, %22 ], [ %67, %63 ]
%73 = phi i32 [ %4, %22 ], [ %65, %63 ]
%74 = sub nsw i32 %73, %72
%75 = icmp eq i32 %7, 0
br i1 %75, label %103, label %76
76: ; preds = %71
%77 = mul nsw i32 %6, %4
%78 = load i32, i32* %10
%79 = icmp eq i32 %78, 0
br i1 %79, label %90, label %80
80: ; preds = %76
%81 = icmp eq i32 %5, 0
br i1 %81, label %89, label %82
82: ; preds = %80
%83 = sext i32 %74 to i64
%84 = getelementptr inbounds i32*, i32** %2, i64 %83
%85 = sext i32 %4 to i64
%86 = sub nsw i64 0, %85
%87 = getelementptr inbounds i32*, i32** %84, i64 %86
%88 = call i32 @stable_grail_swap_n(i32** %87, i32** %84, i32 %72)
br label %89
89: ; preds = %82, %80
store i32 %77, i32* %9
store i32 0, i32* %10
br label %92
90: ; preds = %76
%91 = add nsw i32 %72, %77
store i32 %91, i32* %9
br label %92
92: ; preds = %90, %89
%93 = phi i32 [ %77, %89 ], [ %91, %90 ]
%94 = phi i32 [ %73, %89 ], [ %74, %90 ]
%95 = icmp eq i32 %5, 0
%96 = sext i32 %94 to i64
%97 = getelementptr inbounds i32*, i32** %2, i64 %96
br i1 %95, label %101, label %98
98: ; preds = %92
%99 = sub nsw i32 0, %4
%100 = call i32 @stable_grail_merge_left(i32** %97, i32 %93, i32 %7, i32 %99)
br label %112
101: ; preds = %92
%102 = call i32 @stable_grail_merge_without_buffer(i32** %97, i32 %93, i32 %7)
br label %112
103: ; preds = %71
%104 = icmp eq i32 %5, 0
br i1 %104, label %112, label %105
105: ; preds = %103
%106 = sext i32 %74 to i64
%107 = getelementptr inbounds i32*, i32** %2, i64 %106
%108 = sub nsw i32 %74, %4
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i32*, i32** %2, i64 %109
%111 = call i32 @stable_grail_swap_n(i32** %107, i32** %110, i32 %72)
br label %112
112: ; preds = %101, %98, %105, %103, %17, %20
ret void
}