#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 */
double LinInterp1D(float *, double, long);
scalar_t__ floor(double);
float LinInterp2D(float **arr, double rowind, double colind, long nrow,
                  long ncol) {
  long rowintpart;
  double rowfracpart;
  rowintpart = (long)floor(rowind);
  rowfracpart = rowind - rowintpart;
  if (rowintpart < 0) {
    return (LinInterp1D(arr[0], colind, ncol));
  } else if (rowintpart >= nrow - 1) {
    return (LinInterp1D(arr[nrow - 1], colind, ncol));
  } else {
    return (((1 - rowfracpart) * LinInterp1D(arr[rowintpart], colind, ncol) +
             rowfracpart * LinInterp1D(arr[rowintpart + 1], colind, ncol)) /
            2.0);
  }
}


x86 assembly (clang, -O0):
<LinInterp2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <floor@plt>
mov    %rax,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdq -0x38(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    118e <LinInterp2D+0x6e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movsd  -0x20(%rbp),%xmm0
mov    -0x30(%rbp),%rsi
call   1030 <LinInterp1D@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1258 <LinInterp2D+0x138>
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jl     11cf <LinInterp2D+0xaf>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,8),%rdi
movsd  -0x20(%rbp),%xmm0
mov    -0x30(%rbp),%rsi
call   1030 <LinInterp1D@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1258 <LinInterp2D+0x138>
movsd  0xe31(%rip),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
movsd  -0x20(%rbp),%xmm0
mov    -0x30(%rbp),%rsi
call   1030 <LinInterp1D@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    0x8(%rax,%rcx,8),%rdi
movsd  -0x20(%rbp),%xmm0
mov    -0x30(%rbp),%rsi
call   1030 <LinInterp1D@plt>
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdb5(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LinInterp2D>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
movsd  %xmm1,0x10(%rsp)
mov    %rdi,%r15
movsd  %xmm0,0x8(%rsp)
call   1040 <floor@plt>
test   %rax,%rax
js     11d4 <LinInterp2D+0xb4>
mov    %rax,%rbx
movsd  0x10(%rsp),%xmm0
lea    -0x1(%r12),%rax
cmp    %rax,%rbx
jge    11df <LinInterp2D+0xbf>
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
movsd  0x8(%rsp),%xmm2
subsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0xe7f(%rip),%xmm1
subsd  %xmm2,%xmm1
movsd  %xmm1,0x20(%rsp)
mov    (%r15,%rbx,8),%rdi
mov    %r14,%rsi
call   1030 <LinInterp1D@plt>
movsd  %xmm0,0x18(%rsp)
mov    0x8(%r15,%rbx,8),%rdi
movsd  0x10(%rsp),%xmm0
mov    %r14,%rsi
call   1030 <LinInterp1D@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mulsd  0xe36(%rip),%xmm0
jmp    11ec <LinInterp2D+0xcc>
mov    (%r15),%rdi
movsd  0x10(%rsp),%xmm0
jmp    11e4 <LinInterp2D+0xc4>
mov    -0x8(%r15,%r12,8),%rdi
mov    %r14,%rsi
call   1030 <LinInterp1D@plt>
cvtsd2ss %xmm0,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define float @LinInterp2D(float** %0, double %1, double %2, i64 %3, i64 %4) {
%6 = alloca float
%7 = alloca float**
%8 = alloca double
%9 = alloca double
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca double
store float** %0, float*** %7
store double %1, double* %8
store double %2, double* %9
store i64 %3, i64* %10
store i64 %4, i64* %11
%14 = load double, double* %8
%15 = call i64 @floor(double %14)
store i64 %15, i64* %12
%16 = load double, double* %8
%17 = load i64, i64* %12
%18 = sitofp i64 %17 to double
%19 = fsub double %16, %18
store double %19, double* %13
%20 = load i64, i64* %12
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %5
%23 = load float**, float*** %7
%24 = getelementptr inbounds float*, float** %23, i64 0
%25 = load float*, float** %24
%26 = load double, double* %9
%27 = load i64, i64* %11
%28 = call double @LinInterp1D(float* %25, double %26, i64 %27)
%29 = fptrunc double %28 to float
store float %29, float* %6
br label %68
30: ; preds = %5
%31 = load i64, i64* %12
%32 = load i64, i64* %10
%33 = sub nsw i64 %32, 1
%34 = icmp sge i64 %31, %33
br i1 %34, label %35, label %45
35: ; preds = %30
%36 = load float**, float*** %7
%37 = load i64, i64* %10
%38 = sub nsw i64 %37, 1
%39 = getelementptr inbounds float*, float** %36, i64 %38
%40 = load float*, float** %39
%41 = load double, double* %9
%42 = load i64, i64* %11
%43 = call double @LinInterp1D(float* %40, double %41, i64 %42)
%44 = fptrunc double %43 to float
store float %44, float* %6
br label %68
45: ; preds = %30
%46 = load double, double* %13
%47 = fsub double 1.000000e+00, %46
%48 = load float**, float*** %7
%49 = load i64, i64* %12
%50 = getelementptr inbounds float*, float** %48, i64 %49
%51 = load float*, float** %50
%52 = load double, double* %9
%53 = load i64, i64* %11
%54 = call double @LinInterp1D(float* %51, double %52, i64 %53)
%55 = load double, double* %13
%56 = load float**, float*** %7
%57 = load i64, i64* %12
%58 = add nsw i64 %57, 1
%59 = getelementptr inbounds float*, float** %56, i64 %58
%60 = load float*, float** %59
%61 = load double, double* %9
%62 = load i64, i64* %11
%63 = call double @LinInterp1D(float* %60, double %61, i64 %62)
%64 = fmul double %55, %63
%65 = call double @llvm.fmuladd.f64(double %47, double %54, double %64)
%66 = fdiv double %65, 2.000000e+00
%67 = fptrunc double %66 to float
store float %67, float* %6
br label %68
68: ; preds = %45, %35, %22
%69 = load float, float* %6
ret float %69
}

LLVM IR (-O2):
define float @LinInterp2D(float** nocapture %0, double %1, double %2, i64 %3, i64 %4) {
%6 = tail call i64 @floor(double %1)
%7 = sitofp i64 %6 to double
%8 = fsub double %1, %7
%9 = icmp slt i64 %6, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load float*, float** %0
%12 = tail call double @LinInterp1D(float* %11, double %2, i64 %4)
br label %32
13: ; preds = %5
%14 = add nsw i64 %3, -1
%15 = icmp slt i64 %6, %14
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = getelementptr inbounds float*, float** %0, i64 %14
%18 = load float*, float** %17
%19 = tail call double @LinInterp1D(float* %18, double %2, i64 %4)
br label %32
20: ; preds = %13
%21 = fsub double 1.000000e+00, %8
%22 = getelementptr inbounds float*, float** %0, i64 %6
%23 = load float*, float** %22
%24 = tail call double @LinInterp1D(float* %23, double %2, i64 %4)
%25 = add nuw nsw i64 %6, 1
%26 = getelementptr inbounds float*, float** %0, i64 %25
%27 = load float*, float** %26
%28 = tail call double @LinInterp1D(float* %27, double %2, i64 %4)
%29 = fmul double %8, %28
%30 = tail call double @llvm.fmuladd.f64(double %21, double %24, double %29)
%31 = fmul double %30, 5.000000e-01
br label %32
32: ; preds = %20, %16, %10
%33 = phi double [ %12, %10 ], [ %19, %16 ], [ %31, %20 ]
%34 = fptrunc double %33 to float
ret float %34
}