#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 main(void) {
  int array[999999];
  for (int i = 0; i < 999999; i++) {
    array[i] = rand();
  }
  for (int i = 0; i < 999999; i++) {
    printf("array[%4d]= %d\n", i, array[i]);
  }
  printf("sorting ...\n");
  merge_sort(array, 999999);
  printf("sorted!\n");
  for (int i = 0; i < 999999; i++) {
    printf("array[%4d]= %d\n", i, array[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0910,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3d0904(%rbp)
cmpl   $0xf423f,-0x3d0904(%rbp)
jge    1187 <main+0x57>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%ecx
movslq -0x3d0904(%rbp),%rax
mov    %ecx,-0x3d0900(%rbp,%rax,4)
mov    -0x3d0904(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0904(%rbp)
jmp    114c <main+0x1c>
movl   $0x0,-0x3d0908(%rbp)
cmpl   $0xf423f,-0x3d0908(%rbp)
jge    11d7 <main+0xa7>
mov    -0x3d0908(%rbp),%esi
movslq -0x3d0908(%rbp),%rax
mov    -0x3d0900(%rbp,%rax,4),%edx
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3d0908(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0908(%rbp)
jmp    1191 <main+0x61>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x3d0900(%rbp),%rdi
mov    $0xf423f,%esi
call   1040 <merge_sort@plt>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x3d090c(%rbp)
cmpl   $0xf423f,-0x3d090c(%rbp)
jge    1254 <main+0x124>
mov    -0x3d090c(%rbp),%esi
movslq -0x3d090c(%rbp),%rax
mov    -0x3d0900(%rbp,%rax,4),%edx
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3d090c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d090c(%rbp)
jmp    120e <main+0xde>
mov    -0x4(%rbp),%eax
add    $0x3d0910,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3d0908,%rsp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0xf423f,%rbx
jne    1150 <main+0x10>
lea    0xe92(%rip),%r14
xor    %ebx,%ebx
mov    (%rsp,%rbx,4),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0xf423f,%rbx
jne    1170 <main+0x30>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0xf423f,%esi
call   1050 <merge_sort@plt>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
lea    0xe48(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,4),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0xf423f,%rbx
jne    11c0 <main+0x80>
xor    %eax,%eax
add    $0x3d0908,%rsp
pop    %rbx
pop    %r14
ret

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

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