// File: /workspace/github_c_makefile_star2_O3/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
movsd %xmm0, 0x10(%rsp)
movslq 0x1c(%rdi), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
jle 0x26238
movq %rsi, %rbx
movq %rdi, %r14
movslq 0x30(%rdi), %rax
movl %eax, %ebp
movq 0x38(%rdi), %r15
movq 0x50(%rdi), %rcx
movq %rcx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
leaq (%r15,%rax,8), %rax
addq $-0x8, %rax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
movapd 0xc8190(%rip), %xmm2    # 0xee240
xorpd %xmm5, %xmm5
movapd 0xcb844(%rip), %xmm6    # 0xf1900
movapd 0xcb84c(%rip), %xmm7    # 0xf1910
movdqa 0xcb853(%rip), %xmm8    # 0xf1920
xorl %r13d, %r13d
movsd %xmm1, 0x38(%rsp)
movq %r15, %rcx
cmpl $0x0, 0x28(%rsp)
jle 0x26117
movl %r12d, %eax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %rcx
xorl %eax, %eax
movsd (%rcx,%rax,8), %xmm0
andpd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
ja 0x26107
incq %rax
cmpq %rax, %rbp
jne 0x260ee
movl %ebp, %eax
movq %r15, %rcx
testl %eax, %eax
je 0x26117
movq 0x18(%rsp), %rcx
cmpl %ebp, %eax
jne 0x26133
movsd (%rcx), %xmm0
movsd %xmm0, (%rbx,%r13,8)
incq %r13
addl %ebp, %r12d
cmpq 0x30(%rsp), %r13
jne 0x260d6
jmp 0x26238
movl %eax, %eax
movsd -0x8(%r15,%rax,8), %xmm0
movsd (%r15,%rax,8), %xmm4
movsd %xmm4, (%rbx,%r13,8)
subsd %xmm0, %xmm4
ucomisd 0x10(%rsp), %xmm4
jbe 0x26121
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
xorl %eax, %eax
movsd 0xcb78a(%rip), %xmm2    # 0xf18f0
movapd %xmm2, %xmm3
unpcklps %xmm5, %xmm3            # xmm3 = xmm3[0],xmm5[0],xmm3[1],xmm5[1]
orpd %xmm6, %xmm3
subpd %xmm6, %xmm3
mulpd %xmm4, %xmm3
divpd %xmm7, %xmm3
addpd %xmm0, %xmm3
movapd %xmm3, 0x40(%rsp,%rax,8)
addq $0x2, %rax
paddd %xmm8, %xmm2
cmpq $0xa, %rax
jne 0x26166
movq $0x0, (%rsp)
movq %r14, %rdi
movl $0xa, %esi
movl %r13d, %edx
leaq 0x40(%rsp), %rcx
leaq 0x90(%rsp), %r8
xorl %r9d, %r9d
callq 0x23339
movl $0x1, %eax
movsd 0x38(%rsp), %xmm1
movapd 0xc806f(%rip), %xmm2    # 0xee240
movsd 0x90(%rsp,%rax,8), %xmm0
andpd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
ja 0x261f2
incq %rax
cmpq $0xa, %rax
jne 0x261d1
movl $0xa, %eax
movl %eax, %eax
movsd 0x38(%rsp,%rax,8), %xmm0
movsd 0x40(%rsp,%rax,8), %xmm4
movsd %xmm4, (%rbx,%r13,8)
subsd %xmm0, %xmm4
ucomisd 0x10(%rsp), %xmm4
xorpd %xmm5, %xmm5
movapd 0xcb6e4(%rip), %xmm6    # 0xf1900
movapd 0xcb6ec(%rip), %xmm7    # 0xf1910
movdqa 0xcb6f3(%rip), %xmm8    # 0xf1920
ja 0x26154
jmp 0x26121
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq