#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 *createArray();
int /*<<< orphan*/ free(int *);
long getSystemTime();
scalar_t__ malloc(int);
int /*<<< orphan*/ mergeSort(int *, int /*<<< orphan*/, int, int *);
int /*<<< orphan*/ printf(char *, int, long);
void mergeSortTest() {
  int *myArr = createArray();
  int *temp = (int *)malloc(sizeof(int) * 1000000);
  long startTime = getSystemTime();
  mergeSort(myArr, 0, 1000000 - 1, temp);
  long t_end = getSystemTime();
  printf("mergeSort count %d use time: %ld \n", (1000000),
         (getSystemTime() - startTime));
  free(temp);
  free(myArr);
}


x86 assembly (clang, -O0):
<mergeSortTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <createArray@plt>
mov    %rax,-0x8(%rbp)
mov    $0x3d0900,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getSystemTime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rcx
xor    %esi,%esi
mov    $0xf423f,%edx
call   1070 <mergeSort@plt>
mov    $0x0,%al
call   1050 <getSystemTime@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getSystemTime@plt>
mov    %rax,%rdx
sub    -0x18(%rbp),%rdx
lea    0xe40(%rip),%rdi
mov    $0xf4240,%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSortTest>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1060 <createArray@plt>
mov    %rax,%r14
mov    $0x3d0900,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getSystemTime@plt>
mov    %rax,%r15
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xf423f,%edx
mov    %rbx,%rcx
call   1070 <mergeSort@plt>
xor    %eax,%eax
call   1050 <getSystemTime@plt>
xor    %eax,%eax
call   1050 <getSystemTime@plt>
sub    %r15,%rax
lea    0xe50(%rip),%rdi
mov    $0xf4240,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"mergeSort count %d use time: %ld \0A\00"
define void @mergeSortTest() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
%5 = call i32* (...) @createArray()
store i32* %5, i32** %1
%6 = call i64 @malloc(i32 4000000)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %2
%8 = call i64 (...) @getSystemTime()
store i64 %8, i64* %3
%9 = load i32*, i32** %1
%10 = load i32*, i32** %2
%11 = call i32 @mergeSort(i32* %9, i32 0, i32 999999, i32* %10)
%12 = call i64 (...) @getSystemTime()
store i64 %12, i64* %4
%13 = call i64 (...) @getSystemTime()
%14 = load i64, i64* %3
%15 = sub nsw i64 %13, %14
%16 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 1000000, i64 %15)
%17 = load i32*, i32** %2
%18 = call i32 @free(i32* %17)
%19 = load i32*, i32** %1
%20 = call i32 @free(i32* %19)
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"mergeSort count %d use time: %ld \0A\00"
define void @mergeSortTest() {
%1 = tail call i32* (...) @createArray()
%2 = tail call i64 @malloc(i32 4000000)
%3 = inttoptr i64 %2 to i32*
%4 = tail call i64 (...) @getSystemTime()
%5 = tail call i32 @mergeSort(i32* %1, i32 0, i32 999999, i32* %3)
%6 = tail call i64 (...) @getSystemTime()
%7 = tail call i64 (...) @getSystemTime()
%8 = sub nsw i64 %7, %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 1000000, i64 %8)
%10 = tail call i32 @free(i32* %3)
%11 = tail call i32 @free(i32* %1)
ret void
}