// File: /workspace/github_c_makefile_star2_O3/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 $0x70, %rsp
movq %r9, %r14
movq %r8, %rbx
movq %rsi, %r15
movsd %xmm2, 0x58(%rsp)
movapd %xmm1, %xmm2
movapd %xmm0, %xmm3
movq %rdi, %r12
testq %rdx, %rdx
sete %al
testq %rcx, %rcx
sete %sil
orb %al, %sil
jne 0x26611
movsd (%rdx), %xmm4
movsd (%rcx), %xmm0
movapd %xmm0, (%rsp)
jmp 0x26654
movapd %xmm3, %xmm0
movq %r15, %rdi
movsd %xmm2, 0x10(%rsp)
movsd %xmm3, 0x18(%rsp)
callq *%r12
movapd %xmm0, 0x40(%rsp)
movsd 0x10(%rsp), %xmm0
movq %r15, %rdi
callq *%r12
movapd 0x40(%rsp), %xmm4
movsd 0x18(%rsp), %xmm3
movsd 0x10(%rsp), %xmm2
movapd %xmm0, (%rsp)
addl $0x2, (%r14)
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm4
jbe 0x26665
ucomisd (%rsp), %xmm0
ja 0x2667e
ucomisd %xmm4, %xmm0
jbe 0x268d6
movapd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x268d6
movsd 0xcaf02(%rip), %xmm5    # 0xf1588
movl $0x3e8, %ebp            # imm = 0x3E8
movsd %xmm5, 0x20(%rsp)
movapd %xmm4, 0x40(%rsp)
movsd %xmm2, 0x10(%rsp)
movsd %xmm3, 0x18(%rsp)
addsd %xmm3, %xmm2
mulsd 0xc8621(%rip), %xmm2    # 0xeecd0
movsd %xmm2, 0x38(%rsp)
movapd %xmm2, %xmm0
movq %r15, %rdi
callq *%r12
movapd 0x40(%rsp), %xmm4
incl (%r14)
movapd %xmm0, %xmm9
movapd (%rsp), %xmm3
movapd %xmm3, %xmm1
mulsd %xmm4, %xmm1
mulsd %xmm0, %xmm0
subsd %xmm1, %xmm0
ucomisd 0xc7b6e(%rip), %xmm0    # 0xee258
movapd %xmm9, 0x60(%rsp)
jb 0x266f9
sqrtsd %xmm0, %xmm0
jmp 0x26710
callq 0x82b0
movapd 0x60(%rsp), %xmm9
movapd 0x40(%rsp), %xmm4
movapd (%rsp), %xmm3
ucomisd 0xc7b40(%rip), %xmm0    # 0xee258
movsd 0x18(%rsp), %xmm2
movapd 0xc7b0a(%rip), %xmm5    # 0xee230
movapd 0xc7b12(%rip), %xmm6    # 0xee240
movsd 0x20(%rsp), %xmm8
jne 0x2673d
jnp 0x268cf
movsd 0x38(%rsp), %xmm7
movapd %xmm7, %xmm1
subsd %xmm2, %xmm1
movapd %xmm9, %xmm2
xorpd %xmm5, %xmm2
movapd %xmm3, %xmm5
cmplesd %xmm4, %xmm5
movapd %xmm5, %xmm3
andpd %xmm9, %xmm3
andnpd %xmm2, %xmm5
orpd %xmm3, %xmm5
divsd %xmm0, %xmm5
mulsd %xmm1, %xmm5
addsd %xmm7, %xmm5
movapd %xmm5, %xmm0
subsd %xmm8, %xmm0
andpd %xmm6, %xmm0
movsd 0x58(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x268cf
movapd %xmm5, 0x20(%rsp)
movapd %xmm5, %xmm0
movq %r15, %rdi
callq *%r12
incl (%r14)
ucomisd 0xc7aa6(%rip), %xmm0    # 0xee258
jne 0x267ba
jnp 0x268e4
movapd 0x60(%rsp), %xmm7
movapd %xmm7, %xmm1
movapd 0xc7a74(%rip), %xmm6    # 0xee240
andpd %xmm6, %xmm1
jae 0x26809
movapd 0xc7a56(%rip), %xmm5    # 0xee230
xorpd %xmm5, %xmm1
ucomisd %xmm1, %xmm7
movsd 0x10(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
movapd 0x40(%rsp), %xmm4
jne 0x267f8
jnp 0x2683e
movapd %xmm7, %xmm4
movapd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm5
jmp 0x26832
ucomisd %xmm7, %xmm1
movsd 0x10(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
movapd 0x40(%rsp), %xmm4
movapd 0x20(%rsp), %xmm5
jne 0x26829
jnp 0x2685b
movapd %xmm7, %xmm4
movapd %xmm0, (%rsp)
movapd %xmm5, %xmm2
movsd 0x38(%rsp), %xmm3
jmp 0x268a8
movapd %xmm4, %xmm1
orpd %xmm5, %xmm1
ucomisd %xmm1, %xmm4
jne 0x2684e
jnp 0x26876
movapd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm5
jmp 0x26870
movapd %xmm4, %xmm1
andpd %xmm6, %xmm1
ucomisd %xmm4, %xmm1
jne 0x2686b
jnp 0x2688b
movapd %xmm0, (%rsp)
movapd %xmm5, %xmm2
jmp 0x268a8
movapd (%rsp), %xmm3
movapd %xmm3, %xmm1
orpd %xmm5, %xmm1
movapd 0x20(%rsp), %xmm5
jmp 0x26898
movapd (%rsp), %xmm3
movapd %xmm3, %xmm1
andpd %xmm6, %xmm1
ucomisd %xmm3, %xmm1
movapd %xmm0, %xmm4
movapd %xmm5, %xmm3
jne 0x268a8
jnp 0x2691b
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
andpd %xmm6, %xmm0
movsd 0x58(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x268f0
decl %ebp
jne 0x2668b
callq 0x879b
jmp 0x2691b
movsd %xmm8, (%rbx)
jmp 0x268f4
ucomisd %xmm0, %xmm4
jne 0x26903
jp 0x26903
cvttsd2si %xmm3, %eax
jmp 0x268f6
movapd 0x20(%rsp), %xmm0
movsd %xmm0, (%rbx)
jmp 0x268f4
movsd %xmm5, (%rbx)
xorl %eax, %eax
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movapd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x26916
jp 0x26916
cvttsd2si %xmm2, %eax
jmp 0x268f6
callq 0x877f
movl $0x1, %eax
jmp 0x268f6