#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 */
double get_base(double, double);
int /*<<< orphan*/ isfinite(double);
double log(double);
int log_bin(double input, double error_slope, double error_offset) {
  if (!isfinite(error_slope) || !isfinite(error_offset)) {
    return 0;
  }
  double base = get_base(error_slope, error_offset);
  int bin;
  if (base <= 1 + error_offset * 3.0 / 10.) {
    bin = input / (2 * (error_slope + error_offset) * 3.0);
  } else {
    bin = (log(input * error_slope / error_offset + 1) / log(base)) / 3.0;
  }
  return bin;
}


x86 assembly (clang, -O0):
<log_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <isfinite@plt>
cmp    $0x0,%eax
je     116d <log_bin+0x3d>
movsd  -0x20(%rbp),%xmm0
call   1040 <isfinite@plt>
cmp    $0x0,%eax
jne    1179 <log_bin+0x49>
movl   $0x0,-0x4(%rbp)
jmp    124c <log_bin+0x11c>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1030 <get_base@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  0xe76(%rip),%xmm2
mulsd  -0x20(%rbp),%xmm2
movsd  0xe61(%rip),%xmm0
divsd  %xmm0,%xmm2
movsd  0xe4d(%rip),%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     11f8 <log_bin+0xc8>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
addsd  -0x20(%rbp),%xmm2
movsd  0xe40(%rip),%xmm1
mulsd  %xmm2,%xmm1
movsd  0xe2c(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
jmp    1246 <log_bin+0x116>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  0xdf1(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  0xdd5(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_bin>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  %xmm1,0x18(%rsp)
movapd %xmm1,%xmm0
call   1040 <isfinite@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     121a <log_bin+0xea>
movsd  0x8(%rsp),%xmm0
call   1040 <isfinite@plt>
test   %eax,%eax
je     121a <log_bin+0xea>
movsd  0x18(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <get_base@plt>
movapd %xmm0,%xmm1
movsd  0xe76(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
divsd  0xe70(%rip),%xmm0
addsd  0xe70(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    11f4 <log_bin+0xc4>
movsd  0x10(%rsp),%xmm0
mulsd  0x18(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
addsd  0xe50(%rip),%xmm0
movsd  %xmm1,0x8(%rsp)
call   1050 <log@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <log@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
divsd  0xe0e(%rip),%xmm0
jmp    1216 <log_bin+0xe6>
movsd  0x18(%rsp),%xmm1
addsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm1
mulsd  0xdf4(%rip),%xmm1
movsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @log_bin(double %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%10 = load double, double* %6
%11 = call i32 @isfinite(double %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load double, double* %7
%15 = call i32 @isfinite(double %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %13, %3
store i32 0, i32* %4
br label %52
18: ; preds = %13
%19 = load double, double* %6
%20 = load double, double* %7
%21 = call double @get_base(double %19, double %20)
store double %21, double* %8
%22 = load double, double* %8
%23 = load double, double* %7
%24 = fmul double %23, 3.000000e+00
%25 = fdiv double %24, 1.000000e+01
%26 = fadd double 1.000000e+00, %25
%27 = fcmp ole double %22, %26
br i1 %27, label %28, label %37
28: ; preds = %18
%29 = load double, double* %5
%30 = load double, double* %6
%31 = load double, double* %7
%32 = fadd double %30, %31
%33 = fmul double 2.000000e+00, %32
%34 = fmul double %33, 3.000000e+00
%35 = fdiv double %29, %34
%36 = fptosi double %35 to i32
store i32 %36, i32* %9
br label %50
37: ; preds = %18
%38 = load double, double* %5
%39 = load double, double* %6
%40 = fmul double %38, %39
%41 = load double, double* %7
%42 = fdiv double %40, %41
%43 = fadd double %42, 1.000000e+00
%44 = call double @log(double %43)
%45 = load double, double* %8
%46 = call double @log(double %45)
%47 = fdiv double %44, %46
%48 = fdiv double %47, 3.000000e+00
%49 = fptosi double %48 to i32
store i32 %49, i32* %9
br label %50
50: ; preds = %37, %28
%51 = load i32, i32* %9
store i32 %51, i32* %4
br label %52
52: ; preds = %50, %17
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
define i32 @log_bin(double %0, double %1, double %2) {
%4 = tail call i32 @isfinite(double %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %31, label %6
6: ; preds = %3
%7 = tail call i32 @isfinite(double %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %31, label %9
9: ; preds = %6
%10 = tail call double @get_base(double %1, double %2)
%11 = fmul double %2, 3.000000e+00
%12 = fdiv double %11, 1.000000e+01
%13 = fadd double %12, 1.000000e+00
%14 = fcmp ugt double %10, %13
br i1 %14, label %20, label %15
15: ; preds = %9
%16 = fadd double %1, %2
%17 = fmul double %16, 2.000000e+00
%18 = fmul double %17, 3.000000e+00
%19 = fdiv double %0, %18
br label %28
20: ; preds = %9
%21 = fmul double %0, %1
%22 = fdiv double %21, %2
%23 = fadd double %22, 1.000000e+00
%24 = tail call double @log(double %23)
%25 = tail call double @log(double %10)
%26 = fdiv double %24, %25
%27 = fdiv double %26, 3.000000e+00
br label %28
28: ; preds = %20, %15
%29 = phi double [ %19, %15 ], [ %27, %20 ]
%30 = fptosi double %29 to i32
br label %31
31: ; preds = %3, %6, %28
%32 = phi i32 [ %30, %28 ], [ 0, %6 ], [ 0, %3 ]
ret i32 %32
}