#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 /*<<< orphan*/ BuscaBinaria(int, int, int *);
int /*<<< orphan*/ BuscaSequencial(int, int, int *);
double abst(double);
int rand();
double tempo();
int num_buscas(int v[], int v_aux[], int n, double tempo_ordenacao) {
  int i = 0;
  double inicio_temp1, inicio_temp2, tempo_buscaSeq = 0;
  double tempo_buscaBin = tempo_ordenacao;
  int x = rand();
  inicio_temp1 = tempo();
  BuscaSequencial(x, n, v);
  tempo_buscaSeq = abst(tempo() - inicio_temp1);
  inicio_temp2 = tempo();
  BuscaBinaria(x, n, v_aux);
  tempo_buscaBin += abst(tempo() - inicio_temp2);
  while (tempo_buscaBin >= tempo_buscaSeq) {
    x = rand();
    inicio_temp1 = tempo();
    BuscaSequencial(x, n, v);
    tempo_buscaSeq += abst(tempo() - inicio_temp1);
    inicio_temp2 = tempo();
    BuscaBinaria(x, n, v_aux);
    tempo_buscaBin += abst(tempo() - inicio_temp2);
    i++;
  }
  return (i);
}


x86 assembly (clang, -O0):
<num_buscas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x4c(%rbp)
mov    $0x0,%al
call   1040 <tempo@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x4c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1030 <BuscaSequencial@plt>
mov    $0x0,%al
call   1040 <tempo@plt>
subsd  -0x30(%rbp),%xmm0
call   1050 <abst@plt>
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1040 <tempo@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x4c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1070 <BuscaBinaria@plt>
mov    $0x0,%al
call   1040 <tempo@plt>
subsd  -0x38(%rbp),%xmm0
call   1050 <abst@plt>
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     1286 <num_buscas+0x136>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x4c(%rbp)
mov    $0x0,%al
call   1040 <tempo@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x4c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1030 <BuscaSequencial@plt>
mov    $0x0,%al
call   1040 <tempo@plt>
subsd  -0x30(%rbp),%xmm0
call   1050 <abst@plt>
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1040 <tempo@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x4c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1070 <BuscaBinaria@plt>
mov    $0x0,%al
call   1040 <tempo@plt>
subsd  -0x38(%rbp),%xmm0
call   1050 <abst@plt>
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f2 <num_buscas+0xa2>
mov    -0x24(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_buscas>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x18(%rsp)
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <tempo@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r15,%rdx
call   1030 <BuscaSequencial@plt>
xor    %eax,%eax
call   1040 <tempo@plt>
subsd  0x8(%rsp),%xmm0
call   1050 <abst@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <tempo@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r14,%rdx
call   1070 <BuscaBinaria@plt>
xor    %eax,%eax
call   1040 <tempo@plt>
subsd  0x10(%rsp),%xmm0
call   1050 <abst@plt>
movapd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  0x18(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     128a <num_buscas+0x13a>
xor    %ebp,%ebp
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <tempo@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r15,%rdx
call   1030 <BuscaSequencial@plt>
xor    %eax,%eax
call   1040 <tempo@plt>
subsd  0x10(%rsp),%xmm0
call   1050 <abst@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1040 <tempo@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r14,%rdx
call   1070 <BuscaBinaria@plt>
xor    %eax,%eax
call   1040 <tempo@plt>
subsd  0x10(%rsp),%xmm0
call   1050 <abst@plt>
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
add    $0x1,%ebp
ucomisd %xmm0,%xmm1
jae    11f0 <num_buscas+0xa0>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @num_buscas(i32* %0, i32* %1, i32 %2, double %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store double %3, double* %8
store i32 0, i32* %9
store double 0.000000e+00, double* %12
%15 = load double, double* %8
store double %15, double* %13
%16 = call i32 (...) @rand()
store i32 %16, i32* %14
%17 = call double (...) @tempo()
store double %17, double* %10
%18 = load i32, i32* %14
%19 = load i32, i32* %7
%20 = load i32*, i32** %5
%21 = call i32 @BuscaSequencial(i32 %18, i32 %19, i32* %20)
%22 = call double (...) @tempo()
%23 = load double, double* %10
%24 = fsub double %22, %23
%25 = call double @abst(double %24)
store double %25, double* %12
%26 = call double (...) @tempo()
store double %26, double* %11
%27 = load i32, i32* %14
%28 = load i32, i32* %7
%29 = load i32*, i32** %6
%30 = call i32 @BuscaBinaria(i32 %27, i32 %28, i32* %29)
%31 = call double (...) @tempo()
%32 = load double, double* %11
%33 = fsub double %31, %32
%34 = call double @abst(double %33)
%35 = load double, double* %13
%36 = fadd double %35, %34
store double %36, double* %13
br label %37
37: ; preds = %41, %4
%38 = load double, double* %13
%39 = load double, double* %12
%40 = fcmp oge double %38, %39
br i1 %40, label %41, label %67
41: ; preds = %37
%42 = call i32 (...) @rand()
store i32 %42, i32* %14
%43 = call double (...) @tempo()
store double %43, double* %10
%44 = load i32, i32* %14
%45 = load i32, i32* %7
%46 = load i32*, i32** %5
%47 = call i32 @BuscaSequencial(i32 %44, i32 %45, i32* %46)
%48 = call double (...) @tempo()
%49 = load double, double* %10
%50 = fsub double %48, %49
%51 = call double @abst(double %50)
%52 = load double, double* %12
%53 = fadd double %52, %51
store double %53, double* %12
%54 = call double (...) @tempo()
store double %54, double* %11
%55 = load i32, i32* %14
%56 = load i32, i32* %7
%57 = load i32*, i32** %6
%58 = call i32 @BuscaBinaria(i32 %55, i32 %56, i32* %57)
%59 = call double (...) @tempo()
%60 = load double, double* %11
%61 = fsub double %59, %60
%62 = call double @abst(double %61)
%63 = load double, double* %13
%64 = fadd double %63, %62
store double %64, double* %13
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %37
67: ; preds = %37
%68 = load i32, i32* %9
ret i32 %68
}

LLVM IR (-O2):
define i32 @num_buscas(i32* %0, i32* %1, i32 %2, double %3) {
%5 = tail call i32 (...) @rand()
%6 = tail call double (...) @tempo()
%7 = tail call i32 @BuscaSequencial(i32 %5, i32 %2, i32* %0)
%8 = tail call double (...) @tempo()
%9 = fsub double %8, %6
%10 = tail call double @abst(double %9)
%11 = tail call double (...) @tempo()
%12 = tail call i32 @BuscaBinaria(i32 %5, i32 %2, i32* %1)
%13 = tail call double (...) @tempo()
%14 = fsub double %13, %11
%15 = tail call double @abst(double %14)
%16 = fadd double %15, %3
%17 = fcmp ult double %16, %10
br i1 %17, label %37, label %18
18: ; preds = %4, %18
%19 = phi double [ %34, %18 ], [ %16, %4 ]
%20 = phi double [ %28, %18 ], [ %10, %4 ]
%21 = phi i32 [ %35, %18 ], [ 0, %4 ]
%22 = tail call i32 (...) @rand()
%23 = tail call double (...) @tempo()
%24 = tail call i32 @BuscaSequencial(i32 %22, i32 %2, i32* %0)
%25 = tail call double (...) @tempo()
%26 = fsub double %25, %23
%27 = tail call double @abst(double %26)
%28 = fadd double %20, %27
%29 = tail call double (...) @tempo()
%30 = tail call i32 @BuscaBinaria(i32 %22, i32 %2, i32* %1)
%31 = tail call double (...) @tempo()
%32 = fsub double %31, %29
%33 = tail call double @abst(double %32)
%34 = fadd double %19, %33
%35 = add nuw nsw i32 %21, 1
%36 = fcmp ult double %34, %28
br i1 %36, label %37, label %18
37: ; preds = %18, %4
%38 = phi i32 [ 0, %4 ], [ %35, %18 ]
ret i32 %38
}