#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*/ assert(int);
int *merge_sort(int *, int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  printf("merge sort\n");
  int sorted[8] = {1, 2, 3, 4, 5, 6, 7, 8};
  int sortable[8] = {6, 5, 3, 1, 8, 7, 2, 4};
  int *result = merge_sort(sortable, 0, 7, "initial");
  for (int i = -0; i < 8; i++) {
    printf("expected: %d actual: %d\n", sorted[i], result[i]);
    assert(sorted[i] == result[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0xedc(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed9(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed6(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed0(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x7,%edx
lea    0xe55(%rip),%rcx
call   1050 <merge_sort@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x8,-0x5c(%rbp)
jge    1220 <main+0xf0>
movslq -0x5c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
mov    -0x58(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x5c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    -0x58(%rbp),%rcx
movslq -0x5c(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11c7 <main+0x97>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xef3(%rip),%rdi
call   1030 <puts@plt>
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeaf(%rip),%rcx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1060 <merge_sort@plt>
mov    %rax,%rbx
mov    (%rax),%edx
lea    0xe9c(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x1,(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0x4(%rbx),%edx
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x2,0x4(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rbx),%edx
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x3,0x8(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0xc(%rbx),%edx
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x4,0xc(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0x10(%rbx),%edx
mov    %r14,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x5,0x10(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0x14(%rbx),%edx
mov    %r14,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x6,0x14(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0x18(%rbx),%edx
mov    %r14,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x7,0x18(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0x1c(%rbx),%edx
mov    %r14,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x8,0x1c(%rbx)
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"merge sort\0A\00"
@__const.main.sorted = [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8]
@__const.main.sortable = [8 x i32] [i32 6, i32 5, i32 3, i32 1, i32 8, i32 7, i32 2, i32 4]
@.str.1 = [8 x i8] c"initial\00"
@.str.2 = [25 x i8] c"expected: %d actual: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i32]
%3 = alloca [8 x i32]
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = bitcast [8 x i32]* %2 to i8*
%8 = bitcast [8 x i32]* %3 to i8*
%9 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%10 = call i32* @merge_sort(i32* %9, i32 0, i32 7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %4
store i32 0, i32* %5
br label %11
11: ; preds = %37, %0
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 8
br i1 %13, label %14, label %40
14: ; preds = %11
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %23)
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = load i32*, i32** %4
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = icmp eq i32 %28, %33
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
br label %37
37: ; preds = %14
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %11
40: ; preds = %11
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@__const.main.sortable = [8 x i32] [i32 6, i32 5, i32 3, i32 1, i32 8, i32 7, i32 2, i32 4]
@.str.1 = [8 x i8] c"initial\00"
@.str.2 = [25 x i8] c"expected: %d actual: %d\0A\00"
@str = [11 x i8] c"merge sort\00"
define i32 @main() {
%1 = alloca [8 x i32]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%3 = bitcast [8 x i32]* %1 to i8*
%4 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%5 = call i32* @merge_sort(i32* %4, i32 0, i32 7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %6)
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 1
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = getelementptr inbounds i32, i32* %5, i64 1
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 %13)
%15 = load i32, i32* %12
%16 = icmp eq i32 %15, 2
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = getelementptr inbounds i32, i32* %5, i64 2
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 %20)
%22 = load i32, i32* %19
%23 = icmp eq i32 %22, 3
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = getelementptr inbounds i32, i32* %5, i64 3
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 4, i32 %27)
%29 = load i32, i32* %26
%30 = icmp eq i32 %29, 4
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = getelementptr inbounds i32, i32* %5, i64 4
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 %34)
%36 = load i32, i32* %33
%37 = icmp eq i32 %36, 5
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = getelementptr inbounds i32, i32* %5, i64 5
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 6, i32 %41)
%43 = load i32, i32* %40
%44 = icmp eq i32 %43, 6
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = getelementptr inbounds i32, i32* %5, i64 6
%48 = load i32, i32* %47
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 7, i32 %48)
%50 = load i32, i32* %47
%51 = icmp eq i32 %50, 7
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = getelementptr inbounds i32, i32* %5, i64 7
%55 = load i32, i32* %54
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 8, i32 %55)
%57 = load i32, i32* %54
%58 = icmp eq i32 %57, 8
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
ret i32 0
}