#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 binary_search_double(double *array, double target, size_t size) {
  int low, high, mid;
  low = 0;
  mid = 0;
  high = size - 1;
  while (low <= high) {
    mid = low + (high - low) / 2;
    if (array[mid] > target)
      high = mid - 1;
    else if (array[mid] < target)
      low = mid + 1;
    else
      return mid;
  }
  return low - 1;
}


x86 assembly (clang, -O0):
<binary_search_double>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     11b9 <binary_search_double+0xb9>
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    117a <binary_search_double+0x7a>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b4 <binary_search_double+0xb4>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a4 <binary_search_double+0xa4>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11af <binary_search_double+0xaf>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <binary_search_double+0xc2>
jmp    11b4 <binary_search_double+0xb4>
jmp    112a <binary_search_double+0x2a>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_search_double>:
xor    %ecx,%ecx
add    $0xffffffff,%esi
jns    1119 <binary_search_double+0x19>
jmp    1145 <binary_search_double+0x45>
nopl   0x0(%rax)
add    $0xffffffff,%eax
mov    %eax,%esi
cmp    %ecx,%esi
jl     1145 <binary_search_double+0x45>
mov    %esi,%edx
sub    %ecx,%edx
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
add    %ecx,%eax
movslq %eax,%rdx
movsd  (%rdi,%rdx,8),%xmm1
ucomisd %xmm0,%xmm1
ja     1110 <binary_search_double+0x10>
ucomisd %xmm1,%xmm0
jbe    114a <binary_search_double+0x4a>
add    $0x1,%eax
mov    %eax,%ecx
cmp    %ecx,%esi
jge    1119 <binary_search_double+0x19>
add    $0xffffffff,%ecx
mov    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @binary_search_double(double* %0, double %1, i64 %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store double* %0, double** %5
store double %1, double* %6
store i64 %2, i64* %7
store i32 0, i32* %8
store i32 0, i32* %10
%11 = load i64, i64* %7
%12 = sub i64 %11, 1
%13 = trunc i64 %12 to i32
store i32 %13, i32* %9
br label %14
14: ; preds = %49, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %9
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %50
18: ; preds = %14
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = sub nsw i32 %20, %21
%23 = sdiv i32 %22, 2
%24 = add nsw i32 %19, %23
store i32 %24, i32* %10
%25 = load double*, double** %5
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load double, double* %6
%31 = fcmp ogt double %29, %30
br i1 %31, label %32, label %35
32: ; preds = %18
%33 = load i32, i32* %10
%34 = sub nsw i32 %33, 1
store i32 %34, i32* %9
br label %49
35: ; preds = %18
%36 = load double*, double** %5
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = load double, double* %6
%42 = fcmp olt double %40, %41
br i1 %42, label %43, label %46
43: ; preds = %35
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %48
46: ; preds = %35
%47 = load i32, i32* %10
store i32 %47, i32* %4
br label %53
48: ; preds = %43
br label %49
49: ; preds = %48, %32
br label %14
50: ; preds = %14
%51 = load i32, i32* %8
%52 = sub nsw i32 %51, 1
store i32 %52, i32* %4
br label %53
53: ; preds = %50, %46
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
define i32 @binary_search_double(double* nocapture %0, double %1, i64 %2) {
%4 = trunc i64 %2 to i32
%5 = add i32 %4, -1
%6 = icmp slt i32 %5, 0
br i1 %6, label %27, label %7
7: ; preds = %3, %23
%8 = phi i32 [ %25, %23 ], [ %5, %3 ]
%9 = phi i32 [ %24, %23 ], [ 0, %3 ]
%10 = sub nsw i32 %8, %9
%11 = sdiv i32 %10, 2
%12 = add nsw i32 %11, %9
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = load double, double* %14
%16 = fcmp ogt double %15, %1
br i1 %16, label %17, label %19
17: ; preds = %7
%18 = add nsw i32 %12, -1
br label %23
19: ; preds = %7
%20 = fcmp olt double %15, %1
br i1 %20, label %21, label %30
21: ; preds = %19
%22 = add nsw i32 %12, 1
br label %23
23: ; preds = %21, %17
%24 = phi i32 [ %9, %17 ], [ %22, %21 ]
%25 = phi i32 [ %18, %17 ], [ %8, %21 ]
%26 = icmp slt i32 %25, %24
br i1 %26, label %27, label %7
27: ; preds = %23, %3
%28 = phi i32 [ 0, %3 ], [ %24, %23 ]
%29 = add nsw i32 %28, -1
br label %30
30: ; preds = %19, %27
%31 = phi i32 [ %29, %27 ], [ %12, %19 ]
ret i32 %31
}