#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 */
long atol(char *);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ merge_sort(int *, int /*<<< orphan*/, long);
int /*<<< orphan*/ print_arr(int *, long);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  srand(time(NULL));
  long size = 0;
  if (argc > 1) {
    size = atol(argv[1]);
  }
  size = size ? size : 20;
  int *arr;
  arr = (int *)malloc(sizeof(int) * size);
  for (int i = 0; i < size; i++)
    arr[i] = rand() % 500;
  print_arr(arr, size);
  merge_sort(arr, 0, size - 1);
  print_arr(arr, size);
  free(arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11c9 <main+0x49>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atol@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e1 <main+0x61>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11ef <main+0x6f>
mov    $0x14,%eax
mov    %rax,-0x30(%rbp)
jmp    11ef <main+0x6f>
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1247 <main+0xc7>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x1f4,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1211 <main+0x91>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <print_arr@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
xor    %esi,%esi
call   1080 <merge_sort@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <print_arr@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
cmp    $0x2,%ebp
jl     11c3 <main+0x43>
mov    0x8(%rbx),%rdi
call   1090 <atol@plt>
test   %rax,%rax
je     11c3 <main+0x43>
mov    %rax,%r14
lea    0x0(,%rax,4),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %r14,%r14
jg     11d6 <main+0x56>
jmp    1211 <main+0x91>
mov    $0x50,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x14,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x1f4,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11e0 <main+0x60>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <print_arr@plt>
lea    -0x1(%r14),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <merge_sort@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <print_arr@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
store i64 0, i64* %6
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @atol(i8* %16)
store i64 %17, i64* %6
br label %18
18: ; preds = %13, %2
%19 = load i64, i64* %6
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i64, i64* %6
br label %24
23: ; preds = %18
br label %24
24: ; preds = %23, %21
%25 = phi i64 [ %22, %21 ], [ 20, %23 ]
store i64 %25, i64* %6
%26 = load i64, i64* %6
%27 = mul i64 4, %26
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %7
store i32 0, i32* %8
br label %31
31: ; preds = %43, %24
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = load i64, i64* %6
%35 = icmp slt i64 %33, %34
br i1 %35, label %36, label %46
36: ; preds = %31
%37 = call i32 (...) @rand()
%38 = srem i32 %37, 500
%39 = load i32*, i32** %7
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 %38, i32* %42
br label %43
43: ; preds = %36
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %31
46: ; preds = %31
%47 = load i32*, i32** %7
%48 = load i64, i64* %6
%49 = call i32 @print_arr(i32* %47, i64 %48)
%50 = load i32*, i32** %7
%51 = load i64, i64* %6
%52 = sub nsw i64 %51, 1
%53 = call i32 @merge_sort(i32* %50, i32 0, i64 %52)
%54 = load i32*, i32** %7
%55 = load i64, i64* %6
%56 = call i32 @print_arr(i32* %54, i64 %55)
%57 = load i32*, i32** %7
%58 = call i32 @free(i32* %57)
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @atol(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6, %2
%12 = tail call i64 @malloc(i32 80)
%13 = inttoptr i64 %12 to i32*
br label %20
14: ; preds = %6
%15 = trunc i64 %9 to i32
%16 = shl i32 %15, 2
%17 = tail call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i32*
%19 = icmp sgt i64 %9, 0
br i1 %19, label %20, label %23
20: ; preds = %11, %14
%21 = phi i32* [ %13, %11 ], [ %18, %14 ]
%22 = phi i64 [ 20, %11 ], [ %9, %14 ]
br label %31
23: ; preds = %31, %14
%24 = phi i32* [ %18, %14 ], [ %21, %31 ]
%25 = phi i64 [ %9, %14 ], [ %22, %31 ]
%26 = tail call i32 @print_arr(i32* %24, i64 %25)
%27 = add nsw i64 %25, -1
%28 = tail call i32 @merge_sort(i32* %24, i32 0, i64 %27)
%29 = tail call i32 @print_arr(i32* %24, i64 %25)
%30 = tail call i32 @free(i32* %24)
ret i32 0
31: ; preds = %20, %31
%32 = phi i64 [ 0, %20 ], [ %36, %31 ]
%33 = tail call i32 (...) @rand()
%34 = srem i32 %33, 500
%35 = getelementptr inbounds i32, i32* %21, i64 %32
store i32 %34, i32* %35
%36 = add nuw nsw i64 %32, 1
%37 = icmp eq i64 %36, %22
br i1 %37, label %23, label %31
}