// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x848, %rsp            # imm = 0x848
movl %r9d, 0x14(%rsp)
movsd %xmm2, 0x30(%rsp)
movsd %xmm1, 0x18(%rsp)
movl %r8d, %r14d
movsd %xmm0, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
movl $0x38, %edi
callq 0x8460
movq %rax, (%rbx)
testq %rax, %rax
setne 0x13(%rsp)
je 0x214fd
movq %rax, %rbp
xorl %r15d, %r15d
testl %r14d, %r14d
je 0x2140c
movl $0x78, %edi
callq 0x8460
movq %rax, 0x10(%rbp)
testq %rax, %rax
je 0x21555
movl $0x78, %edi
callq 0x8460
movq %rax, 0x18(%rbp)
testq %rax, %rax
jne 0x21413
jmp 0x21594
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbp)
movq (%rbx), %rax
xorl %ebp, %ebp
movq %rbp, 0x28(%rax)
movq (%rbx), %rax
movq %rbp, 0x30(%rax)
movq (%rbx), %rcx
movq %r13, %rdi
movq %r12, %rsi
movq 0x20(%rsp), %rdx
movsd 0x18(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movl 0x14(%rsp), %r8d
callq 0x218ba
movsd 0x28(%rsp), %xmm0
ucomisd 0xcce0b(%rip), %xmm0    # 0xee260
jae 0x215e0
movq (%rbx), %rdi
movsd 0x8(%rdi), %xmm1
divsd (%rdi), %xmm1
andpd 0xccdd1(%rip), %xmm1    # 0xee240
ucomisd %xmm1, %xmm0
ja 0x215e0
movsd 0x18(%rsp), %xmm1
movapd %xmm1, %xmm2
addsd 0x30(%rsp), %xmm2
mulsd 0xcd83f(%rip), %xmm2    # 0xeecd0
movsd %xmm2, 0x38(%rsp)
addq $0x28, %rdi
mulsd 0xcfb25(%rip), %xmm0    # 0xf0fc8
movq 0x880(%rsp), %rax
movq %rax, (%rsp)
movq %r13, %rsi
movq %r12, %rdx
movq 0x20(%rsp), %rcx
movsd %xmm0, 0x28(%rsp)
movl %r14d, %r8d
movl 0x14(%rsp), %r9d
callq 0x2137e
movq (%rbx), %r15
leaq 0x30(%r15), %rbx
movl $0x38, %edi
callq 0x8460
movq %rax, %rbp
movq %rax, 0x30(%r15)
movb $0x1, %r15b
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
testq %rax, %rax
jne 0x213d8
leaq 0xccb00(%rip), %rsi     # 0xee004
leaq 0xcfe61(%rip), %rdx     # 0xf136c
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movl $0x38, %ecx
xorl %eax, %eax
callq 0x30af0
leaq 0xccb0e(%rip), %rsi     # 0xee034
leaq 0xcfe45(%rip), %rdx     # 0xf1372
movq 0x880(%rsp), %rdi
movl $0x1fd, %ecx            # imm = 0x1FD
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %ebp
movb 0x13(%rsp), %al
movl %eax, %r15d
jmp 0x215e0
leaq 0xccaa8(%rip), %rsi     # 0xee004
leaq 0xcfe18(%rip), %rdx     # 0xf137b
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movl $0x78, %ecx
xorl %eax, %eax
callq 0x30af0
leaq 0xccab6(%rip), %rsi     # 0xee034
leaq 0xcfded(%rip), %rdx     # 0xf1372
movq 0x880(%rsp), %rdi
movl $0x203, %ecx            # imm = 0x203
jmp 0x215d1
leaq 0xcca69(%rip), %rsi     # 0xee004
leaq 0xcfde4(%rip), %rdx     # 0xf1386
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movl $0x78, %ecx
xorl %eax, %eax
callq 0x30af0
leaq 0xcca77(%rip), %rsi     # 0xee034
leaq 0xcfdae(%rip), %rdx     # 0xf1372
movq 0x880(%rsp), %rdi
movl $0x204, %ecx            # imm = 0x204
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %ebp
xorl %eax, %eax
testb $0x1, %r15b
cmovel %ebp, %eax
addq $0x848, %rsp            # imm = 0x848
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq