#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 ceil(float);
int floor(float);
float lut_interp_linear_float(float value, float *table, size_t length) {
  int upper, lower;
  value = value * (length - 1);
  upper = ceil(value);
  lower = floor(value);
  value =
      table[upper] * (1. - (upper - value)) + table[lower] * (upper - value);
  return value;
}


x86 assembly (clang, -O0):
<lut_interp_linear_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x28(%rbp)
test   %rax,%rax
movss  %xmm0,-0x24(%rbp)
js     1180 <lut_interp_linear_float+0x60>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
call   1030 <ceil@plt>
mov    %eax,-0x1c(%rbp)
movss  -0x4(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
subss  -0x4(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xe2c(%rip),%xmm2
subsd  %xmm1,%xmm2
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtsi2ssl -0x1c(%rbp),%xmm3
subss  -0x4(%rbp),%xmm3
mulss  %xmm3,%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lut_interp_linear_float>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rsi
js     1133 <lut_interp_linear_float+0x13>
cvtsi2ss %rsi,%xmm1
jmp    1148 <lut_interp_linear_float+0x28>
mov    %rsi,%rax
shr    %rax
and    $0x1,%esi
or     %rax,%rsi
cvtsi2ss %rsi,%xmm1
addss  %xmm1,%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movaps %xmm1,%xmm0
call   1030 <ceil@plt>
mov    %eax,%ebp
movss  0x4(%rsp),%xmm0
call   1040 <floor@plt>
movslq %ebp,%rcx
movss  (%rbx,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %ecx,%xmm1
subss  0x4(%rsp),%xmm1
cvtss2sd %xmm1,%xmm2
movsd  0xe74(%rip),%xmm3
subsd  %xmm2,%xmm3
mulsd  %xmm0,%xmm3
cltq
mulss  (%rbx,%rax,4),%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
addsd  %xmm3,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define float @lut_interp_linear_float(float %0, float* %1, i64 %2) {
%4 = alloca float
%5 = alloca float*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store float %0, float* %4
store float* %1, float** %5
store i64 %2, i64* %6
%9 = load float, float* %4
%10 = load i64, i64* %6
%11 = sub i64 %10, 1
%12 = uitofp i64 %11 to float
%13 = fmul float %9, %12
store float %13, float* %4
%14 = load float, float* %4
%15 = call i32 @ceil(float %14)
store i32 %15, i32* %7
%16 = load float, float* %4
%17 = call i32 @floor(float %16)
store i32 %17, i32* %8
%18 = load float*, float** %5
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds float, float* %18, i64 %20
%22 = load float, float* %21
%23 = fpext float %22 to double
%24 = load i32, i32* %7
%25 = sitofp i32 %24 to float
%26 = load float, float* %4
%27 = fsub float %25, %26
%28 = fpext float %27 to double
%29 = fsub double 1.000000e+00, %28
%30 = load float*, float** %5
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds float, float* %30, i64 %32
%34 = load float, float* %33
%35 = load i32, i32* %7
%36 = sitofp i32 %35 to float
%37 = load float, float* %4
%38 = fsub float %36, %37
%39 = fmul float %34, %38
%40 = fpext float %39 to double
%41 = call double @llvm.fmuladd.f64(double %23, double %29, double %40)
%42 = fptrunc double %41 to float
store float %42, float* %4
%43 = load float, float* %4
ret float %43
}

LLVM IR (-O2):
define float @lut_interp_linear_float(float %0, float* nocapture %1, i64 %2) {
%4 = add i64 %2, -1
%5 = uitofp i64 %4 to float
%6 = fmul float %5, %0
%7 = tail call i32 @ceil(float %6)
%8 = tail call i32 @floor(float %6)
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds float, float* %1, i64 %9
%11 = load float, float* %10
%12 = fpext float %11 to double
%13 = sitofp i32 %7 to float
%14 = fsub float %13, %6
%15 = fpext float %14 to double
%16 = fsub double 1.000000e+00, %15
%17 = sext i32 %8 to i64
%18 = getelementptr inbounds float, float* %1, i64 %17
%19 = load float, float* %18
%20 = fmul float %14, %19
%21 = fpext float %20 to double
%22 = tail call double @llvm.fmuladd.f64(double %12, double %16, double %21)
%23 = fptrunc double %22 to float
ret float %23
}