#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 scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ copiar_vetor(int *, int *, int);
int /*<<< orphan*/ printf(char *, double, ...);
int /*<<< orphan*/ quick_sort(int *, int /*<<< orphan*/, int);
double benchmark_quick_sort(int vetor_o[], int tam) {
  int i, vetor_c[tam];
  double duracao, duracaoTotal = 0, media;
  clock_t inicio, fim;
  for (i = 0; i < 5; i++) {
    copiar_vetor(vetor_o, vetor_c, tam);
    inicio = clock();
    quick_sort(vetor_c, 0, tam - 1);
    fim = clock();
    duracao = ((double)(fim - inicio)) / CLOCKS_PER_SEC;
    duracaoTotal += duracao;
    printf("Iteracao #%d: %f\n", i + 1, duracao);
  }
  media = duracaoTotal / 5;
  printf("Media: %f\n\n", media);
  return media;
}


x86 assembly (clang, -O0):
<benchmark_quick_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x5,-0x10(%rbp)
jge    121d <benchmark_quick_sort+0xdd>
mov    -0x50(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
call   1060 <copiar_vetor@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,-0x40(%rbp)
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1050 <quick_sort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e0e(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xe00(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1185 <benchmark_quick_sort+0x45>
movsd  -0x30(%rbp),%xmm0
movsd  0xdd6(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xddb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark_quick_sort>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %esi,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x1(%r14),%r12d
mov    %r12d,-0x34(%rbp)
mov    %rdi,%r15
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <copiar_vetor@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r13
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1050 <quick_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r13,%rax
cvtsi2sd %rax,%xmm1
mov    0x2e3a(%rip),%rax
divsd  (%rax),%xmm1
xorpd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xe62(%rip),%rdi
movsd  0xe32(%rip),%xmm0
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r15,%r12
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <copiar_vetor@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r13
mov    %rbx,%rdi
xor    %esi,%esi
mov    -0x34(%rbp),%r15d
mov    %r15d,%edx
call   1050 <quick_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r13,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mov    0x2dce(%rip),%rax
divsd  (%rax),%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xdd4(%rip),%xmm0
lea    0xded(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <copiar_vetor@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r13
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1050 <quick_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r13,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mov    0x2d68(%rip),%rax
divsd  (%rax),%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd76(%rip),%xmm0
lea    0xd87(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <copiar_vetor@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r13
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1050 <quick_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r13,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mov    0x2d02(%rip),%r13
divsd  0x0(%r13),%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd16(%rip),%xmm0
lea    0xd1f(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <copiar_vetor@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1050 <quick_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  0x0(%r13),%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xcbd(%rip),%xmm0
lea    0xcbe(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x30(%rbp),%xmm0
divsd  0xca2(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xcb0(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x30(%rbp),%xmm0
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [18 x i8] c"Iteracao #%d: %f\0A\00"
@.str.1 = [12 x i8] c"Media: %f\0A\0A\00"
define double @benchmark_quick_sort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i64
%12 = alloca i64
store i32* %0, i32** %3
store i32 %1, i32* %4
%13 = load i32, i32* %4
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i32, i64 %14
store i64 %14, i64* %7
store double 0.000000e+00, double* %9
store i32 0, i32* %5
br label %17
17: ; preds = %43, %2
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 5
br i1 %19, label %20, label %46
20: ; preds = %17
%21 = load i32*, i32** %3
%22 = load i32, i32* %4
%23 = call i32 @copiar_vetor(i32* %21, i32* %16, i32 %22)
%24 = call i64 (...) @clock()
store i64 %24, i64* %11
%25 = load i32, i32* %4
%26 = sub nsw i32 %25, 1
%27 = call i32 @quick_sort(i32* %16, i32 0, i32 %26)
%28 = call i64 (...) @clock()
store i64 %28, i64* %12
%29 = load i64, i64* %12
%30 = load i64, i64* %11
%31 = sub nsw i64 %29, %30
%32 = sitofp i64 %31 to double
%33 = load double, double* @CLOCKS_PER_SEC
%34 = fdiv double %32, %33
store double %34, double* %8
%35 = load double, double* %8
%36 = load double, double* %9
%37 = fadd double %36, %35
store double %37, double* %9
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
%40 = sitofp i32 %39 to double
%41 = load double, double* %8
%42 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %40, double %41)
br label %43
43: ; preds = %20
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %17
46: ; preds = %17
%47 = load double, double* %9
%48 = fdiv double %47, 5.000000e+00
store double %48, double* %10
%49 = load double, double* %10
%50 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %49)
%51 = load double, double* %10
%52 = load i8*, i8** %6
ret double %51
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [18 x i8] c"Iteracao #%d: %f\0A\00"
@.str.1 = [12 x i8] c"Media: %f\0A\0A\00"
define double @benchmark_quick_sort(i32* %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = alloca i32, i64 %3
%5 = add nsw i32 %1, -1
%6 = call i32 @copiar_vetor(i32* %0, i32* %4, i32 %1)
%7 = call i64 (...) @clock()
%8 = call i32 @quick_sort(i32* %4, i32 0, i32 %5)
%9 = call i64 (...) @clock()
%10 = sub nsw i64 %9, %7
%11 = sitofp i64 %10 to double
%12 = load double, double* @CLOCKS_PER_SEC
%13 = fdiv double %11, %12
%14 = fadd double %13, 0.000000e+00
%15 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double 1.000000e+00, double %13)
%16 = call i32 @copiar_vetor(i32* %0, i32* %4, i32 %1)
%17 = call i64 (...) @clock()
%18 = call i32 @quick_sort(i32* %4, i32 0, i32 %5)
%19 = call i64 (...) @clock()
%20 = sub nsw i64 %19, %17
%21 = sitofp i64 %20 to double
%22 = load double, double* @CLOCKS_PER_SEC
%23 = fdiv double %21, %22
%24 = fadd double %14, %23
%25 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double 2.000000e+00, double %23)
%26 = call i32 @copiar_vetor(i32* %0, i32* %4, i32 %1)
%27 = call i64 (...) @clock()
%28 = call i32 @quick_sort(i32* %4, i32 0, i32 %5)
%29 = call i64 (...) @clock()
%30 = sub nsw i64 %29, %27
%31 = sitofp i64 %30 to double
%32 = load double, double* @CLOCKS_PER_SEC
%33 = fdiv double %31, %32
%34 = fadd double %24, %33
%35 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double 3.000000e+00, double %33)
%36 = call i32 @copiar_vetor(i32* %0, i32* %4, i32 %1)
%37 = call i64 (...) @clock()
%38 = call i32 @quick_sort(i32* %4, i32 0, i32 %5)
%39 = call i64 (...) @clock()
%40 = sub nsw i64 %39, %37
%41 = sitofp i64 %40 to double
%42 = load double, double* @CLOCKS_PER_SEC
%43 = fdiv double %41, %42
%44 = fadd double %34, %43
%45 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double 4.000000e+00, double %43)
%46 = call i32 @copiar_vetor(i32* %0, i32* %4, i32 %1)
%47 = call i64 (...) @clock()
%48 = call i32 @quick_sort(i32* %4, i32 0, i32 %5)
%49 = call i64 (...) @clock()
%50 = sub nsw i64 %49, %47
%51 = sitofp i64 %50 to double
%52 = load double, double* @CLOCKS_PER_SEC
%53 = fdiv double %51, %52
%54 = fadd double %44, %53
%55 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double 5.000000e+00, double %53)
%56 = fdiv double %54, 5.000000e+00
%57 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %56)
ret double %56
}