#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;
  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) {
    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    $0x40,%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    140c <stable_grail_merge_buffers_left+0x2bc>
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     13d3 <stable_grail_merge_buffers_left+0x283>
cmpl   $0x0,-0x34(%rbp)
je     1379 <stable_grail_merge_buffers_left+0x229>
cmpl   $0x0,-0x24(%rbp)
je     135d <stable_grail_merge_buffers_left+0x20d>
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    1386 <stable_grail_merge_buffers_left+0x236>
mov    -0x20(%rbp),%eax
imul   0x10(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     13b4 <stable_grail_merge_buffers_left+0x264>
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    13ce <stable_grail_merge_buffers_left+0x27e>
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    140c <stable_grail_merge_buffers_left+0x2bc>
cmpl   $0x0,-0x24(%rbp)
je     1407 <stable_grail_merge_buffers_left+0x2b7>
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    140c <stable_grail_merge_buffers_left+0x2bc>
add    $0x40,%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>
cmpl   $0x0,0x8(%rsp)
je     1347 <stable_grail_merge_buffers_left+0x1f7>
test   %r9d,%r9d
je     12fe <stable_grail_merge_buffers_left+0x1ae>
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
imul   %r13d,%ebp
mov    %ebp,0x4(%rsp)
movl   $0x0,0x8(%rsp)
jmp    1354 <stable_grail_merge_buffers_left+0x204>
test   %r9d,%r9d
je     137c <stable_grail_merge_buffers_left+0x22c>
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    137c <stable_grail_merge_buffers_left+0x22c>
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>
imul   %r13d,%ebp
add    %edx,%ebp
mov    %ebp,0x4(%rsp)
mov    %eax,%r15d
movslq %r15d,%rax
lea    (%r14,%rax,8),%rdi
test   %r9d,%r9d
je     1372 <stable_grail_merge_buffers_left+0x222>
neg    %r13d
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
call   1040 <stable_grail_merge_left@plt>
jmp    137c <stable_grail_merge_buffers_left+0x22c>
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
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
%24 = load i32, i32* %12
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %45
26: ; preds = %8
%27 = load i32, i32* %15
%28 = load i32, i32* %13
%29 = mul nsw i32 %27, %28
store i32 %29, i32* %17
%30 = load i32, i32* %14
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %26
%33 = load i32**, i32*** %11
%34 = load i32, i32* %17
%35 = load i32, i32* %16
%36 = load i32, i32* %13
%37 = sub nsw i32 0, %36
%38 = call i32 @stable_grail_merge_left(i32** %33, i32 %34, i32 %35, i32 %37)
br label %44
39: ; preds = %26
%40 = load i32**, i32*** %11
%41 = load i32, i32* %17
%42 = load i32, i32* %16
%43 = call i32 @stable_grail_merge_without_buffer(i32** %40, i32 %41, i32 %42)
br label %44
44: ; preds = %39, %32
br label %206
45: ; preds = %8
%46 = load i32, i32* %13
store i32 %46, i32* %19
%47 = load i32**, i32*** %9
%48 = load i32*, i32** %47
%49 = load i32, i32* %48
%50 = load i32**, i32*** %10
%51 = load i32*, i32** %50
%52 = load i32, i32* %51
%53 = sub nsw i32 %49, %52
%54 = icmp slt i32 %53, 0
%55 = zext i1 %54 to i64
%56 = select i1 %54, i32 0, i32 1
store i32 %56, i32* %20
%57 = load i32, i32* %13
store i32 %57, i32* %21
store i32 1, i32* %22
br label %58
58: ; preds = %123, %45
%59 = load i32, i32* %22
%60 = load i32, i32* %12
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %129
62: ; preds = %58
%63 = load i32, i32* %21
%64 = load i32, i32* %19
%65 = sub nsw i32 %63, %64
store i32 %65, i32* %18
%66 = load i32**, i32*** %9
%67 = load i32, i32* %22
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32*, i32** %66, i64 %68
%70 = load i32*, i32** %69
%71 = load i32, i32* %70
%72 = load i32**, i32*** %10
%73 = load i32*, i32** %72
%74 = load i32, i32* %73
%75 = sub nsw i32 %71, %74
%76 = icmp slt i32 %75, 0
%77 = zext i1 %76 to i64
%78 = select i1 %76, i32 0, i32 1
store i32 %78, i32* %23
%79 = load i32, i32* %23
%80 = load i32, i32* %20
%81 = icmp eq i32 %79, %80
br i1 %81, label %82, label %103
82: ; preds = %62
%83 = load i32, i32* %14
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %100
85: ; preds = %82
%86 = load i32**, i32*** %11
%87 = load i32, i32* %18
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32*, i32** %86, i64 %88
%90 = load i32, i32* %13
%91 = sext i32 %90 to i64
%92 = sub i64 0, %91
%93 = getelementptr inbounds i32*, i32** %89, i64 %92
%94 = load i32**, i32*** %11
%95 = load i32, i32* %18
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i32*, i32** %94, i64 %96
%98 = load i32, i32* %19
%99 = call i32 @stable_grail_swap_n(i32** %93, i32** %97, i32 %98)
br label %100
100: ; preds = %85, %82
%101 = load i32, i32* %21
store i32 %101, i32* %18
%102 = load i32, i32* %13
store i32 %102, i32* %19
br label %122
103: ; preds = %62
%104 = load i32, i32* %14
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %114
106: ; preds = %103
%107 = load i32**, i32*** %11
%108 = load i32, i32* %18
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i32*, i32** %107, i64 %109
%111 = load i32, i32* %13
%112 = load i32, i32* %13
%113 = call i32 @stable_grail_smart_merge_with_buffer(i32** %110, i32* %19, i32* %20, i32 %111, i32 %112)
br label %121
114: ; preds = %103
%115 = load i32**, i32*** %11
%116 = load i32, i32* %18
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds i32*, i32** %115, i64 %117
%119 = load i32, i32* %13
%120 = call i32 @stable_grail_smart_merge_without_buffer(i32** %118, i32* %19, i32* %20, i32 %119)
br label %121
121: ; preds = %114, %106
br label %122
122: ; preds = %121, %100
br label %123
123: ; preds = %122
%124 = load i32, i32* %22
%125 = add nsw i32 %124, 1
store i32 %125, i32* %22
%126 = load i32, i32* %13
%127 = load i32, i32* %21
%128 = add nsw i32 %127, %126
store i32 %128, i32* %21
br label %58
129: ; preds = %58
%130 = load i32, i32* %21
%131 = load i32, i32* %19
%132 = sub nsw i32 %130, %131
store i32 %132, i32* %18
%133 = load i32, i32* %16
%134 = icmp ne i32 %133, 0
br i1 %134, label %135, label %189
135: ; preds = %129
%136 = load i32, i32* %20
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %161
138: ; preds = %135
%139 = load i32, i32* %14
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %156
141: ; preds = %138
%142 = load i32**, i32*** %11
%143 = load i32, i32* %18
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds i32*, i32** %142, i64 %144
%146 = load i32, i32* %13
%147 = sext i32 %146 to i64
%148 = sub i64 0, %147
%149 = getelementptr inbounds i32*, i32** %145, i64 %148
%150 = load i32**, i32*** %11
%151 = load i32, i32* %18
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i32*, i32** %150, i64 %152
%154 = load i32, i32* %19
%155 = call i32 @stable_grail_swap_n(i32** %149, i32** %153, i32 %154)
br label %156
156: ; preds = %141, %138
%157 = load i32, i32* %21
store i32 %157, i32* %18
%158 = load i32, i32* %13
%159 = load i32, i32* %15
%160 = mul nsw i32 %158, %159
store i32 %160, i32* %19
store i32 0, i32* %20
br label %167
161: ; preds = %135
%162 = load i32, i32* %13
%163 = load i32, i32* %15
%164 = mul nsw i32 %162, %163
%165 = load i32, i32* %19
%166 = add nsw i32 %165, %164
store i32 %166, i32* %19
br label %167
167: ; preds = %161, %156
%168 = load i32, i32* %14
%169 = icmp ne i32 %168, 0
br i1 %169, label %170, label %180
170: ; preds = %167
%171 = load i32**, i32*** %11
%172 = load i32, i32* %18
%173 = sext i32 %172 to i64
%174 = getelementptr inbounds i32*, i32** %171, i64 %173
%175 = load i32, i32* %19
%176 = load i32, i32* %16
%177 = load i32, i32* %13
%178 = sub nsw i32 0, %177
%179 = call i32 @stable_grail_merge_left(i32** %174, i32 %175, i32 %176, i32 %178)
br label %188
180: ; preds = %167
%181 = load i32**, i32*** %11
%182 = load i32, i32* %18
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds i32*, i32** %181, i64 %183
%185 = load i32, i32* %19
%186 = load i32, i32* %16
%187 = call i32 @stable_grail_merge_without_buffer(i32** %184, i32 %185, i32 %186)
br label %188
188: ; preds = %180, %170
br label %206
189: ; preds = %129
%190 = load i32, i32* %14
%191 = icmp ne i32 %190, 0
br i1 %191, label %192, label %205
192: ; preds = %189
%193 = load i32**, i32*** %11
%194 = load i32, i32* %18
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds i32*, i32** %193, i64 %195
%197 = load i32**, i32*** %11
%198 = load i32, i32* %18
%199 = load i32, i32* %13
%200 = sub nsw i32 %198, %199
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds i32*, i32** %197, i64 %201
%203 = load i32, i32* %19
%204 = call i32 @stable_grail_swap_n(i32** %196, i32** %202, i32 %203)
br label %205
205: ; preds = %192, %189
br label %206
206: ; preds = %44, %205, %188
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 %113
20: ; preds = %14
%21 = tail call i32 @stable_grail_merge_without_buffer(i32** %2, i32 %15, i32 %7)
br label %113
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 %104, label %76
76: ; preds = %71
%77 = load i32, i32* %10
%78 = icmp eq i32 %77, 0
br i1 %78, label %90, label %79
79: ; preds = %76
%80 = icmp eq i32 %5, 0
br i1 %80, label %88, label %81
81: ; preds = %79
%82 = sext i32 %74 to i64
%83 = getelementptr inbounds i32*, i32** %2, i64 %82
%84 = sext i32 %4 to i64
%85 = sub nsw i64 0, %84
%86 = getelementptr inbounds i32*, i32** %83, i64 %85
%87 = call i32 @stable_grail_swap_n(i32** %86, i32** %83, i32 %72)
br label %88
88: ; preds = %81, %79
%89 = mul nsw i32 %6, %4
store i32 %89, i32* %9
store i32 0, i32* %10
br label %93
90: ; preds = %76
%91 = mul nsw i32 %6, %4
%92 = add nsw i32 %72, %91
store i32 %92, i32* %9
br label %93
93: ; preds = %90, %88
%94 = phi i32 [ %89, %88 ], [ %92, %90 ]
%95 = phi i32 [ %73, %88 ], [ %74, %90 ]
%96 = icmp eq i32 %5, 0
%97 = sext i32 %95 to i64
%98 = getelementptr inbounds i32*, i32** %2, i64 %97
br i1 %96, label %102, label %99
99: ; preds = %93
%100 = sub nsw i32 0, %4
%101 = call i32 @stable_grail_merge_left(i32** %98, i32 %94, i32 %7, i32 %100)
br label %113
102: ; preds = %93
%103 = call i32 @stable_grail_merge_without_buffer(i32** %98, i32 %94, i32 %7)
br label %113
104: ; preds = %71
%105 = icmp eq i32 %5, 0
br i1 %105, label %113, label %106
106: ; preds = %104
%107 = sext i32 %74 to i64
%108 = getelementptr inbounds i32*, i32** %2, i64 %107
%109 = sub nsw i32 %74, %4
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i32*, i32** %2, i64 %110
%112 = call i32 @stable_grail_swap_n(i32** %108, i32** %111, i32 %72)
br label %113
113: ; preds = %102, %99, %106, %104, %17, %20
ret void
}