#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 int /*<<< orphan*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ sorter_binary_insertion_sort(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sorter_grail_build_blocks(int /*<<< orphan*/ *, int, int,
                                             int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sorter_grail_combine_blocks(int /*<<< orphan*/ *,
                                               int /*<<< orphan*/ *, int, int,
                                               int, int, int /*<<< orphan*/ *);
int sorter_grail_find_keys(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ sorter_grail_lazy_stable_sort(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sorter_grail_merge_without_buffer(int /*<<< orphan*/ *, int,
                                                     int);
void sorter_grail_common_sort(int64_t *arr, int Len, int64_t *extbuf,
                              int LExtBuf) {
  int lblock, nkeys, findkeys, ptr, cbuf, lb, nk;
  int havebuf, chavebuf;
  long long s;
  if (Len <= 16) {
    sorter_binary_insertion_sort(arr, Len);
    return;
  }
  lblock = 1;
  while (lblock * lblock < Len) {
    lblock *= 2;
  }
  nkeys = (Len - 1) / lblock + 1;
  findkeys = sorter_grail_find_keys(arr, Len, nkeys + lblock);
  havebuf = 1;
  if (findkeys < nkeys + lblock) {
    if (findkeys < 4) {
      sorter_grail_lazy_stable_sort(arr, Len);
      return;
    }
    nkeys = lblock;
    while (nkeys > findkeys) {
      nkeys /= 2;
    }
    havebuf = 0;
    lblock = 0;
  }
  ptr = lblock + nkeys;
  cbuf = havebuf ? lblock : nkeys;
  if (havebuf) {
    sorter_grail_build_blocks(arr + ptr, Len - ptr, cbuf, extbuf, LExtBuf);
  } else {
    sorter_grail_build_blocks(arr + ptr, Len - ptr, cbuf, NULL, 0);
  }
  while (Len - ptr > (cbuf *= 2)) {
    lb = lblock;
    chavebuf = havebuf;
    if (!havebuf) {
      if (nkeys > 4 && nkeys / 8 * nkeys >= cbuf) {
        lb = nkeys / 2;
        chavebuf = 1;
      } else {
        nk = 1;
        s = (long long)cbuf * findkeys / 2;
        while (nk < nkeys && s != 0) {
          nk *= 2;
          s /= 8;
        }
        lb = (2 * cbuf) / nk;
      }
    }
    sorter_grail_combine_blocks(arr, arr + ptr, Len - ptr, cbuf, lb, chavebuf,
                                chavebuf && lb <= LExtBuf ? extbuf : NULL);
  }
  sorter_binary_insertion_sort(arr, ptr);
  sorter_grail_merge_without_buffer(arr, ptr, Len - ptr);
}


x86 assembly (clang, -O0):
<sorter_grail_common_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x10,-0xc(%rbp)
jg     1194 <sorter_grail_common_sort+0x34>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <sorter_binary_insertion_sort@plt>
jmp    145d <sorter_grail_common_sort+0x2fd>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b9 <sorter_grail_common_sort+0x59>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119b <sorter_grail_common_sort+0x3b>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0x20(%rbp)
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
add    -0x20(%rbp),%edx
call   1030 <sorter_grail_find_keys@plt>
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    1244 <sorter_grail_common_sort+0xe4>
cmpl   $0x4,-0x28(%rbp)
jge    1211 <sorter_grail_common_sort+0xb1>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <sorter_grail_lazy_stable_sort@plt>
jmp    145d <sorter_grail_common_sort+0x2fd>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    1236 <sorter_grail_common_sort+0xd6>
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
jmp    1217 <sorter_grail_common_sort+0xb7>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1262 <sorter_grail_common_sort+0x102>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    1268 <sorter_grail_common_sort+0x108>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     12a2 <sorter_grail_common_sort+0x142>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   1070 <sorter_grail_build_blocks@plt>
jmp    12c6 <sorter_grail_common_sort+0x166>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1070 <sorter_grail_build_blocks@plt>
jmp    12cb <sorter_grail_common_sort+0x16b>
mov    -0xc(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    -0x30(%rbp),%ecx
shl    $0x1,%ecx
mov    %ecx,-0x30(%rbp)
cmp    %ecx,%eax
jle    143f <sorter_grail_common_sort+0x2df>
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    13b3 <sorter_grail_common_sort+0x253>
cmpl   $0x4,-0x24(%rbp)
jle    1334 <sorter_grail_common_sort+0x1d4>
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
imul   -0x24(%rbp),%eax
cmp    -0x30(%rbp),%eax
jl     1334 <sorter_grail_common_sort+0x1d4>
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    13ae <sorter_grail_common_sort+0x24e>
movl   $0x1,-0x38(%rbp)
movslq -0x30(%rbp),%rax
movslq -0x28(%rbp),%rcx
imul   %rcx,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%ecx
xor    %eax,%eax
cmp    -0x24(%rbp),%ecx
mov    %al,-0x4d(%rbp)
jge    1371 <sorter_grail_common_sort+0x211>
cmpq   $0x0,-0x48(%rbp)
setne  %al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    1381 <sorter_grail_common_sort+0x221>
jmp    13a1 <sorter_grail_common_sort+0x241>
mov    -0x38(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
mov    $0x8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x48(%rbp)
jmp    1355 <sorter_grail_common_sort+0x1f5>
mov    -0x30(%rbp),%eax
shl    $0x1,%eax
cltd
idivl  -0x38(%rbp)
mov    %eax,-0x34(%rbp)
jmp    13b3 <sorter_grail_common_sort+0x253>
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x40(%rbp)
je     140c <sorter_grail_common_sort+0x2ac>
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     140c <sorter_grail_common_sort+0x2ac>
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
jmp    1417 <sorter_grail_common_sort+0x2b7>
xor    %eax,%eax
mov    %rax,-0x78(%rbp)
jmp    1417 <sorter_grail_common_sort+0x2b7>
mov    -0x54(%rbp),%r9d
mov    -0x58(%rbp),%r8d
mov    -0x5c(%rbp),%ecx
mov    -0x60(%rbp),%edx
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rax
mov    %rax,(%rsp)
call   1050 <sorter_grail_combine_blocks@plt>
jmp    12cb <sorter_grail_common_sort+0x16b>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1080 <sorter_binary_insertion_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0xc(%rbp),%edx
sub    -0x2c(%rbp),%edx
call   1060 <sorter_grail_merge_without_buffer@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorter_grail_common_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %esi,%ebx
mov    %rdi,%r15
cmp    $0x11,%esi
jge    1190 <sorter_grail_common_sort+0x30>
mov    %r15,%rdi
mov    %ebx,%esi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <sorter_binary_insertion_sort@plt>
mov    %ecx,0x14(%rsp)
mov    %rdx,0x30(%rsp)
mov    $0x1,%ebp
xchg   %ax,%ax
mov    %ebp,%r12d
mov    %ebp,%eax
imul   %ebp,%eax
lea    (%r12,%r12,1),%ebp
cmp    %ebx,%eax
jl     11a0 <sorter_grail_common_sort+0x40>
lea    -0x1(%rbx),%eax
cltd
idiv   %r12d
mov    %eax,%r14d
lea    (%r14,%r12,1),%r13d
add    $0x1,%r13d
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
call   1030 <sorter_grail_find_keys@plt>
cmp    %r13d,%eax
mov    %r13d,0x2c(%rsp)
jge    11f6 <sorter_grail_common_sort+0x96>
cmp    $0x4,%eax
jge    122d <sorter_grail_common_sort+0xcd>
mov    %r15,%rdi
mov    %ebx,%esi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sorter_grail_lazy_stable_sort@plt>
mov    %eax,0x10(%rsp)
add    $0x1,%r14d
movslq %r13d,%rax
mov    %r15,0x18(%rsp)
lea    (%r15,%rax,4),%rdi
sub    %r13d,%ebx
mov    %ebx,%esi
mov    %r12d,%edx
mov    0x30(%rsp),%rcx
mov    0x14(%rsp),%r8d
call   1070 <sorter_grail_build_blocks@plt>
mov    %r12d,%eax
cmp    %ebp,%ebx
jg     128d <sorter_grail_common_sort+0x12d>
jmp    13a6 <sorter_grail_common_sort+0x246>
cmp    %eax,%r12d
jle    1257 <sorter_grail_common_sort+0xf7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%r13d
shr    $0x1f,%r13d
add    %r12d,%r13d
sar    %r13d
mov    %r13d,%r12d
cmp    %eax,%r13d
jg     1240 <sorter_grail_common_sort+0xe0>
jmp    125a <sorter_grail_common_sort+0xfa>
mov    %r12d,%r13d
mov    %eax,0x10(%rsp)
movslq %r13d,%rbp
mov    %r15,0x18(%rsp)
lea    (%r15,%rbp,4),%rdi
sub    %ebp,%ebx
xor    %r12d,%r12d
mov    %ebx,%esi
mov    %ebp,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <sorter_grail_build_blocks@plt>
add    %ebp,%ebp
mov    %r13d,%r14d
mov    %r13d,%eax
cmp    %ebp,%ebx
jle    13a6 <sorter_grail_common_sort+0x246>
mov    %r14d,%ecx
shr    $0x3,%ecx
imul   %r14d,%ecx
mov    %ecx,0x28(%rsp)
mov    %r14d,%ecx
shr    %ecx
mov    %ecx,0x24(%rsp)
movslq 0x10(%rsp),%rcx
mov    %rcx,0x38(%rsp)
movslq %r13d,%rcx
mov    0x18(%rsp),%rdx
lea    (%rdx,%rcx,4),%rcx
mov    %rcx,0x40(%rsp)
jmp    1310 <sorter_grail_common_sort+0x1b0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    0x14(%rsp),%r8d
mov    0x30(%rsp),%rax
mov    $0x0,%ecx
cmovg  %rcx,%rax
mov    $0x1,%r9d
mov    %rax,(%rsp)
mov    0x18(%rsp),%rdi
mov    0x40(%rsp),%rsi
mov    %ebx,%edx
mov    %r15d,%ecx
call   1050 <sorter_grail_combine_blocks@plt>
lea    (%r15,%r15,1),%ebp
mov    %r15d,%eax
cmp    %ebp,%ebx
jle    13a6 <sorter_grail_common_sort+0x246>
mov    %ebp,%r15d
mov    %r12d,%r8d
mov    0x10(%rsp),%ecx
cmp    0x2c(%rsp),%ecx
jge    12d0 <sorter_grail_common_sort+0x170>
cmp    $0x5,%r14d
jl     1332 <sorter_grail_common_sort+0x1d2>
mov    0x24(%rsp),%r8d
cmp    %r15d,0x28(%rsp)
jge    12d0 <sorter_grail_common_sort+0x170>
mov    $0x1,%ecx
cmp    $0x2,%r14d
jl     1393 <sorter_grail_common_sort+0x233>
movslq %r15d,%rsi
imul   0x38(%rsp),%rsi
mov    %rsi,%rdx
or     $0x1,%rdx
cmp    $0x3,%rdx
jb     1393 <sorter_grail_common_sort+0x233>
mov    %rsi,%rdx
shr    $0x3f,%rdx
add    %rsi,%rdx
sar    %rdx
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
add    %ecx,%ecx
lea    0x7(%rdx),%rsi
test   %rdx,%rdx
cmovns %rdx,%rsi
cmp    %r14d,%ecx
jge    1393 <sorter_grail_common_sort+0x233>
sar    $0x3,%rsi
add    $0xfffffffffffffff8,%rdx
cmp    $0xfffffffffffffff1,%rdx
mov    %rsi,%rdx
jb     1370 <sorter_grail_common_sort+0x210>
shl    $0x2,%eax
cltd
idiv   %ecx
mov    %eax,%r8d
xor    %r9d,%r9d
xor    %eax,%eax
jmp    12e9 <sorter_grail_common_sort+0x189>
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    %r13d,%esi
call   1080 <sorter_binary_insertion_sort@plt>
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <sorter_grail_merge_without_buffer@plt>

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

LLVM IR (-O2):
define void @sorter_grail_common_sort(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = icmp slt i32 %1, 17
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @sorter_binary_insertion_sort(i32* %0, i32 %1)
br label %100
8: ; preds = %4, %8
%9 = phi i32 [ %12, %8 ], [ 1, %4 ]
%10 = mul nsw i32 %9, %9
%11 = icmp slt i32 %10, %1
%12 = shl nsw i32 %9, 1
br i1 %11, label %8, label %13
13: ; preds = %8
%14 = add nsw i32 %1, -1
%15 = sdiv i32 %14, %9
%16 = add nsw i32 %15, 1
%17 = add nsw i32 %16, %9
%18 = tail call i32 @sorter_grail_find_keys(i32* %0, i32 %1, i32 %17)
%19 = icmp slt i32 %18, %17
br i1 %19, label %20, label %30
20: ; preds = %13
%21 = icmp slt i32 %18, 4
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = icmp sgt i32 %9, %18
br i1 %23, label %26, label %35
24: ; preds = %20
%25 = tail call i32 @sorter_grail_lazy_stable_sort(i32* %0, i32 %1)
br label %100
26: ; preds = %22, %26
%27 = phi i32 [ %28, %26 ], [ %9, %22 ]
%28 = sdiv i32 %27, 2
%29 = icmp sgt i32 %28, %18
br i1 %29, label %26, label %35
30: ; preds = %13
%31 = sext i32 %17 to i64
%32 = getelementptr inbounds i32, i32* %0, i64 %31
%33 = sub nsw i32 %1, %17
%34 = tail call i32 @sorter_grail_build_blocks(i32* %32, i32 %33, i32 %9, i32* %2, i32 %3)
br label %42
35: ; preds = %26, %22
%36 = phi i32 [ %9, %22 ], [ %28, %26 ]
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %0, i64 %37
%39 = sub nsw i32 %1, %36
%40 = tail call i32 @sorter_grail_build_blocks(i32* %38, i32 %39, i32 %36, i32* null, i32 0)
%41 = shl nsw i32 %36, 1
br label %42
42: ; preds = %35, %30
%43 = phi i32 [ %41, %35 ], [ %12, %30 ]
%44 = phi i32 [ %39, %35 ], [ %33, %30 ]
%45 = phi i32 [ %36, %35 ], [ %17, %30 ]
%46 = phi i32 [ 0, %35 ], [ %9, %30 ]
%47 = phi i32 [ %36, %35 ], [ %16, %30 ]
%48 = phi i32 [ %36, %35 ], [ %9, %30 ]
%49 = icmp sgt i32 %44, %43
br i1 %49, label %50, label %97
50: ; preds = %42
%51 = icmp slt i32 %47, 5
%52 = lshr i32 %47, 3
%53 = mul nsw i32 %52, %47
%54 = lshr i32 %47, 1
%55 = sext i32 %18 to i64
%56 = icmp sgt i32 %47, 1
%57 = sext i32 %45 to i64
%58 = getelementptr inbounds i32, i32* %0, i64 %57
br label %59
59: ; preds = %50, %90
%60 = phi i32 [ %43, %50 ], [ %95, %90 ]
%61 = phi i32 [ %48, %50 ], [ %60, %90 ]
br i1 %19, label %62, label %82
62: ; preds = %59
%63 = icmp slt i32 %53, %60
%64 = select i1 %51, i1 true, i1 %63
br i1 %64, label %65, label %82
65: ; preds = %62
%66 = sext i32 %60 to i64
%67 = mul nsw i64 %66, %55
%68 = or i64 %67, 1
%69 = icmp ugt i64 %68, 2
%70 = select i1 %56, i1 %69, i1 false
br i1 %70, label %71, label %86
71: ; preds = %65
%72 = sdiv i64 %67, 2
br label %73
73: ; preds = %71, %73
%74 = phi i64 [ %77, %73 ], [ %72, %71 ]
%75 = phi i32 [ %76, %73 ], [ 1, %71 ]
%76 = shl nsw i32 %75, 1
%77 = sdiv i64 %74, 8
%78 = icmp slt i32 %76, %47
%79 = add nsw i64 %74, -8
%80 = icmp ult i64 %79, -15
%81 = select i1 %78, i1 %80, i1 false
br i1 %81, label %73, label %86
82: ; preds = %62, %59
%83 = phi i32 [ %46, %59 ], [ %54, %62 ]
%84 = icmp sgt i32 %83, %3
%85 = select i1 %84, i32* null, i32* %2
br label %90
86: ; preds = %73, %65
%87 = phi i32 [ 1, %65 ], [ %76, %73 ]
%88 = shl nsw i32 %61, 2
%89 = sdiv i32 %88, %87
br label %90
90: ; preds = %82, %86
%91 = phi i32 [ 0, %86 ], [ 1, %82 ]
%92 = phi i32 [ %89, %86 ], [ %83, %82 ]
%93 = phi i32* [ null, %86 ], [ %85, %82 ]
%94 = tail call i32 @sorter_grail_combine_blocks(i32* %0, i32* %58, i32 %44, i32 %60, i32 %92, i32 %91, i32* %93)
%95 = shl nsw i32 %60, 1
%96 = icmp sgt i32 %44, %95
br i1 %96, label %59, label %97
97: ; preds = %90, %42
%98 = tail call i32 @sorter_binary_insertion_sort(i32* %0, i32 %45)
%99 = tail call i32 @sorter_grail_merge_without_buffer(i32* %0, i32 %45, i32 %44)
br label %100
100: ; preds = %97, %24, %6
ret void
}