// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../tools/quadrature.c
// Function: get_qsampling
int get_qsampling(double *x,
		  double *w,
		  int *N,
		  int N_max,
		  double rtol,
		  double *qvec,
		  int qsiz,
		  int (*test)(void * params_for_function, double q, double *psi),
		  int (*function)(void * params_for_function, double q, double *f0),
		  void * params_for_function,
		  ErrorMsg errmsg) {

  /* This routine returns the fewest possible number of abscissas and weights under
     the requirement that a test function folded with the neutrino distribution function
     can be integrated to an accuracy of rtol. If the distribution function is Fermi-Dirac
     or close, a Laguerre quadrature formula is often the best choice.

     This function combines two completely different strategies: Adaptive Gauss-Kronrod
     quadrature and Laguerres quadrature formula. */

  int i, NL=2,NR,level,Nadapt=0,NLag,NLag_max,Nold=NL;
  int adapt_converging=_FALSE_,Laguerre_converging=_FALSE_,combined_converging=_FALSE_;
  double y,y1,y2,I,Igk,err,ILag,*b,*c;
  qss_node *root,*root_comb;
  double I_comb,I_atzero,I_atinf,I_comb2;
  int N_comb=0,N_comb_lag=16,N_comb_leg=4;
  double a_comb,b_comb;
  double q_leg[4],w_leg[4];
  double q_lag[N_comb_lag],w_lag[N_comb_lag];
  char method_chosen[40];
  double qmin=0., qmax=0., qmaxm1=0.;
  double *wcomb2=NULL,delq;
  double Itot=0.0;
  int zeroskip=0;

  /* Set roots and weights for Gauss-Legendre 4 point rule: */
  q_leg[3] = sqrt((3.0+2.0*sqrt(6.0/5.0))/7.0);
  q_leg[2] = sqrt((3.0-2.0*sqrt(6.0/5.0))/7.0);
  q_leg[1] = -q_leg[2];
  q_leg[0] = -q_leg[3];
  w_leg[3] = (18.0-sqrt(30.0))/36.0;
  w_leg[2] = (18.0+sqrt(30.0))/36.0;
  w_leg[1] = w_leg[2];
  w_leg[0] = w_leg[3];

  /* Allocate storage for Laguerre coefficients: */
  class_alloc(b,N_max*sizeof(double),errmsg);
  class_alloc(c,N_max*sizeof(double),errmsg);
  /* If a vector of q values has been passed, use it: */
  if ((qvec!=NULL)&&(qsiz>1)){
    qmin = qvec[0];
    qmax = qvec[qsiz-1];
    qmaxm1 = qvec[qsiz-2];
  }
  else{
    qvec = NULL;
  }

  /* First do the adaptive quadrature - this will also give the value of the integral: */
  gk_adapt(&root,(*test),(*function), params_for_function,
	   rtol*1e-4, 1, 0.0, 1.0, _TRUE_, errmsg);
  /* Do a leaf count: */
  leaf_count(root);
  /* I can get the integral now: */
  I = get_integral(root, 1);
  //printf("I = %le |%le, used points: %d\n",I,I-1.0,15*root->leaf_childs);
  Itot += I;

  /* Starting from the top, move down in levels until tolerance is met: */
  for(level=root->leaf_childs; level>=1; level--){
    Igk = get_integral(root,level);
    err = I-Igk;
    if (fabs(err/Itot)<rtol) break;
  }
  if (level>0){
    /* Reduce tree to the found level:*/
    reduce_tree(root,level);
    /* Count the new leafs: */
    leaf_count(root);
    /* I know know how many function evaluations is
       required by the adaptively sampled grid:*/
    Nadapt = 15*root->leaf_childs;
    /* The adaptive routine could not recieve required precision
       using less than the required maximal number of points.*/
    if (Nadapt <= N_max) adapt_converging = _TRUE_;
  }


  /* Combined adaptive quadrature and Laguerre rescaled quadrature: */
  if(qvec!=NULL){
    /* Evaluate [0;qmin] using 4 point Gauss-Legendre rule: */
    (*function)(params_for_function,qmin,&y2);
    for(i=0,I_atzero=0.0; i<N_comb_leg; i++){
      q_leg[i] = 0.5*qmin*(1.0+q_leg[i]);
      w_leg[i] = w_leg[i]*0.5*qmin*y2;
      (*test)(params_for_function,q_leg[i],&y);
      I_atzero +=w_leg[i]*y;
    }

    /* Find asymptotic extrapolation:*/
    (*function)(params_for_function,qmaxm1,&y1);
    (*function)(params_for_function,qmax,&y2);

    b_comb = (y1/y2-1.0)/(qmax-qmaxm1);
    b_comb = MAX(b_comb,1e-100);
    //c_comb = -b_comb*qmax;
    a_comb = y2*exp(b_comb*qmax);
    // printf("f(q) = %g*exp(-%g*q) \n",a_comb,b_comb);
    //(*function)(params_for_function,100,&y2);
    //printf("f(100) = %e ?= %e\n",y2,a_comb*exp(-b_comb*100));

    /* Evaluate tail using 6 point Laguerre: */
    compute_Laguerre(q_lag,w_lag,N_comb_lag,0.0,b,c,_TRUE_);
    for (i=0,I_atinf=0.0; i<N_comb_lag; i++){
      w_lag[i] *= exp(-q_lag[i]);
      q_lag[i] = qmax + q_lag[i]/b_comb;
      w_lag[i] = a_comb/b_comb*exp(-b_comb*qmax)*w_lag[i];
      (*test)(params_for_function,q_lag[i],&y);
      I_atinf +=w_lag[i]*y;
    }

    /* Do the adaptive quadrature - this will also give the main part of the integral: */
    gk_adapt(&root_comb,(*test),(*function), params_for_function,
	     rtol*1e-2, 1, qmin, qmax, _FALSE_, errmsg);
    /* Do a leaf count: */
    leaf_count(root_comb);
    /* Starting from the top, move down in levels until tolerance is met: */
    for(level=root_comb->leaf_childs; level>=1; level--){
      I_comb = get_integral(root_comb,level);
      //printf("%le + %le + %le = %le | %le\n",
      //     I_atzero,I_atinf,I_comb,I_comb+I_atinf+I_atzero,I_comb+I_atinf+I_atzero-1.0);
      I_comb +=(I_atinf+I_atzero);
      err = I-I_comb;
      if (fabs(err/Itot)<rtol) break;
    }
    /* Reduce tree to the found level:*/
    if (level>0){
      reduce_tree(root_comb,level);
      /* Count the new leafs: */
      leaf_count(root_comb);
      N_comb = 15*root_comb->leaf_childs+N_comb_lag+N_comb_leg;
      if (N_comb <= N_max) combined_converging = _TRUE_;
    }

    /* Do the second combined quadrature: Same as above, but with trapezoidal rule
       using the given q grid:  */
    class_alloc(wcomb2,qsiz*sizeof(double),errmsg);
    I_comb2 = 0.0;
    for(i=0; i<qsiz; i++){
      if(i==0){
	delq = qvec[1]-qvec[0];
      }
      else if(i==qsiz-1){
	delq = qvec[qsiz-1]-qvec[qsiz-2];
      }
      else{
	delq = qvec[i+1]-qvec[i-1];
      }
      (*function)(params_for_function,qvec[i],&y2);
      wcomb2[i] = 0.5*y2*delq;
      (*test)(params_for_function,qvec[i],&y);
      I_comb2 +=wcomb2[i]*y;
    }
    I_comb2 +=(I_atzero+I_atinf);
    err = I - I_comb2;
    //    if(fabs(err/Itot)<rtol) combined2_converging= _TRUE_;
    //printf("I_comb2 = %e, rerr = %e\n",I_comb2,fabs(err/I));
  }


  /* Search for the minimal Laguerre quadrature rule: */
  NLag_max = MIN(N_max,80);
  for (NLag=NL; NLag<=NLag_max; NLag = MIN(NLag_max,NLag+10)){
    /* Evaluate integral: */
    compute_Laguerre(x,w,NLag,0.0,b,c,_TRUE_);
    ILag = 0.0;
    for (i=0; i<NLag; i++){
      (*test)(params_for_function,x[i],&y);
      (*function)(params_for_function,x[i],&y2);
      w[i] *= y2;
      ILag += y*w[i];
    }
    err = I-ILag;
    //fprintf(stderr,"\n Computing Laguerre, N=%d, I=%g and err=%g.\n",NLag,ILag,err);
    if (fabs(err/I)<rtol){
      Laguerre_converging = _TRUE_;
      break;
    }
    Nold = NLag;
    if (Nold == NLag_max) break;
  }

  if (Laguerre_converging == _TRUE_){
    /* We must refine NLag: */
    NL = Nold;
    NR = NLag;
    while ((NR-NL)>1) {
      NLag = (NL+NR)/2;
      /* Evaluate integral: */
      compute_Laguerre(x,w,NLag,0.0,b,c,_TRUE_);
      ILag = 0.0;
      for (i=0; i<NLag; i++){
	(*test)(params_for_function,x[i],&y);
	(*function)(params_for_function,x[i],&y2);
	w[i] *= y2;
	ILag += y*w[i];
      }
      err = I-ILag;
      //fprintf(stderr,"\n NLag=%d, rerr=%g.\n",NLag,fabs(err/I));
      if (fabs(err/Itot)<rtol){
	NR = NLag;
      }
      else{
	NL = NLag;
      }
    }
  }

  /* Choose best method if both works: */
  *N = N_max;
  //Laguerre_converging = _FALSE_;
  if (adapt_converging == _TRUE_) {
    *N = Nadapt;
  }
  if (combined_converging == _TRUE_){
    if(N_comb <= *N){
      *N = N_comb;
      adapt_converging = _FALSE_;
    }
    else{
      combined_converging = _FALSE_;
    }
  }
  if (Laguerre_converging == _TRUE_){
    if (NLag <= *N){
      *N = NLag;
      combined_converging = _FALSE_;
      adapt_converging = _FALSE_;
    }
    else{
      Laguerre_converging = _FALSE_;
    }
  }
  //printf("N_adapt=%d, N_combined=%d at level=%d, Nlag=%d\n",Nadapt,N_comb,level,NLag);
  if (adapt_converging==_TRUE_){
    class_sprintf(method_chosen,"Adaptive Gauss-Kronrod Quadrature");
    /* Gather weights and xvalues from tree: */
    i = Nadapt-1;
    get_leaf_x_and_w(root,&i,x,w,_TRUE_);
  }
  else if (Laguerre_converging==_TRUE_){
    class_sprintf(method_chosen,"Gauss-Laguerre Quadrature");
    /* x and w is already populated in this case. */
  }
  else if (combined_converging == _TRUE_){
    class_sprintf(method_chosen,"Combined Quadrature");
    for(i=0; i<N_comb_leg; i++){
      x[i] = q_leg[i];
      w[i] = w_leg[i];
    }
    i = N_comb_leg;
    get_leaf_x_and_w(root_comb,&i,x,w,_FALSE_);
    //printf("from %d to %d\n",N_comb_leg,i);

    for(i=0; i<N_comb_lag; i++){
      x[N_comb-N_comb_lag+i] = q_lag[i];
      w[N_comb-N_comb_lag+i] = w_lag[i];
    }
  }
  else{
    /* Failed to converge! */
    class_stop(errmsg,
		"get_qsampling fails to obtain a relative tolerance of %g as required using atmost %d points. If the PSD is interpolated from a file, try increasing the resolution and the q-interval (qmin;qmax) if possible, or decrease tol_ncdm/tol_ncdm_bg. As a last resort, increase _QUADRATURE_MAX_/_QUADRATURE_MAX_BG_.",rtol,N_max);
  }
  /* Trim weights to avoid zero weights: */
  for(i=0,zeroskip=0; i<*N; i++){
    for( ;(i<*N)&&(w[i+zeroskip]==0.0); zeroskip++,(*N)--);
    x[i] = x[i+zeroskip];
    w[i] = w[i+zeroskip];
  }


  //printf("Chosen sampling: %s, with %d points.\n",method_chosen,*N);
  //for(i=0; i<*N; i++) printf("(q,w) = (%g,%g)\n",x[i],w[i]);
  /* Deallocate tree: */
  burn_tree(root);
  if(qvec!=NULL){
    burn_tree(root_comb);
    free(wcomb2);
  }

  free(b);
  free(c);

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1278, %rsp           # imm = 0x1278
movq %r9, 0x108(%rsp)
movq %r8, 0x38(%rsp)
movsd %xmm0, 0x80(%rsp)
movq %rdx, 0x100(%rsp)
movq %rsi, %r15
movq %rdi, %r12
movq %rsp, %r14
movq 0x12c8(%rsp), %rbp
movaps 0xc9cfd(%rip), %xmm0    # 0xe80f0
movaps %xmm0, 0x140(%rsp)
movaps 0xc9cfe(%rip), %xmm0    # 0xe8100
movaps %xmm0, 0x130(%rsp)
movaps 0xc9cff(%rip), %xmm0    # 0xe8110
movaps %xmm0, 0x120(%rsp)
movapd 0xc9cff(%rip), %xmm0    # 0xe8120
movapd %xmm0, 0x110(%rsp)
movl %ecx, 0x34(%rsp)
movslq %ecx, %rbx
shlq $0x3, %rbx
movq %rbx, %rdi
callq 0x8490
pushq $0x1
popq %rcx
movl %ecx, 0x58(%rsp)
movq %rax, 0xb0(%rsp)
testq %rax, %rax
je 0x1e4c1
movq %rbx, %rdi
callq 0x8490
movq %rax, 0xa8(%rsp)
testq %rax, %rax
je 0x1e4fc
movq 0x38(%rsp), %rsi
testq %rsi, %rsi
sete %al
movq 0x108(%rsp), %rdx
cmpl $0x2, %edx
setl %cl
xorpd %xmm0, %xmm0
movsd %xmm0, 0x90(%rsp)
orb %al, %cl
jne 0x1e54c
movsd (%rsi), %xmm0
movsd %xmm0, 0x78(%rsp)
movl %edx, %eax
movsd -0x10(%rsi,%rax,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd -0x8(%rsi,%rax,8), %xmm0
movsd %xmm0, 0x60(%rsp)
jmp 0x1e567
leaq 0xc6b3c(%rip), %rsi     # 0xe5004
leaq 0xebbdb(%rip), %rdx     # 0x10a0aa
movq %r14, %r15
leaq 0x270(%rsp), %r14
movq %r14, %rdi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2e014
leaq 0xc6b47(%rip), %rsi     # 0xe5034
leaq 0xc9cf1(%rip), %rdx     # 0xe81e5
pushq $0x6c
popq %rcx
movq %rbp, %rdi
jmp 0x1e53a
leaq 0xc6b01(%rip), %rsi     # 0xe5004
leaq 0xe0d01(%rip), %rdx     # 0xff20b
movq %r14, %r15
leaq 0x270(%rsp), %r14
movq %r14, %rdi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2e014
leaq 0xc6b0c(%rip), %rsi     # 0xe5034
leaq 0xc9cb6(%rip), %rdx     # 0xe81e5
pushq $0x6d
popq %rcx
movq 0x12c8(%rsp), %rdi
movq %r14, %r8
movq %r15, %r14
xorl %eax, %eax
callq 0x2e014
jmp 0x1f02f
movq $0x0, 0x38(%rsp)
movsd %xmm0, 0x78(%rsp)
movsd %xmm0, 0x60(%rsp)
movsd %xmm0, 0x18(%rsp)
movq 0x12c8(%rsp), %rax
movsd 0xc77a1(%rip), %xmm0    # 0xe5d18
mulsd 0x80(%rsp), %xmm0
movq %rax, (%rsp)
leaq 0x160(%rsp), %rbx
movsd 0xc6ccc(%rip), %xmm2    # 0xe5260
pushq $0x1
popq %rbp
xorps %xmm1, %xmm1
movq %rbx, %rdi
movq 0x12b0(%rsp), %rsi
movq 0x12b8(%rsp), %rdx
movq 0x12c0(%rsp), %rcx
movl %ebp, %r8d
movl %ebp, %r9d
callq 0x1f0b0
movq (%rbx), %rbx
movq %rbx, %rdi
callq 0x1f311
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1f346
movapd %xmm0, %xmm1
movsd 0x90(%rsp), %xmm0
movsd %xmm1, 0xb8(%rsp)
addsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rsp)
movq %rbx, 0xa0(%rsp)
movl 0x20(%rbx), %ebx
pushq $-0x1
popq %rax
movl %eax, 0x98(%rsp)
testl %ebx, %ebx
jle 0x1e651
movq 0xa0(%rsp), %rdi
movl %ebx, %esi
callq 0x1f346
movsd 0xb8(%rsp), %xmm1
subsd %xmm0, %xmm1
divsd 0x90(%rsp), %xmm1
andpd 0xc6c02(%rip), %xmm1    # 0xe5240
movsd 0x80(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x1e65c
decl %ebx
jmp 0x1e60d
movb $0x1, 0x17(%rsp)
movl 0x34(%rsp), %eax
jmp 0x1e691
movq 0xa0(%rsp), %rbp
movq %rbp, %rdi
movl %ebx, %esi
callq 0x1f381
movq %rbp, %rdi
callq 0x1f311
imull $0xf, 0x20(%rbp), %ecx
movl 0x34(%rsp), %eax
cmpl %eax, %ecx
setg 0x17(%rsp)
cmovll %ecx, %eax
decl %ecx
movl %ecx, 0x98(%rsp)
movq 0x38(%rsp), %r8
testq %r8, %r8
movq %r14, 0x88(%rsp)
movl %eax, 0xdc(%rsp)
je 0x1ea33
leaq 0x68(%rsp), %rsi
movq 0x12c0(%rsp), %rdi
movsd 0x78(%rsp), %xmm0
callq *0x12b8(%rsp)
movsd 0xc75e0(%rip), %xmm0    # 0xe5cb0
mulsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %r14d, %r14d
leaq 0x70(%rsp), %rbx
cmpq $0x4, %r14
je 0x1e77e
movsd 0x130(%rsp,%r14,8), %xmm0
addsd 0xc6b56(%rip), %xmm0    # 0xe5260
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x130(%rsp,%r14,8)
movsd 0x110(%rsp,%r14,8), %xmm1
mulsd 0xc7584(%rip), %xmm1    # 0xe5cb0
mulsd 0x78(%rsp), %xmm1
mulsd 0x68(%rsp), %xmm1
movsd %xmm1, 0x40(%rsp)
movsd %xmm1, 0x110(%rsp,%r14,8)
movq 0x12c0(%rsp), %rdi
movq %rbx, %rsi
callq *0x12b0(%rsp)
movsd 0x40(%rsp), %xmm1
mulsd 0x70(%rsp), %xmm1
movsd 0x28(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
incq %r14
jmp 0x1e6ee
leaq 0x168(%rsp), %r13
movq 0x12c0(%rsp), %rbp
movq %rbp, %rdi
movsd 0x18(%rsp), %xmm0
movq %r13, %rsi
movq 0x12b8(%rsp), %rbx
callq *%rbx
leaq 0x68(%rsp), %r14
movq %rbp, %rdi
movsd 0x60(%rsp), %xmm0
movq %r14, %rsi
callq *%rbx
movsd (%r13), %xmm0
movsd (%r14), %xmm1
movsd %xmm1, 0x40(%rsp)
divsd %xmm1, %xmm0
addsd 0xc7014(%rip), %xmm0    # 0xe57e8
movsd 0x60(%rsp), %xmm2
movapd %xmm2, %xmm1
subsd 0x18(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0xc9788(%rip), %xmm1    # 0xe7f78
maxsd %xmm0, %xmm1
movapd %xmm1, 0xc0(%rsp)
movapd %xmm2, %xmm0
mulsd %xmm1, %xmm0
callq 0x86a0
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
leaq 0x1f0(%rsp), %rdi
leaq 0x170(%rsp), %rsi
pushq $0x10
popq %rdx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
pushq $0x1
popq %r9
movq 0xb0(%rsp), %rcx
movq 0xa8(%rsp), %r8
callq 0x1e002
movapd 0xc0(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
movapd 0xc69c3(%rip), %xmm0    # 0xe5230
xorpd %xmm1, %xmm0
mulsd 0x60(%rsp), %xmm0
movapd %xmm0, 0xe0(%rsp)
xorl %r14d, %r14d
leaq 0x70(%rsp), %rbx
movq 0x108(%rsp), %r13
cmpq $0x10, %r14
je 0x1e951
movsd 0x1f0(%rsp,%r14,8), %xmm0
movapd %xmm0, 0x40(%rsp)
xorpd 0xc697e(%rip), %xmm0    # 0xe5230
callq 0x86a0
mulsd 0x170(%rsp,%r14,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movapd 0x40(%rsp), %xmm0
divsd 0xc0(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movapd %xmm0, 0x40(%rsp)
movsd %xmm0, 0x1f0(%rsp,%r14,8)
movapd 0xe0(%rsp), %xmm0
callq 0x86a0
mulsd 0x58(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd %xmm0, 0x170(%rsp,%r14,8)
movq 0x12c0(%rsp), %rdi
movaps 0x40(%rsp), %xmm0
movq %rbx, %rsi
callq *0x12b0(%rsp)
movsd 0x18(%rsp), %xmm1
mulsd 0x70(%rsp), %xmm1
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
incq %r14
jmp 0x1e890
movl $0x10, 0x9c(%rsp)
movsd 0xc961c(%rip), %xmm0    # 0xe7f80
mulsd 0x80(%rsp), %xmm0
movq 0x12c8(%rsp), %rax
movq %rax, (%rsp)
leaq 0x158(%rsp), %rbx
pushq $0x1
popq %r8
movq $0x0, 0xe0(%rsp)
movq %rbx, %rdi
movq 0x12b0(%rsp), %rsi
movq 0x12b8(%rsp), %rdx
movq 0x12c0(%rsp), %rcx
movl %r8d, 0x58(%rsp)
movsd 0x78(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
xorl %r9d, %r9d
callq 0x1f0b0
movq (%rbx), %r14
movq %r14, %rdi
callq 0x1f311
movl 0x20(%r14), %ebx
movsd 0x28(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r14, 0xf8(%rsp)
testl %ebx, %ebx
jle 0x1ea59
movq %r14, %rdi
movl %ebx, %esi
callq 0x1f346
addsd 0x28(%rsp), %xmm0
movsd 0xb8(%rsp), %xmm1
subsd %xmm0, %xmm1
divsd 0x90(%rsp), %xmm1
andpd 0xc6820(%rip), %xmm1    # 0xe5240
movsd 0x80(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x1ea67
decl %ebx
jmp 0x1e9ee
movq $0x0, 0xe0(%rsp)
movq $0x0, 0xc0(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x1eba1
movq $0x0, 0xc0(%rsp)
jmp 0x1ea98
movq %r14, %rdi
movl %ebx, %esi
callq 0x1f381
movq %r14, %rdi
callq 0x1f311
imull $0xf, 0x20(%r14), %eax
addl $0x14, %eax
movq %rax, 0xe0(%rsp)
cmpl 0x34(%rsp), %eax
setle %al
movq %rax, 0xc0(%rsp)
movslq %r13d, %r14
leaq (,%r14,8), %rbx
movq %rbx, %rdi
callq 0x8490
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x1ee77
leal -0x1(%r13), %edx
movslq %edx, %rax
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x60(%rsp)
leaq -0x10(%rcx,%r14,8), %rax
movq %rax, 0x78(%rsp)
leaq 0x8(%rcx), %rax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
testl %r13d, %r13d
cmovlel %r14d, %r13d
shlq $0x3, %r13
shlq $0x3, %rdx
movq %rdx, 0x20(%rsp)
movq 0x38(%rsp), %rbx
cmpq %r14, %r13
je 0x1eb9c
movq %rbx, %rax
movq 0x28(%rsp), %rcx
testq %r14, %r14
je 0x1eb34
movq 0x78(%rsp), %rax
movq 0x60(%rsp), %rcx
cmpq %r14, 0x20(%rsp)
je 0x1eb34
leaq (%rbx,%r14), %rcx
addq $0x8, %rcx
leaq (%rbx,%r14), %rax
addq $-0x8, %rax
movsd (%rcx), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd (%rbx,%r14), %xmm0
movq 0x12c0(%rsp), %rbp
movq %rbp, %rdi
leaq 0x68(%rsp), %rsi
callq *0x12b8(%rsp)
movsd 0x68(%rsp), %xmm0
mulsd 0xc7143(%rip), %xmm0    # 0xe5cb0
mulsd 0x40(%rsp), %xmm0
movq 0x18(%rsp), %rax
movsd %xmm0, (%rax,%r14)
movsd (%rbx,%r14), %xmm0
movq %rbp, %rdi
leaq 0x70(%rsp), %rsi
callq *0x12b0(%rsp)
addq $0x8, %r14
jmp 0x1eafd
movq 0x38(%rsp), %r8
movl 0x34(%rsp), %eax
cmpl $0x50, %eax
pushq $0x50
popq %rdx
cmovll %eax, %edx
pushq $0x2
popq %rcx
pushq $0x1
popq %rax
movl %eax, 0x58(%rsp)
movl %ecx, %r14d
movq %r8, 0x38(%rsp)
movl %edx, 0x20(%rsp)
movb $0x1, %dil
cmpl %edx, %r14d
jg 0x1eddc
movq %rcx, 0x28(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movl %r14d, %edx
movq 0xb0(%rsp), %rcx
movq 0xa8(%rsp), %r8
pushq $0x1
popq %r9
callq 0x1e002
testl %r14d, %r14d
movl $0x0, %r13d
cmovgl %r14d, %r13d
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0x1ec74
movsd (%r12,%rbp,8), %xmm0
movq 0x12c0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
callq *0x12b0(%rsp)
movsd (%r12,%rbp,8), %xmm0
movq %rbx, %rdi
leaq 0x68(%rsp), %rsi
callq *0x12b8(%rsp)
movsd 0x68(%rsp), %xmm0
mulsd (%r15,%rbp,8), %xmm0
movsd %xmm0, (%r15,%rbp,8)
mulsd 0x70(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
incq %rbp
jmp 0x1ec10
movsd 0xb8(%rsp), %xmm1
movapd %xmm1, %xmm0
subsd 0x40(%rsp), %xmm0
divsd %xmm1, %xmm0
andpd 0xc65ad(%rip), %xmm0    # 0xe5240
movsd 0x80(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x1ecc8
movl 0x20(%rsp), %edx
cmpl %edx, %r14d
movq 0x38(%rsp), %r8
je 0x1edd6
movl %r14d, %ecx
leal 0xa(%r14), %eax
cmpl %eax, %edx
cmovll %edx, %eax
movl %eax, %r14d
jmp 0x1ebc4
leaq 0x68(%rsp), %rbp
movl %r14d, %edx
movq 0x38(%rsp), %r8
movq 0x28(%rsp), %rcx
movl %edx, %eax
subl %ecx, %eax
cmpl $0x2, %eax
jl 0x1edd2
movq %rcx, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
leal (%rcx,%rdx), %r14d
shrl %r14d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movl %r14d, %edx
movq 0xb0(%rsp), %rcx
movq 0xa8(%rsp), %r8
pushq $0x1
popq %r9
callq 0x1e002
xorl %r13d, %r13d
cmpq %r13, %r14
je 0x1ed89
movsd (%r12,%r13,8), %xmm0
movq 0x12c0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
callq *0x12b0(%rsp)
movsd (%r12,%r13,8), %xmm0
movq %rbx, %rdi
movq %rbp, %rsi
callq *0x12b8(%rsp)
movsd 0x68(%rsp), %xmm0
mulsd (%r15,%r13,8), %xmm0
movsd %xmm0, (%r15,%r13,8)
mulsd 0x70(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
incq %r13
jmp 0x1ed27
movsd 0xb8(%rsp), %xmm0
subsd 0x40(%rsp), %xmm0
divsd 0x90(%rsp), %xmm0
andpd 0xc6497(%rip), %xmm0    # 0xe5240
movsd 0x80(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq 0x20(%rsp), %rdx
cmoval %r14d, %edx
movq 0x28(%rsp), %rcx
cmovbel %r14d, %ecx
movq 0x38(%rsp), %r8
jmp 0x1ecda
xorl %edi, %edi
jmp 0x1eddc
movl %edx, %r14d
movb $0x1, %dil
movl 0xdc(%rsp), %ecx
movq 0xe0(%rsp), %rdx
cmpl %ecx, %edx
setle %al
movq 0xc0(%rsp), %rsi
andb %al, %sil
movq %rsi, 0xc0(%rsp)
cmovnel %edx, %ecx
movq 0x100(%rsp), %rax
movl %ecx, (%rax)
testb %dil, %dil
jne 0x1ee22
cmpl %ecx, %r14d
jg 0x1ee22
movl %r14d, (%rax)
jmp 0x1eee7
movb 0x17(%rsp), %al
movq 0xc0(%rsp), %rcx
orb %cl, %al
testb $0x1, %al
je 0x1eeb9
testb %cl, %cl
je 0x1efc0
xorl %eax, %eax
movq 0x88(%rsp), %r14
cmpq $0x4, %rax
je 0x1f048
movsd 0x130(%rsp,%rax,8), %xmm0
movsd %xmm0, (%r12,%rax,8)
movsd 0x110(%rsp,%rax,8), %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0x1ee4a
leaq 0xc6186(%rip), %rsi     # 0xe5004
leaq 0xc936e(%rip), %rdx     # 0xe81f3
leaq 0x270(%rsp), %r14
movq %r14, %rdi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2e014
leaq 0xc6194(%rip), %rsi     # 0xe5034
leaq 0xc933e(%rip), %rdx     # 0xe81e5
movq 0x12c8(%rsp), %rdi
movl $0xd0, %ecx
jmp 0x1f01d
leaq 0x9c(%rsp), %rsi
movl 0x98(%rsp), %eax
movl %eax, (%rsi)
movq %r8, %rbx
pushq $0x1
popq %r8
movq 0xa0(%rsp), %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0x1f3c3
movq %rbx, %r8
movq 0x88(%rsp), %r14
movq %r8, %rbx
movq 0x100(%rsp), %r10
movl (%r10), %r8d
xorl %eax, %eax
xorpd %xmm0, %xmm0
movq %r15, %rcx
xorl %edx, %edx
xorl %esi, %esi
movslq %r8d, %rdi
cmpq %rdi, %rax
jge 0x1ef73
movslq %esi, %r9
addl %r9d, %r8d
addl %edx, %r8d
leaq (%rcx,%r9,8), %r9
cmpq %rdi, %rax
jge 0x1ef3f
movsd (%r9), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1ef44
jp 0x1ef44
decq %rdi
movl %edi, (%r10)
incl %esi
addq $0x8, %r9
jmp 0x1ef1f
movl %r8d, %esi
jmp 0x1ef47
movl %esi, %r8d
movslq %r8d, %r8
addq %rax, %r8
movsd (%r12,%r8,8), %xmm1
movsd %xmm1, (%r12,%rax,8)
movsd (%r15,%r8,8), %xmm1
movsd %xmm1, (%r15,%rax,8)
incq %rax
decl %edx
addq $0x8, %rcx
movl %edi, %r8d
jmp 0x1ef0a
movq 0xa0(%rsp), %rdi
callq 0x1f460
testq %rbx, %rbx
je 0x1ef9c
movq 0xf8(%rsp), %rdi
callq 0x1f460
movq 0x18(%rsp), %rdi
callq 0x8430
movq 0xb0(%rsp), %rdi
callq 0x8430
movq 0xa8(%rsp), %rdi
callq 0x8430
movl $0x0, 0x58(%rsp)
jmp 0x1f02f
leaq 0xc9233(%rip), %rsi     # 0xe81fa
leaq 0x270(%rsp), %rbx
movq %rbx, %rdi
movsd 0x80(%rsp), %xmm0
movl 0x34(%rsp), %edx
movb $0x1, %al
callq 0x2e014
leaq 0xc6598(%rip), %rsi     # 0xe5585
leaq 0xa70(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2e014
leaq 0xc602b(%rip), %rsi     # 0xe5034
leaq 0xc91d5(%rip), %rdx     # 0xe81e5
movq 0x12c8(%rsp), %rdi
movl $0x14e, %ecx            # imm = 0x14E
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
movq 0x88(%rsp), %r14
movq %r14, %rsp
movl 0x58(%rsp), %eax
addq $0x1278, %rsp           # imm = 0x1278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9c(%rsp), %rsi
movl $0x4, (%rsi)
xorl %ebx, %ebx
movq 0xf8(%rsp), %rdi
movq %rdx, %rbp
movq %r12, %rdx
movq %r15, %rcx
movq %r8, %r13
xorl %r8d, %r8d
callq 0x1f3c3
movq %r13, %r8
addl $-0x10, %ebp
movslq %ebp, %rcx
leaq (%r12,%rcx,8), %rax
leaq (%r15,%rcx,8), %rcx
cmpq $0x10, %rbx
je 0x1eeef
movsd 0x1f0(%rsp,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
movsd 0x170(%rsp,%rbx,8), %xmm0
movsd %xmm0, (%rcx,%rbx,8)
incq %rbx
jmp 0x1f085