// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_extrapolate_quadratic
int array_extrapolate_quadratic(double* x, double* y, double xnew, int x_size, double* ynew, double* dynew, ErrorMsg errmsg){

  int i;

  double * xarr = x;
  double * yarr = y;

  double av1=x_size;
  double avx=0.0, avxx=0.0, avxxx=0.0, avxxxx=0.0;
  double avy=0.0, avyx=0.0, avyxx=0.0;

  double div,a,b,c,xval,yval;

  /*
   * We pivot around the zero-th element
   * This removes natural offsets and scales
   * (i.e. transforms it to around unity for x and y)
   * This usually prevents numerical cancelation (offsets) and over/underflow (scales)
   */
  for(i=0;i<x_size;++i){
    xval = (xarr[i]-xarr[0])/xarr[0];
    yval = (yarr[i]-yarr[0])/yarr[0];
    avx += xval;
    avxx += xval*xval;
    avxxx += xval*xval*xval;
    avxxxx += xval*xval*xval*xval;
    avy += yval;
    avyx += yval*xval;
    avyxx += yval*xval*xval;
  }

  div = avxxxx*(avxx*av1-avx*avx) + avxxx*(avxx*avx-avxxx*av1) + avxx*(avxxx*avx-avxx*avxx);
  class_test(div == 0.0,
             errmsg,
             "Cannot extrapolate at x = %g for the given data set",xnew);
  a = avyxx*(avxx*av1-avx*avx) + avyx*(avxx*avx-avxxx*av1) + avy*(avxxx*avx-avxx*avxx);
  b = avyxx*(avxx*avx-avxxx*av1) + avyx*(avxxxx*av1-avxx*avxx) + avy*(avxxx*avxx-avx*avxxxx);
  c = avyxx*(avxxx*avx-avxx*avxx) + avyx*(avxxx*avxx-avxxxx*avx) + avy*(avxxxx*avxx-avxxx*avxxx);

  a/=div; b/=div; c/=div;

  xval = (xnew-xarr[0])/xarr[0];

  *ynew = yarr[0]+yarr[0]*(a*xval*xval + b*xval + c);
  *dynew = yarr[0]*(2.*a/xarr[0]*xval + b/xarr[0]);

  return _SUCCESS_;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x1000, %rsp           # imm = 0x1000
movq %r9, %rbx
cvtsi2sd %edx, %xmm4
xorpd %xmm6, %xmm6
testl %edx, %edx
jle 0x1b57b
movl %edx, %eax
movsd (%rsi), %xmm7
movhpd (%rdi), %xmm7           # xmm7 = xmm7[0],mem[0]
xorpd %xmm2, %xmm2
xorpd %xmm3, %xmm3
xorl %edx, %edx
xorpd %xmm5, %xmm5
xorpd %xmm1, %xmm1
movsd (%rsi,%rdx,8), %xmm8
movhpd (%rdi,%rdx,8), %xmm8    # xmm8 = xmm8[0],mem[0]
subpd %xmm7, %xmm8
divpd %xmm7, %xmm8
movapd %xmm8, %xmm9
unpckhpd %xmm8, %xmm9            # xmm9 = xmm9[1],xmm8[1]
movapd %xmm9, %xmm10
mulsd %xmm8, %xmm10
movapd %xmm9, %xmm11
movapd %xmm8, %xmm12
unpcklpd %xmm10, %xmm12          # xmm12 = xmm12[0],xmm10[0]
mulpd %xmm9, %xmm12
mulsd %xmm9, %xmm9
mulsd %xmm9, %xmm11
addpd %xmm8, %xmm2
shufpd $0x2, %xmm8, %xmm11     # xmm11 = xmm11[0],xmm8[1]
shufpd $0x1, %xmm9, %xmm8      # xmm8 = xmm8[1],xmm9[0]
mulpd %xmm8, %xmm11
addsd %xmm9, %xmm3
addpd %xmm11, %xmm1
addpd %xmm12, %xmm5
incq %rdx
cmpq %rdx, %rax
jne 0x1b504
jmp 0x1b58b
xorpd %xmm2, %xmm2
xorpd %xmm3, %xmm3
xorpd %xmm5, %xmm5
xorpd %xmm1, %xmm1
movapd %xmm2, %xmm9
unpckhpd %xmm2, %xmm9            # xmm9 = xmm9[1],xmm2[1]
movapd 0xd5c92(%rip), %xmm14   # 0xf1230
movapd %xmm9, %xmm7
mulsd %xmm9, %xmm7
movapd %xmm3, %xmm12
mulsd %xmm4, %xmm12
subsd %xmm7, %xmm12
movapd %xmm1, %xmm7
unpckhpd %xmm1, %xmm7            # xmm7 = xmm7[1],xmm1[1]
movapd %xmm4, %xmm8
mulsd %xmm7, %xmm8
movapd %xmm3, %xmm10
mulsd %xmm9, %xmm10
subsd %xmm8, %xmm10
movapd %xmm7, %xmm8
mulsd %xmm10, %xmm8
movapd %xmm1, %xmm13
mulsd %xmm12, %xmm13
addsd %xmm8, %xmm13
movapd %xmm3, %xmm15
xorpd %xmm14, %xmm15
mulsd %xmm3, %xmm15
movapd %xmm7, %xmm11
mulsd %xmm9, %xmm11
addsd %xmm15, %xmm11
movapd %xmm3, %xmm8
mulsd %xmm11, %xmm8
addsd %xmm13, %xmm8
ucomisd %xmm6, %xmm8
jne 0x1b688
jp 0x1b688
leaq 0xd7fa0(%rip), %rsi     # 0xf35ce
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movb $0x1, %al
callq 0x30c2c
leaq 0xd5a3b(%rip), %rsi     # 0xf1082
leaq 0xd7fb4(%rip), %rdx     # 0xf3602
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xd59cf(%rip), %rsi     # 0xf1034
leaq 0xd7fa1(%rip), %rdx     # 0xf360d
movq %rbx, %rdi
movl $0xd86, %ecx            # imm = 0xD86
movq %r15, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
jmp 0x1b798
xorpd %xmm14, %xmm9
movapd %xmm7, %xmm13
xorpd %xmm14, %xmm13
movapd %xmm5, %xmm6
mulsd %xmm10, %xmm6
movapd %xmm5, %xmm14
unpckhpd %xmm5, %xmm14           # xmm14 = xmm14[1],xmm5[1]
mulsd %xmm14, %xmm12
addsd %xmm6, %xmm12
movapd %xmm2, %xmm6
mulsd %xmm11, %xmm6
addsd %xmm12, %xmm6
mulsd %xmm1, %xmm4
addsd %xmm15, %xmm4
mulsd %xmm5, %xmm4
mulsd %xmm14, %xmm10
addsd %xmm4, %xmm10
mulsd %xmm1, %xmm9
movapd %xmm7, %xmm12
mulsd %xmm3, %xmm12
addsd %xmm9, %xmm12
movapd %xmm2, %xmm4
mulsd %xmm12, %xmm4
addsd %xmm10, %xmm4
mulsd %xmm5, %xmm12
mulsd %xmm11, %xmm14
addsd %xmm12, %xmm14
mulsd %xmm7, %xmm13
mulsd %xmm3, %xmm1
addsd %xmm13, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm14, %xmm1
divsd %xmm8, %xmm4
divsd %xmm8, %xmm1
movsd (%rdi), %xmm2
subsd %xmm2, %xmm0
unpcklpd %xmm0, %xmm6            # xmm6 = xmm6[0],xmm0[0]
unpcklpd %xmm2, %xmm8            # xmm8 = xmm8[0],xmm2[0]
divpd %xmm8, %xmm6
movsd (%rsi), %xmm0
movapd %xmm6, %xmm2
unpckhpd %xmm6, %xmm2            # xmm2 = xmm2[1],xmm6[1]
movapd %xmm6, %xmm3
mulsd %xmm2, %xmm3
movapd %xmm4, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm2, %xmm3
addsd %xmm5, %xmm3
addsd %xmm1, %xmm3
mulsd %xmm0, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, (%rcx)
addsd %xmm6, %xmm6
movsd (%rdi), %xmm0
divsd %xmm0, %xmm6
divsd %xmm0, %xmm4
mulsd %xmm2, %xmm6
addsd %xmm4, %xmm6
mulsd (%rsi), %xmm6
movsd %xmm6, (%r8)
xorl %eax, %eax
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r14
popq %r15
retq