// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xb0, %rsp
movsd %xmm5, 0x28(%rsp)
movsd %xmm3, 0x20(%rsp)
movsd %xmm2, 0x18(%rsp)
xorpd %xmm6, %xmm6
cmpl $0x1, (%rcx)
je 0xcc40f
movq %r8, %r14
movq %rcx, %rbx
ucomisd %xmm4, %xmm0
ja 0xcc29d
movl %esi, %r12d
leal -0x1(%r12), %eax
cvtsi2sd %rax, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm4
jbe 0xcc2e9
movaps 0x54cbc(%rip), %xmm0    # 0x120f60
leaq 0x30(%rsp), %rsi
movaps %xmm0, 0x20(%rsi)
movaps 0x54c9c(%rip), %xmm0    # 0x120f50
movaps %xmm0, 0x10(%rsi)
movapd 0x54c80(%rip), %xmm0    # 0x120f40
movapd %xmm0, (%rsi)
movabsq $0xa2e6432707265, %rax  # imm = 0xA2E6432707265
movq %rax, 0x30(%rsi)
movq %r14, %rdi
callq 0x8690
xorpd %xmm6, %xmm6
movl $0x1, (%rbx)
jmp 0xcc40f
movl %edx, %ebp
movq %rdi, %r15
subsd %xmm0, %xmm4
divsd %xmm1, %xmm4
movsd %xmm4, 0x10(%rsp)
movapd %xmm4, %xmm0
callq 0x8610
cvttsd2si %xmm0, %rax
cmpq $0x2, %rax
pushq $0x1
popq %rcx
cmovgeq %rax, %rcx
addl $-0x3, %r12d
cmpq %r12, %rcx
cmovgeq %r12, %rcx
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq (%r15,%rcx,8), %r15
addq $-0x8, %r15
xorl %r12d, %r12d
cmpq $0x4, %r12
je 0xcc36b
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 0xcc0a7
movsd %xmm0, 0x30(%rsp,%r12,8)
incq %r12
jmp 0xcc336
movsd 0x10(%rsp), %xmm6
subsd 0x8(%rsp), %xmm6
movsd 0x30(%rsp), %xmm2
mulsd %xmm6, %xmm2
movsd 0x18ed7(%rip), %xmm0    # 0xe5260
movapd %xmm0, %xmm3
subsd %xmm6, %xmm3
mulsd %xmm3, %xmm2
movsd 0x19943(%rip), %xmm4    # 0xe5ce0
subsd %xmm6, %xmm4
mulsd %xmm4, %xmm2
movsd 0x1a2a3(%rip), %xmm1    # 0xe6650
divsd %xmm1, %xmm2
addsd %xmm6, %xmm0
movsd 0x38(%rsp), %xmm5
mulsd %xmm0, %xmm5
mulsd %xmm3, %xmm5
mulsd %xmm4, %xmm5
movsd 0x198e1(%rip), %xmm3    # 0xe5cb0
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 0x193e5(%rip), %xmm6    # 0xe57e8
mulsd %xmm0, %xmm6
divsd %xmm1, %xmm6
addsd %xmm2, %xmm6
movapd %xmm6, %xmm0
addq $0xb0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq