#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*/ cocktail_sort(int *, int);
int /*<<< orphan*/ copiar_vetor(int *, int *, int);
int /*<<< orphan*/ printf(char *, double, ...);
double benchmark_cocktail_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();
    cocktail_sort(vetor_c, tam);
    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_cocktail_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    1218 <benchmark_cocktail_sort+0xd8>
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),%esi
call   1050 <cocktail_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    0x2e13(%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    0xe05(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1185 <benchmark_cocktail_sort+0x45>
movsd  -0x30(%rbp),%xmm0
movsd  0xddb(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xde0(%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_cocktail_sort>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
mov    %esi,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <copiar_vetor@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <cocktail_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r12,%rax
cvtsi2sd %rax,%xmm1
mov    0x2e47(%rip),%rax
divsd  (%rax),%xmm1
xorpd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xe6f(%rip),%r12
movsd  0xe3f(%rip),%xmm0
mov    %r12,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r15,%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
mov    %r14d,%esi
call   1050 <cocktail_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r13,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mov    0x2de1(%rip),%rax
divsd  (%rax),%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xde7(%rip),%xmm0
mov    %r12,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r15,%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
mov    %r14d,%esi
call   1050 <cocktail_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r13,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mov    0x2d81(%rip),%rax
divsd  (%rax),%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd8f(%rip),%xmm0
mov    %r12,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r15,%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
mov    %r14d,%esi
call   1050 <cocktail_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r13,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mov    0x2d21(%rip),%r13
divsd  0x0(%r13),%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd35(%rip),%xmm0
mov    %r12,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <copiar_vetor@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <cocktail_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r15,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  0x0(%r13),%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xce2(%rip),%xmm0
mov    %r12,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x30(%rbp),%xmm0
divsd  0xccb(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xcd9(%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_cocktail_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 = %42, %2
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 5
br i1 %19, label %20, label %45
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 = call i32 @cocktail_sort(i32* %16, i32 %25)
%27 = call i64 (...) @clock()
store i64 %27, i64* %12
%28 = load i64, i64* %12
%29 = load i64, i64* %11
%30 = sub nsw i64 %28, %29
%31 = sitofp i64 %30 to double
%32 = load double, double* @CLOCKS_PER_SEC
%33 = fdiv double %31, %32
store double %33, double* %8
%34 = load double, double* %8
%35 = load double, double* %9
%36 = fadd double %35, %34
store double %36, double* %9
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
%39 = sitofp i32 %38 to double
%40 = load double, double* %8
%41 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %39, double %40)
br label %42
42: ; preds = %20
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %17
45: ; preds = %17
%46 = load double, double* %9
%47 = fdiv double %46, 5.000000e+00
store double %47, double* %10
%48 = load double, double* %10
%49 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %48)
%50 = load double, double* %10
%51 = load i8*, i8** %6
ret double %50
}

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_cocktail_sort(i32* %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = alloca i32, i64 %3
%5 = call i32 @copiar_vetor(i32* %0, i32* %4, i32 %1)
%6 = call i64 (...) @clock()
%7 = call i32 @cocktail_sort(i32* %4, i32 %1)
%8 = call i64 (...) @clock()
%9 = sub nsw i64 %8, %6
%10 = sitofp i64 %9 to double
%11 = load double, double* @CLOCKS_PER_SEC
%12 = fdiv double %10, %11
%13 = fadd double %12, 0.000000e+00
%14 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double 1.000000e+00, double %12)
%15 = call i32 @copiar_vetor(i32* %0, i32* %4, i32 %1)
%16 = call i64 (...) @clock()
%17 = call i32 @cocktail_sort(i32* %4, i32 %1)
%18 = call i64 (...) @clock()
%19 = sub nsw i64 %18, %16
%20 = sitofp i64 %19 to double
%21 = load double, double* @CLOCKS_PER_SEC
%22 = fdiv double %20, %21
%23 = fadd double %13, %22
%24 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double 2.000000e+00, double %22)
%25 = call i32 @copiar_vetor(i32* %0, i32* %4, i32 %1)
%26 = call i64 (...) @clock()
%27 = call i32 @cocktail_sort(i32* %4, i32 %1)
%28 = call i64 (...) @clock()
%29 = sub nsw i64 %28, %26
%30 = sitofp i64 %29 to double
%31 = load double, double* @CLOCKS_PER_SEC
%32 = fdiv double %30, %31
%33 = fadd double %23, %32
%34 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double 3.000000e+00, double %32)
%35 = call i32 @copiar_vetor(i32* %0, i32* %4, i32 %1)
%36 = call i64 (...) @clock()
%37 = call i32 @cocktail_sort(i32* %4, i32 %1)
%38 = call i64 (...) @clock()
%39 = sub nsw i64 %38, %36
%40 = sitofp i64 %39 to double
%41 = load double, double* @CLOCKS_PER_SEC
%42 = fdiv double %40, %41
%43 = fadd double %33, %42
%44 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double 4.000000e+00, double %42)
%45 = call i32 @copiar_vetor(i32* %0, i32* %4, i32 %1)
%46 = call i64 (...) @clock()
%47 = call i32 @cocktail_sort(i32* %4, i32 %1)
%48 = call i64 (...) @clock()
%49 = sub nsw i64 %48, %46
%50 = sitofp i64 %49 to double
%51 = load double, double* @CLOCKS_PER_SEC
%52 = fdiv double %50, %51
%53 = fadd double %43, %52
%54 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double 5.000000e+00, double %52)
%55 = fdiv double %53, 5.000000e+00
%56 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %55)
ret double %55
}