// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../external/HyRec2020/hyrectools.c
// Function: rec_interp2d
double rec_interp2d(double x10, double dx1, double x20, double dx2, double **ytab,
  unsigned int Nx1, unsigned int Nx2, double x1, double x2, int *error, char error_message[SIZE_ErrorM]) {

  int j;
  long ix1;
  double frac1;
  double temp[4];
  char sub_message[128];
  if (*error == 1) return 0.;

  /* Check if in range in x1 */
  if (x1<x10 || x1>x10+dx1*(Nx1-1)) {
    sprintf(sub_message,"x-value out of range in interpolation in rec_interp2d.\n"); 
    strcat(error_message, sub_message);
    *error = 1;
    return 0.;
  }

  /* Identify location to interpolate in x1 */
  ix1 = (long)floor((x1-x10)/dx1);
  if (ix1<1) ix1=1;
  if (ix1>Nx1-3) ix1=Nx1-3;
  frac1 = (x1-x10)/dx1-ix1;
  ytab += ix1-1;  

  /* Get values interpolated over x2 at the 4 neighboring points in x1 */
  for(j=0;j<4;j++) temp[j] = rec_interp1d(x20,dx2,ytab[j],Nx2,x2, error, error_message);

  return(
    -temp[0]*frac1*(1.-frac1)*(2.-frac1)/6.
    +temp[1]*(1.+frac1)*(1.-frac1)*(2.-frac1)/2.
    +temp[2]*(1.+frac1)*frac1*(2.-frac1)/2.
    +temp[3]*(1.+frac1)*frac1*(frac1-1.)/6.
  );
}

// Assembly:
xorpd %xmm6, %xmm6
cmpl $0x1, (%rcx)
je 0xd3e0a
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xb0, %rsp
movq %r8, %r14
movq %rcx, %rbx
ucomisd %xmm4, %xmm0
ja 0xd3c74
movl %esi, %r12d
leal -0x1(%r12), %eax
xorps %xmm6, %xmm6
cvtsi2sd %rax, %xmm6
mulsd %xmm1, %xmm6
addsd %xmm0, %xmm6
ucomisd %xmm6, %xmm4
jbe 0xd3cc0
movaps 0x56445(%rip), %xmm0    # 0x12a0c0
leaq 0x30(%rsp), %rsi
movaps %xmm0, 0x20(%rsi)
movaps 0x56425(%rip), %xmm0    # 0x12a0b0
movaps %xmm0, 0x10(%rsi)
movapd 0x56409(%rip), %xmm0    # 0x12a0a0
movapd %xmm0, (%rsi)
movabsq $0xa2e6432707265, %rax  # imm = 0xA2E6432707265
movq %rax, 0x30(%rsi)
movq %r14, %rdi
callq 0x8660
xorpd %xmm6, %xmm6
movl $0x1, (%rbx)
jmp 0xd3dfb
movl %edx, %ebp
movq %rdi, %r15
subsd %xmm0, %xmm4
divsd %xmm1, %xmm4
movsd %xmm4, 0x10(%rsp)
movapd %xmm4, %xmm0
movsd %xmm5, 0x28(%rsp)
movsd %xmm3, 0x20(%rsp)
movsd %xmm2, 0x18(%rsp)
callq 0x85e0
cvttsd2si %xmm0, %rax
cmpq $0x2, %rax
movl $0x1, %ecx
cmovgeq %rax, %rcx
addl $-0x3, %r12d
cmpq %r12, %rcx
cmovgeq %r12, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq (%r15,%rcx,8), %r15
addq $-0x8, %r15
xorl %r12d, %r12d
movq (%r15,%r12,8), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movl %ebp, %esi
movsd 0x28(%rsp), %xmm2
movq %rbx, %rdx
movq %r14, %rcx
callq 0xd3a85
movsd %xmm0, 0x30(%rsp,%r12,8)
incq %r12
cmpq $0x4, %r12
jne 0xd3d24
movsd 0x10(%rsp), %xmm6
subsd 0x8(%rsp), %xmm6
movsd 0x30(%rsp), %xmm2
mulsd %xmm6, %xmm2
movsd 0x1a4eb(%rip), %xmm0    # 0xee260
movapd %xmm0, %xmm3
subsd %xmm6, %xmm3
mulsd %xmm3, %xmm2
movsd 0x1af77(%rip), %xmm4    # 0xeed00
subsd %xmm6, %xmm4
mulsd %xmm4, %xmm2
movsd 0x1b8d7(%rip), %xmm1    # 0xef670
divsd %xmm1, %xmm2
addsd %xmm6, %xmm0
movsd 0x38(%rsp), %xmm5
mulsd %xmm0, %xmm5
mulsd %xmm3, %xmm5
mulsd %xmm4, %xmm5
movsd 0x1af15(%rip), %xmm3    # 0xeecd0
mulsd %xmm3, %xmm5
subsd %xmm2, %xmm5
movsd 0x40(%rsp), %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm6, %xmm2
mulsd %xmm4, %xmm2
mulsd %xmm3, %xmm2
mulsd 0x48(%rsp), %xmm0
addsd %xmm5, %xmm2
mulsd %xmm6, %xmm0
addsd 0x1a9f9(%rip), %xmm6    # 0xee7e8
mulsd %xmm0, %xmm6
divsd %xmm1, %xmm6
addsd %xmm2, %xmm6
addq $0xb0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
movapd %xmm6, %xmm0
retq