#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;
int binarySearch(int *, int /*<<< orphan*/, int, int);
scalar_t__ clock();
int *malloc(int);
int /*<<< orphan*/ printf(char *, double);
int main() {
  int *arr = malloc(sizeof(int) * 100000000);
  for (int i = 0; i < 100000000; ++i) {
    arr[i] = i;
  }
  clock_t begin = clock();
  int result = binarySearch(arr, 0, 100000000 - 1, 348437);
  clock_t end = clock();
  double timeSpent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("Found at index: %d\n", result);
  printf("It tooks: %f\n", timeSpent);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x17d78400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5f5e100,-0x14(%rbp)
jge    118d <main+0x4d>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <main+0x24>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x5f5e0ff,%edx
mov    $0x55115,%ecx
call   1050 <binarySearch@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e19(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x17d78400,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movdqa 0xea7(%rip),%xmm0
mov    $0x24,%eax
movdqa 0xea9(%rip),%xmm8
movdqa 0xeb0(%rip),%xmm9
movdqa 0xeb7(%rip),%xmm10
movdqa 0xebe(%rip),%xmm11
movdqa 0xec5(%rip),%xmm12
movdqa 0xecd(%rip),%xmm6
movdqa 0xed5(%rip),%xmm7
movdqa 0xedd(%rip),%xmm1
movdqa 0xee5(%rip),%xmm2
movdqa 0xeed(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqu %xmm0,-0x90(%rbx,%rax,4)
ff ff
movdqu %xmm4,-0x80(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqu %xmm4,-0x70(%rbx,%rax,4)
movdqu %xmm5,-0x60(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqu %xmm4,-0x50(%rbx,%rax,4)
movdqu %xmm5,-0x40(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqu %xmm4,-0x30(%rbx,%rax,4)
movdqu %xmm5,-0x20(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqu %xmm4,-0x10(%rbx,%rax,4)
movdqu %xmm5,(%rbx,%rax,4)
paddd  %xmm3,%xmm0
add    $0x28,%rax
cmp    $0x5f5e124,%rax
jne    11c0 <main+0x80>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5f5e0ff,%edx
mov    $0x55115,%ecx
call   1050 <binarySearch@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2d50(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
lea    0xe09(%rip),%rdi
movsd  (%rsp),%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [20 x i8] c"Found at index: %d\0A\00"
@.str.1 = [14 x i8] c"It tooks: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca double
store i32 0, i32* %1
%8 = call i32* @malloc(i32 400000000)
store i32* %8, i32** %2
store i32 0, i32* %3
br label %9
9: ; preds = %18, %0
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 100000000
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = load i32, i32* %3
%14 = load i32*, i32** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
store i32 %13, i32* %17
br label %18
18: ; preds = %12
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %9
21: ; preds = %9
%22 = call i64 (...) @clock()
store i64 %22, i64* %4
%23 = load i32*, i32** %2
%24 = call i32 @binarySearch(i32* %23, i32 0, i32 99999999, i32 348437)
store i32 %24, i32* %5
%25 = call i64 (...) @clock()
store i64 %25, i64* %6
%26 = load i64, i64* %6
%27 = load i64, i64* %4
%28 = sub nsw i64 %26, %27
%29 = sitofp i64 %28 to double
%30 = load double, double* @CLOCKS_PER_SEC
%31 = fdiv double %29, %30
store double %31, double* %7
%32 = load i32, i32* %5
%33 = sitofp i32 %32 to double
%34 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %33)
%35 = load double, double* %7
%36 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %35)
ret i32 0
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [20 x i8] c"Found at index: %d\0A\00"
@.str.1 = [14 x i8] c"It tooks: %f\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 400000000)
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 0, %0 ], [ %38, %2 ]
%4 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %39, %2 ]
%5 = add <4 x i32> %4, <i32 4, i32 4, i32 4, i32 4>
%6 = getelementptr inbounds i32, i32* %1, i64 %3
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> %4, <4 x i32>* %7
%8 = getelementptr inbounds i32, i32* %6, i64 4
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> %5, <4 x i32>* %9
%10 = add nuw nsw i64 %3, 8
%11 = add <4 x i32> %4, <i32 8, i32 8, i32 8, i32 8>
%12 = add <4 x i32> %4, <i32 12, i32 12, i32 12, i32 12>
%13 = getelementptr inbounds i32, i32* %1, i64 %10
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> %11, <4 x i32>* %14
%15 = getelementptr inbounds i32, i32* %13, i64 4
%16 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> %12, <4 x i32>* %16
%17 = add nuw nsw i64 %3, 16
%18 = add <4 x i32> %4, <i32 16, i32 16, i32 16, i32 16>
%19 = add <4 x i32> %4, <i32 20, i32 20, i32 20, i32 20>
%20 = getelementptr inbounds i32, i32* %1, i64 %17
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> %18, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %20, i64 4
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> %19, <4 x i32>* %23
%24 = add nuw nsw i64 %3, 24
%25 = add <4 x i32> %4, <i32 24, i32 24, i32 24, i32 24>
%26 = add <4 x i32> %4, <i32 28, i32 28, i32 28, i32 28>
%27 = getelementptr inbounds i32, i32* %1, i64 %24
%28 = bitcast i32* %27 to <4 x i32>*
store <4 x i32> %25, <4 x i32>* %28
%29 = getelementptr inbounds i32, i32* %27, i64 4
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> %26, <4 x i32>* %30
%31 = add nuw nsw i64 %3, 32
%32 = add <4 x i32> %4, <i32 32, i32 32, i32 32, i32 32>
%33 = add <4 x i32> %4, <i32 36, i32 36, i32 36, i32 36>
%34 = getelementptr inbounds i32, i32* %1, i64 %31
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> %32, <4 x i32>* %35
%36 = getelementptr inbounds i32, i32* %34, i64 4
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> %33, <4 x i32>* %37
%38 = add nuw nsw i64 %3, 40
%39 = add <4 x i32> %4, <i32 40, i32 40, i32 40, i32 40>
%40 = icmp eq i64 %38, 100000000
br i1 %40, label %41, label %2
41: ; preds = %2
%42 = tail call i64 (...) @clock()
%43 = tail call i32 @binarySearch(i32* %1, i32 0, i32 99999999, i32 348437)
%44 = tail call i64 (...) @clock()
%45 = sub nsw i64 %44, %42
%46 = sitofp i64 %45 to double
%47 = load double, double* @CLOCKS_PER_SEC
%48 = fdiv double %46, %47
%49 = sitofp i32 %43 to double
%50 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %49)
%51 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %48)
ret i32 0
}