#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 /*<<< orphan*/ printf(char *, ...);
void mergeSort(int array[], int lowBound, int highBound) {
  if (lowBound < highBound) {
    int midpoint = (highBound + lowBound) / 2;
    mergeSort(array, lowBound, midpoint);
    mergeSort(array, midpoint + 1, highBound);
    printf("\n\nMerging\n");
    for (int i = lowBound; i <= midpoint; i++)
      printf(" %d ", array[i]);
    printf("\nand\n");
    for (int j = midpoint + 1; j <= highBound; j++)
      printf(" %d ", array[j]);
    merge(array, lowBound, midpoint, highBound);
    printf("\n\nRecursion finished, array is:  ");
    for (int k = 0; k < 9; k++)
      printf(" %d ", array[k]);
  }
}


x86 assembly (clang, -O0):
<mergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    126e <mergeSort+0x13e>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <mergeSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <mergeSort@plt>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11c7 <mergeSort+0x97>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1194 <mergeSort+0x64>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1211 <mergeSort+0xe1>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11de <mergeSort+0xae>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1050 <merge@plt>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x9,-0x20(%rbp)
jge    1269 <mergeSort+0x139>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1238 <mergeSort+0x108>
jmp    126e <mergeSort+0x13e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSort>:
cmp    %edx,%esi
jge    12e4 <mergeSort+0x1a4>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r12
lea    (%rbx,%r14,1),%eax
mov    %eax,%r13d
shr    $0x1f,%r13d
add    %eax,%r13d
sar    %r13d
mov    %r13d,%edx
call   1050 <mergeSort@plt>
lea    0x1(%r13),%esi
mov    %r12,%rdi
mov    %rbx,0x8(%rsp)
mov    %ebx,%edx
call   1050 <mergeSort@plt>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    %r13d,%ebp
mov    %r14,0x10(%rsp)
sub    %r14d,%ebp
jl     11d7 <mergeSort+0x97>
movslq 0x10(%rsp),%rax
lea    (%r12,%rax,4),%r14
add    $0x1,%ebp
lea    0xe4a(%rip),%rbx
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    (%r14,%r15,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r15d,%ebp
jne    11c0 <mergeSort+0x80>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
cmp    0x8(%rsp),%r13d
jge    1226 <mergeSort+0xe6>
movslq %r13d,%rax
lea    (%r12,%rax,4),%r15
add    $0x4,%r15
mov    0x8(%rsp),%rbx
sub    %r13d,%ebx
lea    0xdfc(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%r15,%rbp,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %ebp,%ebx
jne    1210 <mergeSort+0xd0>
mov    %r12,%rdi
mov    0x10(%rsp),%rsi
mov    %r13d,%edx
mov    0x8(%rsp),%rcx
call   1060 <merge@plt>
lea    0xdc3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%esi
lea    0xdac(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%r12),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r12),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%r12),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r12),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%r12),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%r12),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%r12),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%r12),%esi
mov    %rbx,%rdi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
ret

LLVM IR (-O0):
@.str = [11 x i8] c"\0A\0AMerging\0A\00"
@.str.1 = [5 x i8] c" %d \00"
@.str.2 = [6 x i8] c"\0Aand\0A\00"
@.str.3 = [34 x i8] c"\0A\0ARecursion finished, array is: \00"
define void @mergeSort(i32* %0, i32 %1, i32 %2) {
%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** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %81
14: ; preds = %3
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = add nsw i32 %15, %16
%18 = sdiv i32 %17, 2
store i32 %18, i32* %7
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = load i32*, i32** %4
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* %5
store i32 %27, i32* %8
br label %28
28: ; preds = %39, %14
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32*, i32** %4
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %28
42: ; preds = %28
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %46
46: ; preds = %57, %42
%47 = load i32, i32* %9
%48 = load i32, i32* %6
%49 = icmp sle i32 %47, %48
br i1 %49, label %50, label %60
50: ; preds = %46
%51 = load i32*, i32** %4
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %50
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %46
60: ; preds = %46
%61 = load i32*, i32** %4
%62 = load i32, i32* %5
%63 = load i32, i32* %7
%64 = load i32, i32* %6
%65 = call i32 @merge(i32* %61, i32 %62, i32 %63, i32 %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %10
br label %67
67: ; preds = %77, %60
%68 = load i32, i32* %10
%69 = icmp slt i32 %68, 9
br i1 %69, label %70, label %80
70: ; preds = %67
%71 = load i32*, i32** %4
%72 = load i32, i32* %10
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
%75 = load i32, i32* %74
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %75)
br label %77
77: ; preds = %70
%78 = load i32, i32* %10
%79 = add nsw i32 %78, 1
store i32 %79, i32* %10
br label %67
80: ; preds = %67
br label %81
81: ; preds = %80, %3
ret void
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c" %d \00"
@.str.3 = [34 x i8] c"\0A\0ARecursion finished, array is: \00"
@str = [10 x i8] c"\0A\0AMerging\00"
@str.4 = [5 x i8] c"\0Aand\00"
define void @mergeSort(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %65
5: ; preds = %3
%6 = add nsw i32 %2, %1
%7 = sdiv i32 %6, 2
tail call void @mergeSort(i32* %0, i32 %1, i32 %7)
%8 = add nsw i32 %7, 1
tail call void @mergeSort(i32* %0, i32 %8, i32 %2)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%10 = icmp slt i32 %7, %1
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = sext i32 %1 to i64
br label %20
13: ; preds = %20, %5
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0))
%15 = icmp slt i32 %7, %2
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = add nsw i32 %7, 1
%18 = sext i32 %17 to i64
%19 = add i32 %2, 1
br label %57
20: ; preds = %11, %20
%21 = phi i64 [ %12, %11 ], [ %25, %20 ]
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = add nsw i64 %21, 1
%26 = trunc i64 %25 to i32
%27 = icmp eq i32 %8, %26
br i1 %27, label %13, label %20
28: ; preds = %57, %13
%29 = tail call i32 @merge(i32* %0, i32 %1, i32 %7, i32 %2)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* %0
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds i32, i32* %0, i64 1
%34 = load i32, i32* %33
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds i32, i32* %0, i64 2
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds i32, i32* %0, i64 3
%40 = load i32, i32* %39
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds i32, i32* %0, i64 4
%43 = load i32, i32* %42
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds i32, i32* %0, i64 5
%46 = load i32, i32* %45
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds i32, i32* %0, i64 6
%49 = load i32, i32* %48
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds i32, i32* %0, i64 7
%52 = load i32, i32* %51
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds i32, i32* %0, i64 8
%55 = load i32, i32* %54
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %55)
br label %65
57: ; preds = %16, %57
%58 = phi i64 [ %18, %16 ], [ %62, %57 ]
%59 = getelementptr inbounds i32, i32* %0, i64 %58
%60 = load i32, i32* %59
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %60)
%62 = add nsw i64 %58, 1
%63 = trunc i64 %62 to i32
%64 = icmp eq i32 %19, %63
br i1 %64, label %28, label %57
65: ; preds = %28, %3
ret void
}