#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 */
float evaluate_bilinear_cell(float, float, float, float, float, float);
float getsamplen(float *, int, int, int, int, int, int);
void bilinear_interpolation_at(float *result, float *x, int w, int h, int pd,
                               float p, float q) {
  int ip = p;
  int iq = q;
  for (int l = 0; l < (pd); l++) {
    float a = getsamplen(x, w, h, pd, ip, iq, l);
    float b = getsamplen(x, w, h, pd, ip + 1, iq, l);
    float c = getsamplen(x, w, h, pd, ip, iq + 1, l);
    float d = getsamplen(x, w, h, pd, ip + 1, iq + 1, l);
    float r = evaluate_bilinear_cell(a, b, c, d, p - ip, q - iq);
    result[l] = r;
  }
}


x86 assembly (clang, -O0):
<bilinear_interpolation_at>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movss  %xmm0,-0x20(%rbp)
movss  %xmm1,-0x24(%rbp)
cvttss2si -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
cvttss2si -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1265 <bilinear_interpolation_at+0x145>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <getsamplen@plt>
movss  %xmm0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
add    $0x1,%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <getsamplen@plt>
movss  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
add    $0x1,%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <getsamplen@plt>
movss  %xmm0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
add    $0x1,%r8d
mov    -0x2c(%rbp),%r9d
add    $0x1,%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <getsamplen@plt>
movss  %xmm0,-0x40(%rbp)
movss  -0x34(%rbp),%xmm0
movss  -0x38(%rbp),%xmm1
movss  -0x3c(%rbp),%xmm2
movss  -0x40(%rbp),%xmm3
movss  -0x20(%rbp),%xmm4
cvtsi2ssl -0x28(%rbp),%xmm5
subss  %xmm5,%xmm4
movss  -0x24(%rbp),%xmm5
cvtsi2ssl -0x2c(%rbp),%xmm6
subss  %xmm6,%xmm5
call   1040 <evaluate_bilinear_cell@plt>
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    115b <bilinear_interpolation_at+0x3b>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bilinear_interpolation_at>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8d,0x8(%rsp)
test   %r8d,%r8d
jle    1277 <bilinear_interpolation_at+0x157>
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rsi,%r14
movaps %xmm0,%xmm2
cvttss2si %xmm0,%eax
cvttss2si %xmm1,%ecx
mov    0x8(%rsp),%edx
mov    %rdx,0x28(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
subss  %xmm0,%xmm2
movss  %xmm2,0x14(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
mov    %rax,0x30(%rsp)
add    $0x1,%eax
mov    %eax,0xc(%rsp)
mov    %rcx,0x38(%rsp)
lea    0x1(%rcx),%eax
mov    %eax,0x10(%rsp)
subss  %xmm0,%xmm1
movss  %xmm1,0x18(%rsp)
xor    %r13d,%r13d
mov    %rdi,0x40(%rsp)
mov    0x8(%rsp),%r15d
nop
mov    %r13d,(%rsp)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    0x28(%rsp),%rcx
mov    0x30(%rsp),%r8
mov    %r12d,%ebx
mov    %r14,%r12
mov    0x38(%rsp),%r14
mov    %r14d,%r9d
call   1030 <getsamplen@plt>
movss  %xmm0,0x24(%rsp)
mov    %r13d,(%rsp)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    0xc(%rsp),%r8d
mov    %r14d,%r9d
mov    %r12,%r14
mov    %ebx,%r12d
call   1030 <getsamplen@plt>
movss  %xmm0,0x20(%rsp)
mov    %r13d,(%rsp)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    0x30(%rsp),%r8
mov    0x10(%rsp),%ebx
mov    %ebx,%r9d
call   1030 <getsamplen@plt>
movss  %xmm0,0x1c(%rsp)
mov    %r13d,(%rsp)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    0xc(%rsp),%r8d
mov    %ebx,%r9d
call   1030 <getsamplen@plt>
movaps %xmm0,%xmm3
movss  0x24(%rsp),%xmm0
movss  0x20(%rsp),%xmm1
movss  0x1c(%rsp),%xmm2
movss  0x14(%rsp),%xmm4
movss  0x18(%rsp),%xmm5
call   1040 <evaluate_bilinear_cell@plt>
mov    0x40(%rsp),%rdi
movss  %xmm0,(%rdi,%r13,4)
add    $0x1,%r13
cmp    %r13,0x28(%rsp)
jne    11a0 <bilinear_interpolation_at+0x80>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @bilinear_interpolation_at(float* %0, float* %1, i32 %2, i32 %3, i32 %4, float %5, float %6) {
%8 = alloca float*
%9 = alloca float*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca float
%14 = alloca float
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca float
%19 = alloca float
%20 = alloca float
%21 = alloca float
%22 = alloca float
store float* %0, float** %8
store float* %1, float** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store float %5, float* %13
store float %6, float* %14
%23 = load float, float* %13
%24 = fptosi float %23 to i32
store i32 %24, i32* %15
%25 = load float, float* %14
%26 = fptosi float %25 to i32
store i32 %26, i32* %16
store i32 0, i32* %17
br label %27
27: ; preds = %86, %7
%28 = load i32, i32* %17
%29 = load i32, i32* %12
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %89
31: ; preds = %27
%32 = load float*, float** %9
%33 = load i32, i32* %10
%34 = load i32, i32* %11
%35 = load i32, i32* %12
%36 = load i32, i32* %15
%37 = load i32, i32* %16
%38 = load i32, i32* %17
%39 = call float @getsamplen(float* %32, i32 %33, i32 %34, i32 %35, i32 %36, i32 %37, i32 %38)
store float %39, float* %18
%40 = load float*, float** %9
%41 = load i32, i32* %10
%42 = load i32, i32* %11
%43 = load i32, i32* %12
%44 = load i32, i32* %15
%45 = add nsw i32 %44, 1
%46 = load i32, i32* %16
%47 = load i32, i32* %17
%48 = call float @getsamplen(float* %40, i32 %41, i32 %42, i32 %43, i32 %45, i32 %46, i32 %47)
store float %48, float* %19
%49 = load float*, float** %9
%50 = load i32, i32* %10
%51 = load i32, i32* %11
%52 = load i32, i32* %12
%53 = load i32, i32* %15
%54 = load i32, i32* %16
%55 = add nsw i32 %54, 1
%56 = load i32, i32* %17
%57 = call float @getsamplen(float* %49, i32 %50, i32 %51, i32 %52, i32 %53, i32 %55, i32 %56)
store float %57, float* %20
%58 = load float*, float** %9
%59 = load i32, i32* %10
%60 = load i32, i32* %11
%61 = load i32, i32* %12
%62 = load i32, i32* %15
%63 = add nsw i32 %62, 1
%64 = load i32, i32* %16
%65 = add nsw i32 %64, 1
%66 = load i32, i32* %17
%67 = call float @getsamplen(float* %58, i32 %59, i32 %60, i32 %61, i32 %63, i32 %65, i32 %66)
store float %67, float* %21
%68 = load float, float* %18
%69 = load float, float* %19
%70 = load float, float* %20
%71 = load float, float* %21
%72 = load float, float* %13
%73 = load i32, i32* %15
%74 = sitofp i32 %73 to float
%75 = fsub float %72, %74
%76 = load float, float* %14
%77 = load i32, i32* %16
%78 = sitofp i32 %77 to float
%79 = fsub float %76, %78
%80 = call float @evaluate_bilinear_cell(float %68, float %69, float %70, float %71, float %75, float %79)
store float %80, float* %22
%81 = load float, float* %22
%82 = load float*, float** %8
%83 = load i32, i32* %17
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds float, float* %82, i64 %84
store float %81, float* %85
br label %86
86: ; preds = %31
%87 = load i32, i32* %17
%88 = add nsw i32 %87, 1
store i32 %88, i32* %17
br label %27
89: ; preds = %27
ret void
}

LLVM IR (-O2):
define void @bilinear_interpolation_at(float* nocapture writeonly %0, float* %1, i32 %2, i32 %3, i32 %4, float %5, float %6) {
%8 = fptosi float %5 to i32
%9 = fptosi float %6 to i32
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = add nsw i32 %8, 1
%13 = add nsw i32 %9, 1
%14 = sitofp i32 %8 to float
%15 = fsub float %5, %14
%16 = sitofp i32 %9 to float
%17 = fsub float %6, %16
%18 = zext i32 %4 to i64
br label %20
19: ; preds = %20, %7
ret void
20: ; preds = %11, %20
%21 = phi i64 [ 0, %11 ], [ %29, %20 ]
%22 = trunc i64 %21 to i32
%23 = tail call float @getsamplen(float* %1, i32 %2, i32 %3, i32 %4, i32 %8, i32 %9, i32 %22)
%24 = tail call float @getsamplen(float* %1, i32 %2, i32 %3, i32 %4, i32 %12, i32 %9, i32 %22)
%25 = tail call float @getsamplen(float* %1, i32 %2, i32 %3, i32 %4, i32 %8, i32 %13, i32 %22)
%26 = tail call float @getsamplen(float* %1, i32 %2, i32 %3, i32 %4, i32 %12, i32 %13, i32 %22)
%27 = tail call float @evaluate_bilinear_cell(float %23, float %24, float %25, float %26, float %15, float %17)
%28 = getelementptr inbounds float, float* %0, i64 %21
store float %27, float* %28
%29 = add nuw nsw i64 %21, 1
%30 = icmp eq i64 %29, %18
br i1 %30, label %19, label %20
}