#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 const CLOCKS_PER_SEC;
int /*<<< orphan*/ busca_binaria(int *, int, int);
int /*<<< orphan*/ busca_sequencial(int *, int, int);
int clock();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int c1, c2;
  int i;
  int vet[(1 << 20)];
  float ts, tb;
  const int n_test = 1000;
  for (i = 0; i < (1 << 20); i++)
    vet[i] = i * 2;
  printf("Vetor de testes preparado\n");
  printf("Busca sequencial... ");
  c1 = clock();
  for (i = 0; i < n_test; i++) {
    busca_sequencial(vet, (1 << 20), i * ((1 << 20) / n_test));
  }
  c2 = clock();
  ts = (c2 - c1) / (float)(CLOCKS_PER_SEC * n_test);
  printf("%f segundos\n", ts);
  printf("Vetor de testes preparado\n");
  printf("Busca binaria... ");
  c1 = clock();
  for (i = 0; i < n_test; i++) {
    busca_binaria(vet, (1 << 20), i * ((1 << 20) / n_test));
  }
  c2 = clock();
  tb = (c2 - c1) / (float)(CLOCKS_PER_SEC * n_test);
  printf("%f segundos\n", tb);
  printf("\nA busca binaria foi %f vezes mais rapida que a sequencial\n",
         ts / tb);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400020,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x40001c(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x100000,-0x10(%rbp)
jge    118f <main+0x4f>
mov    -0x10(%rbp),%ecx
shl    $0x1,%ecx
movslq -0x10(%rbp),%rax
mov    %ecx,-0x400010(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1163 <main+0x23>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jge    11ef <main+0xaf>
lea    -0x400010(%rbp),%rdi
imul   $0x418,-0x10(%rbp),%edx
mov    $0x100000,%esi
call   1060 <busca_sequencial@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11bc <main+0x7c>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x8(%rbp),%eax
cvtsi2ss %eax,%xmm0
mov    0x2dde(%rip),%rax
imul   $0x3e8,(%rax),%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x400014(%rbp)
ff
movss  -0x400014(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xdfd(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jge    129a <main+0x15a>
lea    -0x400010(%rbp),%rdi
imul   $0x418,-0x10(%rbp),%edx
mov    $0x100000,%esi
call   1030 <busca_binaria@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1267 <main+0x127>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x8(%rbp),%eax
cvtsi2ss %eax,%xmm0
mov    0x2d33(%rip),%rax
imul   $0x3e8,(%rax),%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x400018(%rbp)
ff
movss  -0x400018(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xd52(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movss  -0x400014(%rbp),%xmm0
ff
divss  -0x400018(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xd4f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x400020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400010,%rsp
movdqa 0xe9d(%rip),%xmm0
xor    %eax,%eax
movdqa 0xea3(%rip),%xmm1
movdqa 0xeab(%rip),%xmm2
movdqa 0xeb3(%rip),%xmm3
nopl   (%rax)
movdqa %xmm0,%xmm4
paddd  %xmm0,%xmm4
movdqa %xmm4,%xmm5
paddd  %xmm1,%xmm5
movdqa %xmm4,0x10(%rsp,%rax,4)
movdqa %xmm5,0x20(%rsp,%rax,4)
movdqa %xmm4,%xmm5
paddd  %xmm2,%xmm5
paddd  %xmm3,%xmm4
movdqa %xmm5,0x30(%rsp,%rax,4)
movdqa %xmm4,0x40(%rsp,%rax,4)
add    $0x10,%rax
paddd  %xmm2,%xmm0
cmp    $0x100000,%rax
jne    1180 <main+0x30>
lea    0xee5(%rip),%rdi
call   1040 <puts@plt>
lea    0xe69(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rbp
nop
mov    %rbp,%rdi
mov    $0x100000,%esi
mov    %ebx,%edx
call   1070 <busca_sequencial@plt>
add    $0x418,%ebx
cmp    $0xffdc0,%ebx
jne    11f0 <main+0xa0>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <clock@plt>
sub    %r14d,%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
pxor   %xmm0,%xmm0
divss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe19(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xe66(%rip),%rdi
call   1040 <puts@plt>
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    $0x100000,%esi
mov    %ebx,%edx
call   1030 <busca_binaria@plt>
add    $0x418,%ebx
cmp    $0xffdc0,%ebx
jne    1270 <main+0x120>
xor    %eax,%eax
call   1050 <clock@plt>
sub    %r14d,%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
xorps  %xmm0,%xmm0
divss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xd9c(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0xc(%rsp),%xmm0
divss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd9d(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x400010,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Vetor de testes preparado\0A\00"
@.str.1 = [21 x i8] c"Busca sequencial... \00"
@CLOCKS_PER_SEC = constant i32 0
@.str.2 = [13 x i8] c"%f segundos\0A\00"
@.str.3 = [18 x i8] c"Busca binaria... \00"
@.str.4 = [60 x i8] c"\0AA busca binaria foi %f vezes mais rapida que a sequencial\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1048576 x i32]
%6 = alloca float
%7 = alloca float
%8 = alloca i32
store i32 0, i32* %1
store i32 1000, i32* %8
store i32 0, i32* %4
br label %9
9: ; preds = %18, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1048576
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = load i32, i32* %4
%14 = mul nsw i32 %13, 2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1048576 x i32], [1048576 x i32]* %5, i64 0, i64 %16
store i32 %14, i32* %17
br label %18
18: ; preds = %12
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %9
21: ; preds = %9
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 (...) @clock()
store i32 %24, i32* %2
store i32 0, i32* %4
br label %25
25: ; preds = %33, %21
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 1000
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = getelementptr inbounds [1048576 x i32], [1048576 x i32]* %5, i64 0, i64 0
%30 = load i32, i32* %4
%31 = mul nsw i32 %30, 1048
%32 = call i32 @busca_sequencial(i32* %29, i32 1048576, i32 %31)
br label %33
33: ; preds = %28
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %25
36: ; preds = %25
%37 = call i32 (...) @clock()
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = load i32, i32* %2
%40 = sub nsw i32 %38, %39
%41 = sitofp i32 %40 to float
%42 = load i32, i32* @CLOCKS_PER_SEC
%43 = mul nsw i32 %42, 1000
%44 = sitofp i32 %43 to float
%45 = fdiv float %41, %44
store float %45, float* %6
%46 = load float, float* %6
%47 = fpext float %46 to double
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 (...) @clock()
store i32 %51, i32* %2
store i32 0, i32* %4
br label %52
52: ; preds = %60, %36
%53 = load i32, i32* %4
%54 = icmp slt i32 %53, 1000
br i1 %54, label %55, label %63
55: ; preds = %52
%56 = getelementptr inbounds [1048576 x i32], [1048576 x i32]* %5, i64 0, i64 0
%57 = load i32, i32* %4
%58 = mul nsw i32 %57, 1048
%59 = call i32 @busca_binaria(i32* %56, i32 1048576, i32 %58)
br label %60
60: ; preds = %55
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
br label %52
63: ; preds = %52
%64 = call i32 (...) @clock()
store i32 %64, i32* %3
%65 = load i32, i32* %3
%66 = load i32, i32* %2
%67 = sub nsw i32 %65, %66
%68 = sitofp i32 %67 to float
%69 = load i32, i32* @CLOCKS_PER_SEC
%70 = mul nsw i32 %69, 1000
%71 = sitofp i32 %70 to float
%72 = fdiv float %68, %71
store float %72, float* %7
%73 = load float, float* %7
%74 = fpext float %73 to double
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %74)
%76 = load float, float* %6
%77 = load float, float* %7
%78 = fdiv float %76, %77
%79 = fpext float %78 to double
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), double %79)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"Busca sequencial... \00"
@CLOCKS_PER_SEC = constant i32 0
@.str.2 = [13 x i8] c"%f segundos\0A\00"
@.str.3 = [18 x i8] c"Busca binaria... \00"
@.str.4 = [60 x i8] c"\0AA busca binaria foi %f vezes mais rapida que a sequencial\0A\00"
@str.5 = [26 x i8] c"Vetor de testes preparado\00"
define i32 @main() {
%1 = alloca [1048576 x i32]
%2 = bitcast [1048576 x i32]* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ 0, %0 ], [ %22, %3 ]
%5 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %23, %3 ]
%6 = getelementptr inbounds [1048576 x i32], [1048576 x i32]* %1, i64 0, i64 %4
%7 = shl <4 x i32> %5, <i32 1, i32 1, i32 1, i32 1>
%8 = shl <4 x i32> %5, <i32 1, i32 1, i32 1, i32 1>
%9 = add <4 x i32> %8, <i32 8, i32 8, i32 8, i32 8>
%10 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %6, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %9, <4 x i32>* %12
%13 = or i64 %4, 8
%14 = add <4 x i32> %5, <i32 8, i32 8, i32 8, i32 8>
%15 = getelementptr inbounds [1048576 x i32], [1048576 x i32]* %1, i64 0, i64 %13
%16 = shl <4 x i32> %14, <i32 1, i32 1, i32 1, i32 1>
%17 = shl <4 x i32> %14, <i32 1, i32 1, i32 1, i32 1>
%18 = add <4 x i32> %17, <i32 8, i32 8, i32 8, i32 8>
%19 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> %16, <4 x i32>* %19
%20 = getelementptr inbounds i32, i32* %15, i64 4
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> %18, <4 x i32>* %21
%22 = add nuw nsw i64 %4, 16
%23 = add <4 x i32> %5, <i32 16, i32 16, i32 16, i32 16>
%24 = icmp eq i64 %22, 1048576
br i1 %24, label %25, label %3
25: ; preds = %3
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%28 = tail call i32 (...) @clock()
%29 = getelementptr inbounds [1048576 x i32], [1048576 x i32]* %1, i64 0, i64 0
br label %30
30: ; preds = %25, %30
%31 = phi i32 [ 0, %25 ], [ %34, %30 ]
%32 = mul nuw nsw i32 %31, 1048
%33 = call i32 @busca_sequencial(i32* %29, i32 1048576, i32 %32)
%34 = add nuw nsw i32 %31, 1
%35 = icmp eq i32 %34, 1000
br i1 %35, label %36, label %30
36: ; preds = %30
%37 = call i32 (...) @clock()
%38 = sub nsw i32 %37, %28
%39 = sitofp i32 %38 to float
%40 = fdiv float %39, 0.000000e+00
%41 = fpext float %40 to double
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %41)
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 (...) @clock()
br label %46
46: ; preds = %36, %46
%47 = phi i32 [ 0, %36 ], [ %50, %46 ]
%48 = mul nuw nsw i32 %47, 1048
%49 = call i32 @busca_binaria(i32* %29, i32 1048576, i32 %48)
%50 = add nuw nsw i32 %47, 1
%51 = icmp eq i32 %50, 1000
br i1 %51, label %52, label %46
52: ; preds = %46
%53 = call i32 (...) @clock()
%54 = sub nsw i32 %53, %45
%55 = sitofp i32 %54 to float
%56 = fdiv float %55, 0.000000e+00
%57 = fpext float %56 to double
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %57)
%59 = fdiv float %40, %56
%60 = fpext float %59 to double
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), double %60)
ret i32 0
}