#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);
double get_dx(double const *);
int max(int, int);
int min(int, int);
int find_xb(double x, const double a[], int n, int b) {
  assert(b < n);
  double dx = get_dx(a);
  int ix = (x - a[0]) / dx;
  ix = max(ix, b);
  ix = min(ix, n - b - 1);
  return ix;
}


x86 assembly (clang, -O0):
<find_xb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <get_dx@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <max@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%esi
sub    -0x18(%rbp),%esi
sub    $0x1,%esi
call   1040 <min@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_xb>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
cmp    %edx,%esi
setg   %dil
call   1060 <assert@plt>
mov    %rbp,%rdi
call   1030 <get_dx@plt>
movsd  0x8(%rsp),%xmm1
subsd  0x0(%rbp),%xmm1
divsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
mov    %ebx,%esi
call   1050 <max@plt>
not    %ebx
add    %r14d,%ebx
mov    %eax,%edi
mov    %ebx,%esi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <min@plt>

LLVM IR (-O0):
define i32 @find_xb(double %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
store double %0, double* %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load double*, double** %6
%17 = call double @get_dx(double* %16)
store double %17, double* %9
%18 = load double, double* %5
%19 = load double*, double** %6
%20 = getelementptr inbounds double, double* %19, i64 0
%21 = load double, double* %20
%22 = fsub double %18, %21
%23 = load double, double* %9
%24 = fdiv double %22, %23
%25 = fptosi double %24 to i32
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = load i32, i32* %8
%28 = call i32 @max(i32 %26, i32 %27)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = sub nsw i32 %30, %31
%33 = sub nsw i32 %32, 1
%34 = call i32 @min(i32 %29, i32 %33)
store i32 %34, i32* %10
%35 = load i32, i32* %10
ret i32 %35
}

LLVM IR (-O2):
define i32 @find_xb(double %0, double* %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, %3
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call double @get_dx(double* %1)
%9 = load double, double* %1
%10 = fsub double %0, %9
%11 = fdiv double %10, %8
%12 = fptosi double %11 to i32
%13 = tail call i32 @max(i32 %12, i32 %3)
%14 = xor i32 %3, -1
%15 = add i32 %14, %2
%16 = tail call i32 @min(i32 %13, i32 %15)
ret i32 %16
}