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

/* Variables and functions */
int CLOCKS_PER_SEC;
int binarySearch(int *, int, int, int);
int clock();
int /*<<< orphan*/ fillArray(int *, int);
int /*<<< orphan*/ quickSort(int *, int, int);
int rand();
float getTimeForBinarySearch(int arr[], int left, int right) {
  int result, i, value;
  float total = 0.0;
  clock_t start, stop;
  for (i = 0; i < 5000; i++) {
    value = rand();
    fillArray(arr, right);
    quickSort(arr, left, right);
    start = clock();
    result = binarySearch(arr, left, right, value);
    stop = clock();
    total += (float)(1000 * (stop - start) / CLOCKS_PER_SEC);
  }
  total = (float)total / 5000;
  return total;
}


x86 assembly (clang, -O0):
<getTimeForBinarySearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1388,-0x18(%rbp)
jge    11fe <getTimeForBinarySearch+0xae>
mov    $0x0,%al
call   1070 <rand@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <fillArray@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <quickSort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <binarySearch@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
sub    -0x24(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    0x2e09(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2ss %eax,%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1171 <getTimeForBinarySearch+0x21>
movss  -0x20(%rbp),%xmm0
movss  0xdf5(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTimeForBinarySearch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%r12
xorps  %xmm0,%xmm0
mov    $0x1388,%ebx
nopl   0x0(%rax)
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%r13d
mov    %r12,%rdi
mov    %r15d,%esi
call   1040 <fillArray@plt>
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r15d,%edx
call   1060 <quickSort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %r13d,%ecx
call   1050 <binarySearch@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %ebp,%eax
imul   $0x3e8,%eax,%eax
cltd
mov    0x2e1e(%rip),%rcx
idivl  (%rcx)
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movss  0x4(%rsp),%xmm0
add    $0xffffffff,%ebx
jne    1170 <getTimeForBinarySearch+0x20>
divss  0xe0a(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global i32 0
define float @getTimeForBinarySearch(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca float
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store float 0.000000e+00, float* %10
store i32 0, i32* %8
br label %13
13: ; preds = %41, %3
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 5000
br i1 %15, label %16, label %44
16: ; preds = %13
%17 = call i32 (...) @rand()
store i32 %17, i32* %9
%18 = load i32*, i32** %4
%19 = load i32, i32* %6
%20 = call i32 @fillArray(i32* %18, i32 %19)
%21 = load i32*, i32** %4
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = call i32 @quickSort(i32* %21, i32 %22, i32 %23)
%25 = call i32 (...) @clock()
store i32 %25, i32* %11
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = load i32, i32* %9
%30 = call i32 @binarySearch(i32* %26, i32 %27, i32 %28, i32 %29)
store i32 %30, i32* %7
%31 = call i32 (...) @clock()
store i32 %31, i32* %12
%32 = load i32, i32* %12
%33 = load i32, i32* %11
%34 = sub nsw i32 %32, %33
%35 = mul nsw i32 1000, %34
%36 = load i32, i32* @CLOCKS_PER_SEC
%37 = sdiv i32 %35, %36
%38 = sitofp i32 %37 to float
%39 = load float, float* %10
%40 = fadd float %39, %38
store float %40, float* %10
br label %41
41: ; preds = %16
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %13
44: ; preds = %13
%45 = load float, float* %10
%46 = fdiv float %45, 5.000000e+03
store float %46, float* %10
%47 = load float, float* %10
ret float %47
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global i32 0
define float @getTimeForBinarySearch(i32* %0, i32 %1, i32 %2) {
br label %4
4: ; preds = %3, %4
%5 = phi i32 [ 0, %3 ], [ %19, %4 ]
%6 = phi float [ 0.000000e+00, %3 ], [ %18, %4 ]
%7 = tail call i32 (...) @rand()
%8 = tail call i32 @fillArray(i32* %0, i32 %2)
%9 = tail call i32 @quickSort(i32* %0, i32 %1, i32 %2)
%10 = tail call i32 (...) @clock()
%11 = tail call i32 @binarySearch(i32* %0, i32 %1, i32 %2, i32 %7)
%12 = tail call i32 (...) @clock()
%13 = sub nsw i32 %12, %10
%14 = mul nsw i32 %13, 1000
%15 = load i32, i32* @CLOCKS_PER_SEC
%16 = sdiv i32 %14, %15
%17 = sitofp i32 %16 to float
%18 = fadd float %6, %17
%19 = add nuw nsw i32 %5, 1
%20 = icmp eq i32 %19, 5000
br i1 %20, label %21, label %4
21: ; preds = %4
%22 = fdiv float %18, 5.000000e+03
ret float %22
}