#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_sort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int a[1000] = {0};
  srand(time(0));
  for (int i = 0; i < 1000; a[i] = rand() % 1000, i++) {
  }
  printf("Original array: \n[");
  for (int i = 0; i < 1000; printf("%d, ", a[i++])) {
  }
  printf("\b\b]\n");
  merge_sort(a, 1000);
  printf("\nSorted array: \n[");
  for (int i = 0; i < 1000; printf("%d, ", a[i++])) {
  }
  printf("\b\b]\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xfb0(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1040 <memset@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x3e8,-0xfb4(%rbp)
jge    11ea <main+0x8a>
jmp    11b9 <main+0x59>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq -0xfb4(%rbp),%rax
mov    %edx,-0xfb0(%rbp,%rax,4)
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    11a4 <main+0x44>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xfb8(%rbp)
cmpl   $0x3e8,-0xfb8(%rbp)
jge    1244 <main+0xe4>
jmp    1217 <main+0xb7>
mov    -0xfb8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xfb8(%rbp)
cltq
mov    -0xfb0(%rbp,%rax,4),%esi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1202 <main+0xa2>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xfb0(%rbp),%rdi
mov    $0x3e8,%esi
call   1070 <merge_sort@plt>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xfbc(%rbp)
cmpl   $0x3e8,-0xfbc(%rbp)
jge    12bd <main+0x15d>
jmp    1290 <main+0x130>
mov    -0xfbc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xfbc(%rbp)
cltq
mov    -0xfb0(%rbp,%rax,4),%esi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127b <main+0x11b>
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xfa8,%rsp
mov    %rsp,%rdi
mov    $0xfa0,%edx
xor    %esi,%esi
call   1050 <memset@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    11a0 <main+0x30>
lea    0xe24(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe29(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%rsp,%rbx,4),%esi
add    $0x1,%rbx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x3e8,%rbx
jne    11f0 <main+0x80>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1080 <merge_sort@plt>
lea    0xdee(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xddb(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,4),%esi
add    $0x1,%rbx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x3e8,%rbx
jne    1240 <main+0xd0>
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xfa8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Original array: \0A[\00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.2 = [5 x i8] c"\08\08]\0A\00"
@.str.3 = [18 x i8] c"\0ASorted array: \0A[\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [1000 x i32]* %6 to i8*
%11 = call i32 @time(i32 0)
%12 = call i32 @srand(i32 %11)
store i32 0, i32* %7
br label %13
13: ; preds = %17, %2
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 1000
br i1 %15, label %16, label %25
16: ; preds = %13
br label %17
17: ; preds = %16
%18 = call i32 (...) @rand()
%19 = srem i32 %18, 1000
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %21
store i32 %19, i32* %22
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %13
25: ; preds = %13
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %27
27: ; preds = %31, %25
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 1000
br i1 %29, label %30, label %38
30: ; preds = %27
br label %31
31: ; preds = %30
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %27
38: ; preds = %27
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%40 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 0
%41 = call i32 @merge_sort(i32* %40, i32 1000)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %9
br label %43
43: ; preds = %47, %38
%44 = load i32, i32* %9
%45 = icmp slt i32 %44, 1000
br i1 %45, label %46, label %54
46: ; preds = %43
br label %47
47: ; preds = %46
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %52)
br label %43
54: ; preds = %43
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Original array: \0A[\00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.3 = [18 x i8] c"\0ASorted array: \0A[\00"
@str.4 = [4 x i8] c"\08\08]\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 x i32]
%4 = bitcast [1000 x i32]* %3 to i8*
%5 = tail call i32 @time(i32 0)
%6 = tail call i32 @srand(i32 %5)
br label %9
7: ; preds = %9
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %21
9: ; preds = %2, %9
%10 = phi i64 [ 0, %2 ], [ %14, %9 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 1000
%13 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %10
store i32 %12, i32* %13
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, 1000
br i1 %15, label %7, label %9
16: ; preds = %21
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.4, i64 0, i64 0))
%18 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%19 = call i32 @merge_sort(i32* %18, i32 1000)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %30
21: ; preds = %7, %21
%22 = phi i64 [ 0, %7 ], [ %23, %21 ]
%23 = add nuw nsw i64 %22, 1
%24 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %22
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = icmp eq i64 %23, 1000
br i1 %27, label %16, label %21
28: ; preds = %30
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.4, i64 0, i64 0))
ret i32 0
30: ; preds = %16, %30
%31 = phi i64 [ 0, %16 ], [ %32, %30 ]
%32 = add nuw nsw i64 %31, 1
%33 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %31
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = icmp eq i64 %32, 1000
br i1 %36, label %28, label %30
}