// File: /workspace/github_c_makefile_star2_O0/PoulinV[P]AxiCLASS/build/../tools/hyperspherical.c
// Function: hyperspherical_backwards_recurrence
int hyperspherical_backwards_recurrence(int K,
                                        int lmax,
                                        double beta,
                                        double x,
                                        double sinK,
                                        double cotK,
                                        double * __restrict__ sqrtK,
                                        double * __restrict__ one_over_sqrtK,
                                        double * __restrict__ PhiL){
  double phi0, phi1, phipr1, phi, phi_plus_1_times_sqrtK, phi_minus_1, scaling;
  int l, k, isign;
  int funcreturn = _FAILURE_;
  phi0 = sin(beta*x)/(beta*sinK);

  //printf("in backwards. x = %g\n",x);
  if (K==1){
    if (beta > 1.5*lmax) {
      funcreturn = get_CF1(K,lmax,beta,cotK, &phipr1, &isign);
    }
    if (funcreturn == _FAILURE_) {
      CF1_from_Gegenbauer(lmax,(int) (beta+0.2),sinK,cotK, &phipr1);
    }
    phi1 = 1.0;
  }
  else{
    get_CF1(K,lmax,beta,cotK, &phipr1, &isign);
    phi1 = isign;
    phipr1 *=phi1;
    //printf("isign = %d, phi1 = %g, phipr1 = %g\n",isign,phi1,phipr1);
  }

  PhiL[lmax] = phi1;
  phi = phi1;
  //  phi_plus_1 = 1/sqrtK[lmax+1]*(lmax*cotK*phi1-phipr1);
  phi_plus_1_times_sqrtK = lmax*cotK*phi1-phipr1;


  int l_ini, l_align;
  l_align = lmax-lmax%_HYPER_BLOCK_;

  // Bring l down to _HYPER_BLOCK_ aligned region:
  for (l=lmax; l>l_align; l--){
    //    phi_minus_1 = ( (2*l+1)*cotK*phi-phi_plus_1_times_sqrtK )/sqrtK[l];
    phi_minus_1 = ( (2*l+1)*cotK*phi-phi_plus_1_times_sqrtK )*one_over_sqrtK[l];
    phi_plus_1_times_sqrtK = phi*sqrtK[l];
    phi = phi_minus_1;
    PhiL[l-1] = phi;
  }
  for (l_ini=l_align; l_ini>0; l_ini -= _HYPER_BLOCK_){
    for (l=l_ini; l>(l_ini-_HYPER_BLOCK_); l--){
      //    phi_minus_1 = ( (2*l+1)*cotK*phi-phi_plus_1_times_sqrtK )/sqrtK[l];
      phi_minus_1 = ( (2*l+1)*cotK*phi-phi_plus_1_times_sqrtK )*one_over_sqrtK[l];
      phi_plus_1_times_sqrtK = phi*sqrtK[l];
      phi = phi_minus_1;
      PhiL[l-1] = phi;
    }
    if (fabs(phi)>_HYPER_OVERFLOW_){
      phi *= _ONE_OVER_HYPER_OVERFLOW_;
      phi_plus_1_times_sqrtK *= _ONE_OVER_HYPER_OVERFLOW_;
      //Rescale whole Phi vector until this point:
      for (k=l; k<=lmax; k++)
        PhiL[k] *=_ONE_OVER_HYPER_OVERFLOW_;
    }
  }

  /**
  for (l=lmax; l>=1; l--){
    //    phi_minus_1 = ( (2*l+1)*cotK*phi-phi_plus_1_times_sqrtK )/sqrtK[l];
    phi_minus_1 = ( (2*l+1)*cotK*phi-phi_plus_1_times_sqrtK )*one_over_sqrtK[l];
    phi_plus_1_times_sqrtK = phi*sqrtK[l];
    phi = phi_minus_1;
    PhiL[l-1] = phi;
    if (fabs(phi)>_HYPER_OVERFLOW_){
      //
      phi *= _ONE_OVER_HYPER_OVERFLOW_;
      phi_plus_1_times_sqrtK *= _ONE_OVER_HYPER_OVERFLOW_;
      //Rescale whole Phi vector until this point:
      for (k=l-1; k<=lmax; k++)
        PhiL[k] *=_ONE_OVER_HYPER_OVERFLOW_;
    }
  }
  */
  scaling = phi0/phi;
  for (k=0; k<=lmax; k++)
    PhiL[k] *= scaling;
  return _SUCCESS_;
}

// Assembly:
subq $0x98, %rsp
movl %edi, 0x94(%rsp)
movl %esi, 0x90(%rsp)
movsd %xmm0, 0x88(%rsp)
movsd %xmm1, 0x80(%rsp)
movsd %xmm2, 0x78(%rsp)
movsd %xmm3, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movq %rcx, 0x60(%rsp)
movq %r8, 0x58(%rsp)
movl $0x1, 0x10(%rsp)
movsd 0x88(%rsp), %xmm0
mulsd 0x80(%rsp), %xmm0
callq 0x80a0
movsd 0x88(%rsp), %xmm1
mulsd 0x78(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
cmpl $0x1, 0x94(%rsp)
jne 0x41ff5
movsd 0x88(%rsp), %xmm0
cvtsi2sdl 0x90(%rsp), %xmm2
movsd 0x190cde(%rip), %xmm1   # 0x1d2c50
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x41fac
movl 0x94(%rsp), %edi
movl 0x90(%rsp), %esi
movsd 0x88(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
leaq 0x40(%rsp), %rdx
leaq 0x14(%rsp), %rcx
callq 0x42350
movl %eax, 0x10(%rsp)
cmpl $0x1, 0x10(%rsp)
jne 0x41fe5
movl 0x90(%rsp), %edi
movsd 0x1902be(%rip), %xmm0   # 0x1d2280
addsd 0x88(%rsp), %xmm0
cvttsd2si %xmm0, %esi
movsd 0x78(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
leaq 0x40(%rsp), %rdx
callq 0x42690
movsd 0x19025b(%rip), %xmm0   # 0x1d2248
movsd %xmm0, 0x48(%rsp)
jmp 0x4203f
movl 0x94(%rsp), %edi
movl 0x90(%rsp), %esi
movsd 0x88(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
leaq 0x40(%rsp), %rdx
leaq 0x14(%rsp), %rcx
callq 0x42350
cvtsi2sdl 0x14(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x48(%rsp), %xmm0
movq 0x58(%rsp), %rax
movslq 0x90(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
cvtsi2sdl 0x90(%rsp), %xmm0
mulsd 0x70(%rsp), %xmm0
movsd 0x48(%rsp), %xmm2
movsd 0x40(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x90(%rsp), %eax
movl %eax, 0x4(%rsp)
movl 0x90(%rsp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl 0x4(%rsp), %eax
subl %edx, %eax
movl %eax, 0x8(%rsp)
movl 0x90(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x8(%rsp), %eax
jle 0x42184
movl 0x1c(%rsp), %eax
shll %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm0
mulsd 0x70(%rsp), %xmm0
movsd 0x38(%rsp), %xmm2
movsd 0x30(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x60(%rsp), %rax
movslq 0x1c(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x38(%rsp), %xmm0
movq 0x68(%rsp), %rax
movslq 0x1c(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
movq 0x58(%rsp), %rax
movl 0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x420d2
movl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x422ef
movl 0xc(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl 0xc(%rsp), %ecx
subl $0x8, %ecx
cmpl %ecx, %eax
jle 0x42256
movl 0x1c(%rsp), %eax
shll %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm0
mulsd 0x70(%rsp), %xmm0
movsd 0x38(%rsp), %xmm2
movsd 0x30(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x60(%rsp), %rax
movslq 0x1c(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x38(%rsp), %xmm0
movq 0x68(%rsp), %rax
movslq 0x1c(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
movq 0x58(%rsp), %rax
movl 0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x4219f
movsd 0x38(%rsp), %xmm0
movaps 0x18ffcd(%rip), %xmm1   # 0x1d2230
pand %xmm1, %xmm0
movsd 0x193289(%rip), %xmm1   # 0x1d54f8
ucomisd %xmm1, %xmm0
jbe 0x422dd
movsd 0x193283(%rip), %xmm0   # 0x1d5500
mulsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x19326f(%rip), %xmm0   # 0x1d5500
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x90(%rsp), %eax
jg 0x422db
movq 0x58(%rsp), %rax
movslq 0x18(%rsp), %rcx
movsd 0x19323c(%rip), %xmm0   # 0x1d5500
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x422a5
jmp 0x422dd
jmp 0x422df
movl 0xc(%rsp), %eax
subl $0x8, %eax
movl %eax, 0xc(%rsp)
jmp 0x4218c
movsd 0x50(%rsp), %xmm0
divsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x90(%rsp), %eax
jg 0x4233d
movsd 0x20(%rsp), %xmm0
movq 0x58(%rsp), %rax
movslq 0x18(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x42309
xorl %eax, %eax
addq $0x98, %rsp
retq
nopw (%rax,%rax)