#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 */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ assert(int);
double clock();
int *create_random_array(unsigned int);
int isSorted(int *, unsigned int);
int *malloc(unsigned int);
int /*<<< orphan*/ merge_sort(int *, int /*<<< orphan*/, unsigned int, int *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int main(int argc, char *argv[]) {
  assert(argc == 2);
  unsigned length;
  sscanf(argv[1], "%u", &length);
  int *ptr = create_random_array(length);
  double start = clock();
  int *aux = malloc(length * sizeof(int));
  merge_sort(ptr, 0, length, aux);
  double stop = clock();
  double seconds = (stop - start) / CLOCKS_PER_SEC;
  printf("Time elapsed: %f seconds.\n", seconds);
  assert(isSorted(ptr, length));
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1080 <sscanf@plt>
mov    -0x14(%rbp),%edi
call   1040 <create_random_array@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x30(%rbp),%rcx
xor    %esi,%esi
call   1090 <merge_sort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
mov    0x2dd0(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xdd6(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <isSorted@plt>
mov    %eax,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1060 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xe5c(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1080 <sscanf@plt>
mov    0xc(%rsp),%edi
call   1040 <create_random_array@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,0x10(%rsp)
mov    0xc(%rsp),%ebx
lea    0x0(,%rbx,4),%edi
call   1070 <malloc@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
mov    %rax,%rcx
call   1090 <merge_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
subsd  0x10(%rsp),%xmm0
mov    0x2dee(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdfe(%rip),%rdi
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   10a0 <isSorted@plt>
mov    %eax,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [27 x i8] c"Time elapsed: %f seconds.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca double
%9 = alloca i32*
%10 = alloca double
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 2
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%20 = load i32, i32* %6
%21 = call i32* @create_random_array(i32 %20)
store i32* %21, i32** %7
%22 = call double (...) @clock()
store double %22, double* %8
%23 = load i32, i32* %6
%24 = zext i32 %23 to i64
%25 = mul i64 %24, 4
%26 = trunc i64 %25 to i32
%27 = call i32* @malloc(i32 %26)
store i32* %27, i32** %9
%28 = load i32*, i32** %7
%29 = load i32, i32* %6
%30 = load i32*, i32** %9
%31 = call i32 @merge_sort(i32* %28, i32 0, i32 %29, i32* %30)
%32 = call double (...) @clock()
store double %32, double* %10
%33 = load double, double* %10
%34 = load double, double* %8
%35 = fsub double %33, %34
%36 = load double, double* @CLOCKS_PER_SEC
%37 = fdiv double %35, %36
store double %37, double* %11
%38 = load double, double* %11
%39 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %38)
%40 = load i32*, i32** %7
%41 = load i32, i32* %6
%42 = call i32 @isSorted(i32* %40, i32 %41)
%43 = call i32 @assert(i32 %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [27 x i8] c"Time elapsed: %f seconds.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = call i32* @create_random_array(i32 %11)
%13 = call double (...) @clock()
%14 = load i32, i32* %3
%15 = shl i32 %14, 2
%16 = call i32* @malloc(i32 %15)
%17 = call i32 @merge_sort(i32* %12, i32 0, i32 %14, i32* %16)
%18 = call double (...) @clock()
%19 = fsub double %18, %13
%20 = load double, double* @CLOCKS_PER_SEC
%21 = fdiv double %19, %20
%22 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %21)
%23 = load i32, i32* %3
%24 = call i32 @isSorted(i32* %12, i32 %23)
%25 = call i32 @assert(i32 %24)
ret i32 0
}