// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../source/input.c
// Function: input_find_root
int input_find_root(double *xzero,
                    int *fevals,
                    double tol_x_rel,
                    struct fzerofun_workspace *pfzw,
                    ErrorMsg errmsg){

  /** Summary: */

  /** Define local variables */
  double x1, x2, f1, f2, dxdy, dx;
  int iter, iter2;
  int return_function;

  /** Fisrt we do our guess */
  class_call(input_get_guess(&x1, &dxdy, pfzw, errmsg),
             errmsg,
             errmsg);

  class_call(input_fzerofun_1d(x1, pfzw, &f1, errmsg),
             errmsg,
             errmsg);

  (*fevals)++;
  dx = 1.5*f1*dxdy;

  /** Then we do a linear hunt for the boundaries */
  /* Try fifteen times to go above and below the root (i.e. where shooting succeeds) */
  for (iter=1; iter<=150; iter++){ //vp:default iter max is 15. We increase it to a large number to make sure shooting does not fail for axion.
    x2 = x1 - dx;
    /* Try three times to get a 'reasonable' value, i.e. no CLASS error */
    for (iter2=1; iter2 <= 3; iter2++) {
      return_function = input_fzerofun_1d(x2, pfzw, &f2, errmsg);
      (*fevals)++;
      if (return_function ==_SUCCESS_) {
        break;
      }
      else if (iter2 < 3) {
        dx*=0.5;
        x2 = x1-dx;
      }
      else {
        class_stop(errmsg,errmsg);
      }
    }
    if (f1*f2<0.0){
      /* Root has been bracketed */
      break;
    }
    x1 = x2;
    f1 = f2;
  }
  // printf("here x1 %e x2 %e f1 %e f2 %e!!\n",x1,x2,f1,f2);
  /** Find root using Ridders method (Exchange for bisection if you are old-school) */
  class_call(input_fzero_ridder(input_fzerofun_1d,
                                x1,
                                x2,
                                tol_x_rel*MAX(fabs(x1),fabs(x2)),
                                pfzw,
                                &f1,
                                &f2,
                                xzero,
                                fevals,
                                errmsg),
             errmsg,errmsg);
   // printf("here xzero %e!!\n",xzero);

  return _SUCCESS_;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1068, %rsp           # imm = 0x1068
movq %rcx, %rbx
movq %rdx, %r12
movsd %xmm0, 0x40(%rsp)
movq %rsi, %r14
movq %rdi, %r15
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x3e532
testl %eax, %eax
je 0x3e2e6
leaq 0xb313b(%rip), %rsi     # 0xf13f0
leaq 0xb90e3(%rip), %rdx     # 0xf739f
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xb2d5f(%rip), %rsi     # 0xf1034
leaq 0xb90ed(%rip), %rdx     # 0xf73c9
movq %rbx, %rdi
movl $0x4c4, %ecx            # imm = 0x4C4
jmp 0x3e336
movsd 0x10(%rsp), %xmm0
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
movq %rbx, %rdx
callq 0x40b38
testl %eax, %eax
je 0x3e357
leaq 0xb30e9(%rip), %rsi     # 0xf13f0
leaq 0xb90cb(%rip), %rdx     # 0xf73d9
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xb2d0d(%rip), %rsi     # 0xf1034
leaq 0xb909b(%rip), %rdx     # 0xf73c9
movq %rbx, %rdi
movl $0x4c8, %ecx            # imm = 0x4C8
movq %r14, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
addq $0x1068, %rsp           # imm = 0x1068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, 0x38(%rsp)
incl (%r14)
movsd 0x8(%rsp), %xmm1
mulsd 0xb5c4b(%rip), %xmm1    # 0xf3fb8
mulsd 0x48(%rsp), %xmm1
movl $0x1, %ebp
movsd 0x10(%rsp), %xmm3
leaq 0x30(%rsp), %r13
movapd %xmm3, 0x20(%rsp)
movsd %xmm1, 0x18(%rsp)
subsd %xmm1, %xmm3
movapd %xmm3, 0x50(%rsp)
movapd %xmm3, %xmm0
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x40b38
incl (%r14)
testl %eax, %eax
je 0x3e3fa
movl $0x3, %r15d
decl %r15d
je 0x3e4db
movsd 0x18(%rsp), %xmm1
mulsd 0xb3901(%rip), %xmm1    # 0xf1cd0
movapd 0x20(%rsp), %xmm0
movsd %xmm1, 0x18(%rsp)
subsd %xmm1, %xmm0
movapd %xmm0, 0x50(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x40b38
incl (%r14)
testl %eax, %eax
jne 0x3e3b8
movsd 0x30(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
movapd 0x50(%rsp), %xmm3
ja 0x3e440
movsd %xmm0, 0x8(%rsp)
incl %ebp
movapd %xmm3, 0x20(%rsp)
cmpl $0x97, %ebp
movsd 0x18(%rsp), %xmm1
jne 0x3e389
movapd %xmm3, 0x20(%rsp)
movapd 0x20(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movapd 0xb2dec(%rip), %xmm2    # 0xf1240
movapd %xmm0, %xmm1
andpd %xmm2, %xmm1
andpd %xmm3, %xmm2
maxsd %xmm1, %xmm2
mulsd 0x40(%rsp), %xmm2
movq %rbx, (%rsp)
leaq 0x26c3(%rip), %rdi      # 0x40b38
leaq 0x8(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movapd %xmm3, %xmm1
movq %r12, %rsi
movq 0x38(%rsp), %r8
movq %r14, %r9
callq 0x40bbf
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x1, %ecx
jne 0x3e345
leaq 0xb2f49(%rip), %rsi     # 0xf13f0
leaq 0xb8f54(%rip), %rdx     # 0xf7402
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xb2b6d(%rip), %rsi     # 0xf1034
leaq 0xb8efb(%rip), %rdx     # 0xf73c9
movq %rbx, %rdi
movl $0x4f3, %ecx            # imm = 0x4F3
jmp 0x3e336
movaps 0x20(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x30c2c
leaq 0xb3086(%rip), %rsi     # 0xf1585
leaq 0x860(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30c2c
leaq 0xb2b19(%rip), %rsi     # 0xf1034
leaq 0xb8ea7(%rip), %rdx     # 0xf73c9
movq %rbx, %rdi
movl $0x4dd, %ecx            # imm = 0x4DD
movq %r15, %r8
jmp 0x3e339