// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/hyperspherical.c
// Function: fzero_ridder
int fzero_ridder(double (*func)(double, void *),
                  double x1,
                  double x2,
                  double xtol,
                  void *param,
                  double *Fx1,
                  double *Fx2,
                  double *xzero,
                  int *fevals){
   /**Using Ridders' method, return the root of a function func known to
      lie between x1 and x2. The root, returned as zriddr, will be found to
      an approximate accuracy xtol.
   */
   int j,MAXIT=1000;
    double ans,fh,fl,fm,fnew,s,xh,xl,xm,xnew;
    if ((Fx1!=NULL)&&(Fx2!=NULL)){
      fl = *Fx1;
      fh = *Fx2;
    }
    else{
      fl=(*func)(x1,param);
      fh=(*func)(x2,param);
      *fevals = (*fevals)+2;
    }
    if ((fl > 0.0 && fh < 0.0) || (fl < 0.0 && fh > 0.0)) {
      xl=x1;
      xh=x2;
      ans=-1.11e11;
      for (j=1;j<=MAXIT;j++) {
        xm=0.5*(xl+xh);
        fm=(*func)(xm,param);
        *fevals = (*fevals)+1;
        s=sqrt(fm*fm-fl*fh);
        if (s == 0.0){
          *xzero = ans;
          //printf("Success 1\n");
          return _SUCCESS_;
        }
        xnew=xm+(xm-xl)*((fl >= fh ? 1.0 : -1.0)*fm/s);
        if (fabs(xnew-ans) <= xtol) {
          *xzero = ans;
          return _SUCCESS_;
        }
        ans=xnew;
        fnew=(*func)(ans,param);
        *fevals = (*fevals)+1;
        if (fnew == 0.0){
          *xzero = ans;
          //printf("Success 2, ans=%g\n",ans);
          return _SUCCESS_;
        }
        if (NRSIGN(fm,fnew) != fm) {
          xl=xm;
          fl=fm;
          xh=ans;
          fh=fnew;
        } else if (NRSIGN(fl,fnew) != fl) {
          xh=ans;
          fh=fnew;
        } else if (NRSIGN(fh,fnew) != fh) {
          xl=ans;
          fl=fnew;
        } else return _FAILURE_;
        if (fabs(xh-xl) <= xtol) {
          *xzero = ans;
          //        printf("Success 3\n");
          return _SUCCESS_;
        }
      }
      fprintf(stderr,"zriddr exceed maximum iterations");
      return _FAILURE_;
    }
    else {
      if (fl == 0.0) return x1;
      if (fh == 0.0) return x2;
      fprintf(stderr,"root must be bracketed in zriddr.");
      return _FAILURE_;
    }
    fprintf(stderr,"Failure in Ridder\n");
    return _FAILURE_;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x60, %rsp
movq %r9, %r14
movq %r8, %rbx
movq %rsi, %r15
movsd %xmm2, 0x40(%rsp)
movapd %xmm0, %xmm3
movq %rdi, %r12
testq %rdx, %rdx
sete %al
testq %rcx, %rcx
sete %sil
orb %al, %sil
jne 0x26786
movsd (%rdx), %xmm5
movsd (%rcx), %xmm0
movapd %xmm0, (%rsp)
jmp 0x267c9
movapd %xmm3, %xmm0
movq %r15, %rdi
movsd %xmm1, 0x10(%rsp)
movsd %xmm3, 0x18(%rsp)
callq *%r12
movapd %xmm0, 0x30(%rsp)
movsd 0x10(%rsp), %xmm0
movq %r15, %rdi
callq *%r12
movapd 0x30(%rsp), %xmm5
movsd 0x18(%rsp), %xmm3
movsd 0x10(%rsp), %xmm1
movapd %xmm0, (%rsp)
addl $0x2, (%r14)
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm5
jbe 0x267da
ucomisd (%rsp), %xmm0
ja 0x267f3
ucomisd %xmm5, %xmm0
jbe 0x26a35
movapd (%rsp), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x26a35
movsd 0xcdd7d(%rip), %xmm4    # 0xf4578
movl $0x3e8, %ebp            # imm = 0x3E8
movsd %xmm4, 0x20(%rsp)
movapd %xmm5, 0x30(%rsp)
movsd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
movsd %xmm3, 0x18(%rsp)
addsd %xmm3, %xmm0
mulsd 0xcb4a8(%rip), %xmm0    # 0xf1cd0
movsd %xmm0, 0x48(%rsp)
movq %r15, %rdi
callq *%r12
movapd 0x30(%rsp), %xmm3
incl (%r14)
movapd %xmm0, %xmm8
movapd (%rsp), %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm0, %xmm0
subsd %xmm1, %xmm0
ucomisd 0xca9fd(%rip), %xmm0    # 0xf1258
movapd %xmm8, 0x50(%rsp)
jb 0x2686a
sqrtsd %xmm0, %xmm0
jmp 0x2687c
callq 0x82b0
movapd 0x50(%rsp), %xmm8
movapd 0x30(%rsp), %xmm3
ucomisd 0xca9d4(%rip), %xmm0    # 0xf1258
movsd 0x18(%rsp), %xmm2
movapd 0xca99e(%rip), %xmm4    # 0xf1230
movapd 0xca9a6(%rip), %xmm5    # 0xf1240
movsd 0x20(%rsp), %xmm7
jne 0x268a8
jnp 0x26a2f
movsd 0x48(%rsp), %xmm6
movapd %xmm6, %xmm1
subsd %xmm2, %xmm1
movapd %xmm8, %xmm2
xorpd %xmm4, %xmm2
movapd (%rsp), %xmm4
cmplesd %xmm3, %xmm4
movapd %xmm4, %xmm3
andpd %xmm8, %xmm3
andnpd %xmm2, %xmm4
orpd %xmm3, %xmm4
divsd %xmm0, %xmm4
mulsd %xmm1, %xmm4
addsd %xmm6, %xmm4
movapd %xmm4, %xmm0
subsd %xmm7, %xmm0
andpd %xmm5, %xmm0
movsd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x26a2f
movapd %xmm4, 0x20(%rsp)
movapd %xmm4, %xmm0
movq %r15, %rdi
callq *%r12
incl (%r14)
ucomisd 0xca93b(%rip), %xmm0    # 0xf1258
jne 0x26925
jnp 0x26a43
movapd 0x50(%rsp), %xmm5
movapd %xmm5, %xmm2
movapd 0xca909(%rip), %xmm7    # 0xf1240
andpd %xmm7, %xmm2
movapd %xmm5, %xmm3
movapd 0xca8e9(%rip), %xmm6    # 0xf1230
orpd %xmm6, %xmm3
xorpd %xmm1, %xmm1
cmplesd %xmm0, %xmm1
andpd %xmm1, %xmm2
movapd %xmm1, %xmm4
andnpd %xmm3, %xmm4
orpd %xmm2, %xmm4
ucomisd %xmm5, %xmm4
jne 0x2696c
jnp 0x26986
movapd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm4
movapd %xmm4, %xmm1
movsd 0x48(%rsp), %xmm3
jmp 0x26a08
movapd 0x30(%rsp), %xmm5
movapd %xmm5, %xmm2
andpd %xmm7, %xmm2
movapd %xmm5, %xmm3
orpd %xmm6, %xmm3
andpd %xmm1, %xmm2
movapd %xmm1, %xmm4
andnpd %xmm3, %xmm4
orpd %xmm2, %xmm4
ucomisd %xmm5, %xmm4
jne 0x269b4
jnp 0x269cb
movapd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm4
movapd %xmm4, %xmm1
movsd 0x18(%rsp), %xmm3
jmp 0x26a08
movapd (%rsp), %xmm4
movapd %xmm4, %xmm2
andpd %xmm7, %xmm2
movapd %xmm4, %xmm3
orpd %xmm6, %xmm3
andpd %xmm1, %xmm2
andnpd %xmm3, %xmm1
orpd %xmm2, %xmm1
ucomisd %xmm4, %xmm1
movapd %xmm0, %xmm5
movapd 0x20(%rsp), %xmm4
movapd %xmm4, %xmm3
movsd 0x10(%rsp), %xmm1
jne 0x26a08
jnp 0x26a7a
movapd %xmm1, %xmm0
subsd %xmm3, %xmm0
andpd %xmm7, %xmm0
movsd 0x40(%rsp), %xmm2
ucomisd %xmm0, %xmm2
jae 0x26a4f
decl %ebp
jne 0x26800
callq 0x879d
jmp 0x26a7a
movsd %xmm7, (%rbx)
jmp 0x26a53
ucomisd %xmm0, %xmm5
jne 0x26a62
jp 0x26a62
cvttsd2si %xmm3, %eax
jmp 0x26a55
movapd 0x20(%rsp), %xmm0
movsd %xmm0, (%rbx)
jmp 0x26a53
movsd %xmm4, (%rbx)
xorl %eax, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movapd (%rsp), %xmm2
ucomisd %xmm0, %xmm2
jne 0x26a75
jp 0x26a75
cvttsd2si %xmm1, %eax
jmp 0x26a55
callq 0x8781
movl $0x1, %eax
jmp 0x26a55