#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*/ copyArray(int *, int *, int, int);
int /*<<< orphan*/ insertionSort(int *, int);
int /*<<< orphan*/ merge(int *, int *, int, int, int);
void mergeSort(int *array, int *arrayCopy, int begin, int end) {
  if ((end - begin) <= 3) {
    insertionSort(array, end);
    return;
  }
  int middle = (begin + end) / 2;
  mergeSort(array, arrayCopy, begin, middle);
  mergeSort(array, arrayCopy, middle, end);
  merge(array, arrayCopy, begin, middle, end);
  copyArray(array, arrayCopy, begin, end);
}


x86 assembly (clang, -O0):
<mergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0x3,%eax
jg     1176 <mergeSort+0x36>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <insertionSort@plt>
jmp    11d7 <mergeSort+0x97>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <mergeSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <mergeSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1040 <merge@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1060 <copyArray@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebx
mov    %rdi,%r12
mov    %ecx,%eax
sub    %edx,%eax
cmp    $0x3,%eax
jg     1168 <mergeSort+0x28>
mov    %r12,%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <insertionSort@plt>
mov    %edx,%r14d
mov    %rsi,%r15
lea    (%rbx,%r14,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r12,%rdi
mov    %ebp,%ecx
call   1030 <mergeSort@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <mergeSort@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
call   1040 <merge@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <copyArray@plt>

LLVM IR (-O0):
define void @mergeSort(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* %8
%11 = load i32, i32* %7
%12 = sub nsw i32 %10, %11
%13 = icmp sle i32 %12, 3
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i32*, i32** %5
%16 = load i32, i32* %8
%17 = call i32 @insertionSort(i32* %15, i32 %16)
br label %42
18: ; preds = %4
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = add nsw i32 %19, %20
%22 = sdiv i32 %21, 2
store i32 %22, i32* %9
%23 = load i32*, i32** %5
%24 = load i32*, i32** %6
%25 = load i32, i32* %7
%26 = load i32, i32* %9
%27 = load i32*, i32** %5
%28 = load i32*, i32** %6
%29 = load i32, i32* %9
%30 = load i32, i32* %8
%31 = load i32*, i32** %5
%32 = load i32*, i32** %6
%33 = load i32, i32* %7
%34 = load i32, i32* %9
%35 = load i32, i32* %8
%36 = call i32 @merge(i32* %31, i32* %32, i32 %33, i32 %34, i32 %35)
%37 = load i32*, i32** %5
%38 = load i32*, i32** %6
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = call i32 @copyArray(i32* %37, i32* %38, i32 %39, i32 %40)
br label %42
42: ; preds = %18, %14
ret void
}

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