#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 */
long floor(int);
int log10(double const);
long AT_histo_logarithmic_bin_no(const long number_of_bins,
                                 const double lowest_left_limit,
                                 const double step, const double value) {
  double factor = value / lowest_left_limit;
  if (factor < 1.0) {
    return (-1);
  }
  long bin_no = floor(log10(factor) / log10(step));
  if (bin_no > number_of_bins - 1) {
    return (-2);
  }
  return (bin_no);
}


x86 assembly (clang, -O0):
<AT_histo_logarithmic_bin_no>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xeae(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    116a <AT_histo_logarithmic_bin_no+0x4a>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11be <AT_histo_logarithmic_bin_no+0x9e>
movsd  -0x30(%rbp),%xmm0
call   1030 <log10@plt>
mov    %eax,-0x3c(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <log10@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <floor@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jle    11b6 <AT_histo_logarithmic_bin_no+0x96>
movq   $0xfffffffffffffffe,-0x8(%rbp)
ff
jmp    11be <AT_histo_logarithmic_bin_no+0x9e>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AT_histo_logarithmic_bin_no>:
push   %rbp
push   %rbx
push   %rax
divsd  %xmm0,%xmm2
mov    $0xffffffffffffffff,%rax
movsd  0xeca(%rip),%xmm0
ucomisd %xmm2,%xmm0
ja     1178 <AT_histo_logarithmic_bin_no+0x58>
mov    %rdi,%rbx
movapd %xmm2,%xmm0
movsd  %xmm1,(%rsp)
call   1030 <log10@plt>
mov    %eax,%ebp
movsd  (%rsp),%xmm0
call   1030 <log10@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <floor@plt>
mov    %rax,%rcx
cmp    %rbx,%rax
mov    $0xfffffffffffffffe,%rax
cmovl  %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i64 @AT_histo_logarithmic_bin_no(i64 %0, double %1, double %2, double %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i64
store i64 %0, i64* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%12 = load double, double* %9
%13 = load double, double* %7
%14 = fdiv double %12, %13
store double %14, double* %10
%15 = load double, double* %10
%16 = fcmp olt double %15, 1.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %4
store i64 -1, i64* %5
br label %32
18: ; preds = %4
%19 = load double, double* %10
%20 = call i32 @log10(double %19)
%21 = load double, double* %8
%22 = call i32 @log10(double %21)
%23 = sdiv i32 %20, %22
%24 = call i64 @floor(i32 %23)
store i64 %24, i64* %11
%25 = load i64, i64* %11
%26 = load i64, i64* %6
%27 = sub nsw i64 %26, 1
%28 = icmp sgt i64 %25, %27
br i1 %28, label %29, label %30
29: ; preds = %18
store i64 -2, i64* %5
br label %32
30: ; preds = %18
%31 = load i64, i64* %11
store i64 %31, i64* %5
br label %32
32: ; preds = %30, %29, %17
%33 = load i64, i64* %5
ret i64 %33
}

LLVM IR (-O2):
define i64 @AT_histo_logarithmic_bin_no(i64 %0, double %1, double %2, double %3) {
%5 = fdiv double %3, %1
%6 = fcmp olt double %5, 1.000000e+00
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = tail call i32 @log10(double %5)
%9 = tail call i32 @log10(double %2)
%10 = sdiv i32 %8, %9
%11 = tail call i64 @floor(i32 %10)
%12 = icmp slt i64 %11, %0
%13 = select i1 %12, i64 %11, i64 -2
br label %14
14: ; preds = %4, %7
%15 = phi i64 [ %13, %7 ], [ -1, %4 ]
ret i64 %15
}