// File: /workspace/github_c_makefile_star2_O2/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
xorl %eax, %eax
testl %edx, %edx
movl $0x0, %r9d
cmovgl %edx, %r9d
xorpd %xmm2, %xmm2
xorpd %xmm3, %xmm3
xorpd %xmm4, %xmm4
xorpd %xmm1, %xmm1
cmpq %rax, %r9
je 0x19389
movsd (%rsi,%rax,8), %xmm5
movhpd (%rdi,%rax,8), %xmm5    # xmm5 = xmm5[0],mem[0]
movsd (%rsi), %xmm6
movhpd (%rdi), %xmm6           # xmm6 = xmm6[0],mem[0]
subpd %xmm6, %xmm5
divpd %xmm6, %xmm5
movapd %xmm5, %xmm6
unpckhpd %xmm5, %xmm6            # xmm6 = xmm6[1],xmm5[1]
movapd %xmm6, %xmm7
movapd %xmm6, %xmm8
mulsd %xmm5, %xmm8
movapd %xmm5, %xmm9
unpcklpd %xmm8, %xmm9            # xmm9 = xmm9[0],xmm8[0]
mulpd %xmm6, %xmm9
mulsd %xmm6, %xmm6
addsd %xmm6, %xmm3
mulsd %xmm6, %xmm7
addpd %xmm5, %xmm2
shufpd $0x2, %xmm5, %xmm7      # xmm7 = xmm7[0],xmm5[1]
shufpd $0x1, %xmm6, %xmm5      # xmm5 = xmm5[1],xmm6[0]
mulpd %xmm5, %xmm7
addpd %xmm7, %xmm1
addpd %xmm9, %xmm4
incq %rax
jmp 0x19319
cvtsi2sd %edx, %xmm9
movapd %xmm2, %xmm8
unpckhpd %xmm2, %xmm8            # xmm8 = xmm8[1],xmm2[1]
movapd 0xcbe90(%rip), %xmm5    # 0xe5230
movapd %xmm8, %xmm6
mulsd %xmm8, %xmm6
movapd %xmm3, %xmm12
mulsd %xmm9, %xmm12
subsd %xmm6, %xmm12
movapd %xmm1, %xmm6
unpckhpd %xmm1, %xmm6            # xmm6 = xmm6[1],xmm1[1]
movapd %xmm9, %xmm7
mulsd %xmm6, %xmm7
movapd %xmm3, %xmm10
mulsd %xmm8, %xmm10
subsd %xmm7, %xmm10
movapd %xmm6, %xmm7
mulsd %xmm10, %xmm7
movapd %xmm1, %xmm13
mulsd %xmm12, %xmm13
addsd %xmm7, %xmm13
movapd %xmm3, %xmm15
xorpd %xmm5, %xmm15
mulsd %xmm3, %xmm15
movapd %xmm6, %xmm11
mulsd %xmm8, %xmm11
addsd %xmm15, %xmm11
movapd %xmm3, %xmm7
mulsd %xmm11, %xmm7
addsd %xmm13, %xmm7
xorpd %xmm13, %xmm13
ucomisd %xmm13, %xmm7
jne 0x1948a
jp 0x1948a
leaq 0xce16c(%rip), %rsi     # 0xe759e
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movb $0x1, %al
callq 0x2e014
leaq 0xcbc37(%rip), %rsi     # 0xe5082
leaq 0xce180(%rip), %rdx     # 0xe75d2
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xcbbcb(%rip), %rsi     # 0xe5034
leaq 0xce16d(%rip), %rdx     # 0xe75dd
movq %rbx, %rdi
movl $0xd86, %ecx            # imm = 0xD86
movq %r15, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
jmp 0x1959d
xorpd %xmm5, %xmm8
movapd %xmm6, %xmm13
xorpd %xmm5, %xmm13
movapd %xmm4, %xmm5
mulsd %xmm10, %xmm5
movapd %xmm4, %xmm14
unpckhpd %xmm4, %xmm14           # xmm14 = xmm14[1],xmm4[1]
mulsd %xmm14, %xmm12
addsd %xmm5, %xmm12
movapd %xmm2, %xmm5
mulsd %xmm11, %xmm5
addsd %xmm12, %xmm5
mulsd %xmm1, %xmm9
addsd %xmm15, %xmm9
mulsd %xmm4, %xmm9
mulsd %xmm14, %xmm10
addsd %xmm9, %xmm10
mulsd %xmm1, %xmm8
movapd %xmm6, %xmm9
mulsd %xmm3, %xmm9
addsd %xmm8, %xmm9
movapd %xmm2, %xmm8
mulsd %xmm9, %xmm8
addsd %xmm10, %xmm8
mulsd %xmm4, %xmm9
mulsd %xmm11, %xmm14
addsd %xmm9, %xmm14
mulsd %xmm6, %xmm13
mulsd %xmm3, %xmm1
addsd %xmm13, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm14, %xmm1
divsd %xmm7, %xmm8
divsd %xmm7, %xmm1
movsd (%rdi), %xmm2
subsd %xmm2, %xmm0
unpcklpd %xmm0, %xmm5            # xmm5 = xmm5[0],xmm0[0]
unpcklpd %xmm2, %xmm7            # xmm7 = xmm7[0],xmm2[0]
divpd %xmm7, %xmm5
movsd (%rsi), %xmm0
movapd %xmm5, %xmm2
unpckhpd %xmm5, %xmm2            # xmm2 = xmm2[1],xmm5[1]
movapd %xmm5, %xmm3
mulsd %xmm2, %xmm3
movapd %xmm8, %xmm4
mulsd %xmm2, %xmm4
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
addsd %xmm1, %xmm3
mulsd %xmm0, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, (%rcx)
addsd %xmm5, %xmm5
movsd (%rdi), %xmm0
divsd %xmm0, %xmm5
divsd %xmm0, %xmm8
mulsd %xmm2, %xmm5
addsd %xmm8, %xmm5
mulsd (%rsi), %xmm5
movsd %xmm5, (%r8)
xorl %eax, %eax
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r14
popq %r15
retq