#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, int);
void mergeSort(int *A, int *B, int *X, int *Y, int left, int right, int N) {
  int mid = 0;
  if (left >= right)
    return;
  mid = (left + right) / 2;
  mergeSort(A, B, X, Y, left, mid, N);
  mergeSort(A, B, X, Y, mid + 1, right, N);
  merge(A, B, X, Y, left, mid, right, N);
}


x86 assembly (clang, -O0):
<mergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jl     115b <mergeSort+0x3b>
jmp    11e2 <mergeSort+0xc2>
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <mergeSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
add    $0x1,%r8d
mov    -0x28(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <mergeSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x28(%rbp),%r10d
mov    0x10(%rbp),%eax
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1040 <merge@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSort>:
cmp    %r9d,%r8d
jge    11bf <mergeSort+0x9f>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%ebx
mov    %r8d,%r12d
mov    0x50(%rsp),%ebp
lea    (%rbx,%r12,1),%eax
mov    %eax,%r14d
shr    $0x1f,%r14d
add    %eax,%r14d
sar    %r14d
mov    %ebp,(%rsp)
mov    %rdi,0x10(%rsp)
mov    %rsi,%rbp
mov    %rdx,%r13
mov    %rcx,%r15
mov    %r14d,%r9d
call   1030 <mergeSort@plt>
lea    0x1(%r14),%r8d
mov    0x50(%rsp),%eax
mov    %eax,(%rsp)
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %ebx,%r9d
call   1030 <mergeSort@plt>
mov    0x50(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,(%rsp)
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %r12d,%r8d
mov    %r14d,%r9d
call   1040 <merge@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
ret

LLVM IR (-O0):
define void @mergeSort(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
store i32 0, i32* %15
%16 = load i32, i32* %12
%17 = load i32, i32* %13
%18 = icmp sge i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %7
br label %49
20: ; preds = %7
%21 = load i32, i32* %12
%22 = load i32, i32* %13
%23 = add nsw i32 %21, %22
%24 = sdiv i32 %23, 2
store i32 %24, i32* %15
%25 = load i32*, i32** %8
%26 = load i32*, i32** %9
%27 = load i32*, i32** %10
%28 = load i32*, i32** %11
%29 = load i32, i32* %12
%30 = load i32, i32* %15
%31 = load i32, i32* %14
%32 = load i32*, i32** %8
%33 = load i32*, i32** %9
%34 = load i32*, i32** %10
%35 = load i32*, i32** %11
%36 = load i32, i32* %15
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %13
%39 = load i32, i32* %14
%40 = load i32*, i32** %8
%41 = load i32*, i32** %9
%42 = load i32*, i32** %10
%43 = load i32*, i32** %11
%44 = load i32, i32* %12
%45 = load i32, i32* %15
%46 = load i32, i32* %13
%47 = load i32, i32* %14
%48 = call i32 @merge(i32* %40, i32* %41, i32* %42, i32* %43, i32 %44, i32 %45, i32 %46, i32 %47)
br label %49
49: ; preds = %20, %19
ret void
}

LLVM IR (-O2):
define void @mergeSort(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4, i32 %5, i32 %6) {
%8 = icmp slt i32 %4, %5
br i1 %8, label %10, label %9
9: ; preds = %7, %10
ret void
10: ; preds = %7
%11 = add nsw i32 %5, %4
%12 = sdiv i32 %11, 2
tail call void @mergeSort(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4, i32 %12, i32 %6)
%13 = add nsw i32 %12, 1
tail call void @mergeSort(i32* %0, i32* %1, i32* %2, i32* %3, i32 %13, i32 %5, i32 %6)
%14 = tail call i32 @merge(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4, i32 %12, i32 %5, i32 %6)
br label %9
}