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),%rdx
shl    $0x3,%rdx
call   1060 <memcpy@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1291 <stable_grail_build_blocks+0x131>
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    123c <stable_grail_build_blocks+0xdc>
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    11f8 <stable_grail_build_blocks+0x98>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12c7 <stable_grail_build_blocks+0x167>
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    13e0 <stable_grail_build_blocks+0x280>
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
mov    $0x0,%al
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    12fb <stable_grail_build_blocks+0x19b>
mov    -0xc(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    1377 <stable_grail_build_blocks+0x217>
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
mov    $0x0,%al
call   1080 <stable_grail_merge_left_with_x_buf@plt>
jmp    13b8 <stable_grail_build_blocks+0x258>
jmp    137c <stable_grail_build_blocks+0x21c>
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13b3 <stable_grail_build_blocks+0x253>
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    137c <stable_grail_build_blocks+0x21c>
jmp    13b8 <stable_grail_build_blocks+0x258>
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    12da <stable_grail_build_blocks+0x17a>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x40(%rbp),%rdx
shl    $0x3,%rdx
call   1060 <memcpy@plt>
jmp    150f <stable_grail_build_blocks+0x3af>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    14bb <stable_grail_build_blocks+0x35b>
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
mov    $0x0,%al
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
mov    $0x0,%al
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     14fc <stable_grail_build_blocks+0x39c>
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
mov    $0x0,%al
call   1070 <stable_grail_swap1@plt>
mov    -0x8(%rbp),%rax
add    $0xfffffffffffffff0,%rax
mov    %rax,-0x8(%rbp)
movl   $0x2,-0x28(%rbp)
jmp    1514 <stable_grail_build_blocks+0x3b4>
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1605 <stable_grail_build_blocks+0x4a5>
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     1573 <stable_grail_build_blocks+0x413>
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
mov    $0x0,%al
call   1050 <stable_grail_merge_left@plt>
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1535 <stable_grail_build_blocks+0x3d5>
mov    -0xc(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    15b1 <stable_grail_build_blocks+0x451>
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
mov    $0x0,%al
call   1050 <stable_grail_merge_left@plt>
jmp    15dd <stable_grail_build_blocks+0x47d>
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
mov    $0x0,%al
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    1514 <stable_grail_build_blocks+0x3b4>
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     164a <stable_grail_build_blocks+0x4ea>
mov    -0x8(%rbp),%rdi
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x38(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    $0x0,%al
call   1040 <stable_grail_rotate@plt>
jmp    166c <stable_grail_build_blocks+0x50c>
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
mov    $0x0,%al
call   1030 <stable_grail_merge_right@plt>
jmp    1671 <stable_grail_build_blocks+0x511>
cmpl   $0x0,-0x3c(%rbp)
jle    16ad <stable_grail_build_blocks+0x54d>
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
mov    $0x0,%al
call   1030 <stable_grail_merge_right@plt>
jmp    1671 <stable_grail_build_blocks+0x511>
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,%ebx
mov    %esi,%r13d
mov    %rdi,%r12
cmp    %r8d,%edx
cmovl  %edx,%r8d
nopl   (%rax)
mov    %r8d,%ebp
lea    -0x1(%rbp),%r8d
and    %ebp,%r8d
jne    1180 <stable_grail_build_blocks+0x20>
test   %ebp,%ebp
mov    %r13,0x28(%rsp)
mov    %rbx,0x8(%rsp)
je     14b2 <stable_grail_build_blocks+0x352>
movslq %ebp,%rdx
shl    $0x3,%rdx
mov    %r12,%rsi
sub    %rdx,%rsi
mov    %rcx,0x38(%rsp)
mov    %rcx,%rdi
mov    %rdx,0x30(%rsp)
call   1060 <memcpy@plt>
cmp    $0x2,%r13d
jl     120d <stable_grail_build_blocks+0xad>
mov    %r13d,%eax
mov    $0x1,%ecx
nopl   0x0(%rax,%rax,1)
mov    -0x8(%r12,%rcx,8),%rdx
mov    (%r12,%rcx,8),%rsi
mov    (%rdx),%edx
xor    %edi,%edi
cmp    (%rsi),%edx
setg   %dil
lea    (%rcx,%rdi,1),%rdx
mov    -0x8(%r12,%rdx,8),%rdx
mov    %rdx,-0x18(%r12,%rcx,8)
shl    $0x3,%rdi
mov    %r12,%rdx
sub    %rdi,%rdx
mov    (%rdx,%rcx,8),%rdx
mov    %rdx,-0x10(%r12,%rcx,8)
add    $0x2,%rcx
cmp    %rax,%rcx
jb     11d0 <stable_grail_build_blocks+0x70>
movslq %r13d,%rbx
test   $0x1,%r13b
je     1220 <stable_grail_build_blocks+0xc0>
mov    -0x8(%r12,%rbx,8),%rax
mov    %rax,-0x18(%r12,%rbx,8)
add    $0xfffffffffffffff0,%r12
mov    $0x2,%r10d
cmp    $0x3,%ebp
jl     1494 <stable_grail_build_blocks+0x334>
mov    $0x2,%r10d
mov    %rbp,0x40(%rsp)
mov    %rbx,(%rsp)
jmp    127e <stable_grail_build_blocks+0x11e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %r15d,%rax
lea    (%r12,%rax,8),%rdi
mov    %ebx,%ecx
neg    %ecx
mov    %ebx,%esi
xor    %eax,%eax
mov    %r10,%rbx
call   1080 <stable_grail_merge_left_with_x_buf@plt>
mov    %rbx,%r10
mov    (%rsp),%rbx
shl    $0x3,%r14
sub    %r14,%r12
cmp    %ebp,%r10d
jge    1494 <stable_grail_build_blocks+0x334>
mov    %r10d,%ebx
lea    (%rbx,%rbx,1),%r10d
mov    %r13d,%eax
sub    %r10d,%eax
mov    $0x0,%r15d
js     12f1 <stable_grail_build_blocks+0x191>
mov    %ebx,%ebp
neg    %ebp
mov    %r10,0x10(%rsp)
movslq %r10d,%r14
mov    %eax,%eax
mov    %rax,0x20(%rsp)
lea    0x0(,%r14,8),%r13
mov    %r12,0x18(%rsp)
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1080 <stable_grail_merge_left_with_x_buf@plt>
add    %r14,%r15
add    %r13,%r12
cmp    0x20(%rsp),%r15
jle    12c0 <stable_grail_build_blocks+0x160>
mov    0x28(%rsp),%r13
mov    0x18(%rsp),%r12
mov    0x10(%rsp),%r10
mov    0x40(%rsp),%rbp
mov    %r13d,%edx
sub    %r15d,%edx
movslq %ebx,%r14
sub    %ebx,%edx
jg     1250 <stable_grail_build_blocks+0xf0>
cmp    %r13d,%r15d
mov    (%rsp),%rbx
jge    126e <stable_grail_build_blocks+0x10e>
movslq %r15d,%rax
mov    %rbx,%rcx
sub    %rax,%rcx
cmp    $0x4,%rcx
jb     1400 <stable_grail_build_blocks+0x2a0>
mov    %rax,%rdi
sub    %r14,%rdi
lea    (%r12,%rdi,8),%rsi
lea    (%r12,%rbx,8),%rdx
cmp    %rdx,%rsi
jae    134d <stable_grail_build_blocks+0x1ed>
lea    0x0(,%r14,8),%rsi
sub    %rsi,%rdx
lea    (%r12,%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,%r9
shr    $0x2,%r9
add    $0x1,%r9
test   %rdx,%rdx
je     13c2 <stable_grail_build_blocks+0x262>
mov    %r9,%rsi
and    $0xfffffffffffffffe,%rsi
lea    (%r12,%rdi,8),%rdx
add    $0x30,%rdx
lea    (%r12,%rax,8),%rbx
add    $0x30,%rbx
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movups -0x30(%rbx,%rdi,8),%xmm0
movups -0x20(%rbx,%rdi,8),%xmm1
movups %xmm0,-0x30(%rdx,%rdi,8)
movups %xmm1,-0x20(%rdx,%rdi,8)
movups -0x10(%rbx,%rdi,8),%xmm0
movups (%rbx,%rdi,8),%xmm1
movups %xmm0,-0x10(%rdx,%rdi,8)
movups %xmm1,(%rdx,%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,%r9b
mov    (%rsp),%rbx
je     13ea <stable_grail_build_blocks+0x28a>
add    %rax,%rdi
movups (%r12,%rdi,8),%xmm0
movups 0x10(%r12,%rdi,8),%xmm1
sub    %r14,%rdi
movups %xmm0,(%r12,%rdi,8)
movups %xmm1,0x10(%r12,%rdi,8)
cmp    %r8,%rcx
je     126e <stable_grail_build_blocks+0x10e>
add    %r8,%rax
cs 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(,%r14,8),%rdi
mov    %r12,%rsi
sub    %rdi,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12,%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     126e <stable_grail_build_blocks+0x10e>
lea    0x0(,%r14,8),%rdx
mov    %r12,%rcx
sub    %rdx,%rcx
add    $0x18,%rcx
xchg   %ax,%ax
mov    (%r12,%rax,8),%rdx
mov    %rdx,-0x18(%rcx,%rax,8)
mov    0x8(%r12,%rax,8),%rdx
mov    %rdx,-0x10(%rcx,%rax,8)
mov    0x10(%r12,%rax,8),%rdx
mov    %rdx,-0x8(%rcx,%rax,8)
mov    0x18(%r12,%rax,8),%rdx
mov    %rdx,(%rcx,%rax,8)
add    $0x4,%rax
cmp    %rax,%rbx
jne    1460 <stable_grail_build_blocks+0x300>
jmp    126e <stable_grail_build_blocks+0x10e>
lea    (%r12,%rbx,8),%rdi
mov    0x38(%rsp),%rsi
mov    0x30(%rsp),%rdx
mov    %r10,%rbx
call   1060 <memcpy@plt>
mov    %rbx,%rsi
jmp    1546 <stable_grail_build_blocks+0x3e6>
cmp    $0x2,%r13d
jl     151d <stable_grail_build_blocks+0x3bd>
mov    %r13d,%r15d
lea    0x8(%r12),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
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    (%r12,%rax,8),%rsi
xor    %eax,%eax
call   1070 <stable_grail_swap1@plt>
lea    -0x10(%r14),%rdi
shl    $0x3,%rbp
mov    %r14,%rsi
sub    %rbp,%rsi
xor    %eax,%eax
call   1070 <stable_grail_swap1@plt>
add    $0x10,%r14
lea    0x2(%rbx),%rax
add    $0x3,%rbx
cmp    %r15,%rbx
mov    %rax,%rbx
jl     14d0 <stable_grail_build_blocks+0x370>
test   $0x1,%r13b
je     153d <stable_grail_build_blocks+0x3dd>
movslq %r13d,%rax
lea    (%r12,%rax,8),%rdi
add    $0xfffffffffffffff8,%rdi
lea    (%r12,%rax,8),%rsi
add    $0xffffffffffffffe8,%rsi
xor    %eax,%eax
call   1070 <stable_grail_swap1@plt>
add    $0xfffffffffffffff0,%r12
mov    $0x2,%esi
mov    0x8(%rsp),%r14
cmp    %r14d,%esi
jl     15b3 <stable_grail_build_blocks+0x453>
lea    (%r14,%r14,1),%ebx
mov    %r13d,%eax
cltd
idiv   %ebx
sub    %edx,%r13d
mov    %edx,%eax
movslq %r13d,%rcx
lea    (%r12,%rcx,8),%rdi
sub    %r14d,%eax
jle    1654 <stable_grail_build_blocks+0x4f4>
mov    %r14d,%esi
mov    %eax,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1030 <stable_grail_merge_right@plt>
test   %r13d,%r13d
jg     1665 <stable_grail_build_blocks+0x505>
jmp    1693 <stable_grail_build_blocks+0x533>
nopl   0x0(%rax)
mov    %rbx,%rbp
neg    %rbp
shl    $0x3,%rbx
sub    %rbx,%rdi
xor    %eax,%eax
call   1040 <stable_grail_rotate@plt>
mov    %rbp,%rbx
lea    (%r12,%rbx,8),%r12
mov    %r15d,%esi
cmp    %r14d,%r15d
jge    1550 <stable_grail_build_blocks+0x3f0>
lea    (%rsi,%rsi,1),%r15d
mov    %r13d,%eax
sub    %r15d,%eax
mov    $0x0,%ebx
js     1626 <stable_grail_build_blocks+0x4c6>
mov    %r12,%rbp
mov    %esi,%r12d
neg    %r12d
mov    %r15d,0x10(%rsp)
movslq %r15d,%r14
mov    %eax,%eax
mov    %rax,0x20(%rsp)
lea    0x0(,%r14,8),%r15
mov    %rbp,0x18(%rsp)
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %esi,%edx
mov    %r12d,%ecx
xor    %eax,%eax
mov    %rsi,%r13
call   1050 <stable_grail_merge_left@plt>
mov    %r13,%rsi
add    %r14,%rbx
add    %r15,%rbp
cmp    0x20(%rsp),%rbx
jle    15f0 <stable_grail_build_blocks+0x490>
mov    0x8(%rsp),%r14
mov    0x28(%rsp),%r13
mov    0x18(%rsp),%r12
mov    0x10(%rsp),%r15d
mov    %r13d,%edx
sub    %ebx,%edx
mov    %edx,%eax
movslq %ebx,%rcx
lea    (%r12,%rcx,8),%rdi
movslq %esi,%rbx
sub    %esi,%eax
jle    1590 <stable_grail_build_blocks+0x430>
mov    %esi,%ecx
neg    %ecx
mov    %eax,%edx
xor    %eax,%eax
call   1050 <stable_grail_merge_left@plt>
neg    %rbx
jmp    15a7 <stable_grail_build_blocks+0x447>
mov    %edx,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <stable_grail_rotate@plt>
test   %r13d,%r13d
jle    1693 <stable_grail_build_blocks+0x533>
mov    %ebx,%ebp
neg    %ebp
nopl   0x0(%rax)
lea    0x0(%rbp,%r13,1),%eax
sub    %ebx,%r13d
cltq
lea    (%r12,%rax,8),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1030 <stable_grail_merge_right@plt>
test   %r13d,%r13d
jg     1670 <stable_grail_build_blocks+0x510>
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 = bitcast i32** %44 to i8*
%46 = load i32**, i32*** %6
%47 = load i32, i32* %19
%48 = sext i32 %47 to i64
%49 = sub i64 0, %48
%50 = getelementptr inbounds i32*, i32** %46, i64 %49
%51 = bitcast i32** %50 to i8*
%52 = load i32, i32* %19
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 8
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 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_left_with_x_buf to i32 (i32**, i32, i32, i32, ...)*)(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 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_left_with_x_buf to i32 (i32**, i32, i32, i32, ...)*)(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 = bitcast i32** %204 to i8*
%206 = load i32**, i32*** %9
%207 = bitcast i32** %206 to i8*
%208 = load i32, i32* %19
%209 = sext i32 %208 to i64
%210 = mul i64 %209, 8
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 (i32**, i32**, ...) bitcast (i32 (...)* @stable_grail_swap1 to i32 (i32**, i32**, ...)*)(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 (i32**, i32**, ...) bitcast (i32 (...)* @stable_grail_swap1 to i32 (i32**, i32**, ...)*)(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 (i32**, i32**, ...) bitcast (i32 (...)* @stable_grail_swap1 to i32 (i32**, i32**, ...)*)(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 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_left to i32 (i32**, i32, i32, i32, ...)*)(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 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_left to i32 (i32**, i32, i32, i32, ...)*)(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 (i32**, i32, i32, ...) bitcast (i32 (...)* @stable_grail_rotate to i32 (i32**, i32, i32, ...)*)(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 (i32**, i32, i32, ...) bitcast (i32 (...)* @stable_grail_rotate to i32 (i32**, i32, i32, ...)*)(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 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_right to i32 (i32**, i32, i32, i32, ...)*)(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 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_right to i32 (i32**, i32, i32, i32, ...)*)(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** nocapture %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 %250
17: ; preds = %15
%18 = zext i32 %1 to i64
br label %227
19: ; preds = %13
%20 = bitcast i32** %3 to i8*
%21 = sext i32 %9 to i64
%22 = sub nsw i64 0, %21
%23 = getelementptr inbounds i32*, i32** %0, i64 %22
%24 = bitcast i32** %23 to i8*
%25 = shl nsw i64 %21, 3
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %20, i8* align 8 %24, i64 %25, i1 false)
%26 = icmp sgt i32 %1, 1
br i1 %26, label %27, label %52
27: ; preds = %19
%28 = zext i32 %1 to i64
br label %29
29: ; preds = %27, %29
%30 = phi i64 [ 1, %27 ], [ %50, %29 ]
%31 = add nsw i64 %30, -1
%32 = getelementptr inbounds i32*, i32** %0, i64 %31
%33 = load i32*, i32** %32
%34 = load i32, i32* %33
%35 = getelementptr inbounds i32*, i32** %0, i64 %30
%36 = load i32*, i32** %35
%37 = load i32, i32* %36
%38 = icmp sgt i32 %34, %37
%39 = zext i1 %38 to i64
%40 = add nuw nsw i64 %31, %39
%41 = getelementptr inbounds i32*, i32** %0, i64 %40
%42 = load i32*, i32** %41
%43 = add nsw i64 %30, -3
%44 = getelementptr inbounds i32*, i32** %0, i64 %43
store i32* %42, i32** %44
%45 = sub nsw i64 %30, %39
%46 = getelementptr inbounds i32*, i32** %0, i64 %45
%47 = load i32*, i32** %46
%48 = add nsw i64 %30, -2
%49 = getelementptr inbounds i32*, i32** %0, i64 %48
store i32* %47, i32** %49
%50 = add nuw nsw i64 %30, 2
%51 = icmp ult i64 %50, %28
br i1 %51, label %29, label %52
52: ; preds = %29, %19
%53 = and i32 %1, 1
%54 = icmp eq i32 %53, 0
br i1 %54, label %63, label %55
55: ; preds = %52
%56 = add nsw i32 %1, -1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32*, i32** %0, i64 %57
%59 = load i32*, i32** %58
%60 = add nsw i32 %1, -3
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32*, i32** %0, i64 %61
store i32* %59, i32** %62
br label %63
63: ; preds = %55, %52
%64 = getelementptr inbounds i32*, i32** %0, i64 -2
%65 = icmp sgt i32 %9, 2
br i1 %65, label %66, label %221
66: ; preds = %63
%67 = sext i32 %1 to i64
br label %68
68: ; preds = %66, %216
%69 = phi i32** [ %219, %216 ], [ %64, %66 ]
%70 = phi i32 [ %71, %216 ], [ 2, %66 ]
%71 = shl i32 %70, 1
%72 = sub nsw i32 %1, %71
%73 = icmp slt i32 %72, 0
br i1 %73, label %86, label %74
74: ; preds = %68
%75 = sub nsw i32 0, %70
%76 = sext i32 %71 to i64
%77 = zext i32 %72 to i64
br label %78
78: ; preds = %74, %78
%79 = phi i64 [ 0, %74 ], [ %82, %78 ]
%80 = getelementptr inbounds i32*, i32** %69, i64 %79
%81 = tail call i32 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_left_with_x_buf to i32 (i32**, i32, i32, i32, ...)*)(i32** %80, i32 %70, i32 %70, i32 %75)
%82 = add i64 %79, %76
%83 = icmp sgt i64 %82, %77
br i1 %83, label %84, label %78
84: ; preds = %78
%85 = trunc i64 %82 to i32
br label %86
86: ; preds = %84, %68
%87 = phi i32 [ 0, %68 ], [ %85, %84 ]
%88 = sub nsw i32 %1, %87
%89 = icmp sgt i32 %88, %70
br i1 %89, label %187, label %90
90: ; preds = %86
%91 = icmp slt i32 %87, %1
br i1 %91, label %92, label %216
92: ; preds = %90
%93 = sext i32 %87 to i64
%94 = sext i32 %70 to i64
%95 = sub nsw i64 %67, %93
%96 = icmp ult i64 %95, 4
br i1 %96, label %167, label %97
97: ; preds = %92
%98 = sub nsw i64 %93, %94
%99 = getelementptr i32*, i32** %69, i64 %98
%100 = getelementptr i32*, i32** %69, i64 %67
%101 = sub nsw i64 0, %94
%102 = getelementptr i32*, i32** %100, i64 %101
%103 = getelementptr i32*, i32** %69, i64 %93
%104 = getelementptr i32*, i32** %69, i64 %67
%105 = icmp ult i32** %99, %104
%106 = icmp ult i32** %103, %102
%107 = and i1 %105, %106
br i1 %107, label %167, label %108
108: ; preds = %97
%109 = and i64 %95, -4
%110 = add nsw i64 %109, %93
%111 = add nsw i64 %109, -4
%112 = lshr exact i64 %111, 2
%113 = add nuw nsw i64 %112, 1
%114 = and i64 %113, 1
%115 = icmp eq i64 %111, 0
br i1 %115, label %149, label %116
116: ; preds = %108
%117 = and i64 %113, 9223372036854775806
br label %118
118: ; preds = %118, %116
%119 = phi i64 [ 0, %116 ], [ %146, %118 ]
%120 = phi i64 [ 0, %116 ], [ %147, %118 ]
%121 = add i64 %119, %93
%122 = getelementptr inbounds i32*, i32** %69, i64 %121
%123 = bitcast i32** %122 to <2 x i32*>*
%124 = load <2 x i32*>, <2 x i32*>* %123
%125 = getelementptr inbounds i32*, i32** %122, i64 2
%126 = bitcast i32** %125 to <2 x i32*>*
%127 = load <2 x i32*>, <2 x i32*>* %126
%128 = sub nsw i64 %121, %94
%129 = getelementptr inbounds i32*, i32** %69, i64 %128
%130 = bitcast i32** %129 to <2 x i32*>*
store <2 x i32*> %124, <2 x i32*>* %130
%131 = getelementptr inbounds i32*, i32** %129, i64 2
%132 = bitcast i32** %131 to <2 x i32*>*
store <2 x i32*> %127, <2 x i32*>* %132
%133 = or i64 %119, 4
%134 = add i64 %133, %93
%135 = getelementptr inbounds i32*, i32** %69, i64 %134
%136 = bitcast i32** %135 to <2 x i32*>*
%137 = load <2 x i32*>, <2 x i32*>* %136
%138 = getelementptr inbounds i32*, i32** %135, i64 2
%139 = bitcast i32** %138 to <2 x i32*>*
%140 = load <2 x i32*>, <2 x i32*>* %139
%141 = sub nsw i64 %134, %94
%142 = getelementptr inbounds i32*, i32** %69, i64 %141
%143 = bitcast i32** %142 to <2 x i32*>*
store <2 x i32*> %137, <2 x i32*>* %143
%144 = getelementptr inbounds i32*, i32** %142, i64 2
%145 = bitcast i32** %144 to <2 x i32*>*
store <2 x i32*> %140, <2 x i32*>* %145
%146 = add nuw i64 %119, 8
%147 = add i64 %120, 2
%148 = icmp eq i64 %147, %117
br i1 %148, label %149, label %118
149: ; preds = %118, %108
%150 = phi i64 [ 0, %108 ], [ %146, %118 ]
%151 = icmp eq i64 %114, 0
br i1 %151, label %165, label %152
152: ; preds = %149
%153 = add i64 %150, %93
%154 = getelementptr inbounds i32*, i32** %69, i64 %153
%155 = bitcast i32** %154 to <2 x i32*>*
%156 = load <2 x i32*>, <2 x i32*>* %155
%157 = getelementptr inbounds i32*, i32** %154, i64 2
%158 = bitcast i32** %157 to <2 x i32*>*
%159 = load <2 x i32*>, <2 x i32*>* %158
%160 = sub nsw i64 %153, %94
%161 = getelementptr inbounds i32*, i32** %69, i64 %160
%162 = bitcast i32** %161 to <2 x i32*>*
store <2 x i32*> %156, <2 x i32*>* %162
%163 = getelementptr inbounds i32*, i32** %161, i64 2
%164 = bitcast i32** %163 to <2 x i32*>*
store <2 x i32*> %159, <2 x i32*>* %164
br label %165
165: ; preds = %149, %152
%166 = icmp eq i64 %95, %109
br i1 %166, label %216, label %167
167: ; preds = %97, %92, %165
%168 = phi i64 [ %93, %97 ], [ %93, %92 ], [ %110, %165 ]
%169 = sub nsw i64 %67, %168
%170 = xor i64 %168, -1
%171 = add nsw i64 %170, %67
%172 = and i64 %169, 3
%173 = icmp eq i64 %172, 0
br i1 %173, label %184, label %174
174: ; preds = %167, %174
%175 = phi i64 [ %181, %174 ], [ %168, %167 ]
%176 = phi i64 [ %182, %174 ], [ 0, %167 ]
%177 = getelementptr inbounds i32*, i32** %69, i64 %175
%178 = load i32*, i32** %177
%179 = sub nsw i64 %175, %94
%180 = getelementptr inbounds i32*, i32** %69, i64 %179
store i32* %178, i32** %180
%181 = add nsw i64 %175, 1
%182 = add i64 %176, 1
%183 = icmp eq i64 %182, %172
br i1 %183, label %184, label %174
184: ; preds = %174, %167
%185 = phi i64 [ %168, %167 ], [ %181, %174 ]
%186 = icmp ult i64 %171, 3
br i1 %186, label %216, label %193
187: ; preds = %86
%188 = sext i32 %87 to i64
%189 = getelementptr inbounds i32*, i32** %69, i64 %188
%190 = sub nsw i32 %88, %70
%191 = sub nsw i32 0, %70
%192 = tail call i32 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_left_with_x_buf to i32 (i32**, i32, i32, i32, ...)*)(i32** %189, i32 %70, i32 %190, i32 %191)
br label %216
193: ; preds = %184, %193
%194 = phi i64 [ %214, %193 ], [ %185, %184 ]
%195 = getelementptr inbounds i32*, i32** %69, i64 %194
%196 = load i32*, i32** %195
%197 = sub nsw i64 %194, %94
%198 = getelementptr inbounds i32*, i32** %69, i64 %197
store i32* %196, i32** %198
%199 = add nsw i64 %194, 1
%200 = getelementptr inbounds i32*, i32** %69, i64 %199
%201 = load i32*, i32** %200
%202 = sub nsw i64 %199, %94
%203 = getelementptr inbounds i32*, i32** %69, i64 %202
store i32* %201, i32** %203
%204 = add nsw i64 %194, 2
%205 = getelementptr inbounds i32*, i32** %69, i64 %204
%206 = load i32*, i32** %205
%207 = sub nsw i64 %204, %94
%208 = getelementptr inbounds i32*, i32** %69, i64 %207
store i32* %206, i32** %208
%209 = add nsw i64 %194, 3
%210 = getelementptr inbounds i32*, i32** %69, i64 %209
%211 = load i32*, i32** %210
%212 = sub nsw i64 %209, %94
%213 = getelementptr inbounds i32*, i32** %69, i64 %212
store i32* %211, i32** %213
%214 = add nsw i64 %194, 4
%215 = icmp eq i64 %214, %67
br i1 %215, label %216, label %193
216: ; preds = %184, %193, %165, %90, %187
%217 = sext i32 %70 to i64
%218 = sub nsw i64 0, %217
%219 = getelementptr inbounds i32*, i32** %69, i64 %218
%220 = icmp slt i32 %71, %9
br i1 %220, label %68, label %221
221: ; preds = %216, %63
%222 = phi i32 [ 2, %63 ], [ %71, %216 ]
%223 = phi i32** [ %64, %63 ], [ %219, %216 ]
%224 = sext i32 %1 to i64
%225 = getelementptr inbounds i32*, i32** %223, i64 %224
%226 = bitcast i32** %225 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %226, i8* align 8 %20, i64 %25, i1 false)
br label %263
227: ; preds = %17, %227
%228 = phi i64 [ 1, %17 ], [ %248, %227 ]
%229 = add nsw i64 %228, -1
%230 = getelementptr inbounds i32*, i32** %0, i64 %229
%231 = load i32*, i32** %230
%232 = load i32, i32* %231
%233 = getelementptr inbounds i32*, i32** %0, i64 %228
%234 = load i32*, i32** %233
%235 = load i32, i32* %234
%236 = icmp sgt i32 %232, %235
%237 = add nsw i64 %228, -3
%238 = getelementptr inbounds i32*, i32** %0, i64 %237
%239 = zext i1 %236 to i64
%240 = add nuw nsw i64 %229, %239
%241 = getelementptr inbounds i32*, i32** %0, i64 %240
%242 = tail call i32 (i32**, i32**, ...) bitcast (i32 (...)* @stable_grail_swap1 to i32 (i32**, i32**, ...)*)(i32** %238, i32** %241)
%243 = add nsw i64 %228, -2
%244 = getelementptr inbounds i32*, i32** %0, i64 %243
%245 = sub nsw i64 %228, %239
%246 = getelementptr inbounds i32*, i32** %0, i64 %245
%247 = tail call i32 (i32**, i32**, ...) bitcast (i32 (...)* @stable_grail_swap1 to i32 (i32**, i32**, ...)*)(i32** %244, i32** %246)
%248 = add nuw i64 %228, 2
%249 = icmp slt i64 %248, %18
br i1 %249, label %227, label %250
250: ; preds = %227, %15
%251 = and i32 %1, 1
%252 = icmp eq i32 %251, 0
br i1 %252, label %261, label %253
253: ; preds = %250
%254 = add nsw i32 %1, -1
%255 = sext i32 %254 to i64
%256 = getelementptr inbounds i32*, i32** %0, i64 %255
%257 = add nsw i32 %1, -3
%258 = sext i32 %257 to i64
%259 = getelementptr inbounds i32*, i32** %0, i64 %258
%260 = tail call i32 (i32**, i32**, ...) bitcast (i32 (...)* @stable_grail_swap1 to i32 (i32**, i32**, ...)*)(i32** %256, i32** %259)
br label %261
261: ; preds = %253, %250
%262 = getelementptr inbounds i32*, i32** %0, i64 -2
br label %263
263: ; preds = %261, %221
%264 = phi i32 [ %222, %221 ], [ 2, %261 ]
%265 = phi i32** [ %223, %221 ], [ %262, %261 ]
%266 = icmp slt i32 %264, %2
br i1 %266, label %267, label %306
267: ; preds = %263, %302
%268 = phi i32** [ %304, %302 ], [ %265, %263 ]
%269 = phi i32 [ %270, %302 ], [ %264, %263 ]
%270 = shl i32 %269, 1
%271 = sub nsw i32 %1, %270
%272 = icmp slt i32 %271, 0
br i1 %272, label %285, label %273
273: ; preds = %267
%274 = sub nsw i32 0, %269
%275 = sext i32 %270 to i64
%276 = zext i32 %271 to i64
br label %277
277: ; preds = %273, %277
%278 = phi i64 [ 0, %273 ], [ %281, %277 ]
%279 = getelementptr inbounds i32*, i32** %268, i64 %278
%280 = tail call i32 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_left to i32 (i32**, i32, i32, i32, ...)*)(i32** %279, i32 %269, i32 %269, i32 %274)
%281 = add i64 %278, %275
%282 = icmp sgt i64 %281, %276
br i1 %282, label %283, label %277
283: ; preds = %277
%284 = trunc i64 %281 to i32
br label %285
285: ; preds = %283, %267
%286 = phi i32 [ 0, %267 ], [ %284, %283 ]
%287 = sub nsw i32 %1, %286
%288 = icmp sgt i32 %287, %269
%289 = sext i32 %286 to i64
%290 = getelementptr inbounds i32*, i32** %268, i64 %289
br i1 %288, label %291, label %297
291: ; preds = %285
%292 = sub nsw i32 %287, %269
%293 = sub nsw i32 0, %269
%294 = tail call i32 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_left to i32 (i32**, i32, i32, i32, ...)*)(i32** %290, i32 %269, i32 %292, i32 %293)
%295 = sext i32 %269 to i64
%296 = sub nsw i64 0, %295
br label %302
297: ; preds = %285
%298 = sext i32 %269 to i64
%299 = sub nsw i64 0, %298
%300 = getelementptr inbounds i32*, i32** %290, i64 %299
%301 = tail call i32 (i32**, i32, i32, ...) bitcast (i32 (...)* @stable_grail_rotate to i32 (i32**, i32, i32, ...)*)(i32** %300, i32 %269, i32 %287)
br label %302
302: ; preds = %297, %291
%303 = phi i64 [ %299, %297 ], [ %296, %291 ]
%304 = getelementptr inbounds i32*, i32** %268, i64 %303
%305 = icmp slt i32 %270, %2
br i1 %305, label %267, label %306
306: ; preds = %302, %263
%307 = phi i32** [ %265, %263 ], [ %304, %302 ]
%308 = shl nsw i32 %2, 1
%309 = srem i32 %1, %308
%310 = sub nsw i32 %1, %309
%311 = icmp sgt i32 %309, %2
%312 = sext i32 %310 to i64
%313 = getelementptr inbounds i32*, i32** %307, i64 %312
br i1 %311, label %316, label %314
314: ; preds = %306
%315 = tail call i32 (i32**, i32, i32, ...) bitcast (i32 (...)* @stable_grail_rotate to i32 (i32**, i32, i32, ...)*)(i32** %313, i32 %309, i32 %2)
br label %319
316: ; preds = %306
%317 = sub nsw i32 %309, %2
%318 = tail call i32 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_right to i32 (i32**, i32, i32, i32, ...)*)(i32** %313, i32 %2, i32 %317, i32 %2)
br label %319
319: ; preds = %316, %314
%320 = icmp sgt i32 %310, 0
br i1 %320, label %321, label %328
321: ; preds = %319, %321
%322 = phi i32 [ %323, %321 ], [ %310, %319 ]
%323 = sub nsw i32 %322, %308
%324 = sext i32 %323 to i64
%325 = getelementptr inbounds i32*, i32** %307, i64 %324
%326 = tail call i32 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @stable_grail_merge_right to i32 (i32**, i32, i32, i32, ...)*)(i32** %325, i32 %2, i32 %2, i32 %2)
%327 = icmp sgt i32 %323, 0
br i1 %327, label %321, label %328
328: ; preds = %321, %319
ret void
}