// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../tools/hyperspherical.c
// Function: hyperspherical_get_xmin_from_Airy
int hyperspherical_get_xmin_from_Airy(int K,
                                      int l,
                                      double beta,
                                      double xtol,
                                      double phiminabs,
                                      double *xmin,
                                      int *fevals){
  double xold, xtp=0, xleft, xright, xnew;
  double Fnew, Fold, Fleft, Fright;
  double delx, lambda;
  double AIRY_SAFETY = 1e-6;
  struct WKB_parameters wkbstruct;
  //Start searching from turning point:
  switch (K){
  case -1:
    xtp = asinh(sqrt(l*(l+1.))/beta);
    break;
  case 0:
    xtp = sqrt(l*(l+1.))/beta;
    break;
  case 1:
    xtp = asin(sqrt(l*(l+1.))/beta);
    break;
  }
  wkbstruct.K = K;
  wkbstruct.l = l;
  wkbstruct.beta = beta;
  wkbstruct.phiminabs = phiminabs;

  xnew = 0.99*xtp;

  Fnew = PhiWKB_minus_phiminabs(xnew,&wkbstruct);
  *fevals = (*fevals)+1;

  lambda = 2*_PI_/(beta+5.0);
  if (Fnew>0)
    delx = -lambda;
  else
    delx = 0.25*lambda;

  do {
    //printf("In the loop: xnew = %g, Fnew=%g, Fold=%g\n",xnew,Fnew,Fold);
    xold = xnew;
    Fold = Fnew;
    xnew += delx;
    if (xnew<AIRY_SAFETY){
      xnew = AIRY_SAFETY;
      Fnew = PhiWKB_minus_phiminabs(xnew,&wkbstruct);
      *fevals = (*fevals)+1;
      if (Fnew>=0.0){
        *xmin = xnew;
        return _SUCCESS_;
      }
      else{
        break;
      }
    }
    Fnew = PhiWKB_minus_phiminabs(xnew,&wkbstruct);
    *fevals = (*fevals)+1;
  } while (SIGN(Fnew)==(SIGN(Fold)));

  if (Fnew<=0.0){
    xleft = xnew;
    Fleft = Fnew;
    xright = xold;
    Fright = Fold;
  }
  else{
    xleft = xold;
    Fleft = Fold;
    xright = xnew;
    Fright = Fnew;
  }

  fzero_ridder(PhiWKB_minus_phiminabs,
               xleft,
               xright,
               xtol,
               &wkbstruct,
               &Fleft,
               &Fright,
               xmin,
               fevals);

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x70, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movsd %xmm1, 0x28(%rsp)
movapd %xmm0, %xmm3
movl %esi, %ebp
movl %edi, %r15d
cmpl $0x1, %edi
movsd %xmm0, 0x10(%rsp)
je 0x23b58
testl %r15d, %r15d
je 0x23b34
xorpd %xmm0, %xmm0
cmpl $-0x1, %r15d
jne 0x23bd5
movsd %xmm2, 0x8(%rsp)
cvtsi2sd %ebp, %xmm1
movsd 0xc174b(%rip), %xmm0    # 0xe5260
addsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x23bb5
sqrtsd %xmm0, %xmm0
jmp 0x23bc0
cvtsi2sd %ebp, %xmm1
movsd 0xc1720(%rip), %xmm0    # 0xe5260
addsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x23b82
sqrtsd %xmm0, %xmm0
jmp 0x23b99
movsd %xmm2, 0x8(%rsp)
cvtsi2sd %ebp, %xmm1
movsd 0xc16f6(%rip), %xmm0    # 0xe5260
addsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x23b9f
sqrtsd %xmm0, %xmm0
jmp 0x23baa
movsd %xmm2, 0x8(%rsp)
callq 0x82d0
movsd 0x8(%rsp), %xmm2
movsd 0x10(%rsp), %xmm3
divsd %xmm3, %xmm0
jmp 0x23bd5
callq 0x82d0
movsd 0x10(%rsp), %xmm3
divsd %xmm3, %xmm0
callq 0x85d0
jmp 0x23bc9
callq 0x82d0
movsd 0x10(%rsp), %xmm3
divsd %xmm3, %xmm0
callq 0x84a0
movsd 0x10(%rsp), %xmm3
movsd 0x8(%rsp), %xmm2
leaq 0x48(%rsp), %r12
movl %r15d, (%r12)
movl %ebp, 0x4(%r12)
movsd %xmm3, 0x8(%r12)
movsd %xmm2, 0x10(%r12)
mulsd 0xc48ff(%rip), %xmm0    # 0xe84f8
movsd %xmm0, 0x8(%rsp)
movq %r12, %rdi
callq 0x23da1
movsd 0x8(%rsp), %xmm3
incl (%r14)
movsd 0x10(%rsp), %xmm2
addsd 0xc1652(%rip), %xmm2    # 0xe5270
movsd 0xc47c2(%rip), %xmm1    # 0xe83e8
divsd %xmm2, %xmm1
movapd 0xc15fe(%rip), %xmm2    # 0xe5230
xorpd %xmm1, %xmm2
mulsd 0xc48c2(%rip), %xmm1    # 0xe8500
xorpd %xmm4, %xmm4
cmpltsd %xmm0, %xmm4
andpd %xmm4, %xmm2
andnpd %xmm1, %xmm4
orpd %xmm2, %xmm4
movapd %xmm4, 0x30(%rsp)
movapd %xmm0, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
movsd %xmm3, 0x20(%rsp)
addsd %xmm3, %xmm0
movsd 0xc2059(%rip), %xmm1    # 0xe5cd0
ucomisd %xmm0, %xmm1
ja 0x23cea
movq %r12, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0x23da1
incl (%r14)
xorpd %xmm1, %xmm1
cmpltsd %xmm0, %xmm1
movapd %xmm1, %xmm2
movsd 0xc15bd(%rip), %xmm5    # 0xe5260
andpd %xmm5, %xmm2
movsd 0xc1b39(%rip), %xmm6    # 0xe57e8
andnpd %xmm6, %xmm1
orpd %xmm2, %xmm1
xorpd %xmm2, %xmm2
movapd 0x10(%rsp), %xmm4
cmpltsd %xmm4, %xmm2
movapd %xmm2, %xmm3
andpd %xmm5, %xmm3
andnpd %xmm6, %xmm2
orpd %xmm3, %xmm2
movsd 0x8(%rsp), %xmm3
ucomisd %xmm2, %xmm1
jne 0x23d17
jnp 0x23c59
jmp 0x23d17
leaq 0x48(%rsp), %rdi
movsd 0xc1fd9(%rip), %xmm0    # 0xe5cd0
callq 0x23da1
incl (%r14)
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movsd 0xc1fc1(%rip), %xmm3    # 0xe5cd0
movapd 0x10(%rsp), %xmm4
jae 0x23d85
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movapd %xmm0, %xmm2
cmpnlesd %xmm1, %xmm2
movapd %xmm2, %xmm1
andpd %xmm4, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
jb 0x23d42
movsd 0x20(%rsp), %xmm1
jmp 0x23d50
movapd %xmm0, %xmm4
movapd %xmm3, %xmm1
movsd 0x20(%rsp), %xmm3
leaq 0x68(%rsp), %rdx
movlpd %xmm2, (%rdx)
leaq 0x60(%rsp), %rcx
movsd %xmm4, (%rcx)
leaq 0x38(%rip), %rdi        # 0x23da1
leaq 0x48(%rsp), %rsi
movapd %xmm3, %xmm0
movsd 0x28(%rsp), %xmm2
movq %rbx, %r8
movq %r14, %r9
callq 0x23dda
jmp 0x23d92
movabsq $0x3eb0c6f7a0b5ed8d, %rax # imm = 0x3EB0C6F7A0B5ED8D
movq %rax, (%rbx)
xorl %eax, %eax
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq