#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 */
typedef int /*<<< orphan*/ time_t;
typedef double clock_t;

/* Variables and functions */
float CLOCKS_PER_SEC;
int atoi(char *);
double clock();
scalar_t__ malloc(int);
int /*<<< orphan*/ mergeSort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  clock_t t;
  time_t timer;
  srand(time(NULL));
  if (argc < 2) {
    printf("Entre com o tamanho do vetor\n");
    return 1;
  }
  int tmp, i, j, r, n = atoi(argv[1]);
  int *v = (int *)malloc(n * sizeof(int));
  for (i = 0; i < n; i++) {
    r = rand() % n;
    v[i] = r;
  }
  t = clock();
  mergeSort(v, n);
  for (i = 0; i < n; i++) {
    printf("%d ", v[i]);
  }
  printf("%f time \n", t, ((float)t) / CLOCKS_PER_SEC);
  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)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11ca <main+0x4a>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ae <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x30(%rbp)
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    122a <main+0xaa>
mov    $0x0,%al
call   10a0 <rand@plt>
cltd
idivl  -0x30(%rbp)
mov    %edx,-0x2c(%rbp)
mov    -0x2c(%rbp),%edx
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f4 <main+0x74>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1060 <mergeSort@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    127c <main+0xfc>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1249 <main+0xc9>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
cvtsd2ss %xmm1,%xmm1
mov    0x2d57(%rip),%rax
divss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd82(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmp    $0x1,%ebp
jg     11cb <main+0x3b>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
jmp    127d <main+0xed>
mov    0x8(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r15d
lea    0x0(,%r15,4),%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %r15d,%r12d
test   %r15d,%r15d
jle    1217 <main+0x87>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <rand@plt>
cltd
idiv   %r15d
mov    %edx,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1200 <main+0x70>
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r15d,%esi
call   1070 <mergeSort@plt>
test   %r15d,%r15d
jle    1256 <main+0xc6>
lea    0xdc2(%rip),%r15
xor    %ebp,%ebp
mov    (%rbx,%rbp,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1240 <main+0xb0>
movsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm1
mov    0x2d81(%rip),%rax
divss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd8e(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Entre com o tamanho do vetor\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [10 x i8] c"%f time \0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 @time(i32* null)
%15 = call i32 @srand(i32 %14)
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %74
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %12
%25 = load i32, i32* %12
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %13
store i32 0, i32* %9
br label %31
31: ; preds = %44, %20
%32 = load i32, i32* %9
%33 = load i32, i32* %12
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %47
35: ; preds = %31
%36 = call i32 (...) @rand()
%37 = load i32, i32* %12
%38 = srem i32 %36, %37
store i32 %38, i32* %11
%39 = load i32, i32* %11
%40 = load i32*, i32** %13
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 %39, i32* %43
br label %44
44: ; preds = %35
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %31
47: ; preds = %31
%48 = call double (...) @clock()
store double %48, double* %6
%49 = load i32*, i32** %13
%50 = load i32, i32* %12
%51 = call i32 @mergeSort(i32* %49, i32 %50)
store i32 0, i32* %9
br label %52
52: ; preds = %63, %47
%53 = load i32, i32* %9
%54 = load i32, i32* %12
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %66
56: ; preds = %52
%57 = load i32*, i32** %13
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %56
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %52
66: ; preds = %52
%67 = load double, double* %6
%68 = load double, double* %6
%69 = fptrunc double %68 to float
%70 = load float, float* @CLOCKS_PER_SEC
%71 = fdiv float %69, %70
%72 = fpext float %71 to double
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %67, double %72)
store i32 0, i32* %3
br label %74
74: ; preds = %66, %18
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [10 x i8] c"%f time \0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@str = [29 x i8] c"Entre com o tamanho do vetor\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %43
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = shl i32 %11, 2
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
%15 = icmp sgt i32 %11, 0
br i1 %15, label %16, label %25
16: ; preds = %8
%17 = zext i32 %11 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %23, %18 ]
%20 = tail call i32 (...) @rand()
%21 = srem i32 %20, %11
%22 = getelementptr inbounds i32, i32* %14, i64 %19
store i32 %21, 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, %8
%26 = tail call double (...) @clock()
%27 = tail call i32 @mergeSort(i32* %14, i32 %11)
br i1 %15, label %28, label %37
28: ; preds = %25
%29 = zext i32 %11 to i64
br label %30
30: ; preds = %28, %30
%31 = phi i64 [ 0, %28 ], [ %35, %30 ]
%32 = getelementptr inbounds i32, i32* %14, i64 %31
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = add nuw nsw i64 %31, 1
%36 = icmp eq i64 %35, %29
br i1 %36, label %37, label %30
37: ; preds = %30, %25
%38 = fptrunc double %26 to float
%39 = load float, float* @CLOCKS_PER_SEC
%40 = fdiv float %38, %39
%41 = fpext float %40 to double
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %26, double %41)
br label %43
43: ; preds = %37, %6
%44 = phi i32 [ 1, %6 ], [ 0, %37 ]
ret i32 %44
}