#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 binsearch(int, int *, int);
int binsearch_one_test(int, int *, int);
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double, ...);
int main() {
  int i;
  int v[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
  int n = 10;
  clock_t begin, end;
  double runtime;
  begin = clock();
  for (i = 0; i < n; i++) {
    printf("expected: %d, actual: %d\n", i,
           binsearch_one_test((i + 1) * 10, v, n));
  }
  end = clock();
  runtime = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("time: %lf\n", runtime);
  begin = clock();
  for (i = 0; i < n; i++) {
    printf("expected: %d, actual: %d\n", i, binsearch((i + 1) * 10, v, n));
  }
  end = clock();
  runtime = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("time: %lf\n", runtime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x28,%edx
call   1070 <memcpy@plt>
movl   $0xa,-0x34(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11db <main+0x8b>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
imul   $0xa,%eax,%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1050 <binsearch_one_test@plt>
movsd  -0x58(%rbp),%xmm0
mov    %eax,%esi
lea    0xe62(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118d <main+0x3d>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dee(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
lea    0xe33(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1276 <main+0x126>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
imul   $0xa,%eax,%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <binsearch@plt>
movsd  -0x60(%rbp),%xmm0
mov    %eax,%esi
lea    0xdc7(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1228 <main+0xd8>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d53(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
lea    0xd98(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    0xf1c(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xf00(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xee4(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r15
mov    %rsp,%r14
mov    $0xa,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearch_one_test@plt>
lea    0xee2(%rip),%rbx
xorps  %xmm0,%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x14,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearch_one_test@plt>
movsd  0xe41(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x1e,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearch_one_test@plt>
movsd  0xe23(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x28,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearch_one_test@plt>
movsd  0xe05(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x32,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearch_one_test@plt>
movsd  0xde7(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x3c,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearch_one_test@plt>
movsd  0xdc9(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x46,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearch_one_test@plt>
movsd  0xdab(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x50,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearch_one_test@plt>
movsd  0xd8d(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x5a,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearch_one_test@plt>
movsd  0xd6f(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x64,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearch_one_test@plt>
movsd  0xd51(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r15,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2cd4(%rip),%r13
divsd  0x0(%r13),%xmm0
lea    0xd71(%rip),%r15
mov    %r15,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r12
mov    $0xa,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
xorpd  %xmm0,%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x14,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
movsd  0xc8c(%rip),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x1e,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
movsd  0xc6e(%rip),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x28,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
movsd  0xc50(%rip),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x32,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
movsd  0xc32(%rip),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x3c,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
movsd  0xc14(%rip),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x46,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
movsd  0xbf6(%rip),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x50,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
movsd  0xbd8(%rip),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x5a,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
movsd  0xbba(%rip),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x64,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
movsd  0xb9c(%rip),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r12,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0x0(%r13),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.v = [10 x i32] [i32 10, i32 20, i32 30, i32 40, i32 50, i32 60, i32 70, i32 80, i32 90, i32 100]
@.str = [26 x i8] c"expected: %d, actual: %d\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [11 x i8] c"time: %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i32]
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
store i32 0, i32* %1
%8 = bitcast [10 x i32]* %3 to i8*
store i32 10, i32* %4
%9 = call i64 (...) @clock()
store i64 %9, i64* %5
store i32 0, i32* %2
br label %10
10: ; preds = %24, %0
%11 = load i32, i32* %2
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %10
%15 = load i32, i32* %2
%16 = sitofp i32 %15 to double
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
%19 = mul nsw i32 %18, 10
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%21 = load i32, i32* %4
%22 = call i32 @binsearch_one_test(i32 %19, i32* %20, i32 %21)
%23 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %16, i32 %22)
br label %24
24: ; preds = %14
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %10
27: ; preds = %10
%28 = call i64 (...) @clock()
store i64 %28, i64* %6
%29 = load i64, i64* %6
%30 = load i64, i64* %5
%31 = sub nsw i64 %29, %30
%32 = sitofp i64 %31 to double
%33 = load double, double* @CLOCKS_PER_SEC
%34 = fdiv double %32, %33
store double %34, double* %7
%35 = load double, double* %7
%36 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %35)
%37 = call i64 (...) @clock()
store i64 %37, i64* %5
store i32 0, i32* %2
br label %38
38: ; preds = %52, %27
%39 = load i32, i32* %2
%40 = load i32, i32* %4
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %55
42: ; preds = %38
%43 = load i32, i32* %2
%44 = sitofp i32 %43 to double
%45 = load i32, i32* %2
%46 = add nsw i32 %45, 1
%47 = mul nsw i32 %46, 10
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%49 = load i32, i32* %4
%50 = call i32 @binsearch(i32 %47, i32* %48, i32 %49)
%51 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %44, i32 %50)
br label %52
52: ; preds = %42
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 1
store i32 %54, i32* %2
br label %38
55: ; preds = %38
%56 = call i64 (...) @clock()
store i64 %56, i64* %6
%57 = load i64, i64* %6
%58 = load i64, i64* %5
%59 = sub nsw i64 %57, %58
%60 = sitofp i64 %59 to double
%61 = load double, double* @CLOCKS_PER_SEC
%62 = fdiv double %60, %61
store double %62, double* %7
%63 = load double, double* %7
%64 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %63)
ret i32 0
}

LLVM IR (-O2):
@__const.main.v = [10 x i32] [i32 10, i32 20, i32 30, i32 40, i32 50, i32 60, i32 70, i32 80, i32 90, i32 100]
@.str = [26 x i8] c"expected: %d, actual: %d\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [11 x i8] c"time: %lf\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = tail call i64 (...) @clock()
%4 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%5 = call i32 @binsearch_one_test(i32 10, i32* %4, i32 10)
%6 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 0.000000e+00, i32 %5)
%7 = call i32 @binsearch_one_test(i32 20, i32* %4, i32 10)
%8 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 1.000000e+00, i32 %7)
%9 = call i32 @binsearch_one_test(i32 30, i32* %4, i32 10)
%10 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 2.000000e+00, i32 %9)
%11 = call i32 @binsearch_one_test(i32 40, i32* %4, i32 10)
%12 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 3.000000e+00, i32 %11)
%13 = call i32 @binsearch_one_test(i32 50, i32* %4, i32 10)
%14 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 4.000000e+00, i32 %13)
%15 = call i32 @binsearch_one_test(i32 60, i32* %4, i32 10)
%16 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 5.000000e+00, i32 %15)
%17 = call i32 @binsearch_one_test(i32 70, i32* %4, i32 10)
%18 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 6.000000e+00, i32 %17)
%19 = call i32 @binsearch_one_test(i32 80, i32* %4, i32 10)
%20 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 7.000000e+00, i32 %19)
%21 = call i32 @binsearch_one_test(i32 90, i32* %4, i32 10)
%22 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 8.000000e+00, i32 %21)
%23 = call i32 @binsearch_one_test(i32 100, i32* %4, i32 10)
%24 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 9.000000e+00, i32 %23)
%25 = call i64 (...) @clock()
%26 = sub nsw i64 %25, %3
%27 = sitofp i64 %26 to double
%28 = load double, double* @CLOCKS_PER_SEC
%29 = fdiv double %27, %28
%30 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %29)
%31 = call i64 (...) @clock()
%32 = call i32 @binsearch(i32 10, i32* %4, i32 10)
%33 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 0.000000e+00, i32 %32)
%34 = call i32 @binsearch(i32 20, i32* %4, i32 10)
%35 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 1.000000e+00, i32 %34)
%36 = call i32 @binsearch(i32 30, i32* %4, i32 10)
%37 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 2.000000e+00, i32 %36)
%38 = call i32 @binsearch(i32 40, i32* %4, i32 10)
%39 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 3.000000e+00, i32 %38)
%40 = call i32 @binsearch(i32 50, i32* %4, i32 10)
%41 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 4.000000e+00, i32 %40)
%42 = call i32 @binsearch(i32 60, i32* %4, i32 10)
%43 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 5.000000e+00, i32 %42)
%44 = call i32 @binsearch(i32 70, i32* %4, i32 10)
%45 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 6.000000e+00, i32 %44)
%46 = call i32 @binsearch(i32 80, i32* %4, i32 10)
%47 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 7.000000e+00, i32 %46)
%48 = call i32 @binsearch(i32 90, i32* %4, i32 10)
%49 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 8.000000e+00, i32 %48)
%50 = call i32 @binsearch(i32 100, i32* %4, i32 10)
%51 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 9.000000e+00, i32 %50)
%52 = call i64 (...) @clock()
%53 = sub nsw i64 %52, %31
%54 = sitofp i64 %53 to double
%55 = load double, double* @CLOCKS_PER_SEC
%56 = fdiv double %54, %55
%57 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %56)
ret i32 0
}