#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 *);
void merge_sort(int arrayPtr[], int start, int end, int aux[]) {
  if (end - start < 2)
    return;
  int middle = (start + end) / 2;
  merge_sort(arrayPtr, start, middle, aux);
  merge_sort(arrayPtr, middle, end, aux);
  merge(arrayPtr, start, middle, end, aux);
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x2,%eax
jge    114a <merge_sort+0x2a>
jmp    1197 <merge_sort+0x77>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
mov    %edx,%eax
sub    %esi,%eax
cmp    $0x1,%eax
jg     112a <merge_sort+0xa>
ret
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%r12
lea    (%r15,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%edx
call   1040 <merge_sort@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1040 <merge_sort@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r14,%r8
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <merge@plt>

LLVM IR (-O0):
define void @merge_sort(i32* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = sub nsw i32 %10, %11
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %4
br label %34
15: ; preds = %4
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = add nsw i32 %16, %17
%19 = sdiv i32 %18, 2
store i32 %19, i32* %9
%20 = load i32*, i32** %5
%21 = load i32, i32* %6
%22 = load i32, i32* %9
%23 = load i32*, i32** %8
%24 = load i32*, i32** %5
%25 = load i32, i32* %9
%26 = load i32, i32* %7
%27 = load i32*, i32** %8
%28 = load i32*, i32** %5
%29 = load i32, i32* %6
%30 = load i32, i32* %9
%31 = load i32, i32* %7
%32 = load i32*, i32** %8
%33 = call i32 @merge(i32* %28, i32 %29, i32 %30, i32 %31, i32* %32)
br label %34
34: ; preds = %15, %14
ret void
}

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