// File: /workspace/github_c_makefile_star2_O3/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 0xd402e
pushq %rbx
subq $0x80, %rsp
movq %rcx, %rbx
cmpl $0x3, %edx
ja 0xd3e5d
movups 0x5630b(%rip), %xmm0    # 0x12a13e
movq %rsp, %rsi
movups %xmm0, 0x2e(%rsi)
movups 0x562ef(%rip), %xmm0    # 0x12a130
movaps %xmm0, 0x20(%rsi)
movups 0x562d4(%rip), %xmm0    # 0x12a120
movaps %xmm0, 0x10(%rsi)
movupd 0x562b8(%rip), %xmm0    # 0x12a110
jmp 0xd4010
movsd (%rdi), %xmm1
ucomisd 0x8(%rdi), %xmm1
jbe 0xd3e99
movups 0x56308(%rip), %xmm0    # 0x12a177
movq %rsp, %rsi
movups %xmm0, 0x29(%rsi)
movups 0x562f1(%rip), %xmm0    # 0x12a16e
movaps %xmm0, 0x20(%rsi)
movups 0x562d6(%rip), %xmm0    # 0x12a15e
movaps %xmm0, 0x10(%rsi)
movupd 0x562ba(%rip), %xmm0    # 0x12a14e
jmp 0xd4010
ucomisd %xmm0, %xmm1
ja 0xd3fef
leal -0x1(%rdx), %ecx
ucomisd (%rdi,%rcx,8), %xmm0
jae 0xd3fef
xorl %eax, %eax
leaq (%rcx,%rax), %r9
movq %r9, %r8
shrq $0x3f, %r8
addq %r9, %r8
sarq %r8
movsd (%rdi,%r8,8), %xmm1
ucomisd %xmm1, %xmm0
jb 0xd3ed3
movq %r8, %rax
ucomisd %xmm0, %xmm1
ja 0xd3edc
movq %rcx, %r8
movq %r8, %r9
subq %rax, %r9
movq %r8, %rcx
cmpq $0x1, %r9
jg 0xd3eb3
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 0xd4026
movups 0x561aa(%rip), %xmm0    # 0x12a1a0
movq %rsp, %rsi
movups %xmm0, 0x19(%rsi)
movups 0x56193(%rip), %xmm0    # 0x12a197
movaps %xmm0, 0x10(%rsi)
movupd 0x56177(%rip), %xmm0    # 0x12a187
movapd %xmm0, (%rsi)
movq %r8, %rdi
callq 0x8660
xorpd %xmm1, %xmm1
movl $0x1, (%rbx)
addq $0x80, %rsp
popq %rbx
movapd %xmm1, %xmm0
retq
nop