#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*/ assert(int);
long floor(double);
long AT_histo_linear_bin_no(const long number_of_bins,
                            const double lowest_left_limit, const double step,
                            const double value) {
  double difference = value - lowest_left_limit;
  if (difference < 0) {
    return (-1);
  }
  assert(step > 0.0);
  long bin_no = floor(difference / step);
  if (bin_no > number_of_bins - 1) {
    return (-2);
  }
  return (bin_no);
}


x86 assembly (clang, -O0):
<AT_histo_linear_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
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1165 <AT_histo_linear_bin_no+0x45>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11bb <AT_histo_linear_bin_no+0x9b>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  -0x30(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <floor@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jle    11b3 <AT_histo_linear_bin_no+0x93>
movq   $0xfffffffffffffffe,-0x8(%rbp)
ff
jmp    11bb <AT_histo_linear_bin_no+0x9b>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AT_histo_linear_bin_no>:
subsd  %xmm0,%xmm2
mov    $0xffffffffffffffff,%rax
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
ja     117d <AT_histo_linear_bin_no+0x5d>
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
ucomisd %xmm0,%xmm1
seta   %dil
movsd  %xmm2,(%rsp)
movsd  %xmm1,0x8(%rsp)
call   1030 <assert@plt>
movsd  (%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
call   1040 <floor@plt>
mov    %rax,%rcx
cmp    %rbx,%rax
mov    $0xfffffffffffffffe,%rax
cmovl  %rcx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @AT_histo_linear_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 = fsub double %12, %13
store double %14, double* %10
%15 = load double, double* %10
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %4
store i64 -1, i64* %5
br label %34
18: ; preds = %4
%19 = load double, double* %8
%20 = fcmp ogt double %19, 0.000000e+00
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load double, double* %10
%24 = load double, double* %8
%25 = fdiv double %23, %24
%26 = call i64 @floor(double %25)
store i64 %26, i64* %11
%27 = load i64, i64* %11
%28 = load i64, i64* %6
%29 = sub nsw i64 %28, 1
%30 = icmp sgt i64 %27, %29
br i1 %30, label %31, label %32
31: ; preds = %18
store i64 -2, i64* %5
br label %34
32: ; preds = %18
%33 = load i64, i64* %11
store i64 %33, i64* %5
br label %34
34: ; preds = %32, %31, %17
%35 = load i64, i64* %5
ret i64 %35
}

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