#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 */
struct node {
  int dummy;
};
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ MergeSort(struct node **);
int /*<<< orphan*/ TopDownMergeSort(unsigned int *, unsigned int *, int);
int atoi(char *);
scalar_t__ clock();
struct node *insertionSort(struct node *);
unsigned int *insertionSortArr(unsigned int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ push(struct node **, unsigned int);
unsigned int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  struct node *head = NULL;
  struct node *sorted = NULL;
  int count = 0, length, i;
  unsigned int randVal, *arr = NULL, *sortedArr = NULL;
  clock_t start, end;
  length = atoi(argv[1]);
  arr = (unsigned int *)malloc(length * sizeof(unsigned int));
  sortedArr = (unsigned int *)malloc(length * sizeof(unsigned int));
  srand(time(NULL));
  start = clock();
  for (i = 0; i < length; i++) {
    randVal = rand();
    push(&head, randVal);
    arr[i] = randVal;
  }
  end = clock();
  printf("fill structures: %7.5f secs\n",
         ((double)(end - start)) / CLOCKS_PER_SEC);
  start = clock();
  sorted = insertionSort(head);
  end = clock();
  printf("insertionSort in linked list: %7.5f secs\n",
         ((double)(end - start)) / CLOCKS_PER_SEC);
  start = clock();
  sortedArr = insertionSortArr(arr, length);
  end = clock();
  printf("insertionSort in array: %7.5f secs\n",
         ((double)(end - start)) / CLOCKS_PER_SEC);
  start = clock();
  MergeSort(&head);
  ;
  end = clock();
  printf("mergeSort in linked list: %7.5f secs\n",
         ((double)(end - start)) / CLOCKS_PER_SEC);
  start = clock();
  TopDownMergeSort(arr, sortedArr, length);
  end = clock();
  printf("mergeSort in array: %7.5f secs\n",
         ((double)(end - start)) / CLOCKS_PER_SEC);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x28(%rbp)
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1293 <main+0xd3>
mov    $0x0,%al
call   10e0 <rand@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   10a0 <push@plt>
mov    -0x30(%rbp),%edx
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1255 <main+0x95>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d36(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd43(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <insertionSort@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2cef(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd19(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   10d0 <insertionSortArr@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2ca5(%rip),%rax
divsd  (%rax),%xmm0
lea    0xcf9(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x48(%rbp)
lea    -0x18(%rbp),%rdi
call   10b0 <MergeSort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2c62(%rip),%rax
divsd  (%rax),%xmm0
lea    0xcda(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1070 <TopDownMergeSort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2c18(%rip),%rax
divsd  (%rax),%xmm0
lea    0xcb6(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebp
lea    0x0(,%rbp,4),%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %ebx,%edi
call   1080 <malloc@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r15
mov    %rbp,0x10(%rsp)
test   %ebp,%ebp
jle    1250 <main+0x90>
mov    0x10(%rsp),%ebx
lea    0x8(%rsp),%r13
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10e0 <rand@plt>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %eax,%esi
call   10a0 <push@plt>
mov    %ebp,(%r12,%r14,4)
add    $0x1,%r14
cmp    %r14,%rbx
jne    1230 <main+0x70>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r15,%rax
cvtsi2sd %rax,%xmm0
mov    0x2d82(%rip),%r14
divsd  (%r14),%xmm0
lea    0xd8e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1090 <insertionSort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
lea    0xd74(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    0x10(%rsp),%rbp
mov    %ebp,%esi
call   10d0 <insertionSortArr@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1030 <clock@plt>
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
lea    0xd5f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
call   10b0 <MergeSort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
lea    0xd4c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1070 <TopDownMergeSort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
lea    0xd38(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [29 x i8] c"fill structures: %7.5f secs\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [42 x i8] c"insertionSort in linked list: %7.5f secs\0A\00"
@.str.2 = [36 x i8] c"insertionSort in array: %7.5f secs\0A\00"
@.str.3 = [38 x i8] c"mergeSort in linked list: %7.5f secs\0A\00"
@.str.4 = [32 x i8] c"mergeSort in array: %7.5f secs\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.node*
%7 = alloca %struct.node*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i64
%15 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.node* null, %struct.node** %6
store %struct.node* null, %struct.node** %7
store i32 0, i32* %8
store i32* null, i32** %12
store i32* null, i32** %13
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 4
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %12
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 4
%29 = trunc i64 %28 to i32
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i32*
store i32* %31, i32** %13
%32 = call i32 @time(i32* null)
%33 = call i32 @srand(i32 %32)
%34 = call i64 (...) @clock()
store i64 %34, i64* %14
store i32 0, i32* %10
br label %35
35: ; preds = %48, %2
%36 = load i32, i32* %10
%37 = load i32, i32* %9
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %51
39: ; preds = %35
%40 = call i32 (...) @rand()
store i32 %40, i32* %11
%41 = load i32, i32* %11
%42 = call i32 @push(%struct.node** %6, i32 %41)
%43 = load i32, i32* %11
%44 = load i32*, i32** %12
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
store i32 %43, i32* %47
br label %48
48: ; preds = %39
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %35
51: ; preds = %35
%52 = call i64 (...) @clock()
store i64 %52, i64* %15
%53 = load i64, i64* %15
%54 = load i64, i64* %14
%55 = sub nsw i64 %53, %54
%56 = sitofp i64 %55 to double
%57 = load double, double* @CLOCKS_PER_SEC
%58 = fdiv double %56, %57
%59 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), double %58)
%60 = call i64 (...) @clock()
store i64 %60, i64* %14
%61 = load %struct.node*, %struct.node** %6
%62 = call %struct.node* @insertionSort(%struct.node* %61)
store %struct.node* %62, %struct.node** %7
%63 = call i64 (...) @clock()
store i64 %63, i64* %15
%64 = load i64, i64* %15
%65 = load i64, i64* %14
%66 = sub nsw i64 %64, %65
%67 = sitofp i64 %66 to double
%68 = load double, double* @CLOCKS_PER_SEC
%69 = fdiv double %67, %68
%70 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), double %69)
%71 = call i64 (...) @clock()
store i64 %71, i64* %14
%72 = load i32*, i32** %12
%73 = load i32, i32* %9
%74 = call i32* @insertionSortArr(i32* %72, i32 %73)
store i32* %74, i32** %13
%75 = call i64 (...) @clock()
store i64 %75, i64* %15
%76 = load i64, i64* %15
%77 = load i64, i64* %14
%78 = sub nsw i64 %76, %77
%79 = sitofp i64 %78 to double
%80 = load double, double* @CLOCKS_PER_SEC
%81 = fdiv double %79, %80
%82 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %81)
%83 = call i64 (...) @clock()
store i64 %83, i64* %14
%84 = call i32 @MergeSort(%struct.node** %6)
%85 = call i64 (...) @clock()
store i64 %85, i64* %15
%86 = load i64, i64* %15
%87 = load i64, i64* %14
%88 = sub nsw i64 %86, %87
%89 = sitofp i64 %88 to double
%90 = load double, double* @CLOCKS_PER_SEC
%91 = fdiv double %89, %90
%92 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), double %91)
%93 = call i64 (...) @clock()
store i64 %93, i64* %14
%94 = load i32*, i32** %12
%95 = load i32*, i32** %13
%96 = load i32, i32* %9
%97 = call i32 @TopDownMergeSort(i32* %94, i32* %95, i32 %96)
%98 = call i64 (...) @clock()
store i64 %98, i64* %15
%99 = load i64, i64* %15
%100 = load i64, i64* %14
%101 = sub nsw i64 %99, %100
%102 = sitofp i64 %101 to double
%103 = load double, double* @CLOCKS_PER_SEC
%104 = fdiv double %102, %103
%105 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), double %104)
ret i32 0
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [29 x i8] c"fill structures: %7.5f secs\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [42 x i8] c"insertionSort in linked list: %7.5f secs\0A\00"
@.str.2 = [36 x i8] c"insertionSort in array: %7.5f secs\0A\00"
@.str.3 = [38 x i8] c"mergeSort in linked list: %7.5f secs\0A\00"
@.str.4 = [32 x i8] c"mergeSort in array: %7.5f secs\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.node*
%4 = bitcast %struct.node** %3 to i8*
store %struct.node* null, %struct.node** %3
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = shl i32 %7, 2
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
%11 = tail call i64 @malloc(i32 %8)
%12 = tail call i32 @time(i32* null)
%13 = tail call i32 @srand(i32 %12)
%14 = tail call i64 (...) @clock()
%15 = icmp sgt i32 %7, 0
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = zext i32 %7 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %23, %18 ]
%20 = call i32 (...) @rand()
%21 = call i32 @push(%struct.node** %3, i32 %20)
%22 = getelementptr inbounds i32, i32* %10, i64 %19
store i32 %20, i32* %22
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, %17
br i1 %24, label %25, label %18
25: ; preds = %18, %2
%26 = call i64 (...) @clock()
%27 = sub nsw i64 %26, %14
%28 = sitofp i64 %27 to double
%29 = load double, double* @CLOCKS_PER_SEC
%30 = fdiv double %28, %29
%31 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), double %30)
%32 = call i64 (...) @clock()
%33 = load %struct.node*, %struct.node** %3
%34 = call %struct.node* @insertionSort(%struct.node* %33)
%35 = call i64 (...) @clock()
%36 = sub nsw i64 %35, %32
%37 = sitofp i64 %36 to double
%38 = load double, double* @CLOCKS_PER_SEC
%39 = fdiv double %37, %38
%40 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), double %39)
%41 = call i64 (...) @clock()
%42 = call i32* @insertionSortArr(i32* %10, i32 %7)
%43 = call i64 (...) @clock()
%44 = sub nsw i64 %43, %41
%45 = sitofp i64 %44 to double
%46 = load double, double* @CLOCKS_PER_SEC
%47 = fdiv double %45, %46
%48 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %47)
%49 = call i64 (...) @clock()
%50 = call i32 @MergeSort(%struct.node** %3)
%51 = call i64 (...) @clock()
%52 = sub nsw i64 %51, %49
%53 = sitofp i64 %52 to double
%54 = load double, double* @CLOCKS_PER_SEC
%55 = fdiv double %53, %54
%56 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), double %55)
%57 = call i64 (...) @clock()
%58 = call i32 @TopDownMergeSort(i32* %10, i32* %42, i32 %7)
%59 = call i64 (...) @clock()
%60 = sub nsw i64 %59, %57
%61 = sitofp i64 %60 to double
%62 = load double, double* @CLOCKS_PER_SEC
%63 = fdiv double %61, %62
%64 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), double %63)
ret i32 0
}