#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*/ merge(int *, int, int, int, int, int *);
int /*<<< orphan*/ printf(char *, int, int);
void mergesort_rec(int A[], int h, int low, int high, int B[]) {
  int div;
  if (low > high) {
    printf("FATAL: low: %d, high: %d\n", low, high);
    return;
  }
  if (low == high) {
    return;
  }
  div = (low + high) / 2;
  mergesort_rec(B, h, low, div, A);
  mergesort_rec(B, h, div + 1, high, A);
  merge(A, low, div, div + 1, high, B);
}


x86 assembly (clang, -O0):
<mergesort_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    116c <mergesort_rec+0x3c>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
jmp    11da <mergesort_rec+0xaa>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    117d <mergesort_rec+0x4d>
jmp    11da <mergesort_rec+0xaa>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%r8
call   1050 <mergesort_rec@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%r8
call   1050 <mergesort_rec@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    -0x14(%rbp),%r8d
mov    -0x20(%rbp),%r9
call   1040 <merge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergesort_rec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebx
cmp    %ecx,%edx
jle    1163 <mergesort_rec+0x33>
lea    0xeb5(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
jne    1174 <mergesort_rec+0x44>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r8,%r14
mov    %esi,%r13d
mov    %rdi,%r12
lea    (%r15,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r8,%rdi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r12,%r8
call   1050 <mergesort_rec@plt>
lea    0x1(%rbp),%edx
mov    %r14,%rdi
mov    %r13d,%esi
mov    %edx,%r13d
mov    %r15d,%ecx
mov    %r12,%r8
call   1050 <mergesort_rec@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
mov    %r15d,%r8d
mov    %r14,%r9
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <merge@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"FATAL: low: %d, high: %d\0A\00"
define void @mergesort_rec(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
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
%12 = load i32, i32* %8
%13 = load i32, i32* %9
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %5
%16 = load i32, i32* %8
%17 = load i32, i32* %9
%18 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
br label %48
19: ; preds = %5
%20 = load i32, i32* %8
%21 = load i32, i32* %9
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19
br label %48
24: ; preds = %19
%25 = load i32, i32* %8
%26 = load i32, i32* %9
%27 = add nsw i32 %25, %26
%28 = sdiv i32 %27, 2
store i32 %28, i32* %11
%29 = load i32*, i32** %10
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = load i32, i32* %11
%33 = load i32*, i32** %6
%34 = load i32*, i32** %10
%35 = load i32, i32* %7
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %9
%39 = load i32*, i32** %6
%40 = load i32*, i32** %6
%41 = load i32, i32* %8
%42 = load i32, i32* %11
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
%45 = load i32, i32* %9
%46 = load i32*, i32** %10
%47 = call i32 @merge(i32* %40, i32 %41, i32 %42, i32 %44, i32 %45, i32* %46)
br label %48
48: ; preds = %24, %23, %15
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"FATAL: low: %d, high: %d\0A\00"
define void @mergesort_rec(i32* %0, i32 %1, i32 %2, i32 %3, i32* %4) {
%6 = icmp sgt i32 %2, %3
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3)
br label %11
9: ; preds = %5
%10 = icmp eq i32 %2, %3
br i1 %10, label %11, label %12
11: ; preds = %7, %9, %12
ret void
12: ; preds = %9
%13 = add nsw i32 %3, %2
%14 = sdiv i32 %13, 2
tail call void @mergesort_rec(i32* %4, i32 %1, i32 %2, i32 %14, i32* %0)
%15 = add nsw i32 %14, 1
tail call void @mergesort_rec(i32* %4, i32 %1, i32 %15, i32 %3, i32* %0)
%16 = tail call i32 @merge(i32* %0, i32 %2, i32 %14, i32 %15, i32 %3, i32* %4)
br label %11
}