#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int Which_bin(float data, float bin_maxes[], int bin_count, float min_meas) {
  int bottom = 0, top = bin_count - 1;
  int mid;
  float bin_max, bin_min;
  while (bottom <= top) {
    mid = (bottom + top) / 2;
    bin_max = bin_maxes[mid];
    bin_min = (mid == 0) ? min_meas : bin_maxes[mid - 1];
    if (data >= bin_max)
      bottom = mid + 1;
    else if (data < bin_min)
      top = mid - 1;
    else
      return mid;
  }
  fprintf(stderr, "Data = %f doesn't belong to a bin!\n", data);
  fprintf(stderr, "Quitting\n");
  exit(-1);
}


x86 assembly (clang, -O0):
<Which_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movss  %xmm1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1203 <Which_bin+0xe3>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1191 <Which_bin+0x71>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
jmp    11a8 <Which_bin+0x88>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x4(%rbp),%xmm0
ucomiss -0x28(%rbp),%xmm0
jb     11cf <Which_bin+0xaf>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fe <Which_bin+0xde>
movss  -0x4(%rbp),%xmm1
movss  -0x2c(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    11f0 <Which_bin+0xd0>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11f9 <Which_bin+0xd9>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret
jmp    11fe <Which_bin+0xde>
jmp    1149 <Which_bin+0x29>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde4(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<Which_bin>:
push   %rbx
test   %esi,%esi
jle    1175 <Which_bin+0x55>
add    $0xffffffff,%esi
xor    %r8d,%r8d
jmp    113b <Which_bin+0x1b>
nopl   (%rax)
add    $0x1,%eax
mov    %eax,%r8d
cmp    %esi,%r8d
jg     1175 <Which_bin+0x55>
lea    (%r8,%rsi,1),%edx
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
movslq %eax,%rdx
lea    (%r8,%rsi,1),%ecx
add    $0x1,%ecx
movaps %xmm1,%xmm2
cmp    $0x3,%ecx
jb     1160 <Which_bin+0x40>
movss  -0x4(%rdi,%rdx,4),%xmm2
ucomiss (%rdi,%rdx,4),%xmm0
jae    1130 <Which_bin+0x10>
ucomiss %xmm0,%xmm2
jbe    11aa <Which_bin+0x8a>
add    $0xffffffff,%eax
mov    %eax,%esi
cmp    %esi,%r8d
jle    113b <Which_bin+0x1b>
mov    0x2e64(%rip),%rbx
mov    (%rbx),%edi
cvtss2sd %xmm0,%xmm0
lea    0xe77(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe8b(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Data = %f doesn't belong to a bin!\0A\00"
@.str.1 = [10 x i8] c"Quitting\0A\00"
define i32 @Which_bin(float %0, float* %1, i32 %2, float %3) {
%5 = alloca float
%6 = alloca float*
%7 = alloca i32
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca float
%13 = alloca float
store float %0, float* %5
store float* %1, float** %6
store i32 %2, i32* %7
store float %3, float* %8
store i32 0, i32* %9
%14 = load i32, i32* %7
%15 = sub nsw i32 %14, 1
store i32 %15, i32* %10
br label %16
16: ; preds = %59, %4
%17 = load i32, i32* %9
%18 = load i32, i32* %10
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %60
20: ; preds = %16
%21 = load i32, i32* %9
%22 = load i32, i32* %10
%23 = add nsw i32 %21, %22
%24 = sdiv i32 %23, 2
store i32 %24, i32* %11
%25 = load float*, float** %6
%26 = load i32, i32* %11
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds float, float* %25, i64 %27
%29 = load float, float* %28
store float %29, float* %12
%30 = load i32, i32* %11
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = load float, float* %8
br label %41
34: ; preds = %20
%35 = load float*, float** %6
%36 = load i32, i32* %11
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds float, float* %35, i64 %38
%40 = load float, float* %39
br label %41
41: ; preds = %34, %32
%42 = phi float [ %33, %32 ], [ %40, %34 ]
store float %42, float* %13
%43 = load float, float* %5
%44 = load float, float* %12
%45 = fcmp oge float %43, %44
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %59
49: ; preds = %41
%50 = load float, float* %5
%51 = load float, float* %13
%52 = fcmp olt float %50, %51
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* %11
%55 = sub nsw i32 %54, 1
store i32 %55, i32* %10
br label %58
56: ; preds = %49
%57 = load i32, i32* %11
ret i32 %57
58: ; preds = %53
br label %59
59: ; preds = %58, %46
br label %16
60: ; preds = %16
%61 = load i32, i32* @stderr
%62 = load float, float* %5
%63 = fpext float %62 to double
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %63)
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%67 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Data = %f doesn't belong to a bin!\0A\00"
@.str.1 = [10 x i8] c"Quitting\0A\00"
define i32 @Which_bin(float %0, float* nocapture %1, i32 %2, float %3) {
%5 = icmp slt i32 %2, 1
br i1 %5, label %37, label %6
6: ; preds = %4
%7 = add nsw i32 %2, -1
br label %8
8: ; preds = %6, %33
%9 = phi i32 [ %35, %33 ], [ 0, %6 ]
%10 = phi i32 [ %34, %33 ], [ %7, %6 ]
%11 = add nsw i32 %9, %10
%12 = sdiv i32 %11, 2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds float, float* %1, i64 %13
%15 = load float, float* %14
%16 = add i32 %11, 1
%17 = icmp ult i32 %16, 3
br i1 %17, label %23, label %18
18: ; preds = %8
%19 = add nsw i32 %12, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds float, float* %1, i64 %20
%22 = load float, float* %21
br label %23
23: ; preds = %8, %18
%24 = phi float [ %22, %18 ], [ %3, %8 ]
%25 = fcmp ugt float %15, %0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = add nsw i32 %12, 1
br label %33
28: ; preds = %23
%29 = fcmp ogt float %24, %0
br i1 %29, label %30, label %32
30: ; preds = %28
%31 = add nsw i32 %12, -1
br label %33
32: ; preds = %28
ret i32 %12
33: ; preds = %30, %26
%34 = phi i32 [ %10, %26 ], [ %31, %30 ]
%35 = phi i32 [ %27, %26 ], [ %9, %30 ]
%36 = icmp sgt i32 %35, %34
br i1 %36, label %37, label %8
37: ; preds = %33, %4
%38 = load i32, i32* @stderr
%39 = fpext float %0 to double
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %39)
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%43 = tail call i32 @exit(i32 -1)
unreachable
}