#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 */
typedef scalar_t__ int64_t;

/* Variables and functions */
int /*<<< orphan*/ sorter_grail_merge_left(scalar_t__ *, int, int, int);
int /*<<< orphan*/ sorter_grail_merge_without_buffer(scalar_t__ *, int, int);
int /*<<< orphan*/ sorter_grail_smart_merge_with_buffer(scalar_t__ *, int *,
                                                        int *, int, int);
int /*<<< orphan*/ sorter_grail_smart_merge_without_buffer(scalar_t__ *, int *,
                                                           int *, int);
int /*<<< orphan*/ sorter_grail_swap_n(scalar_t__ *, scalar_t__ *, int);
void sorter_grail_merge_buffers_left(int64_t *keys, int64_t *midkey,
                                     int64_t *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) {
      sorter_grail_merge_left(arr, l, llast, -lblock);
    } else {
      sorter_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) {
        sorter_grail_swap_n(arr + prest - lblock, arr + prest, lrest);
      }
      prest = pidx;
      lrest = lblock;
    } else {
      if (havebuf) {
        sorter_grail_smart_merge_with_buffer(arr + prest, &lrest, &frest,
                                             lblock, lblock);
      } else {
        sorter_grail_smart_merge_without_buffer(arr + prest, &lrest, &frest,
                                                lblock);
      }
    }
  }
  prest = pidx - lrest;
  if (llast) {
    if (frest) {
      if (havebuf) {
        sorter_grail_swap_n(arr + prest - lblock, arr + prest, lrest);
      }
      prest = pidx;
      lrest = lblock * nblock2;
      frest = 0;
    } else {
      lrest += lblock * nblock2;
    }
    if (havebuf) {
      sorter_grail_merge_left(arr + prest, lrest, llast, -lblock);
    } else {
      sorter_grail_merge_without_buffer(arr + prest, lrest, llast);
    }
  } else {
    if (havebuf) {
      sorter_grail_swap_n(arr + prest, arr + (prest - lblock), lrest);
    }
  }
}


x86 assembly (clang, -O0):
<sorter_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 <sorter_grail_merge_buffers_left+0x70>
mov    0x10(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11ac <sorter_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   1060 <sorter_grail_merge_left@plt>
jmp    11bb <sorter_grail_merge_buffers_left+0x6b>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    0x18(%rbp),%edx
call   1050 <sorter_grail_merge_without_buffer@plt>
jmp    1406 <sorter_grail_merge_buffers_left+0x2b6>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
sub    (%rax),%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
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    12fa <sorter_grail_merge_buffers_left+0x1aa>
mov    -0x38(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
sub    (%rax),%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovl  %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    1288 <sorter_grail_merge_buffers_left+0x138>
cmpl   $0x0,-0x24(%rbp)
je     1277 <sorter_grail_merge_buffers_left+0x127>
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   1040 <sorter_grail_swap_n@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    12de <sorter_grail_merge_buffers_left+0x18e>
cmpl   $0x0,-0x24(%rbp)
je     12ba <sorter_grail_merge_buffers_left+0x16a>
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   1070 <sorter_grail_smart_merge_with_buffer@plt>
jmp    12d9 <sorter_grail_merge_buffers_left+0x189>
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   1030 <sorter_grail_smart_merge_without_buffer@plt>
jmp    12de <sorter_grail_merge_buffers_left+0x18e>
jmp    12e3 <sorter_grail_merge_buffers_left+0x193>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    11f2 <sorter_grail_merge_buffers_left+0xa2>
mov    -0x38(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,0x18(%rbp)
je     13cd <sorter_grail_merge_buffers_left+0x27d>
cmpl   $0x0,-0x34(%rbp)
je     1373 <sorter_grail_merge_buffers_left+0x223>
cmpl   $0x0,-0x24(%rbp)
je     1357 <sorter_grail_merge_buffers_left+0x207>
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   1040 <sorter_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    1380 <sorter_grail_merge_buffers_left+0x230>
mov    -0x20(%rbp),%eax
imul   0x10(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     13ae <sorter_grail_merge_buffers_left+0x25e>
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   1060 <sorter_grail_merge_left@plt>
jmp    13c8 <sorter_grail_merge_buffers_left+0x278>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%esi
mov    0x18(%rbp),%edx
call   1050 <sorter_grail_merge_without_buffer@plt>
jmp    1406 <sorter_grail_merge_buffers_left+0x2b6>
cmpl   $0x0,-0x24(%rbp)
je     1401 <sorter_grail_merge_buffers_left+0x2b1>
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   1040 <sorter_grail_swap_n@plt>
jmp    1406 <sorter_grail_merge_buffers_left+0x2b6>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorter_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 <sorter_grail_merge_buffers_left+0x13f>
mov    %r13d,0x4(%rsp)
mov    (%rsi),%rbx
xor    %eax,%eax
cmp    %rbx,(%rdi)
setge  %al
mov    %eax,0x8(%rsp)
mov    %r13d,%edx
mov    %r13d,%r15d
cmp    $0x2,%ecx
mov    %r9d,0xc(%rsp)
jl     12cb <sorter_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)
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    %rbx,0x8(%rdi,%rbp,8)
setge  %cl
cmp    %ecx,%eax
jne    1230 <sorter_grail_merge_buffers_left+0xe0>
test   %r9d,%r9d
je     121b <sorter_grail_merge_buffers_left+0xcb>
movslq %edx,%rax
shl    $0x3,%rax
lea    (%r14,%r12,1),%rsi
sub    %rax,%rsi
mov    %r14,%rdi
sub    %rax,%rdi
call   1040 <sorter_grail_swap_n@plt>
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    0xc(%rsp),%r9d
mov    %r13d,0x4(%rsp)
jmp    126e <sorter_grail_merge_buffers_left+0x11e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
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 <sorter_grail_merge_buffers_left+0x10a>
mov    %r13d,%r8d
call   1070 <sorter_grail_smart_merge_with_buffer@plt>
jmp    125f <sorter_grail_merge_buffers_left+0x10f>
call   1030 <sorter_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 <sorter_grail_merge_buffers_left+0x16d>
mov    (%rsi),%rbx
mov    0x8(%rsp),%eax
add    $0x1,%rbp
add    %r12,%r14
add    %r13d,%r15d
jmp    11e0 <sorter_grail_merge_buffers_left+0x90>
imul   %r13d,%ebp
test   %r9d,%r9d
je     132c <sorter_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    1060 <sorter_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 <sorter_grail_merge_buffers_left+0x1c0>
cmpl   $0x0,0x8(%rsp)
je     1347 <sorter_grail_merge_buffers_left+0x1f7>
test   %r9d,%r9d
je     12fe <sorter_grail_merge_buffers_left+0x1ae>
cltq
lea    (%r14,%rax,8),%rsi
movslq %r13d,%rax
shl    $0x3,%rax
mov    %rsi,%rdi
sub    %rax,%rdi
call   1040 <sorter_grail_swap_n@plt>
mov    0xc(%rsp),%r9d
imul   %r13d,%ebp
mov    %ebp,0x4(%rsp)
movl   $0x0,0x8(%rsp)
jmp    1354 <sorter_grail_merge_buffers_left+0x204>
test   %r9d,%r9d
je     137c <sorter_grail_merge_buffers_left+0x22c>
movslq %eax,%rcx
lea    (%r14,%rcx,8),%rdi
sub    %r13d,%eax
cltq
lea    (%r14,%rax,8),%rsi
call   1040 <sorter_grail_swap_n@plt>
jmp    137c <sorter_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    1050 <sorter_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 <sorter_grail_merge_buffers_left+0x222>
neg    %r13d
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
call   1060 <sorter_grail_merge_left@plt>
jmp    137c <sorter_grail_merge_buffers_left+0x22c>
mov    %ebp,%esi
mov    %r12d,%edx
call   1050 <sorter_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 @sorter_grail_merge_buffers_left(i64* %0, i64* %1, i64* %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i64*
%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 i64* %0, i64** %9
store i64* %1, i64** %10
store i64* %2, i64** %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 i64*, i64** %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 @sorter_grail_merge_left(i64* %33, i32 %34, i32 %35, i32 %37)
br label %44
39: ; preds = %26
%40 = load i64*, i64** %11
%41 = load i32, i32* %17
%42 = load i32, i32* %16
%43 = call i32 @sorter_grail_merge_without_buffer(i64* %40, i32 %41, i32 %42)
br label %44
44: ; preds = %39, %32
br label %202
45: ; preds = %8
%46 = load i32, i32* %13
store i32 %46, i32* %19
%47 = load i64*, i64** %9
%48 = load i64, i64* %47
%49 = load i64*, i64** %10
%50 = load i64, i64* %49
%51 = sub nsw i64 %48, %50
%52 = icmp slt i64 %51, 0
%53 = zext i1 %52 to i64
%54 = select i1 %52, i32 0, i32 1
store i32 %54, i32* %20
%55 = load i32, i32* %13
store i32 %55, i32* %21
store i32 1, i32* %22
br label %56
56: ; preds = %119, %45
%57 = load i32, i32* %22
%58 = load i32, i32* %12
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %125
60: ; preds = %56
%61 = load i32, i32* %21
%62 = load i32, i32* %19
%63 = sub nsw i32 %61, %62
store i32 %63, i32* %18
%64 = load i64*, i64** %9
%65 = load i32, i32* %22
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i64, i64* %64, i64 %66
%68 = load i64, i64* %67
%69 = load i64*, i64** %10
%70 = load i64, i64* %69
%71 = sub nsw i64 %68, %70
%72 = icmp slt i64 %71, 0
%73 = zext i1 %72 to i64
%74 = select i1 %72, i32 0, i32 1
store i32 %74, i32* %23
%75 = load i32, i32* %23
%76 = load i32, i32* %20
%77 = icmp eq i32 %75, %76
br i1 %77, label %78, label %99
78: ; preds = %60
%79 = load i32, i32* %14
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %96
81: ; preds = %78
%82 = load i64*, i64** %11
%83 = load i32, i32* %18
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i64, i64* %82, i64 %84
%86 = load i32, i32* %13
%87 = sext i32 %86 to i64
%88 = sub i64 0, %87
%89 = getelementptr inbounds i64, i64* %85, i64 %88
%90 = load i64*, i64** %11
%91 = load i32, i32* %18
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i64, i64* %90, i64 %92
%94 = load i32, i32* %19
%95 = call i32 @sorter_grail_swap_n(i64* %89, i64* %93, i32 %94)
br label %96
96: ; preds = %81, %78
%97 = load i32, i32* %21
store i32 %97, i32* %18
%98 = load i32, i32* %13
store i32 %98, i32* %19
br label %118
99: ; preds = %60
%100 = load i32, i32* %14
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %110
102: ; preds = %99
%103 = load i64*, i64** %11
%104 = load i32, i32* %18
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i64, i64* %103, i64 %105
%107 = load i32, i32* %13
%108 = load i32, i32* %13
%109 = call i32 @sorter_grail_smart_merge_with_buffer(i64* %106, i32* %19, i32* %20, i32 %107, i32 %108)
br label %117
110: ; preds = %99
%111 = load i64*, i64** %11
%112 = load i32, i32* %18
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i64, i64* %111, i64 %113
%115 = load i32, i32* %13
%116 = call i32 @sorter_grail_smart_merge_without_buffer(i64* %114, i32* %19, i32* %20, i32 %115)
br label %117
117: ; preds = %110, %102
br label %118
118: ; preds = %117, %96
br label %119
119: ; preds = %118
%120 = load i32, i32* %22
%121 = add nsw i32 %120, 1
store i32 %121, i32* %22
%122 = load i32, i32* %13
%123 = load i32, i32* %21
%124 = add nsw i32 %123, %122
store i32 %124, i32* %21
br label %56
125: ; preds = %56
%126 = load i32, i32* %21
%127 = load i32, i32* %19
%128 = sub nsw i32 %126, %127
store i32 %128, i32* %18
%129 = load i32, i32* %16
%130 = icmp ne i32 %129, 0
br i1 %130, label %131, label %185
131: ; preds = %125
%132 = load i32, i32* %20
%133 = icmp ne i32 %132, 0
br i1 %133, label %134, label %157
134: ; preds = %131
%135 = load i32, i32* %14
%136 = icmp ne i32 %135, 0
br i1 %136, label %137, label %152
137: ; preds = %134
%138 = load i64*, i64** %11
%139 = load i32, i32* %18
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i64, i64* %138, i64 %140
%142 = load i32, i32* %13
%143 = sext i32 %142 to i64
%144 = sub i64 0, %143
%145 = getelementptr inbounds i64, i64* %141, i64 %144
%146 = load i64*, i64** %11
%147 = load i32, i32* %18
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds i64, i64* %146, i64 %148
%150 = load i32, i32* %19
%151 = call i32 @sorter_grail_swap_n(i64* %145, i64* %149, i32 %150)
br label %152
152: ; preds = %137, %134
%153 = load i32, i32* %21
store i32 %153, i32* %18
%154 = load i32, i32* %13
%155 = load i32, i32* %15
%156 = mul nsw i32 %154, %155
store i32 %156, i32* %19
store i32 0, i32* %20
br label %163
157: ; preds = %131
%158 = load i32, i32* %13
%159 = load i32, i32* %15
%160 = mul nsw i32 %158, %159
%161 = load i32, i32* %19
%162 = add nsw i32 %161, %160
store i32 %162, i32* %19
br label %163
163: ; preds = %157, %152
%164 = load i32, i32* %14
%165 = icmp ne i32 %164, 0
br i1 %165, label %166, label %176
166: ; preds = %163
%167 = load i64*, i64** %11
%168 = load i32, i32* %18
%169 = sext i32 %168 to i64
%170 = getelementptr inbounds i64, i64* %167, i64 %169
%171 = load i32, i32* %19
%172 = load i32, i32* %16
%173 = load i32, i32* %13
%174 = sub nsw i32 0, %173
%175 = call i32 @sorter_grail_merge_left(i64* %170, i32 %171, i32 %172, i32 %174)
br label %184
176: ; preds = %163
%177 = load i64*, i64** %11
%178 = load i32, i32* %18
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i64, i64* %177, i64 %179
%181 = load i32, i32* %19
%182 = load i32, i32* %16
%183 = call i32 @sorter_grail_merge_without_buffer(i64* %180, i32 %181, i32 %182)
br label %184
184: ; preds = %176, %166
br label %202
185: ; preds = %125
%186 = load i32, i32* %14
%187 = icmp ne i32 %186, 0
br i1 %187, label %188, label %201
188: ; preds = %185
%189 = load i64*, i64** %11
%190 = load i32, i32* %18
%191 = sext i32 %190 to i64
%192 = getelementptr inbounds i64, i64* %189, i64 %191
%193 = load i64*, i64** %11
%194 = load i32, i32* %18
%195 = load i32, i32* %13
%196 = sub nsw i32 %194, %195
%197 = sext i32 %196 to i64
%198 = getelementptr inbounds i64, i64* %193, i64 %197
%199 = load i32, i32* %19
%200 = call i32 @sorter_grail_swap_n(i64* %192, i64* %198, i32 %199)
br label %201
201: ; preds = %188, %185
br label %202
202: ; preds = %44, %201, %184
ret void
}

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