#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*/ memcpy(int **, int **, int);
int /*<<< orphan*/ stable_grail_merge_left(int **, int, int, int);
int /*<<< orphan*/ stable_grail_merge_left_with_x_buf(int **, int, int, int);
int /*<<< orphan*/ stable_grail_merge_right(int **, int, int, int);
int /*<<< orphan*/ stable_grail_rotate(int **, int, int);
int /*<<< orphan*/ stable_grail_swap1(int **, int **);
void stable_grail_build_blocks(int **arr, int L, int K, int **extbuf,
                               int LExtBuf) {
  int m, u, h, p0, p1, rest, restk, p, kbuf;
  kbuf = K < LExtBuf ? K : LExtBuf;
  while (kbuf & (kbuf - 1)) {
    kbuf &= kbuf - 1;
  }
  if (kbuf) {
    memcpy(extbuf, arr - kbuf, kbuf * sizeof(int *));
    for (m = 1; m < L; m += 2) {
      u = 0;
      if ((*(*(arr + (m - 1))) - *(*(arr + m))) > 0) {
        u = 1;
      }
      arr[m - 3] = arr[m - 1 + u];
      arr[m - 2] = arr[m - u];
    }
    if (L % 2) {
      arr[L - 3] = arr[L - 1];
    }
    arr -= 2;
    for (h = 2; h < kbuf; h *= 2) {
      p0 = 0;
      p1 = L - 2 * h;
      while (p0 <= p1) {
        stable_grail_merge_left_with_x_buf(arr + p0, h, h, -h);
        p0 += 2 * h;
      }
      rest = L - p0;
      if (rest > h) {
        stable_grail_merge_left_with_x_buf(arr + p0, h, rest - h, -h);
      } else {
        for (; p0 < L; p0++) {
          arr[p0 - h] = arr[p0];
        }
      }
      arr -= h;
    }
    memcpy(arr + L, extbuf, kbuf * sizeof(int *));
  } else {
    for (m = 1; m < L; m += 2) {
      u = 0;
      if ((*(*(arr + (m - 1))) - *(*(arr + m))) > 0) {
        u = 1;
      }
      stable_grail_swap1(arr + (m - 3), arr + (m - 1 + u));
      stable_grail_swap1(arr + (m - 2), arr + (m - u));
    }
    if (L % 2) {
      stable_grail_swap1(arr + (L - 1), arr + (L - 3));
    }
    arr -= 2;
    h = 2;
  }
  for (; h < K; h *= 2) {
    p0 = 0;
    p1 = L - 2 * h;
    while (p0 <= p1) {
      stable_grail_merge_left(arr + p0, h, h, -h);
      p0 += 2 * h;
    }
    rest = L - p0;
    if (rest > h) {
      stable_grail_merge_left(arr + p0, h, rest - h, -h);
    } else {
      stable_grail_rotate(arr + p0 - h, h, rest);
    }
    arr -= h;
  }
  restk = L % (2 * K);
  p = L - restk;
  if (restk <= K) {
    stable_grail_rotate(arr + p, restk, K);
  } else {
    stable_grail_merge_right(arr + p, K, restk - K, K);
  }
  while (p > 0) {
    p -= 2 * K;
    stable_grail_merge_right(arr + p, K, K, K);
  }
}


x86 assembly (clang, -O0):
<stable_grail_build_blocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1191 <stable_grail_build_blocks+0x31>
mov    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    1197 <stable_grail_build_blocks+0x37>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x40(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11c2 <stable_grail_build_blocks+0x62>
mov    -0x40(%rbp),%eax
sub    $0x1,%eax
and    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    119d <stable_grail_build_blocks+0x3d>
cmpl   $0x0,-0x40(%rbp)
je     1405 <stable_grail_build_blocks+0x2a5>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x40(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
shl    $0x3,%rax
add    %rax,%rsi
movslq -0x40(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1293 <stable_grail_build_blocks+0x133>
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
movslq -0x20(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
sub    (%rcx),%eax
cmp    $0x0,%eax
jle    123e <stable_grail_build_blocks+0xde>
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    -0x24(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    11fa <stable_grail_build_blocks+0x9a>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12c9 <stable_grail_build_blocks+0x169>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
add    $0xfffffffffffffff0,%rax
mov    %rax,-0x8(%rbp)
movl   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    13de <stable_grail_build_blocks+0x27e>
movl   $0x0,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x28(%rbp),%ecx
shl    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jg     1339 <stable_grail_build_blocks+0x1d9>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%esi
mov    -0x28(%rbp),%edx
xor    %ecx,%ecx
sub    -0x28(%rbp),%ecx
call   1080 <stable_grail_merge_left_with_x_buf@plt>
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    12fd <stable_grail_build_blocks+0x19d>
mov    -0xc(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    1375 <stable_grail_build_blocks+0x215>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%esi
mov    -0x34(%rbp),%edx
sub    -0x28(%rbp),%edx
xor    %ecx,%ecx
sub    -0x28(%rbp),%ecx
call   1080 <stable_grail_merge_left_with_x_buf@plt>
jmp    13b6 <stable_grail_build_blocks+0x256>
jmp    137a <stable_grail_build_blocks+0x21a>
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13b1 <stable_grail_build_blocks+0x251>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    -0x28(%rbp),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    137a <stable_grail_build_blocks+0x21a>
jmp    13b6 <stable_grail_build_blocks+0x256>
mov    -0x28(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12dc <stable_grail_build_blocks+0x17c>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x40(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
jmp    1509 <stable_grail_build_blocks+0x3a9>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    14b7 <stable_grail_build_blocks+0x357>
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
movslq -0x20(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
sub    (%rcx),%eax
cmp    $0x0,%eax
jle    1450 <stable_grail_build_blocks+0x2f0>
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
sub    $0x3,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
add    -0x24(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
call   1070 <stable_grail_swap1@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%eax
sub    -0x24(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
call   1070 <stable_grail_swap1@plt>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    140c <stable_grail_build_blocks+0x2ac>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     14f6 <stable_grail_build_blocks+0x396>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    $0x3,%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
call   1070 <stable_grail_swap1@plt>
mov    -0x8(%rbp),%rax
add    $0xfffffffffffffff0,%rax
mov    %rax,-0x8(%rbp)
movl   $0x2,-0x28(%rbp)
jmp    150e <stable_grail_build_blocks+0x3ae>
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    15f9 <stable_grail_build_blocks+0x499>
movl   $0x0,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x28(%rbp),%ecx
shl    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jg     156b <stable_grail_build_blocks+0x40b>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%esi
mov    -0x28(%rbp),%edx
xor    %ecx,%ecx
sub    -0x28(%rbp),%ecx
call   1050 <stable_grail_merge_left@plt>
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    152f <stable_grail_build_blocks+0x3cf>
mov    -0xc(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    15a7 <stable_grail_build_blocks+0x447>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%esi
mov    -0x34(%rbp),%edx
sub    -0x28(%rbp),%edx
xor    %ecx,%ecx
sub    -0x28(%rbp),%ecx
call   1050 <stable_grail_merge_left@plt>
jmp    15d1 <stable_grail_build_blocks+0x471>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
movslq -0x28(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1040 <stable_grail_rotate@plt>
mov    -0x28(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    150e <stable_grail_build_blocks+0x3ae>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x38(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     163c <stable_grail_build_blocks+0x4dc>
mov    -0x8(%rbp),%rdi
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x38(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <stable_grail_rotate@plt>
jmp    165c <stable_grail_build_blocks+0x4fc>
mov    -0x8(%rbp),%rdi
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
mov    -0x38(%rbp),%edx
sub    -0x10(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <stable_grail_merge_right@plt>
jmp    1661 <stable_grail_build_blocks+0x501>
cmpl   $0x0,-0x3c(%rbp)
jle    169b <stable_grail_build_blocks+0x53b>
mov    -0x10(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x3c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <stable_grail_merge_right@plt>
jmp    1661 <stable_grail_build_blocks+0x501>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stable_grail_build_blocks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%r14
cmp    %r8d,%edx
cmovl  %edx,%r8d
xchg   %ax,%ax
mov    %r8d,%r15d
lea    -0x1(%r15),%r8d
and    %r15d,%r8d
jne    1180 <stable_grail_build_blocks+0x20>
test   %r15d,%r15d
mov    %r13,0x30(%rsp)
mov    %r12,0x28(%rsp)
je     14bf <stable_grail_build_blocks+0x35f>
movslq %r15d,%rax
shl    $0x3,%rax
mov    %r14,%rsi
sub    %rax,%rsi
lea    0x0(,%r15,8),%edx
mov    %rcx,0x38(%rsp)
mov    %rcx,%rdi
mov    %edx,0x24(%rsp)
call   1060 <memcpy@plt>
cmp    $0x2,%r13d
jl     121d <stable_grail_build_blocks+0xbd>
mov    %r13d,%eax
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x8(%r14,%rcx,8),%rdx
mov    (%r14,%rcx,8),%rsi
mov    (%rdx),%edx
xor    %edi,%edi
cmp    (%rsi),%edx
setg   %dil
lea    (%rcx,%rdi,1),%rdx
mov    -0x8(%r14,%rdx,8),%rdx
mov    %rdx,-0x18(%r14,%rcx,8)
shl    $0x3,%rdi
mov    %r14,%rdx
sub    %rdi,%rdx
mov    (%rdx,%rcx,8),%rdx
mov    %rdx,-0x10(%r14,%rcx,8)
add    $0x2,%rcx
cmp    %rax,%rcx
jb     11e0 <stable_grail_build_blocks+0x80>
movslq %r13d,%rbx
test   $0x1,%r13b
je     1230 <stable_grail_build_blocks+0xd0>
mov    -0x8(%r14,%rbx,8),%rax
mov    %rax,-0x18(%r14,%rbx,8)
add    $0xfffffffffffffff0,%r14
mov    $0x2,%r9d
cmp    $0x3,%r15d
jl     1494 <stable_grail_build_blocks+0x334>
mov    $0x2,%r9d
mov    %r15,0x40(%rsp)
mov    %rbx,0x8(%rsp)
jmp    128d <stable_grail_build_blocks+0x12d>
cs nopw 0x0(%rax,%rax,1)
movslq %ebp,%rax
lea    (%r14,%rax,8),%rdi
mov    %ebx,%ecx
neg    %ecx
mov    %ebx,%esi
mov    %r9,%rbx
call   1080 <stable_grail_merge_left_with_x_buf@plt>
mov    %rbx,%r9
mov    0x8(%rsp),%rbx
shl    $0x3,%r12
sub    %r12,%r14
cmp    %r15d,%r9d
jge    1494 <stable_grail_build_blocks+0x334>
mov    %r9d,%ebx
lea    (%rbx,%rbx,1),%r9d
mov    %r13d,%eax
sub    %r9d,%eax
mov    $0x0,%ebp
js     12ff <stable_grail_build_blocks+0x19f>
mov    %ebx,%r13d
neg    %r13d
mov    %r14,%r12
mov    %r9,0x10(%rsp)
movslq %r9d,%r14
mov    %eax,%eax
mov    %rax,(%rsp)
lea    0x0(,%r14,8),%r15
mov    %r12,0x18(%rsp)
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
call   1080 <stable_grail_merge_left_with_x_buf@plt>
add    %r14,%rbp
add    %r15,%r12
cmp    (%rsp),%rbp
jle    12d0 <stable_grail_build_blocks+0x170>
mov    0x30(%rsp),%r13
mov    0x18(%rsp),%r14
mov    0x10(%rsp),%r9
mov    0x40(%rsp),%r15
mov    %r13d,%edx
sub    %ebp,%edx
movslq %ebx,%r12
sub    %ebx,%edx
jg     1260 <stable_grail_build_blocks+0x100>
cmp    %r13d,%ebp
mov    0x8(%rsp),%rbx
jge    127d <stable_grail_build_blocks+0x11d>
movslq %ebp,%rax
mov    %rbx,%rcx
sub    %rax,%rcx
cmp    $0x4,%rcx
jb     1400 <stable_grail_build_blocks+0x2a0>
mov    %rax,%rdi
sub    %r12,%rdi
lea    (%r14,%rdi,8),%rsi
lea    (%r14,%rbx,8),%rdx
cmp    %rdx,%rsi
jae    135b <stable_grail_build_blocks+0x1fb>
lea    0x0(,%r12,8),%rsi
sub    %rsi,%rdx
lea    (%r14,%rax,8),%rsi
cmp    %rdx,%rsi
jb     1400 <stable_grail_build_blocks+0x2a0>
mov    %rcx,%r8
and    $0xfffffffffffffffc,%r8
lea    -0x4(%r8),%rdx
mov    %rdx,%rbp
shr    $0x2,%rbp
add    $0x1,%rbp
test   %rdx,%rdx
je     13c2 <stable_grail_build_blocks+0x262>
mov    %rbp,%rsi
and    $0xfffffffffffffffe,%rsi
lea    (%r14,%rdi,8),%rbx
add    $0x30,%rbx
lea    (%r14,%rax,8),%rdx
add    $0x30,%rdx
xor    %edi,%edi
nop
movups -0x30(%rdx,%rdi,8),%xmm0
movups -0x20(%rdx,%rdi,8),%xmm1
movups %xmm0,-0x30(%rbx,%rdi,8)
movups %xmm1,-0x20(%rbx,%rdi,8)
movups -0x10(%rdx,%rdi,8),%xmm0
movups (%rdx,%rdi,8),%xmm1
movups %xmm0,-0x10(%rbx,%rdi,8)
movups %xmm1,(%rbx,%rdi,8)
add    $0x8,%rdi
add    $0xfffffffffffffffe,%rsi
jne    1390 <stable_grail_build_blocks+0x230>
jmp    13c4 <stable_grail_build_blocks+0x264>
xor    %edi,%edi
test   $0x1,%bpl
mov    0x8(%rsp),%rbx
je     13eb <stable_grail_build_blocks+0x28b>
add    %rax,%rdi
movups (%r14,%rdi,8),%xmm0
movups 0x10(%r14,%rdi,8),%xmm1
sub    %r12,%rdi
movups %xmm0,(%r14,%rdi,8)
movups %xmm1,0x10(%r14,%rdi,8)
cmp    %r8,%rcx
je     127d <stable_grail_build_blocks+0x11d>
add    %r8,%rax
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edx
sub    %eax,%edx
mov    %rax,%rcx
not    %rcx
add    %rbx,%rcx
and    $0x3,%rdx
je     1442 <stable_grail_build_blocks+0x2e2>
lea    0x0(,%r12,8),%rdi
mov    %r14,%rsi
sub    %rdi,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rax,8),%rdi
mov    %rdi,(%rsi,%rax,8)
add    $0x1,%rax
add    $0xffffffffffffffff,%rdx
jne    1430 <stable_grail_build_blocks+0x2d0>
cmp    $0x3,%rcx
jb     127d <stable_grail_build_blocks+0x11d>
lea    0x0(,%r12,8),%rdx
mov    %r14,%rcx
sub    %rdx,%rcx
add    $0x18,%rcx
xchg   %ax,%ax
mov    (%r14,%rax,8),%rdx
mov    %rdx,-0x18(%rcx,%rax,8)
mov    0x8(%r14,%rax,8),%rdx
mov    %rdx,-0x10(%rcx,%rax,8)
mov    0x10(%r14,%rax,8),%rdx
mov    %rdx,-0x8(%rcx,%rax,8)
mov    0x18(%r14,%rax,8),%rdx
mov    %rdx,(%rcx,%rax,8)
add    $0x4,%rax
cmp    %rax,%rbx
jne    1460 <stable_grail_build_blocks+0x300>
jmp    127d <stable_grail_build_blocks+0x11d>
lea    (%r14,%rbx,8),%rdi
mov    0x38(%rsp),%rsi
mov    0x24(%rsp),%edx
mov    %r9,%rbx
call   1060 <memcpy@plt>
mov    %rbx,%rsi
mov    0x28(%rsp),%r12
cmp    %r12d,%esi
jl     15c1 <stable_grail_build_blocks+0x461>
jmp    1559 <stable_grail_build_blocks+0x3f9>
cmp    $0x2,%r13d
mov    %r14,%r15
jl     152a <stable_grail_build_blocks+0x3ca>
mov    %r13d,%eax
mov    %rax,(%rsp)
lea    0x8(%r15),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    -0x8(%r14),%rax
mov    (%r14),%rcx
mov    (%rax),%eax
xor    %ebp,%ebp
cmp    (%rcx),%eax
setg   %bpl
lea    -0x18(%r14),%rdi
lea    (%rbx,%rbp,1),%rax
lea    (%r15,%rax,8),%rsi
call   1070 <stable_grail_swap1@plt>
lea    -0x10(%r14),%rdi
shl    $0x3,%rbp
mov    %r14,%rsi
sub    %rbp,%rsi
call   1070 <stable_grail_swap1@plt>
add    $0x10,%r14
lea    0x2(%rbx),%rax
add    $0x3,%rbx
cmp    (%rsp),%rbx
mov    %rax,%rbx
jl     14e0 <stable_grail_build_blocks+0x380>
test   $0x1,%r13b
mov    %r15,%r14
je     154b <stable_grail_build_blocks+0x3eb>
movslq %r13d,%rax
lea    (%r14,%rax,8),%rdi
add    $0xfffffffffffffff8,%rdi
lea    (%r14,%rax,8),%rsi
add    $0xffffffffffffffe8,%rsi
call   1070 <stable_grail_swap1@plt>
add    $0xfffffffffffffff0,%r14
mov    $0x2,%esi
cmp    %r12d,%esi
jl     15c1 <stable_grail_build_blocks+0x461>
lea    (%r12,%r12,1),%ebx
mov    %r13d,%eax
cltd
idiv   %ebx
sub    %edx,%r13d
mov    %edx,%eax
movslq %r13d,%rcx
lea    (%r14,%rcx,8),%rdi
sub    %r12d,%eax
jle    165f <stable_grail_build_blocks+0x4ff>
mov    %r12d,%esi
mov    %eax,%edx
mov    %r12d,%ecx
call   1030 <stable_grail_merge_right@plt>
test   %r13d,%r13d
jg     166e <stable_grail_build_blocks+0x50e>
jmp    16a1 <stable_grail_build_blocks+0x541>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rbp
neg    %rbp
shl    $0x3,%rbx
sub    %rbx,%rdi
call   1040 <stable_grail_rotate@plt>
mov    %rbp,%rbx
lea    (%r14,%rbx,8),%r14
mov    %r15d,%esi
cmp    %r12d,%r15d
jge    1559 <stable_grail_build_blocks+0x3f9>
lea    (%rsi,%rsi,1),%r15d
mov    %r13d,%eax
sub    %r15d,%eax
mov    $0x0,%ebx
js     1633 <stable_grail_build_blocks+0x4d3>
mov    %esi,%r13d
neg    %r13d
mov    %r14,%rbp
mov    %r15d,0x10(%rsp)
movslq %r15d,%r14
mov    %eax,%eax
mov    %rax,(%rsp)
lea    0x0(,%r14,8),%r12
mov    %rbp,0x18(%rsp)
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %esi,%edx
mov    %r13d,%ecx
mov    %rsi,%r15
call   1050 <stable_grail_merge_left@plt>
mov    %r15,%rsi
add    %r14,%rbx
add    %r12,%rbp
cmp    (%rsp),%rbx
jle    1600 <stable_grail_build_blocks+0x4a0>
mov    0x28(%rsp),%r12
mov    0x30(%rsp),%r13
mov    0x18(%rsp),%r14
mov    0x10(%rsp),%r15d
mov    %r13d,%edx
sub    %ebx,%edx
mov    %edx,%eax
movslq %ebx,%rcx
lea    (%r14,%rcx,8),%rdi
movslq %esi,%rbx
sub    %esi,%eax
jle    15a0 <stable_grail_build_blocks+0x440>
mov    %esi,%ecx
neg    %ecx
mov    %eax,%edx
call   1050 <stable_grail_merge_left@plt>
neg    %rbx
jmp    15b5 <stable_grail_build_blocks+0x455>
mov    %edx,%esi
mov    %r12d,%edx
call   1040 <stable_grail_rotate@plt>
test   %r13d,%r13d
jle    16a1 <stable_grail_build_blocks+0x541>
mov    %ebx,%ebp
neg    %ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x0(%rbp,%r13,1),%eax
sub    %ebx,%r13d
cltq
lea    (%r14,%rax,8),%rdi
mov    %r12d,%esi
mov    %r12d,%edx
mov    %r12d,%ecx
call   1030 <stable_grail_merge_right@plt>
test   %r13d,%r13d
jg     1680 <stable_grail_build_blocks+0x520>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @stable_grail_build_blocks(i32** %0, i32 %1, i32 %2, i32** %3, i32 %4) {
%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 i32
%19 = alloca i32
store i32** %0, i32*** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32** %3, i32*** %9
store i32 %4, i32* %10
%20 = load i32, i32* %8
%21 = load i32, i32* %10
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %5
%24 = load i32, i32* %8
br label %27
25: ; preds = %5
%26 = load i32, i32* %10
br label %27
27: ; preds = %25, %23
%28 = phi i32 [ %24, %23 ], [ %26, %25 ]
store i32 %28, i32* %19
br label %29
29: ; preds = %35, %27
%30 = load i32, i32* %19
%31 = load i32, i32* %19
%32 = sub nsw i32 %31, 1
%33 = and i32 %30, %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* %19
%37 = sub nsw i32 %36, 1
%38 = load i32, i32* %19
%39 = and i32 %38, %37
store i32 %39, i32* %19
br label %29
40: ; preds = %29
%41 = load i32, i32* %19
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %211
43: ; preds = %40
%44 = load i32**, i32*** %9
%45 = load i32**, i32*** %6
%46 = load i32, i32* %19
%47 = sext i32 %46 to i64
%48 = sub i64 0, %47
%49 = getelementptr inbounds i32*, i32** %45, i64 %48
%50 = load i32, i32* %19
%51 = sext i32 %50 to i64
%52 = mul i64 %51, 8
%53 = trunc i64 %52 to i32
%54 = call i32 @memcpy(i32** %44, i32** %49, i32 %53)
store i32 1, i32* %11
br label %55
55: ; preds = %102, %43
%56 = load i32, i32* %11
%57 = load i32, i32* %7
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %105
59: ; preds = %55
store i32 0, i32* %12
%60 = load i32**, i32*** %6
%61 = load i32, i32* %11
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32*, i32** %60, i64 %63
%65 = load i32*, i32** %64
%66 = load i32, i32* %65
%67 = load i32**, i32*** %6
%68 = load i32, i32* %11
%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 = sub nsw i32 %66, %72
%74 = icmp sgt i32 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %59
store i32 1, i32* %12
br label %76
76: ; preds = %75, %59
%77 = load i32**, i32*** %6
%78 = load i32, i32* %11
%79 = sub nsw i32 %78, 1
%80 = load i32, i32* %12
%81 = add nsw i32 %79, %80
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i32*, i32** %77, i64 %82
%84 = load i32*, i32** %83
%85 = load i32**, i32*** %6
%86 = load i32, i32* %11
%87 = sub nsw i32 %86, 3
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32*, i32** %85, i64 %88
store i32* %84, i32** %89
%90 = load i32**, i32*** %6
%91 = load i32, i32* %11
%92 = load i32, i32* %12
%93 = sub nsw i32 %91, %92
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i32*, i32** %90, i64 %94
%96 = load i32*, i32** %95
%97 = load i32**, i32*** %6
%98 = load i32, i32* %11
%99 = sub nsw i32 %98, 2
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i32*, i32** %97, i64 %100
store i32* %96, i32** %101
br label %102
102: ; preds = %76
%103 = load i32, i32* %11
%104 = add nsw i32 %103, 2
store i32 %104, i32* %11
br label %55
105: ; preds = %55
%106 = load i32, i32* %7
%107 = srem i32 %106, 2
%108 = icmp ne i32 %107, 0
br i1 %108, label %109, label %121
109: ; preds = %105
%110 = load i32**, i32*** %6
%111 = load i32, i32* %7
%112 = sub nsw i32 %111, 1
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i32*, i32** %110, i64 %113
%115 = load i32*, i32** %114
%116 = load i32**, i32*** %6
%117 = load i32, i32* %7
%118 = sub nsw i32 %117, 3
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i32*, i32** %116, i64 %119
store i32* %115, i32** %120
br label %121
121: ; preds = %109, %105
%122 = load i32**, i32*** %6
%123 = getelementptr inbounds i32*, i32** %122, i64 -2
store i32** %123, i32*** %6
store i32 2, i32* %13
br label %124
124: ; preds = %197, %121
%125 = load i32, i32* %13
%126 = load i32, i32* %19
%127 = icmp slt i32 %125, %126
br i1 %127, label %128, label %200
128: ; preds = %124
store i32 0, i32* %14
%129 = load i32, i32* %7
%130 = load i32, i32* %13
%131 = mul nsw i32 2, %130
%132 = sub nsw i32 %129, %131
store i32 %132, i32* %15
br label %133
133: ; preds = %137, %128
%134 = load i32, i32* %14
%135 = load i32, i32* %15
%136 = icmp sle i32 %134, %135
br i1 %136, label %137, label %151
137: ; preds = %133
%138 = load i32**, i32*** %6
%139 = load i32, i32* %14
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i32*, i32** %138, i64 %140
%142 = load i32, i32* %13
%143 = load i32, i32* %13
%144 = load i32, i32* %13
%145 = sub nsw i32 0, %144
%146 = call i32 @stable_grail_merge_left_with_x_buf(i32** %141, i32 %142, i32 %143, i32 %145)
%147 = load i32, i32* %13
%148 = mul nsw i32 2, %147
%149 = load i32, i32* %14
%150 = add nsw i32 %149, %148
store i32 %150, i32* %14
br label %133
151: ; preds = %133
%152 = load i32, i32* %7
%153 = load i32, i32* %14
%154 = sub nsw i32 %152, %153
store i32 %154, i32* %16
%155 = load i32, i32* %16
%156 = load i32, i32* %13
%157 = icmp sgt i32 %155, %156
br i1 %157, label %158, label %170
158: ; preds = %151
%159 = load i32**, i32*** %6
%160 = load i32, i32* %14
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds i32*, i32** %159, i64 %161
%163 = load i32, i32* %13
%164 = load i32, i32* %16
%165 = load i32, i32* %13
%166 = sub nsw i32 %164, %165
%167 = load i32, i32* %13
%168 = sub nsw i32 0, %167
%169 = call i32 @stable_grail_merge_left_with_x_buf(i32** %162, i32 %163, i32 %166, i32 %168)
br label %191
170: ; preds = %151
br label %171
171: ; preds = %187, %170
%172 = load i32, i32* %14
%173 = load i32, i32* %7
%174 = icmp slt i32 %172, %173
br i1 %174, label %175, label %190
175: ; preds = %171
%176 = load i32**, i32*** %6
%177 = load i32, i32* %14
%178 = sext i32 %177 to i64
%179 = getelementptr inbounds i32*, i32** %176, i64 %178
%180 = load i32*, i32** %179
%181 = load i32**, i32*** %6
%182 = load i32, i32* %14
%183 = load i32, i32* %13
%184 = sub nsw i32 %182, %183
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds i32*, i32** %181, i64 %185
store i32* %180, i32** %186
br label %187
187: ; preds = %175
%188 = load i32, i32* %14
%189 = add nsw i32 %188, 1
store i32 %189, i32* %14
br label %171
190: ; preds = %171
br label %191
191: ; preds = %190, %158
%192 = load i32, i32* %13
%193 = load i32**, i32*** %6
%194 = sext i32 %192 to i64
%195 = sub i64 0, %194
%196 = getelementptr inbounds i32*, i32** %193, i64 %195
store i32** %196, i32*** %6
br label %197
197: ; preds = %191
%198 = load i32, i32* %13
%199 = mul nsw i32 %198, 2
store i32 %199, i32* %13
br label %124
200: ; preds = %124
%201 = load i32**, i32*** %6
%202 = load i32, i32* %7
%203 = sext i32 %202 to i64
%204 = getelementptr inbounds i32*, i32** %201, i64 %203
%205 = load i32**, i32*** %9
%206 = load i32, i32* %19
%207 = sext i32 %206 to i64
%208 = mul i64 %207, 8
%209 = trunc i64 %208 to i32
%210 = call i32 @memcpy(i32** %204, i32** %205, i32 %209)
br label %281
211: ; preds = %40
store i32 1, i32* %11
br label %212
212: ; preds = %259, %211
%213 = load i32, i32* %11
%214 = load i32, i32* %7
%215 = icmp slt i32 %213, %214
br i1 %215, label %216, label %262
216: ; preds = %212
store i32 0, i32* %12
%217 = load i32**, i32*** %6
%218 = load i32, i32* %11
%219 = sub nsw i32 %218, 1
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds i32*, i32** %217, i64 %220
%222 = load i32*, i32** %221
%223 = load i32, i32* %222
%224 = load i32**, i32*** %6
%225 = load i32, i32* %11
%226 = sext i32 %225 to i64
%227 = getelementptr inbounds i32*, i32** %224, i64 %226
%228 = load i32*, i32** %227
%229 = load i32, i32* %228
%230 = sub nsw i32 %223, %229
%231 = icmp sgt i32 %230, 0
br i1 %231, label %232, label %233
232: ; preds = %216
store i32 1, i32* %12
br label %233
233: ; preds = %232, %216
%234 = load i32**, i32*** %6
%235 = load i32, i32* %11
%236 = sub nsw i32 %235, 3
%237 = sext i32 %236 to i64
%238 = getelementptr inbounds i32*, i32** %234, i64 %237
%239 = load i32**, i32*** %6
%240 = load i32, i32* %11
%241 = sub nsw i32 %240, 1
%242 = load i32, i32* %12
%243 = add nsw i32 %241, %242
%244 = sext i32 %243 to i64
%245 = getelementptr inbounds i32*, i32** %239, i64 %244
%246 = call i32 @stable_grail_swap1(i32** %238, i32** %245)
%247 = load i32**, i32*** %6
%248 = load i32, i32* %11
%249 = sub nsw i32 %248, 2
%250 = sext i32 %249 to i64
%251 = getelementptr inbounds i32*, i32** %247, i64 %250
%252 = load i32**, i32*** %6
%253 = load i32, i32* %11
%254 = load i32, i32* %12
%255 = sub nsw i32 %253, %254
%256 = sext i32 %255 to i64
%257 = getelementptr inbounds i32*, i32** %252, i64 %256
%258 = call i32 @stable_grail_swap1(i32** %251, i32** %257)
br label %259
259: ; preds = %233
%260 = load i32, i32* %11
%261 = add nsw i32 %260, 2
store i32 %261, i32* %11
br label %212
262: ; preds = %212
%263 = load i32, i32* %7
%264 = srem i32 %263, 2
%265 = icmp ne i32 %264, 0
br i1 %265, label %266, label %278
266: ; preds = %262
%267 = load i32**, i32*** %6
%268 = load i32, i32* %7
%269 = sub nsw i32 %268, 1
%270 = sext i32 %269 to i64
%271 = getelementptr inbounds i32*, i32** %267, i64 %270
%272 = load i32**, i32*** %6
%273 = load i32, i32* %7
%274 = sub nsw i32 %273, 3
%275 = sext i32 %274 to i64
%276 = getelementptr inbounds i32*, i32** %272, i64 %275
%277 = call i32 @stable_grail_swap1(i32** %271, i32** %276)
br label %278
278: ; preds = %266, %262
%279 = load i32**, i32*** %6
%280 = getelementptr inbounds i32*, i32** %279, i64 -2
store i32** %280, i32*** %6
store i32 2, i32* %13
br label %281
281: ; preds = %278, %200
br label %282
282: ; preds = %346, %281
%283 = load i32, i32* %13
%284 = load i32, i32* %8
%285 = icmp slt i32 %283, %284
br i1 %285, label %286, label %349
286: ; preds = %282
store i32 0, i32* %14
%287 = load i32, i32* %7
%288 = load i32, i32* %13
%289 = mul nsw i32 2, %288
%290 = sub nsw i32 %287, %289
store i32 %290, i32* %15
br label %291
291: ; preds = %295, %286
%292 = load i32, i32* %14
%293 = load i32, i32* %15
%294 = icmp sle i32 %292, %293
br i1 %294, label %295, label %309
295: ; preds = %291
%296 = load i32**, i32*** %6
%297 = load i32, i32* %14
%298 = sext i32 %297 to i64
%299 = getelementptr inbounds i32*, i32** %296, i64 %298
%300 = load i32, i32* %13
%301 = load i32, i32* %13
%302 = load i32, i32* %13
%303 = sub nsw i32 0, %302
%304 = call i32 @stable_grail_merge_left(i32** %299, i32 %300, i32 %301, i32 %303)
%305 = load i32, i32* %13
%306 = mul nsw i32 2, %305
%307 = load i32, i32* %14
%308 = add nsw i32 %307, %306
store i32 %308, i32* %14
br label %291
309: ; preds = %291
%310 = load i32, i32* %7
%311 = load i32, i32* %14
%312 = sub nsw i32 %310, %311
store i32 %312, i32* %16
%313 = load i32, i32* %16
%314 = load i32, i32* %13
%315 = icmp sgt i32 %313, %314
br i1 %315, label %316, label %328
316: ; preds = %309
%317 = load i32**, i32*** %6
%318 = load i32, i32* %14
%319 = sext i32 %318 to i64
%320 = getelementptr inbounds i32*, i32** %317, i64 %319
%321 = load i32, i32* %13
%322 = load i32, i32* %16
%323 = load i32, i32* %13
%324 = sub nsw i32 %322, %323
%325 = load i32, i32* %13
%326 = sub nsw i32 0, %325
%327 = call i32 @stable_grail_merge_left(i32** %320, i32 %321, i32 %324, i32 %326)
br label %340
328: ; preds = %309
%329 = load i32**, i32*** %6
%330 = load i32, i32* %14
%331 = sext i32 %330 to i64
%332 = getelementptr inbounds i32*, i32** %329, i64 %331
%333 = load i32, i32* %13
%334 = sext i32 %333 to i64
%335 = sub i64 0, %334
%336 = getelementptr inbounds i32*, i32** %332, i64 %335
%337 = load i32, i32* %13
%338 = load i32, i32* %16
%339 = call i32 @stable_grail_rotate(i32** %336, i32 %337, i32 %338)
br label %340
340: ; preds = %328, %316
%341 = load i32, i32* %13
%342 = load i32**, i32*** %6
%343 = sext i32 %341 to i64
%344 = sub i64 0, %343
%345 = getelementptr inbounds i32*, i32** %342, i64 %344
store i32** %345, i32*** %6
br label %346
346: ; preds = %340
%347 = load i32, i32* %13
%348 = mul nsw i32 %347, 2
store i32 %348, i32* %13
br label %282
349: ; preds = %282
%350 = load i32, i32* %7
%351 = load i32, i32* %8
%352 = mul nsw i32 2, %351
%353 = srem i32 %350, %352
store i32 %353, i32* %17
%354 = load i32, i32* %7
%355 = load i32, i32* %17
%356 = sub nsw i32 %354, %355
store i32 %356, i32* %18
%357 = load i32, i32* %17
%358 = load i32, i32* %8
%359 = icmp sle i32 %357, %358
br i1 %359, label %360, label %368
360: ; preds = %349
%361 = load i32**, i32*** %6
%362 = load i32, i32* %18
%363 = sext i32 %362 to i64
%364 = getelementptr inbounds i32*, i32** %361, i64 %363
%365 = load i32, i32* %17
%366 = load i32, i32* %8
%367 = call i32 @stable_grail_rotate(i32** %364, i32 %365, i32 %366)
br label %379
368: ; preds = %349
%369 = load i32**, i32*** %6
%370 = load i32, i32* %18
%371 = sext i32 %370 to i64
%372 = getelementptr inbounds i32*, i32** %369, i64 %371
%373 = load i32, i32* %8
%374 = load i32, i32* %17
%375 = load i32, i32* %8
%376 = sub nsw i32 %374, %375
%377 = load i32, i32* %8
%378 = call i32 @stable_grail_merge_right(i32** %372, i32 %373, i32 %376, i32 %377)
br label %379
379: ; preds = %368, %360
br label %380
380: ; preds = %383, %379
%381 = load i32, i32* %18
%382 = icmp sgt i32 %381, 0
br i1 %382, label %383, label %396
383: ; preds = %380
%384 = load i32, i32* %8
%385 = mul nsw i32 2, %384
%386 = load i32, i32* %18
%387 = sub nsw i32 %386, %385
store i32 %387, i32* %18
%388 = load i32**, i32*** %6
%389 = load i32, i32* %18
%390 = sext i32 %389 to i64
%391 = getelementptr inbounds i32*, i32** %388, i64 %390
%392 = load i32, i32* %8
%393 = load i32, i32* %8
%394 = load i32, i32* %8
%395 = call i32 @stable_grail_merge_right(i32** %391, i32 %392, i32 %393, i32 %394)
br label %380
396: ; preds = %380
ret void
}

LLVM IR (-O2):
define void @stable_grail_build_blocks(i32** %0, i32 %1, i32 %2, i32** %3, i32 %4) {
%6 = icmp slt i32 %2, %4
%7 = select i1 %6, i32 %2, i32 %4
br label %8
8: ; preds = %8, %5
%9 = phi i32 [ %7, %5 ], [ %11, %8 ]
%10 = add nsw i32 %9, -1
%11 = and i32 %10, %9
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %8
13: ; preds = %8
%14 = icmp eq i32 %9, 0
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = icmp sgt i32 %1, 1
br i1 %16, label %17, label %249
17: ; preds = %15
%18 = zext i32 %1 to i64
br label %226
19: ; preds = %13
%20 = sext i32 %9 to i64
%21 = sub nsw i64 0, %20
%22 = getelementptr inbounds i32*, i32** %0, i64 %21
%23 = shl i32 %9, 3
%24 = tail call i32 @memcpy(i32** %3, i32** %22, i32 %23)
%25 = icmp sgt i32 %1, 1
br i1 %25, label %26, label %51
26: ; preds = %19
%27 = zext i32 %1 to i64
br label %28
28: ; preds = %26, %28
%29 = phi i64 [ 1, %26 ], [ %49, %28 ]
%30 = add nsw i64 %29, -1
%31 = getelementptr inbounds i32*, i32** %0, i64 %30
%32 = load i32*, i32** %31
%33 = load i32, i32* %32
%34 = getelementptr inbounds i32*, i32** %0, i64 %29
%35 = load i32*, i32** %34
%36 = load i32, i32* %35
%37 = icmp sgt i32 %33, %36
%38 = zext i1 %37 to i64
%39 = add nuw nsw i64 %30, %38
%40 = getelementptr inbounds i32*, i32** %0, i64 %39
%41 = load i32*, i32** %40
%42 = add nsw i64 %29, -3
%43 = getelementptr inbounds i32*, i32** %0, i64 %42
store i32* %41, i32** %43
%44 = sub nsw i64 %29, %38
%45 = getelementptr inbounds i32*, i32** %0, i64 %44
%46 = load i32*, i32** %45
%47 = add nsw i64 %29, -2
%48 = getelementptr inbounds i32*, i32** %0, i64 %47
store i32* %46, i32** %48
%49 = add nuw nsw i64 %29, 2
%50 = icmp ult i64 %49, %27
br i1 %50, label %28, label %51
51: ; preds = %28, %19
%52 = and i32 %1, 1
%53 = icmp eq i32 %52, 0
br i1 %53, label %62, label %54
54: ; preds = %51
%55 = add nsw i32 %1, -1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32*, i32** %0, i64 %56
%58 = load i32*, i32** %57
%59 = add nsw i32 %1, -3
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32*, i32** %0, i64 %60
store i32* %58, i32** %61
br label %62
62: ; preds = %54, %51
%63 = getelementptr inbounds i32*, i32** %0, i64 -2
%64 = icmp sgt i32 %9, 2
br i1 %64, label %65, label %220
65: ; preds = %62
%66 = sext i32 %1 to i64
br label %67
67: ; preds = %65, %215
%68 = phi i32** [ %218, %215 ], [ %63, %65 ]
%69 = phi i32 [ %70, %215 ], [ 2, %65 ]
%70 = shl i32 %69, 1
%71 = sub nsw i32 %1, %70
%72 = icmp slt i32 %71, 0
br i1 %72, label %85, label %73
73: ; preds = %67
%74 = sub nsw i32 0, %69
%75 = sext i32 %70 to i64
%76 = zext i32 %71 to i64
br label %77
77: ; preds = %73, %77
%78 = phi i64 [ 0, %73 ], [ %81, %77 ]
%79 = getelementptr inbounds i32*, i32** %68, i64 %78
%80 = tail call i32 @stable_grail_merge_left_with_x_buf(i32** %79, i32 %69, i32 %69, i32 %74)
%81 = add i64 %78, %75
%82 = icmp sgt i64 %81, %76
br i1 %82, label %83, label %77
83: ; preds = %77
%84 = trunc i64 %81 to i32
br label %85
85: ; preds = %83, %67
%86 = phi i32 [ 0, %67 ], [ %84, %83 ]
%87 = sub nsw i32 %1, %86
%88 = icmp sgt i32 %87, %69
br i1 %88, label %186, label %89
89: ; preds = %85
%90 = icmp slt i32 %86, %1
br i1 %90, label %91, label %215
91: ; preds = %89
%92 = sext i32 %86 to i64
%93 = sext i32 %69 to i64
%94 = sub nsw i64 %66, %92
%95 = icmp ult i64 %94, 4
br i1 %95, label %166, label %96
96: ; preds = %91
%97 = sub nsw i64 %92, %93
%98 = getelementptr i32*, i32** %68, i64 %97
%99 = getelementptr i32*, i32** %68, i64 %66
%100 = sub nsw i64 0, %93
%101 = getelementptr i32*, i32** %99, i64 %100
%102 = getelementptr i32*, i32** %68, i64 %92
%103 = getelementptr i32*, i32** %68, i64 %66
%104 = icmp ult i32** %98, %103
%105 = icmp ult i32** %102, %101
%106 = and i1 %104, %105
br i1 %106, label %166, label %107
107: ; preds = %96
%108 = and i64 %94, -4
%109 = add nsw i64 %108, %92
%110 = add nsw i64 %108, -4
%111 = lshr exact i64 %110, 2
%112 = add nuw nsw i64 %111, 1
%113 = and i64 %112, 1
%114 = icmp eq i64 %110, 0
br i1 %114, label %148, label %115
115: ; preds = %107
%116 = and i64 %112, 9223372036854775806
br label %117
117: ; preds = %117, %115
%118 = phi i64 [ 0, %115 ], [ %145, %117 ]
%119 = phi i64 [ 0, %115 ], [ %146, %117 ]
%120 = add i64 %118, %92
%121 = getelementptr inbounds i32*, i32** %68, i64 %120
%122 = bitcast i32** %121 to <2 x i32*>*
%123 = load <2 x i32*>, <2 x i32*>* %122
%124 = getelementptr inbounds i32*, i32** %121, i64 2
%125 = bitcast i32** %124 to <2 x i32*>*
%126 = load <2 x i32*>, <2 x i32*>* %125
%127 = sub nsw i64 %120, %93
%128 = getelementptr inbounds i32*, i32** %68, i64 %127
%129 = bitcast i32** %128 to <2 x i32*>*
store <2 x i32*> %123, <2 x i32*>* %129
%130 = getelementptr inbounds i32*, i32** %128, i64 2
%131 = bitcast i32** %130 to <2 x i32*>*
store <2 x i32*> %126, <2 x i32*>* %131
%132 = or i64 %118, 4
%133 = add i64 %132, %92
%134 = getelementptr inbounds i32*, i32** %68, i64 %133
%135 = bitcast i32** %134 to <2 x i32*>*
%136 = load <2 x i32*>, <2 x i32*>* %135
%137 = getelementptr inbounds i32*, i32** %134, i64 2
%138 = bitcast i32** %137 to <2 x i32*>*
%139 = load <2 x i32*>, <2 x i32*>* %138
%140 = sub nsw i64 %133, %93
%141 = getelementptr inbounds i32*, i32** %68, i64 %140
%142 = bitcast i32** %141 to <2 x i32*>*
store <2 x i32*> %136, <2 x i32*>* %142
%143 = getelementptr inbounds i32*, i32** %141, i64 2
%144 = bitcast i32** %143 to <2 x i32*>*
store <2 x i32*> %139, <2 x i32*>* %144
%145 = add nuw i64 %118, 8
%146 = add i64 %119, 2
%147 = icmp eq i64 %146, %116
br i1 %147, label %148, label %117
148: ; preds = %117, %107
%149 = phi i64 [ 0, %107 ], [ %145, %117 ]
%150 = icmp eq i64 %113, 0
br i1 %150, label %164, label %151
151: ; preds = %148
%152 = add i64 %149, %92
%153 = getelementptr inbounds i32*, i32** %68, i64 %152
%154 = bitcast i32** %153 to <2 x i32*>*
%155 = load <2 x i32*>, <2 x i32*>* %154
%156 = getelementptr inbounds i32*, i32** %153, i64 2
%157 = bitcast i32** %156 to <2 x i32*>*
%158 = load <2 x i32*>, <2 x i32*>* %157
%159 = sub nsw i64 %152, %93
%160 = getelementptr inbounds i32*, i32** %68, i64 %159
%161 = bitcast i32** %160 to <2 x i32*>*
store <2 x i32*> %155, <2 x i32*>* %161
%162 = getelementptr inbounds i32*, i32** %160, i64 2
%163 = bitcast i32** %162 to <2 x i32*>*
store <2 x i32*> %158, <2 x i32*>* %163
br label %164
164: ; preds = %148, %151
%165 = icmp eq i64 %94, %108
br i1 %165, label %215, label %166
166: ; preds = %96, %91, %164
%167 = phi i64 [ %92, %96 ], [ %92, %91 ], [ %109, %164 ]
%168 = sub nsw i64 %66, %167
%169 = xor i64 %167, -1
%170 = add nsw i64 %169, %66
%171 = and i64 %168, 3
%172 = icmp eq i64 %171, 0
br i1 %172, label %183, label %173
173: ; preds = %166, %173
%174 = phi i64 [ %180, %173 ], [ %167, %166 ]
%175 = phi i64 [ %181, %173 ], [ 0, %166 ]
%176 = getelementptr inbounds i32*, i32** %68, i64 %174
%177 = load i32*, i32** %176
%178 = sub nsw i64 %174, %93
%179 = getelementptr inbounds i32*, i32** %68, i64 %178
store i32* %177, i32** %179
%180 = add nsw i64 %174, 1
%181 = add i64 %175, 1
%182 = icmp eq i64 %181, %171
br i1 %182, label %183, label %173
183: ; preds = %173, %166
%184 = phi i64 [ %167, %166 ], [ %180, %173 ]
%185 = icmp ult i64 %170, 3
br i1 %185, label %215, label %192
186: ; preds = %85
%187 = sext i32 %86 to i64
%188 = getelementptr inbounds i32*, i32** %68, i64 %187
%189 = sub nsw i32 %87, %69
%190 = sub nsw i32 0, %69
%191 = tail call i32 @stable_grail_merge_left_with_x_buf(i32** %188, i32 %69, i32 %189, i32 %190)
br label %215
192: ; preds = %183, %192
%193 = phi i64 [ %213, %192 ], [ %184, %183 ]
%194 = getelementptr inbounds i32*, i32** %68, i64 %193
%195 = load i32*, i32** %194
%196 = sub nsw i64 %193, %93
%197 = getelementptr inbounds i32*, i32** %68, i64 %196
store i32* %195, i32** %197
%198 = add nsw i64 %193, 1
%199 = getelementptr inbounds i32*, i32** %68, i64 %198
%200 = load i32*, i32** %199
%201 = sub nsw i64 %198, %93
%202 = getelementptr inbounds i32*, i32** %68, i64 %201
store i32* %200, i32** %202
%203 = add nsw i64 %193, 2
%204 = getelementptr inbounds i32*, i32** %68, i64 %203
%205 = load i32*, i32** %204
%206 = sub nsw i64 %203, %93
%207 = getelementptr inbounds i32*, i32** %68, i64 %206
store i32* %205, i32** %207
%208 = add nsw i64 %193, 3
%209 = getelementptr inbounds i32*, i32** %68, i64 %208
%210 = load i32*, i32** %209
%211 = sub nsw i64 %208, %93
%212 = getelementptr inbounds i32*, i32** %68, i64 %211
store i32* %210, i32** %212
%213 = add nsw i64 %193, 4
%214 = icmp eq i64 %213, %66
br i1 %214, label %215, label %192
215: ; preds = %183, %192, %164, %89, %186
%216 = sext i32 %69 to i64
%217 = sub nsw i64 0, %216
%218 = getelementptr inbounds i32*, i32** %68, i64 %217
%219 = icmp slt i32 %70, %9
br i1 %219, label %67, label %220
220: ; preds = %215, %62
%221 = phi i32 [ 2, %62 ], [ %70, %215 ]
%222 = phi i32** [ %63, %62 ], [ %218, %215 ]
%223 = sext i32 %1 to i64
%224 = getelementptr inbounds i32*, i32** %222, i64 %223
%225 = tail call i32 @memcpy(i32** %224, i32** %3, i32 %23)
br label %262
226: ; preds = %17, %226
%227 = phi i64 [ 1, %17 ], [ %247, %226 ]
%228 = add nsw i64 %227, -1
%229 = getelementptr inbounds i32*, i32** %0, i64 %228
%230 = load i32*, i32** %229
%231 = load i32, i32* %230
%232 = getelementptr inbounds i32*, i32** %0, i64 %227
%233 = load i32*, i32** %232
%234 = load i32, i32* %233
%235 = icmp sgt i32 %231, %234
%236 = add nsw i64 %227, -3
%237 = getelementptr inbounds i32*, i32** %0, i64 %236
%238 = zext i1 %235 to i64
%239 = add nuw nsw i64 %228, %238
%240 = getelementptr inbounds i32*, i32** %0, i64 %239
%241 = tail call i32 @stable_grail_swap1(i32** %237, i32** %240)
%242 = add nsw i64 %227, -2
%243 = getelementptr inbounds i32*, i32** %0, i64 %242
%244 = sub nsw i64 %227, %238
%245 = getelementptr inbounds i32*, i32** %0, i64 %244
%246 = tail call i32 @stable_grail_swap1(i32** %243, i32** %245)
%247 = add nuw i64 %227, 2
%248 = icmp slt i64 %247, %18
br i1 %248, label %226, label %249
249: ; preds = %226, %15
%250 = and i32 %1, 1
%251 = icmp eq i32 %250, 0
br i1 %251, label %260, label %252
252: ; preds = %249
%253 = add nsw i32 %1, -1
%254 = sext i32 %253 to i64
%255 = getelementptr inbounds i32*, i32** %0, i64 %254
%256 = add nsw i32 %1, -3
%257 = sext i32 %256 to i64
%258 = getelementptr inbounds i32*, i32** %0, i64 %257
%259 = tail call i32 @stable_grail_swap1(i32** %255, i32** %258)
br label %260
260: ; preds = %252, %249
%261 = getelementptr inbounds i32*, i32** %0, i64 -2
br label %262
262: ; preds = %260, %220
%263 = phi i32 [ %221, %220 ], [ 2, %260 ]
%264 = phi i32** [ %222, %220 ], [ %261, %260 ]
%265 = icmp slt i32 %263, %2
br i1 %265, label %266, label %305
266: ; preds = %262, %301
%267 = phi i32** [ %303, %301 ], [ %264, %262 ]
%268 = phi i32 [ %269, %301 ], [ %263, %262 ]
%269 = shl i32 %268, 1
%270 = sub nsw i32 %1, %269
%271 = icmp slt i32 %270, 0
br i1 %271, label %284, label %272
272: ; preds = %266
%273 = sub nsw i32 0, %268
%274 = sext i32 %269 to i64
%275 = zext i32 %270 to i64
br label %276
276: ; preds = %272, %276
%277 = phi i64 [ 0, %272 ], [ %280, %276 ]
%278 = getelementptr inbounds i32*, i32** %267, i64 %277
%279 = tail call i32 @stable_grail_merge_left(i32** %278, i32 %268, i32 %268, i32 %273)
%280 = add i64 %277, %274
%281 = icmp sgt i64 %280, %275
br i1 %281, label %282, label %276
282: ; preds = %276
%283 = trunc i64 %280 to i32
br label %284
284: ; preds = %282, %266
%285 = phi i32 [ 0, %266 ], [ %283, %282 ]
%286 = sub nsw i32 %1, %285
%287 = icmp sgt i32 %286, %268
%288 = sext i32 %285 to i64
%289 = getelementptr inbounds i32*, i32** %267, i64 %288
br i1 %287, label %290, label %296
290: ; preds = %284
%291 = sub nsw i32 %286, %268
%292 = sub nsw i32 0, %268
%293 = tail call i32 @stable_grail_merge_left(i32** %289, i32 %268, i32 %291, i32 %292)
%294 = sext i32 %268 to i64
%295 = sub nsw i64 0, %294
br label %301
296: ; preds = %284
%297 = sext i32 %268 to i64
%298 = sub nsw i64 0, %297
%299 = getelementptr inbounds i32*, i32** %289, i64 %298
%300 = tail call i32 @stable_grail_rotate(i32** %299, i32 %268, i32 %286)
br label %301
301: ; preds = %296, %290
%302 = phi i64 [ %298, %296 ], [ %295, %290 ]
%303 = getelementptr inbounds i32*, i32** %267, i64 %302
%304 = icmp slt i32 %269, %2
br i1 %304, label %266, label %305
305: ; preds = %301, %262
%306 = phi i32** [ %264, %262 ], [ %303, %301 ]
%307 = shl nsw i32 %2, 1
%308 = srem i32 %1, %307
%309 = sub nsw i32 %1, %308
%310 = icmp sgt i32 %308, %2
%311 = sext i32 %309 to i64
%312 = getelementptr inbounds i32*, i32** %306, i64 %311
br i1 %310, label %315, label %313
313: ; preds = %305
%314 = tail call i32 @stable_grail_rotate(i32** %312, i32 %308, i32 %2)
br label %318
315: ; preds = %305
%316 = sub nsw i32 %308, %2
%317 = tail call i32 @stable_grail_merge_right(i32** %312, i32 %2, i32 %316, i32 %2)
br label %318
318: ; preds = %315, %313
%319 = icmp sgt i32 %309, 0
br i1 %319, label %320, label %327
320: ; preds = %318, %320
%321 = phi i32 [ %322, %320 ], [ %309, %318 ]
%322 = sub nsw i32 %321, %307
%323 = sext i32 %322 to i64
%324 = getelementptr inbounds i32*, i32** %306, i64 %323
%325 = tail call i32 @stable_grail_merge_right(i32** %324, i32 %2, i32 %2, i32 %2)
%326 = icmp sgt i32 %322, 0
br i1 %326, label %320, label %327
327: ; preds = %320, %318
ret void
}