// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../external/HyRec2020/hyrectools.c
// Function: rec_interpol_G
double rec_interpol_G(double x, double *xtab, double *ytab, unsigned int Nx, int *error, char error_message[SIZE_ErrorM]) {

  char sub_message[128];
  if (*error == 1) return 0.;
  
  if (Nx < 4) {
    sprintf(sub_message, "Table needs to be of dimension 4 at least in rec_interpol_G.\n");
    strcat(error_message, sub_message);
    *error = 1;
    return 0.;
  }
  if (xtab[0] > xtab[1]) {
    sprintf(sub_message, "Array does not seem to be increasing in rec_interpol_G.\n");
    strcat(error_message, sub_message);
    *error = 1;
    return 0.;
  }
  if (x < xtab[0] || x >= xtab[Nx-1]) {
    sprintf(sub_message, "x-value out of range in rec_interpol_G.\n");
    strcat(error_message, sub_message);
    *error = 1;
    return 0.;
  }
  
  long int ix;
  long int ilo = 0;
  long int ihi = Nx-1;
  long int imid; 

  while (ihi - ilo > 1) {
    imid = (ihi + ilo)/2;
    if (x >= xtab[imid]) ilo = imid;
    if (x < xtab[imid]) ihi = imid;     
  }
  
  ix = ilo;
 
  if (ix<1) ix = 1; 
  if (ix>Nx-3) ix = Nx-3;
  xtab += ix-1;
  ytab += ix-1;

  /* Return value */
  return(
     ytab[0] *(x-xtab[1])*(x-xtab[2])*(x-xtab[3])
             /(xtab[0]-xtab[1])/(xtab[0]-xtab[2])/(xtab[0]-xtab[3])
           + ytab[1] *(x-xtab[0])*(x-xtab[2])*(x-xtab[3])
             /(xtab[1]-xtab[0])/(xtab[1]-xtab[2])/(xtab[1]-xtab[3])
           + ytab[2] *(x-xtab[0])*(x-xtab[1])*(x-xtab[3])
             /(xtab[2]-xtab[0])/(xtab[2]-xtab[1])/(xtab[2]-xtab[3])
           + ytab[3] *(x-xtab[0])*(x-xtab[1])*(x-xtab[2])
             /(xtab[3]-xtab[0])/(xtab[3]-xtab[1])/(xtab[3]-xtab[2])	 
  );
}

// Assembly:
xorpd %xmm1, %xmm1
cmpl $0x1, (%rcx)
je 0xd782b
pushq %rbx
subq $0x80, %rsp
movq %rcx, %rbx
cmpl $0x3, %edx
ja 0xd7655
movups 0x55ae3(%rip), %xmm0    # 0x12d10e
movq %rsp, %rsi
movups %xmm0, 0x2e(%rsi)
movups 0x55ac7(%rip), %xmm0    # 0x12d100
movaps %xmm0, 0x20(%rsi)
movups 0x55aac(%rip), %xmm0    # 0x12d0f0
movaps %xmm0, 0x10(%rsi)
movupd 0x55a90(%rip), %xmm0    # 0x12d0e0
jmp 0xd780d
movsd (%rdi), %xmm1
ucomisd 0x8(%rdi), %xmm1
jbe 0xd7691
movups 0x55ae0(%rip), %xmm0    # 0x12d147
movq %rsp, %rsi
movups %xmm0, 0x29(%rsi)
movups 0x55ac9(%rip), %xmm0    # 0x12d13e
movaps %xmm0, 0x20(%rsi)
movups 0x55aae(%rip), %xmm0    # 0x12d12e
movaps %xmm0, 0x10(%rsi)
movupd 0x55a92(%rip), %xmm0    # 0x12d11e
jmp 0xd780d
ucomisd %xmm0, %xmm1
ja 0xd77ec
leal -0x1(%rdx), %ecx
ucomisd (%rdi,%rcx,8), %xmm0
jae 0xd77ec
xorl %eax, %eax
cmpl $0x2, %ecx
jb 0xd76e8
leaq (%rcx,%rax), %r9
movq %r9, %r8
shrq $0x3f, %r8
addq %r9, %r8
sarq %r8
movsd (%rdi,%r8,8), %xmm1
ucomisd %xmm1, %xmm0
jb 0xd76d0
movq %r8, %rax
ucomisd %xmm0, %xmm1
ja 0xd76d9
movq %rcx, %r8
movq %r8, %r9
subq %rax, %r9
movq %r8, %rcx
cmpq $0x1, %r9
jg 0xd76b0
cmpq $0x2, %rax
movl $0x1, %ecx
cmovgeq %rax, %rcx
addl $-0x3, %edx
cmpq %rdx, %rcx
cmovgeq %rdx, %rcx
movupd -0x8(%rdi,%rcx,8), %xmm3
movupd 0x8(%rdi,%rcx,8), %xmm1
movapd %xmm1, %xmm2
shufpd $0x1, %xmm1, %xmm2      # xmm2 = xmm2[1],xmm1[0]
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm0, %xmm4
subpd %xmm2, %xmm4
movapd %xmm3, %xmm5
shufpd $0x1, %xmm3, %xmm5      # xmm5 = xmm5[1],xmm3[0]
subpd %xmm5, %xmm0
movupd -0x8(%rsi,%rcx,8), %xmm6
movupd 0x8(%rsi,%rcx,8), %xmm8
mulpd %xmm0, %xmm6
movapd %xmm3, %xmm7
subpd %xmm5, %xmm7
movapd %xmm0, %xmm9
unpckhpd %xmm0, %xmm9            # xmm9 = xmm9[1],xmm0[1]
mulpd %xmm8, %xmm9
movapd %xmm4, %xmm5
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm9, %xmm0
mulpd %xmm4, %xmm0
unpckhpd %xmm4, %xmm4            # xmm4 = xmm4[1,1]
mulpd %xmm6, %xmm4
unpcklpd %xmm5, %xmm5            # xmm5 = xmm5[0,0]
mulpd %xmm4, %xmm5
divpd %xmm7, %xmm5
movapd %xmm1, %xmm4
unpcklpd %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0]
movapd %xmm3, %xmm6
subpd %xmm4, %xmm6
divpd %xmm6, %xmm5
movapd %xmm1, %xmm4
unpckhpd %xmm1, %xmm4            # xmm4 = xmm4[1],xmm1[1]
movapd %xmm3, %xmm6
subpd %xmm4, %xmm6
divpd %xmm6, %xmm5
movapd %xmm3, %xmm4
unpcklpd %xmm3, %xmm4            # xmm4 = xmm4[0],xmm3[0]
movapd %xmm1, %xmm6
subpd %xmm4, %xmm6
divpd %xmm6, %xmm0
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
movapd %xmm1, %xmm4
subpd %xmm3, %xmm4
divpd %xmm4, %xmm0
subpd %xmm2, %xmm1
divpd %xmm1, %xmm0
movapd %xmm5, %xmm1
unpckhpd %xmm5, %xmm1            # xmm1 = xmm1[1],xmm5[1]
addsd %xmm5, %xmm1
addsd %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movapd %xmm0, %xmm1
jmp 0xd7823
movups 0x5597d(%rip), %xmm0    # 0x12d170
movq %rsp, %rsi
movups %xmm0, 0x19(%rsi)
movups 0x55966(%rip), %xmm0    # 0x12d167
movaps %xmm0, 0x10(%rsi)
movupd 0x5594a(%rip), %xmm0    # 0x12d157
movapd %xmm0, (%rsi)
movq %r8, %rdi
callq 0x8660
xorpd %xmm1, %xmm1
movl $0x1, (%rbx)
addq $0x80, %rsp
popq %rbx
movapd %xmm1, %xmm0
retq