#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 */
scalar_t__ floor(double);
int getindex(double value, const double *range) {
  if (range[2] == 0.0)
    return 0;
  if (range[1] > 0.0 && (value < range[0] || range[1] < value))
    return -1;
  if (range[1] < 0.0 && (value < range[1] || range[0] < value))
    return -1;
  return (int)floor((value - range[0]) / range[2] + 0.5);
}


x86 assembly (clang, -O0):
<getindex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1149 <getindex+0x39>
jp     1149 <getindex+0x39>
movl   $0x0,-0x4(%rbp)
jmp    1211 <getindex+0x101>
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    119a <getindex+0x8a>
movsd  -0x10(%rbp),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
ja     118e <getindex+0x7e>
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    119a <getindex+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <getindex+0x101>
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd 0x8(%rax),%xmm0
jbe    11e7 <getindex+0xd7>
movsd  -0x10(%rbp),%xmm1
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
ucomisd %xmm1,%xmm0
ja     11db <getindex+0xcb>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e7 <getindex+0xd7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <getindex+0x101>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
divsd  0x10(%rax),%xmm0
movsd  0xdfb(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <floor@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getindex>:
push   %rax
movsd  0x10(%rdi),%xmm1
xor    %eax,%eax
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
jne    1126 <getindex+0x16>
jp     1126 <getindex+0x16>
pop    %rcx
ret
movsd  0x8(%rdi),%xmm2
ucomisd %xmm3,%xmm2
jbe    1146 <getindex+0x36>
movsd  (%rdi),%xmm3
ucomisd %xmm0,%xmm3
mov    $0xffffffff,%eax
ja     1124 <getindex+0x14>
ucomisd %xmm2,%xmm0
ja     1124 <getindex+0x14>
xorpd  %xmm3,%xmm3
ucomisd %xmm2,%xmm3
jbe    1167 <getindex+0x57>
mov    $0xffffffff,%eax
ucomisd %xmm0,%xmm2
ja     1124 <getindex+0x14>
movsd  (%rdi),%xmm2
ucomisd %xmm2,%xmm0
jbe    116b <getindex+0x5b>
jmp    1124 <getindex+0x14>
movsd  (%rdi),%xmm2
subsd  %xmm2,%xmm0
divsd  %xmm1,%xmm0
addsd  0xe85(%rip),%xmm0
call   1030 <floor@plt>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @getindex(double %0, double* %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double*
store double %0, double* %4
store double* %1, double** %5
%6 = load double*, double** %5
%7 = getelementptr inbounds double, double* %6, i64 2
%8 = load double, double* %7
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %60
11: ; preds = %2
%12 = load double*, double** %5
%13 = getelementptr inbounds double, double* %12, i64 1
%14 = load double, double* %13
%15 = fcmp ogt double %14, 0.000000e+00
br i1 %15, label %16, label %29
16: ; preds = %11
%17 = load double, double* %4
%18 = load double*, double** %5
%19 = getelementptr inbounds double, double* %18, i64 0
%20 = load double, double* %19
%21 = fcmp olt double %17, %20
br i1 %21, label %28, label %22
22: ; preds = %16
%23 = load double*, double** %5
%24 = getelementptr inbounds double, double* %23, i64 1
%25 = load double, double* %24
%26 = load double, double* %4
%27 = fcmp olt double %25, %26
br i1 %27, label %28, label %29
28: ; preds = %22, %16
store i32 -1, i32* %3
br label %60
29: ; preds = %22, %11
%30 = load double*, double** %5
%31 = getelementptr inbounds double, double* %30, i64 1
%32 = load double, double* %31
%33 = fcmp olt double %32, 0.000000e+00
br i1 %33, label %34, label %47
34: ; preds = %29
%35 = load double, double* %4
%36 = load double*, double** %5
%37 = getelementptr inbounds double, double* %36, i64 1
%38 = load double, double* %37
%39 = fcmp olt double %35, %38
br i1 %39, label %46, label %40
40: ; preds = %34
%41 = load double*, double** %5
%42 = getelementptr inbounds double, double* %41, i64 0
%43 = load double, double* %42
%44 = load double, double* %4
%45 = fcmp olt double %43, %44
br i1 %45, label %46, label %47
46: ; preds = %40, %34
store i32 -1, i32* %3
br label %60
47: ; preds = %40, %29
%48 = load double, double* %4
%49 = load double*, double** %5
%50 = getelementptr inbounds double, double* %49, i64 0
%51 = load double, double* %50
%52 = fsub double %48, %51
%53 = load double*, double** %5
%54 = getelementptr inbounds double, double* %53, i64 2
%55 = load double, double* %54
%56 = fdiv double %52, %55
%57 = fadd double %56, 5.000000e-01
%58 = call i64 @floor(double %57)
%59 = trunc i64 %58 to i32
store i32 %59, i32* %3
br label %60
60: ; preds = %47, %46, %28, %10
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
define i32 @getindex(double %0, double* nocapture %1) {
%3 = getelementptr inbounds double, double* %1, i64 2
%4 = load double, double* %3
%5 = fcmp oeq double %4, 0.000000e+00
br i1 %5, label %31, label %6
6: ; preds = %2
%7 = getelementptr inbounds double, double* %1, i64 1
%8 = load double, double* %7
%9 = fcmp ogt double %8, 0.000000e+00
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load double, double* %1
%12 = fcmp ogt double %11, %0
%13 = fcmp olt double %8, %0
%14 = select i1 %12, i1 true, i1 %13
br i1 %14, label %31, label %15
15: ; preds = %10, %6
%16 = fcmp olt double %8, 0.000000e+00
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = load double, double* %1
br label %24
19: ; preds = %15
%20 = fcmp ogt double %8, %0
br i1 %20, label %31, label %21
21: ; preds = %19
%22 = load double, double* %1
%23 = fcmp olt double %22, %0
br i1 %23, label %31, label %24
24: ; preds = %17, %21
%25 = phi double [ %18, %17 ], [ %22, %21 ]
%26 = fsub double %0, %25
%27 = fdiv double %26, %4
%28 = fadd double %27, 5.000000e-01
%29 = tail call i64 @floor(double %28)
%30 = trunc i64 %29 to i32
br label %31
31: ; preds = %19, %21, %10, %2, %24
%32 = phi i32 [ %30, %24 ], [ 0, %2 ], [ -1, %10 ], [ -1, %21 ], [ -1, %19 ]
ret i32 %32
}