// File: /workspace/github_c_makefile_star2_O0/PoulinV[P]AxiCLASS/build/../tools/quadrature.c
// Function: gk_adapt
int gk_adapt(
	     qss_node** node,
	     int (*test)(void * params_for_function, double q, double *psi),
	     int (*function)(void * params_for_function, double q, double *f0),
	     void * params_for_function,
	     double tol,
	     int treemode,
	     double a,
	     double b,
	     int isindefinite,
	     ErrorMsg errmsg){
  /* Do adaptive Gauss-Kronrod quadrature, while building the
     recurrence tree. If treemode!=0, store x-values and weights aswell.
     At first call, a and b should be 0 and 1 if isdefinite==_TRUE_. */
  double mid;
  /* Allocate current node: */
  class_alloc(*node,sizeof(qss_node),errmsg);
  if (treemode==0){
    (*node)->x = NULL;
    (*node)->w = NULL;
  }
  else{
    class_alloc((*node)->x,15*sizeof(double),errmsg);
    class_alloc((*node)->w,15*sizeof(double),errmsg);
  }
  (*node)->left = NULL; (*node)->right = NULL;

  gk_quad((*test), (*function), params_for_function, *node, a, b, isindefinite);
  if ((fabs((*node)->err/(*node)->I) < tol)||(tol>=1.0)){
    /* Stop recursion and return. tol>=1.0 in case of I=0 infinite recursion */
    return _SUCCESS_;
  }
  else{
    /* Call gk_adapt recursively on children:*/
    mid = 0.5*(a+b);
    //printf("<-%g,%g,%g,%g",mid,tol,(*node)->err,(*node)->I);
    gk_adapt(&((*node)->left),(*test),(*function), params_for_function, 1.5*tol,
	     treemode, a, mid, isindefinite, errmsg);
    //printf("%g->",mid);
    gk_adapt(&((*node)->right),(*test),(*function), params_for_function, 1.5*tol,
	     treemode, mid, b, isindefinite, errmsg);
    /* Update integral and error in this node and return: */
    /* Actually, it is more convenient just to keep the nodes own estimate of the
       integral for our purposes.
       (*node)->I = (*node)->left->I + (*node)->right->I;
       (*node)->err = sqrt(pow(node->left->err,2)+pow(node->right->err,2));
    */
    return _SUCCESS_;
  }
}

// Assembly:
subq $0x1898, %rsp           # imm = 0x1898
movq 0x18a0(%rsp), %rax
movq %rdi, 0x1888(%rsp)
movq %rsi, 0x1880(%rsp)
movq %rdx, 0x1878(%rsp)
movq %rcx, 0x1870(%rsp)
movsd %xmm0, 0x1868(%rsp)
movl %r8d, 0x1864(%rsp)
movsd %xmm1, 0x1858(%rsp)
movsd %xmm2, 0x1850(%rsp)
movl %r9d, 0x184c(%rsp)
movl $0x38, %edi
callq 0x8460
movq %rax, %rcx
movq 0x1888(%rsp), %rax
movq %rcx, (%rax)
movq 0x1888(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x3cda9
movl $0x38, 0x183c(%rsp)
leaq 0x1030(%rsp), %rdi
movl 0x183c(%rsp), %ecx
leaq 0x1952a3(%rip), %rsi    # 0x1d2004
leaq 0x19860c(%rip), %rdx    # 0x1d5374
movb $0x0, %al
callq 0x5b9c0
movq 0x18a0(%rsp), %rdi
leaq 0x1030(%rsp), %r8
leaq 0x1952ae(%rip), %rsi    # 0x1d2034
leaq 0x1985ed(%rip), %rdx    # 0x1d537a
movl $0x1fd, %ecx            # imm = 0x1FD
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x1894(%rsp)
jmp 0x3d0d8
cmpl $0x0, 0x1864(%rsp)
jne 0x3cdde
movq 0x1888(%rsp), %rax
movq (%rax), %rax
movq $0x0, 0x10(%rax)
movq 0x1888(%rsp), %rax
movq (%rax), %rax
movq $0x0, 0x18(%rax)
jmp 0x3cf08
movl $0x78, %edi
callq 0x8460
movq %rax, %rcx
movq 0x1888(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x1888(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, 0x10(%rax)
jne 0x3ce75
movl $0x78, 0x102c(%rsp)
leaq 0x820(%rsp), %rdi
movl 0x102c(%rsp), %ecx
leaq 0x1951d7(%rip), %rsi    # 0x1d2004
leaq 0x19854f(%rip), %rdx    # 0x1d5383
movb $0x0, %al
callq 0x5b9c0
movq 0x18a0(%rsp), %rdi
leaq 0x820(%rsp), %r8
leaq 0x1951e2(%rip), %rsi    # 0x1d2034
leaq 0x198521(%rip), %rdx    # 0x1d537a
movl $0x203, %ecx            # imm = 0x203
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x1894(%rsp)
jmp 0x3d0d8
movl $0x78, %edi
callq 0x8460
movq %rax, %rcx
movq 0x1888(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x18(%rax)
movq 0x1888(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, 0x18(%rax)
jne 0x3cf06
movl $0x78, 0x81c(%rsp)
leaq 0x10(%rsp), %rdi
movl 0x81c(%rsp), %ecx
leaq 0x195143(%rip), %rsi    # 0x1d2004
leaq 0x1984c6(%rip), %rdx    # 0x1d538e
movb $0x0, %al
callq 0x5b9c0
movq 0x18a0(%rsp), %rdi
leaq 0x10(%rsp), %r8
leaq 0x195151(%rip), %rsi    # 0x1d2034
leaq 0x198490(%rip), %rdx    # 0x1d537a
movl $0x204, %ecx            # imm = 0x204
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x1894(%rsp)
jmp 0x3d0d8
jmp 0x3cf08
movq 0x1888(%rsp), %rax
movq (%rax), %rax
movq $0x0, 0x28(%rax)
movq 0x1888(%rsp), %rax
movq (%rax), %rax
movq $0x0, 0x30(%rax)
movq 0x1880(%rsp), %rdi
movq 0x1878(%rsp), %rsi
movq 0x1870(%rsp), %rdx
movq 0x1888(%rsp), %rax
movq (%rax), %rcx
movsd 0x1858(%rsp), %xmm0
movsd 0x1850(%rsp), %xmm1
movl 0x184c(%rsp), %r8d
callq 0x3d620
movq 0x1888(%rsp), %rax
movq (%rax), %rax
movsd 0x8(%rax), %xmm1
movq 0x1888(%rsp), %rax
movq (%rax), %rax
divsd (%rax), %xmm1
movaps 0x19529a(%rip), %xmm0   # 0x1d2230
pand %xmm0, %xmm1
movsd 0x1868(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x3cfc0
movsd 0x1868(%rsp), %xmm0
movsd 0x19528e(%rip), %xmm1   # 0x1d2248
ucomisd %xmm1, %xmm0
jb 0x3cfd0
movl $0x0, 0x1894(%rsp)
jmp 0x3d0d8
movsd 0x1858(%rsp), %xmm1
addsd 0x1850(%rsp), %xmm1
movsd 0x195c9e(%rip), %xmm0   # 0x1d2c88
mulsd %xmm1, %xmm0
movsd %xmm0, 0x1840(%rsp)
movq 0x1888(%rsp), %rax
movq (%rax), %rdi
addq $0x28, %rdi
movq 0x1880(%rsp), %rsi
movq 0x1878(%rsp), %rdx
movq 0x1870(%rsp), %rcx
movsd 0x195c2a(%rip), %xmm0   # 0x1d2c50
mulsd 0x1868(%rsp), %xmm0
movl 0x1864(%rsp), %r8d
movsd 0x1858(%rsp), %xmm1
movsd 0x1840(%rsp), %xmm2
movl 0x184c(%rsp), %r9d
movq 0x18a0(%rsp), %rax
movq %rax, (%rsp)
callq 0x3ccc0
movq 0x1888(%rsp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
movq 0x1880(%rsp), %rsi
movq 0x1878(%rsp), %rdx
movq 0x1870(%rsp), %rcx
movsd 0x195bbf(%rip), %xmm0   # 0x1d2c50
mulsd 0x1868(%rsp), %xmm0
movl 0x1864(%rsp), %r8d
movsd 0x1840(%rsp), %xmm1
movsd 0x1850(%rsp), %xmm2
movl 0x184c(%rsp), %r9d
movq 0x18a0(%rsp), %rax
movq %rax, (%rsp)
callq 0x3ccc0
movl $0x0, 0x1894(%rsp)
movl 0x1894(%rsp), %eax
addq $0x1898, %rsp           # imm = 0x1898
retq
nopw (%rax,%rax)