#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 */
typedef int /*<<< orphan*/ collection_2;
typedef int /*<<< orphan*/ collection_1;
typedef int /*<<< orphan*/ collection_0;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ merge_sort(int *, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ print_int_array(int *, int);
int /*<<< orphan*/ printf(char *);
int main() {
  printf("Merge sort example - Copyright 2016, Sjors van Gelderen\n\n");
  int collection_0[] = {14, 2, 6, 23, 6, 753, 2};
  int collection_1[] = {0, 4, 2, 6, 3, 745, 7, 3};
  int collection_2[] = {6, 6, 6, 6, 6, 6, 3};
  int size_0 = sizeof(collection_0) / sizeof(collection_0[0]);
  int size_1 = sizeof(collection_1) / sizeof(collection_1[0]);
  int size_2 = sizeof(collection_2) / sizeof(collection_2[0]);
  merge_sort(collection_0, size_0, 0, size_0 - 1);
  printf("Final result: ");
  print_int_array(collection_0, size_0);
  printf("\n\n");
  merge_sort(collection_1, size_1, 0, size_1 - 1);
  printf("Final result: ");
  print_int_array(collection_1, size_1);
  printf("\n\n");
  merge_sort(collection_2, size_2, 0, size_2 - 1);
  printf("Final result: ");
  print_int_array(collection_2, size_2);
  printf("\n\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
mov    0xefe(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xefb(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xef8(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xef6(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    0xf14(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xf11(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xf0e(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xf0b(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec8(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xec5(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xec2(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xec0(%rip),%eax
mov    %eax,-0x48(%rbp)
movl   $0x7,-0x64(%rbp)
movl   $0x8,-0x68(%rbp)
movl   $0x7,-0x6c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x64(%rbp),%esi
mov    -0x64(%rbp),%ecx
sub    $0x1,%ecx
xor    %edx,%edx
call   1040 <merge_sort@plt>
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1050 <print_int_array@plt>
lea    0xe24(%rip),%rdi
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x68(%rbp),%esi
mov    -0x68(%rbp),%ecx
sub    $0x1,%ecx
xor    %edx,%edx
call   1040 <merge_sort@plt>
lea    0xe07(%rip),%rdi
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x68(%rbp),%esi
call   1050 <print_int_array@plt>
lea    0xdec(%rip),%rdi
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x6c(%rbp),%esi
mov    -0x6c(%rbp),%ecx
sub    $0x1,%ecx
xor    %edx,%edx
call   1040 <merge_sort@plt>
lea    0xdcf(%rip),%rdi
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x6c(%rbp),%esi
call   1050 <print_int_array@plt>
lea    0xdb4(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xf1f(%rip),%rdi
call   1030 <puts@plt>
movups 0xeb0(%rip),%xmm0
movups %xmm0,0x2c(%rsp)
movaps 0xe98(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xedc(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xec0(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movups 0xea0(%rip),%xmm0
movups %xmm0,0xc(%rsp)
movaps 0xe88(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %edx,%edx
mov    $0x6,%ecx
call   1050 <merge_sort@plt>
lea    0xea4(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1060 <print_int_array@plt>
lea    0xece(%rip),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %edx,%edx
mov    $0x7,%ecx
call   1050 <merge_sort@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1060 <print_int_array@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %edx,%edx
mov    $0x6,%ecx
call   1050 <merge_sort@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1060 <print_int_array@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [58 x i8] c"Merge sort example - Copyright 2016, Sjors van Gelderen\0A\0A\00"
@__const.main.collection_0 = [7 x i32] [i32 14, i32 2, i32 6, i32 23, i32 6, i32 753, i32 2]
@__const.main.collection_1 = [8 x i32] [i32 0, i32 4, i32 2, i32 6, i32 3, i32 745, i32 7, i32 3]
@__const.main.collection_2 = [7 x i32] [i32 6, i32 6, i32 6, i32 6, i32 6, i32 6, i32 3]
@.str.1 = [15 x i8] c"Final result: \00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [7 x i32]
%3 = alloca [8 x i32]
%4 = alloca [7 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%9 = bitcast [7 x i32]* %2 to i8*
%10 = bitcast [8 x i32]* %3 to i8*
%11 = bitcast [7 x i32]* %4 to i8*
store i32 7, i32* %5
store i32 8, i32* %6
store i32 7, i32* %7
%12 = getelementptr inbounds [7 x i32], [7 x i32]* %2, i64 0, i64 0
%13 = load i32, i32* %5
%14 = load i32, i32* %5
%15 = sub nsw i32 %14, 1
%16 = call i32 @merge_sort(i32* %12, i32 %13, i32 0, i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds [7 x i32], [7 x i32]* %2, i64 0, i64 0
%19 = load i32, i32* %5
%20 = call i32 @print_int_array(i32* %18, i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%23 = load i32, i32* %6
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 1
%26 = call i32 @merge_sort(i32* %22, i32 %23, i32 0, i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%29 = load i32, i32* %6
%30 = call i32 @print_int_array(i32* %28, i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%32 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 0
%33 = load i32, i32* %7
%34 = load i32, i32* %7
%35 = sub nsw i32 %34, 1
%36 = call i32 @merge_sort(i32* %32, i32 %33, i32 0, i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%38 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 0
%39 = load i32, i32* %7
%40 = call i32 @print_int_array(i32* %38, i32 %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @EXIT_SUCCESS
ret i32 %42
}

LLVM IR (-O2):
@__const.main.collection_0 = [7 x i32] [i32 14, i32 2, i32 6, i32 23, i32 6, i32 753, i32 2]
@__const.main.collection_1 = [8 x i32] [i32 0, i32 4, i32 2, i32 6, i32 3, i32 745, i32 7, i32 3]
@__const.main.collection_2 = [7 x i32] [i32 6, i32 6, i32 6, i32 6, i32 6, i32 6, i32 3]
@.str.1 = [15 x i8] c"Final result: \00"
@EXIT_SUCCESS = global i32 0
@str = [57 x i8] c"Merge sort example - Copyright 2016, Sjors van Gelderen\0A\00"
@str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [7 x i32]
%2 = alloca [8 x i32]
%3 = alloca [7 x i32]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%5 = bitcast [7 x i32]* %1 to i8*
%6 = bitcast [8 x i32]* %2 to i8*
%7 = bitcast [7 x i32]* %3 to i8*
%8 = getelementptr inbounds [7 x i32], [7 x i32]* %1, i64 0, i64 0
%9 = call i32 @merge_sort(i32* %8, i32 7, i32 0, i32 6)
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @print_int_array(i32* %8, i32 7)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%13 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%14 = call i32 @merge_sort(i32* %13, i32 8, i32 0, i32 7)
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @print_int_array(i32* %13, i32 8)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%18 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 0
%19 = call i32 @merge_sort(i32* %18, i32 7, i32 0, i32 6)
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @print_int_array(i32* %18, i32 7)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}