// File: /workspace/github_c_makefile_star2_O1/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 0x263a0
movq %rsi, %rbx
movq %rdi, %r14
movslq 0x30(%rdi), %rax
movl %eax, %ebp
movq 0x38(%rdi), %rcx
movq 0x50(%rdi), %rdx
movq %rdx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq %rcx, 0x8(%rsp)
leaq (%rcx,%rax,8), %rax
addq $-0x8, %rax
movq %rax, 0x18(%rsp)
xorl %r15d, %r15d
movapd 0xcb032(%rip), %xmm2    # 0xf1240
xorpd %xmm5, %xmm5
movapd 0xce6d6(%rip), %xmm6    # 0xf48f0
movapd 0xce6de(%rip), %xmm7    # 0xf4900
movdqa 0xce6e5(%rip), %xmm8    # 0xf4910
leaq 0x90(%rsp), %r12
xorl %r13d, %r13d
movsd %xmm1, 0x38(%rsp)
movl $0x0, %eax
cmpl $0x0, 0x28(%rsp)
jle 0x2626f
movl %r15d, %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 0x2626f
incq %rax
cmpq %rax, %rbp
jne 0x26256
movl %ebp, %eax
movq 0x8(%rsp), %rcx
testl %eax, %eax
je 0x26281
movq 0x18(%rsp), %rcx
cmpl %ebp, %eax
jne 0x2629d
movsd (%rcx), %xmm0
movsd %xmm0, (%rbx,%r13,8)
incq %r13
addl %ebp, %r15d
cmpq 0x30(%rsp), %r13
jne 0x2623c
jmp 0x263a0
movl %eax, %eax
movq 0x8(%rsp), %rcx
movsd -0x8(%rcx,%rax,8), %xmm0
movsd (%rcx,%rax,8), %xmm4
movsd %xmm4, (%rbx,%r13,8)
subsd %xmm0, %xmm4
ucomisd 0x10(%rsp), %xmm4
jbe 0x2628b
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
xorl %eax, %eax
movsd 0xce60d(%rip), %xmm2    # 0xf48e0
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 0x262d3
movq $0x0, (%rsp)
movq %r14, %rdi
movl $0xa, %esi
movl %r13d, %edx
leaq 0x40(%rsp), %rcx
movq %r12, %r8
xorl %r9d, %r9d
callq 0x23483
movl $0x1, %eax
movsd 0x38(%rsp), %xmm1
movapd 0xcaf07(%rip), %xmm2    # 0xf1240
movsd 0x90(%rsp,%rax,8), %xmm0
andpd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
ja 0x2635a
incq %rax
cmpq $0xa, %rax
jne 0x26339
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 0xce56c(%rip), %xmm6    # 0xf48f0
movapd 0xce574(%rip), %xmm7    # 0xf4900
movdqa 0xce57b(%rip), %xmm8    # 0xf4910
ja 0x262c1
jmp 0x2628b
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq