#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ stable_grail_rec_merge(int **, int, int);
int /*<<< orphan*/ stable_grail_swap1(int **, int **);
void stable_rec_stable_sort(int **arr, int L) {
  int u, m, h, p0, p1, rest;
  for (m = 1; m < L; m += 2) {
    u = 0;
    if ((*(*(arr + m - 1)) - *(*(arr + m))) > 0) {
      stable_grail_swap1(arr + (m - 1), arr + m);
    }
  }
  for (h = 2; h < L; h *= 2) {
    p0 = 0;
    p1 = L - 2 * h;
    while (p0 <= p1) {
      stable_grail_rec_merge(arr + p0, h, h);
      p0 += 2 * h;
    }
    rest = L - p0;
    if (rest > h) {
      stable_grail_rec_merge(arr + p0, h, rest - h);
    }
  }
}


x86 assembly (clang, -O0):
<stable_rec_stable_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a9 <stable_rec_stable_sort+0x89>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    -0x8(%rax,%rcx,8),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
sub    (%rcx),%eax
cmp    $0x0,%eax
jle    1196 <stable_rec_stable_sort+0x76>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <stable_grail_swap1@plt>
jmp    119b <stable_rec_stable_sort+0x7b>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <stable_rec_stable_sort+0x16>
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124d <stable_rec_stable_sort+0x12d>
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1208 <stable_rec_stable_sort+0xe8>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <stable_grail_rec_merge@plt>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11d1 <stable_rec_stable_sort+0xb1>
mov    -0xc(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    123a <stable_rec_stable_sort+0x11a>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%esi
mov    -0x24(%rbp),%edx
sub    -0x18(%rbp),%edx
call   1040 <stable_grail_rec_merge@plt>
jmp    123f <stable_rec_stable_sort+0x11f>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b0 <stable_rec_stable_sort+0x90>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stable_rec_stable_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
cmp    $0x2,%esi
jl     1225 <stable_rec_stable_sort+0x105>
mov    %esi,%r14d
mov    %esi,%r12d
mov    0x8(%rsp),%rax
lea    0x8(%rax),%rbx
mov    $0x1,%ebp
jmp    116d <stable_rec_stable_sort+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x2,%rbp
add    $0x10,%rbx
cmp    %r12,%rbp
jge    1188 <stable_rec_stable_sort+0x68>
mov    -0x8(%rbx),%rax
mov    (%rbx),%rcx
mov    (%rax),%eax
cmp    (%rcx),%eax
jle    1160 <stable_rec_stable_sort+0x40>
lea    -0x8(%rbx),%rdi
mov    %rbx,%rsi
call   1030 <stable_grail_swap1@plt>
jmp    1160 <stable_rec_stable_sort+0x40>
cmp    $0x3,%r14d
jl     1225 <stable_rec_stable_sort+0x105>
mov    $0x2,%r13d
mov    %r14d,0x10(%rsp)
jmp    11a8 <stable_rec_stable_sort+0x88>
nop
mov    %ebp,%r13d
cmp    %r14d,%ebp
jge    1225 <stable_rec_stable_sort+0x105>
lea    0x0(%r13,%r13,1),%ebp
mov    %r14d,%eax
sub    %ebp,%eax
mov    $0x0,%ebx
js     1202 <stable_rec_stable_sort+0xe2>
mov    %ebp,0x14(%rsp)
movslq %ebp,%r14
mov    %eax,%r15d
lea    0x0(,%r14,8),%r12
mov    0x8(%rsp),%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %r13d,%edx
call   1040 <stable_grail_rec_merge@plt>
add    %r14,%rbx
add    %r12,%rbp
cmp    %r15,%rbx
jle    11e0 <stable_rec_stable_sort+0xc0>
mov    0x10(%rsp),%r14d
mov    0x14(%rsp),%ebp
mov    %r14d,%edx
sub    %ebx,%edx
sub    %r13d,%edx
jle    11a0 <stable_rec_stable_sort+0x80>
movslq %ebx,%rax
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,8),%rdi
mov    %r13d,%esi
call   1040 <stable_grail_rec_merge@plt>
jmp    11a0 <stable_rec_stable_sort+0x80>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @stable_rec_stable_sort(i32** %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32** %0, i32*** %3
store i32 %1, i32* %4
store i32 1, i32* %6
br label %11
11: ; preds = %43, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %46
15: ; preds = %11
store i32 0, i32* %5
%16 = load i32**, i32*** %3
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32*, i32** %16, i64 %18
%20 = getelementptr inbounds i32*, i32** %19, i64 -1
%21 = load i32*, i32** %20
%22 = load i32, i32* %21
%23 = load i32**, i32*** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32*, i32** %23, i64 %25
%27 = load i32*, i32** %26
%28 = load i32, i32* %27
%29 = sub nsw i32 %22, %28
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %15
%32 = load i32**, i32*** %3
%33 = load i32, i32* %6
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32*, i32** %32, i64 %35
%37 = load i32**, i32*** %3
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32*, i32** %37, i64 %39
%41 = call i32 @stable_grail_swap1(i32** %36, i32** %40)
br label %42
42: ; preds = %31, %15
br label %43
43: ; preds = %42
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 2
store i32 %45, i32* %6
br label %11
46: ; preds = %11
store i32 2, i32* %7
br label %47
47: ; preds = %90, %46
%48 = load i32, i32* %7
%49 = load i32, i32* %4
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %93
51: ; preds = %47
store i32 0, i32* %8
%52 = load i32, i32* %4
%53 = load i32, i32* %7
%54 = mul nsw i32 2, %53
%55 = sub nsw i32 %52, %54
store i32 %55, i32* %9
br label %56
56: ; preds = %60, %51
%57 = load i32, i32* %8
%58 = load i32, i32* %9
%59 = icmp sle i32 %57, %58
br i1 %59, label %60, label %72
60: ; preds = %56
%61 = load i32**, i32*** %3
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32*, i32** %61, i64 %63
%65 = load i32, i32* %7
%66 = load i32, i32* %7
%67 = call i32 @stable_grail_rec_merge(i32** %64, i32 %65, i32 %66)
%68 = load i32, i32* %7
%69 = mul nsw i32 2, %68
%70 = load i32, i32* %8
%71 = add nsw i32 %70, %69
store i32 %71, i32* %8
br label %56
72: ; preds = %56
%73 = load i32, i32* %4
%74 = load i32, i32* %8
%75 = sub nsw i32 %73, %74
store i32 %75, i32* %10
%76 = load i32, i32* %10
%77 = load i32, i32* %7
%78 = icmp sgt i32 %76, %77
br i1 %78, label %79, label %89
79: ; preds = %72
%80 = load i32**, i32*** %3
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i32*, i32** %80, i64 %82
%84 = load i32, i32* %7
%85 = load i32, i32* %10
%86 = load i32, i32* %7
%87 = sub nsw i32 %85, %86
%88 = call i32 @stable_grail_rec_merge(i32** %83, i32 %84, i32 %87)
br label %89
89: ; preds = %79, %72
br label %90
90: ; preds = %89
%91 = load i32, i32* %7
%92 = mul nsw i32 %91, 2
store i32 %92, i32* %7
br label %47
93: ; preds = %47
ret void
}

LLVM IR (-O2):
define void @stable_rec_stable_sort(i32** %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %51
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %8
6: ; preds = %21
%7 = icmp sgt i32 %1, 2
br i1 %7, label %24, label %51
8: ; preds = %4, %21
%9 = phi i64 [ 1, %4 ], [ %22, %21 ]
%10 = getelementptr inbounds i32*, i32** %0, i64 %9
%11 = getelementptr inbounds i32*, i32** %10, i64 -1
%12 = load i32*, i32** %11
%13 = load i32, i32* %12
%14 = load i32*, i32** %10
%15 = load i32, i32* %14
%16 = icmp sgt i32 %13, %15
br i1 %16, label %17, label %21
17: ; preds = %8
%18 = add nsw i64 %9, -1
%19 = getelementptr inbounds i32*, i32** %0, i64 %18
%20 = tail call i32 @stable_grail_swap1(i32** %19, i32** %10)
br label %21
21: ; preds = %8, %17
%22 = add nuw i64 %9, 2
%23 = icmp slt i64 %22, %5
br i1 %23, label %8, label %6
24: ; preds = %6, %49
%25 = phi i32 [ %26, %49 ], [ 2, %6 ]
%26 = shl i32 %25, 1
%27 = sub nsw i32 %1, %26
%28 = icmp slt i32 %27, 0
br i1 %28, label %40, label %29
29: ; preds = %24
%30 = sext i32 %26 to i64
%31 = zext i32 %27 to i64
br label %32
32: ; preds = %29, %32
%33 = phi i64 [ 0, %29 ], [ %36, %32 ]
%34 = getelementptr inbounds i32*, i32** %0, i64 %33
%35 = tail call i32 @stable_grail_rec_merge(i32** %34, i32 %25, i32 %25)
%36 = add i64 %33, %30
%37 = icmp sgt i64 %36, %31
br i1 %37, label %38, label %32
38: ; preds = %32
%39 = trunc i64 %36 to i32
br label %40
40: ; preds = %38, %24
%41 = phi i32 [ 0, %24 ], [ %39, %38 ]
%42 = sub nsw i32 %1, %41
%43 = icmp sgt i32 %42, %25
br i1 %43, label %44, label %49
44: ; preds = %40
%45 = sext i32 %41 to i64
%46 = getelementptr inbounds i32*, i32** %0, i64 %45
%47 = sub nsw i32 %42, %25
%48 = tail call i32 @stable_grail_rec_merge(i32** %46, i32 %25, i32 %47)
br label %49
49: ; preds = %40, %44
%50 = icmp slt i32 %26, %1
br i1 %50, label %24, label %51
51: ; preds = %49, %2, %6
ret void
}