#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;
double clock();
int /*<<< orphan*/ insertionsort(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, tam, j = 0;
  double seconds = 0;
  clock_t t;
  time_t timer;
  printf("tamanho do vetor\n");
  scanf("%d", &tam);
  int *vet = (int *)malloc(sizeof(int) * tam);
  for (i = 0; i < tam; i++) {
    j = rand() % tam;
    vet[i] = j;
  }
  t = clock();
  insertionsort(vet, tam);
  printf("%f time \n", t, ((float)t) / CLOCKS_PER_SEC);
  for (i = 0; i < tam; i++) {
    printf("%d ", vet[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7f(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ec <main+0x8c>
mov    $0x0,%al
call   1080 <rand@plt>
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b6 <main+0x56>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <insertionsort@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
cvtsd2ss %xmm1,%xmm1
mov    0x2dcf(%rip),%rax
divss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xded(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1269 <main+0x109>
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1236 <main+0xd6>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
lea    0xe64(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1090 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
cmpl   $0x0,0x4(%rsp)
jle    11de <main+0x5e>
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   10a0 <rand@plt>
cltd
idivl  0x4(%rsp)
mov    %edx,(%r15,%rbx,4)
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     11c0 <main+0x40>
xor    %eax,%eax
call   1050 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x4(%rsp),%esi
mov    %r15,%rdi
call   1070 <insertionsort@plt>
movsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm1
mov    0x2de0(%rip),%rax
divss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xdec(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    124c <main+0xcc>
lea    0xde1(%rip),%r14
xor    %ebx,%ebx
xchg   %ax,%ax
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     1230 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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