#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 log(int);
int pow(double, int);
int binarySearch(int *A, int value) {
  int i = 16 / 2;
  for (int j = 1; j <= log(16) / log(2); j++) {
    if (value == A[i]) {
      return i;
    } else if (value < A[i]) {
      i -= 16 * pow(0.5, j + 1);
    } else if (value > A[i]) {
      i += 16 * pow(0.5, j + 1);
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<binarySearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x8,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x10,%edi
call   1030 <log@plt>
mov    %eax,-0x24(%rbp)
mov    $0x2,%edi
call   1030 <log@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jg     1214 <binarySearch+0xf4>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    118e <binarySearch+0x6e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121b <binarySearch+0xfb>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    11c7 <binarySearch+0xa7>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
movsd  0xe50(%rip),%xmm0
call   1040 <pow@plt>
mov    %eax,%ecx
shl    $0x4,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    11fc <binarySearch+0xdc>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11f7 <binarySearch+0xd7>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
movsd  0xe17(%rip),%xmm0
call   1040 <pow@plt>
shl    $0x4,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11fc <binarySearch+0xdc>
jmp    1201 <binarySearch+0xe1>
jmp    1206 <binarySearch+0xe6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <binarySearch+0x1d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binarySearch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%r14
mov    $0x10,%edi
call   1030 <log@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1030 <log@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    $0xffffffff,%r13d
test   %eax,%eax
jle    11de <binarySearch+0xbe>
mov    $0x8,%r13d
mov    $0x1,%r15d
jmp    11aa <binarySearch+0x8a>
nopw   0x0(%rax,%rax,1)
movsd  0xe88(%rip),%xmm0
mov    %ebp,%edi
call   1040 <pow@plt>
shl    $0x4,%eax
sub    %eax,%r13d
mov    $0x10,%edi
call   1030 <log@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   1030 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
cmp    %eax,%r15d
mov    %ebp,%r15d
jge    11d8 <binarySearch+0xb8>
movslq %r13d,%rax
mov    (%r14,%rax,4),%eax
cmp    %r12d,%eax
je     11de <binarySearch+0xbe>
lea    0x1(%r15),%ebp
jg     1170 <binarySearch+0x50>
cmp    %r12d,%eax
jge    1185 <binarySearch+0x65>
movsd  0xe37(%rip),%xmm0
mov    %ebp,%edi
call   1040 <pow@plt>
shl    $0x4,%eax
add    %eax,%r13d
jmp    1185 <binarySearch+0x65>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @binarySearch(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 8, i32* %6
store i32 1, i32* %7
br label %8
8: ; preds = %57, %2
%9 = load i32, i32* %7
%10 = call i32 @log(i32 16)
%11 = call i32 @log(i32 2)
%12 = sdiv i32 %10, %11
%13 = icmp sle i32 %9, %12
br i1 %13, label %14, label %60
14: ; preds = %8
%15 = load i32, i32* %5
%16 = load i32*, i32** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = icmp eq i32 %15, %20
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = load i32, i32* %6
store i32 %23, i32* %3
br label %61
24: ; preds = %14
%25 = load i32, i32* %5
%26 = load i32*, i32** %4
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = icmp slt i32 %25, %30
br i1 %31, label %32, label %39
32: ; preds = %24
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
%35 = call i32 @pow(double 5.000000e-01, i32 %34)
%36 = mul nsw i32 16, %35
%37 = load i32, i32* %6
%38 = sub nsw i32 %37, %36
store i32 %38, i32* %6
br label %55
39: ; preds = %24
%40 = load i32, i32* %5
%41 = load i32*, i32** %4
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = icmp sgt i32 %40, %45
br i1 %46, label %47, label %54
47: ; preds = %39
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
%50 = call i32 @pow(double 5.000000e-01, i32 %49)
%51 = mul nsw i32 16, %50
%52 = load i32, i32* %6
%53 = add nsw i32 %52, %51
store i32 %53, i32* %6
br label %54
54: ; preds = %47, %39
br label %55
55: ; preds = %54, %32
br label %56
56: ; preds = %55
br label %57
57: ; preds = %56
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %8
60: ; preds = %8
store i32 -1, i32* %3
br label %61
61: ; preds = %60, %22
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
define i32 @binarySearch(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @log(i32 16)
%4 = tail call i32 @log(i32 2)
%5 = sdiv i32 %3, %4
%6 = icmp slt i32 %5, 1
br i1 %6, label %35, label %7
7: ; preds = %2, %28
%8 = phi i32 [ %29, %28 ], [ 1, %2 ]
%9 = phi i32 [ %30, %28 ], [ 8, %2 ]
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, %1
br i1 %13, label %35, label %14
14: ; preds = %7
%15 = icmp sgt i32 %12, %1
br i1 %15, label %16, label %21
16: ; preds = %14
%17 = add nuw nsw i32 %8, 1
%18 = tail call i32 @pow(double 5.000000e-01, i32 %17)
%19 = mul i32 %18, -16
%20 = add i32 %19, %9
br label %28
21: ; preds = %14
%22 = icmp slt i32 %12, %1
%23 = add nuw nsw i32 %8, 1
br i1 %22, label %24, label %28
24: ; preds = %21
%25 = tail call i32 @pow(double 5.000000e-01, i32 %23)
%26 = shl nsw i32 %25, 4
%27 = add nsw i32 %26, %9
br label %28
28: ; preds = %21, %24, %16
%29 = phi i32 [ %23, %24 ], [ %17, %16 ], [ %23, %21 ]
%30 = phi i32 [ %27, %24 ], [ %20, %16 ], [ %9, %21 ]
%31 = tail call i32 @log(i32 16)
%32 = tail call i32 @log(i32 2)
%33 = sdiv i32 %31, %32
%34 = icmp slt i32 %8, %33
br i1 %34, label %7, label %35
35: ; preds = %28, %7, %2
%36 = phi i32 [ -1, %2 ], [ %9, %7 ], [ -1, %28 ]
ret i32 %36
}