#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*/ getchar();
int /*<<< orphan*/ merge_sort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  srand(time(NULL));
  int array[50];
  unsigned int i = 0;
  for (i = 0; i < 50; i++)
    array[i] = rand() % 100000 + 1;
  printf("Unsorted array:");
  for (i = 0; i < 50; i++)
    printf("%d\n", array[i]);
  merge_sort(array, 0, 50 - 1);
  printf("\nSorted array?\n");
  for (i = 0; i < 50; i++)
    printf("%d\n", array[i]);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0xd4(%rbp)
movl   $0x0,-0xd4(%rbp)
cmpl   $0x32,-0xd4(%rbp)
jae    11d6 <main+0x76>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x186a0,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    -0xd4(%rbp),%eax
mov    %edx,-0xd0(%rbp,%rax,4)
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    1196 <main+0x36>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xd4(%rbp)
cmpl   $0x32,-0xd4(%rbp)
jae    122a <main+0xca>
mov    -0xd4(%rbp),%eax
mov    -0xd0(%rbp,%rax,4),%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    11ee <main+0x8e>
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x31,%edx
call   1070 <merge_sort@plt>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xd4(%rbp)
cmpl   $0x32,-0xd4(%rbp)
jae    1291 <main+0x131>
mov    -0xd4(%rbp),%eax
mov    -0xd0(%rbp,%rax,4),%esi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    1255 <main+0xf5>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xc8,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x14f8b589,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2d,%rcx
add    %edx,%ecx
imul   $0x186a0,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    1190 <main+0x20>
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe34(%rip),%r14
xor    %ebx,%ebx
xchg   %ax,%ax
mov    (%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    11e0 <main+0x70>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x31,%edx
call   1080 <merge_sort@plt>
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf7(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    1220 <main+0xb0>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r14
ret

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

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