// File: wcochran[P]pano_to_cube/PPM.cpp
// Function: PPM::bilerp(float, float, float*) const
void PPM::bilerp(float r, float c, float pix[3]) const {
  if (r < 0 || r >= H || c < 0 || c >= W) { // clamp to black
    pix[0] = pix[1] = pix[2] = 0;
  } else {
    const int r0 = static_cast<int>(floorf(r));
    const int c0 = static_cast<int>(floorf(c));
    const int r1 = (r0 < H-1) ? (r0 + 1) : r0;
    const int c1 = (c0 < W-1) ? (c0 + 1) : c0;
    const unsigned char *pix00 = this->operator()(r0,c0);
    const unsigned char *pix01 = this->operator()(r0,c1);
    const unsigned char *pix10 = this->operator()(r1,c0);
    const unsigned char *pix11 = this->operator()(r1,c1);
    const float s = c - c0;
    const float t = r - r0;
    float pix0[3], pix1[3];
    for (int i = 0; i < 3; i++) {
      pix0[i] = (1-s)*pix00[i] + s*pix01[i];
      pix1[i] = (1-s)*pix10[i] + s*pix11[i];
    }
    for (int i = 0; i < 3; i++)
      pix[i] = (1-t)*pix0[i] + t*pix1[i];
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movss %xmm1, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
xorps %xmm0, %xmm0
ucomiss -0xc(%rbp), %xmm0
ja 0x46ec
movq -0x78(%rbp), %rax
movss -0xc(%rbp), %xmm0
cvtsi2ssl 0x4(%rax), %xmm1
ucomiss %xmm1, %xmm0
jae 0x46ec
xorps %xmm0, %xmm0
ucomiss -0x10(%rbp), %xmm0
ja 0x46ec
movq -0x78(%rbp), %rax
movss -0x10(%rbp), %xmm0
cvtsi2ssl (%rax), %xmm1
ucomiss %xmm1, %xmm0
jb 0x4714
movq -0x18(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rax)
movq -0x18(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x4(%rax)
movq -0x18(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
jmp 0x48fb
movss -0xc(%rbp), %xmm0
callq 0x2090
cvttss2si %xmm0, %eax
movl %eax, -0x1c(%rbp)
movss -0x10(%rbp), %xmm0
callq 0x2090
movq -0x78(%rbp), %rcx
cvttss2si %xmm0, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movl 0x4(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4752
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x4758
movl -0x1c(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x78(%rbp), %rcx
movl -0x7c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4779
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x477f
movl -0x20(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movl -0x80(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x4a20
movq -0x78(%rbp), %rdi
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0x4a20
movq -0x78(%rbp), %rdi
movq %rax, -0x38(%rbp)
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x4a20
movq -0x78(%rbp), %rdi
movq %rax, -0x40(%rbp)
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0x4a20
movq %rax, -0x48(%rbp)
movss -0x10(%rbp), %xmm0
cvtsi2ssl -0x20(%rbp), %xmm1
subss %xmm1, %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0xc(%rbp), %xmm0
cvtsi2ssl -0x1c(%rbp), %xmm1
subss %xmm1, %xmm0
movss %xmm0, -0x50(%rbp)
movl $0x0, -0x6c(%rbp)
cmpl $0x3, -0x6c(%rbp)
jge 0x48a6
movss 0x1834(%rip), %xmm0     # 0x6044
subss -0x4c(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cvtsi2ss %eax, %xmm2
movss -0x4c(%rbp), %xmm1
movq -0x38(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cvtsi2ss %eax, %xmm3
mulss %xmm3, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movslq -0x6c(%rbp), %rax
movss %xmm0, -0x5c(%rbp,%rax,4)
movss 0x17ec(%rip), %xmm0     # 0x6044
subss -0x4c(%rbp), %xmm0
movq -0x40(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cvtsi2ss %eax, %xmm2
movss -0x4c(%rbp), %xmm1
movq -0x48(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cvtsi2ss %eax, %xmm3
mulss %xmm3, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movslq -0x6c(%rbp), %rax
movss %xmm0, -0x68(%rbp,%rax,4)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x47fe
movl $0x0, -0x70(%rbp)
cmpl $0x3, -0x70(%rbp)
jge 0x48f9
movss 0x1789(%rip), %xmm0     # 0x6044
subss -0x50(%rbp), %xmm0
movslq -0x70(%rbp), %rax
movss -0x5c(%rbp,%rax,4), %xmm2
movss -0x50(%rbp), %xmm1
movslq -0x70(%rbp), %rax
mulss -0x68(%rbp,%rax,4), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x18(%rbp), %rax
movslq -0x70(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x48ad
jmp 0x48fb
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop