// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../tools/hyperspherical.c
// Function: hyperspherical_get_xmin
int hyperspherical_get_xmin(HyperInterpStruct *pHIS,
                            double xtol,
                            double phiminabs,
                            double *xmin){
  int left_index, right_index, index_l, j;
  int nl = pHIS->l_size;
  int nx = pHIS->x_size;
  int REFINE=10;
  double x[REFINE];
  double Phi[REFINE];
  double *phivec = pHIS->phi;
  double *xvec = pHIS->x;
  double xleft, xright;

  for (index_l=0; index_l<nl; index_l++){
    for (right_index = 0; right_index<nx; right_index++){
      if (fabs(phivec[index_l*nx+right_index])>phiminabs)
        break;
    }
    if (right_index==0){
      xmin[index_l] = xvec[0];
      //printf("special case: xmin = %.16e for index_l=%d\n",xmin[index_l],index_l);
      continue;
    }
    if (right_index==nx){
      xmin[index_l] = xvec[nx-1];
      //printf("special case: xmin = %.16e for index_l=%d\n",xmin[index_l],index_l);
      continue;
    }
    left_index = right_index-1;
    xleft = xvec[left_index];
    xright = xvec[right_index];
    xmin[index_l] = xright;
    while ((xright-xleft)>xtol){
      //Create interpolation vector
      //printf("Refining\n");
      for (j=0; j<REFINE; j++)
        x[j] = xleft+j*(xright-xleft)/(REFINE-1.0);
      hyperspherical_Hermite_interpolation_vector(pHIS,REFINE,
                                                  index_l, x, Phi, NULL,NULL);
      for (right_index = 1; right_index<REFINE; right_index++){
        if (fabs(Phi[right_index])>phiminabs)
          break;
      }
      left_index = right_index-1;
      xleft = x[left_index];
      xright = x[right_index];
      xmin[index_l] = xright;
    }
    //printf("xmin = %.16e\n",xmin[index_l]);
  }
  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %rbx
movsd %xmm0, 0x38(%rsp)
movq %rdi, %r14
movl 0x1c(%rdi), %eax
movslq 0x30(%rdi), %rcx
movq 0x50(%rdi), %rbp
movq 0x38(%rdi), %rdx
xorl %r15d, %r15d
testl %ecx, %ecx
movl $0x0, %r12d
cmovgl %ecx, %r12d
movq %rdx, 0x8(%rsp)
leaq (%rdx,%rcx,8), %rdx
addq $-0x8, %rdx
movq %rdx, 0x10(%rsp)
testl %eax, %eax
cmovlel %r15d, %eax
movq %rax, 0x28(%rsp)
movq %rcx, 0x18(%rsp)
shlq $0x3, %rcx
movq %rcx, 0x20(%rsp)
pushq $0x8
popq %r13
movapd 0xc18a0(%rip), %xmm2    # 0xe5240
movsd 0xc2d10(%rip), %xmm4    # 0xe66b8
movsd %xmm1, 0x30(%rsp)
cmpq 0x28(%rsp), %r15
je 0x23ab0
xorl %eax, %eax
cmpq %rax, %r12
je 0x239d5
movsd (%rbp,%rax,8), %xmm0
andpd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
ja 0x239d8
incq %rax
jmp 0x239bb
movl %r12d, %eax
movq 0x8(%rsp), %rcx
testl %eax, %eax
je 0x239ec
movq 0x10(%rsp), %rcx
cmpl 0x18(%rsp), %eax
jne 0x23a00
movsd (%rcx), %xmm0
movsd %xmm0, (%rbx,%r15,8)
incq %r15
addq 0x20(%rsp), %rbp
jmp 0x239ae
movl %eax, %eax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movsd -0x8(%rax), %xmm0
movsd (%rax), %xmm3
movsd %xmm3, (%rbx,%r15,8)
subsd %xmm0, %xmm3
ucomisd 0x38(%rsp), %xmm3
jbe 0x239f6
xorl %eax, %eax
cmpq $0xa, %rax
je 0x23a49
cvtsi2sd %eax, %xmm2
mulsd %xmm3, %xmm2
divsd %xmm4, %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, 0x40(%rsp,%rax,8)
incq %rax
jmp 0x23a28
andq $0x0, (%rsp)
movq %r14, %rdi
pushq $0xa
popq %rsi
movl %r15d, %edx
leaq 0x40(%rsp), %rcx
leaq 0x90(%rsp), %r8
xorl %r9d, %r9d
callq 0x20f53
movq %r13, %rax
movsd 0x30(%rsp), %xmm1
movapd 0xc17c3(%rip), %xmm2    # 0xe5240
cmpq $0x50, %rax
je 0x23a9c
movsd 0x90(%rsp,%rax), %xmm0
andpd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
ja 0x23a9c
addq $0x8, %rax
jmp 0x23a7d
addq %rsp, %rax
addq $0x40, %rax
movsd 0xc2c0d(%rip), %xmm4    # 0xe66b8
jmp 0x23a0b
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq