// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../tools/hyperspherical.c
// Function: hyperspherical_backwards_recurrence_chunk
int hyperspherical_backwards_recurrence_chunk(int K,
                                              int lmax,
                                              double beta,
                                              double * __restrict__ x,
                                              double * __restrict__ sinK,
                                              double * __restrict__ cotK,
                                              int chunk,
                                              double * __restrict__ sqrtK,
                                              double * __restrict__ one_over_sqrtK,
                                              double * __restrict__ PhiL){
  double phi0, phi1, phipr1;
  int l, k, isign;
  int funcreturn = _FAILURE_;
  int index_x;
  double scalevec[_HYPER_CHUNK_]={0};

  for (index_x=0; index_x<chunk; index_x++){
    if (K==1){
      if (beta > 1.5*lmax) {
        funcreturn = get_CF1(K,lmax,beta,cotK[index_x], &phipr1, &isign);
      }
      if (funcreturn == _FAILURE_) {
        CF1_from_Gegenbauer(lmax,(int) (beta+0.2),sinK[index_x],cotK[index_x], &phipr1);
      }
      phi1 = 1.0;
    }
    else{
      get_CF1(K,lmax,beta,cotK[index_x], &phipr1, &isign);
      phi1 = isign;
      phipr1 *=phi1;
    }

    PhiL[lmax*chunk+index_x] = phi1;
    PhiL[(lmax-1)*chunk+index_x] = one_over_sqrtK[lmax]*
      ((lmax+1)*cotK[index_x]*phi1+phipr1);

  }
  for (l=lmax-2; l>=0; l--){
    //Use recurrence Phi_{l} = --Phi_{l+1} + -- Phi_{l+2}
    for (index_x=0; index_x<chunk; index_x++){
      PhiL[l*chunk+index_x] = one_over_sqrtK[l+1]*
        ((2*l+3)*cotK[index_x]*PhiL[(l+1)*chunk+index_x]-
         sqrtK[l+2]*PhiL[(l+2)*chunk+index_x]);
    }

    if (fabs(PhiL[l*chunk])>_HYPER_OVERFLOW_){
      //Rescale whole Phi vector until this point.
      //Create scale vector:
      for (index_x=0; index_x<chunk; index_x++)
        scalevec[index_x] = fabs(1.0/PhiL[l*chunk+index_x]);
      //Now do the scaling: (We do it this way to access elements in order)
      for (k=l; k<=lmax; k++){
        for (index_x=0; index_x<chunk; index_x++){
          PhiL[k*chunk+index_x] *= scalevec[index_x];
        }
      }
    }
  }
  for(index_x=0; index_x<chunk; index_x++){
    phi0 = sin(beta*x[index_x])/(beta*sinK[index_x]);
    scalevec[index_x] = phi0/PhiL[index_x];
  }
  for (k=0; k<=lmax; k++){
    for (index_x=0; index_x<chunk; index_x++){
      PhiL[k*chunk+index_x] *= scalevec[index_x];
    }
  }

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r8, %r15
movq %rcx, 0x40(%rsp)
movq %rdx, 0x68(%rsp)
movq 0x140(%rsp), %rbx
movq 0x138(%rsp), %r13
xorps %xmm1, %xmm1
movaps %xmm1, 0xe0(%rsp)
movaps %xmm1, 0xd0(%rsp)
movaps %xmm1, 0xc0(%rsp)
movaps %xmm1, 0xb0(%rsp)
movaps %xmm1, 0xa0(%rsp)
movaps %xmm1, 0x90(%rsp)
movaps %xmm1, 0x80(%rsp)
movaps %xmm1, 0x70(%rsp)
cvtsi2sd %esi, %xmm1
mulsd 0xc57c8(%rip), %xmm1    # 0xe7f88
movsd %xmm1, 0x48(%rsp)
movsd 0xc2aca(%rip), %xmm1    # 0xe5298
movsd %xmm0, 0x10(%rsp)
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0x38(%rsp)
movl %r9d, %eax
imull %esi, %eax
movl %esi, 0x8(%rsp)
movslq %esi, %rbp
leal 0x1(%rbp), %ecx
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x60(%rsp)
leal -0x1(%rbp), %ecx
imull %r9d, %ecx
movslq %ecx, %rcx
xorl %r14d, %r14d
testl %r9d, %r9d
movl $0x0, %r12d
movl %r9d, 0x34(%rsp)
cmovgl %r9d, %r12d
cltq
leaq (%rbx,%rax,8), %rax
movq %rax, 0x58(%rsp)
leaq (%rbx,%rcx,8), %rax
movq %rax, 0x50(%rsp)
pushq $0x1
popq %rcx
movl %edi, 0xc(%rsp)
cmpq %r14, %r12
je 0x22957
cmpl $0x1, %edi
jne 0x228c1
movsd 0x10(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x22878
movsd (%r15,%r14,8), %xmm1
pushq $0x1
popq %rdi
movl 0x8(%rsp), %esi
movsd 0x10(%rsp), %xmm0
leaq 0x18(%rsp), %rdx
leaq 0x24(%rsp), %rcx
callq 0x2225e
movl 0xc(%rsp), %edi
movl %eax, %ecx
cmpl $0x1, %ecx
jne 0x22914
movq 0x40(%rsp), %rax
movsd (%rax,%r14,8), %xmm0
movsd (%r15,%r14,8), %xmm1
movsd %xmm1, 0x28(%rsp)
movl 0x8(%rsp), %edi
movl 0x38(%rsp), %esi
leaq 0x18(%rsp), %rdx
callq 0x224ca
movsd 0x28(%rsp), %xmm1
movl 0xc(%rsp), %edi
movsd 0xc29a4(%rip), %xmm0    # 0xe5260
pushq $0x1
popq %rcx
jmp 0x22922
movsd (%r15,%r14,8), %xmm1
movsd %xmm1, 0x28(%rsp)
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %esi
movsd 0x10(%rsp), %xmm0
leaq 0x18(%rsp), %rdx
movl %ecx, 0x3c(%rsp)
leaq 0x24(%rsp), %rcx
callq 0x2225e
movl 0x3c(%rsp), %ecx
movl 0xc(%rsp), %edi
cvtsi2sdl 0x24(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movsd 0x28(%rsp), %xmm1
jmp 0x22922
movsd (%r15,%r14,8), %xmm1
movsd 0xc293e(%rip), %xmm0    # 0xe5260
mulsd 0x60(%rsp), %xmm1
movq 0x58(%rsp), %rax
movsd %xmm0, (%rax,%r14,8)
mulsd %xmm0, %xmm1
addsd 0x18(%rsp), %xmm1
mulsd (%r13,%rbp,8), %xmm1
movq 0x50(%rsp), %rax
movsd %xmm1, (%rax,%r14,8)
incq %r14
jmp 0x22834
movl 0x8(%rsp), %eax
addl $-0x2, %eax
cltq
movslq 0x34(%rsp), %rcx
movq %rcx, %rdx
imulq %rax, %rdx
leaq (%rbx,%rdx,8), %rdx
leaq (,%rcx,8), %r14
movq %r14, %rsi
negq %rsi
leaq 0x2(%rax), %rdi
imulq %rcx, %rdi
leaq (%rbx,%rdi,8), %rdi
leaq 0x1(%rax), %r8
imulq %rcx, %r8
leaq (%rbx,%r8,8), %r8
movapd 0xc28a2(%rip), %xmm0    # 0xe5240
movsd 0xc5ab2(%rip), %xmm1    # 0xe8458
movsd 0xc28b2(%rip), %xmm2    # 0xe5260
testq %rax, %rax
js 0x22a84
leal 0x3(,%rax,2), %r9d
cvtsi2sd %r9d, %xmm3
movq %rax, %r9
imulq %rcx, %r9
xorl %r10d, %r10d
cmpq %r10, %r12
je 0x22a0e
movsd (%r15,%r10,8), %xmm4
movsd (%rdi,%r10,8), %xmm5
movq 0x130(%rsp), %r11
mulsd 0x10(%r11,%rax,8), %xmm5
mulsd %xmm3, %xmm4
mulsd (%r8,%r10,8), %xmm4
subsd %xmm5, %xmm4
mulsd 0x8(%r13,%rax,8), %xmm4
movsd %xmm4, (%rdx,%r10,8)
incq %r10
jmp 0x229ce
movsd (%rbx,%r9,8), %xmm3
andpd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
jbe 0x22a73
xorl %r9d, %r9d
cmpq %r9, %r12
je 0x22a40
movapd %xmm2, %xmm3
divsd (%rdx,%r9,8), %xmm3
andpd %xmm0, %xmm3
movlpd %xmm3, 0x70(%rsp,%r9,8)
incq %r9
jmp 0x22a21
movq %rdx, %r9
movq %rax, %r10
cmpq %rbp, %r10
jg 0x22a73
xorl %r11d, %r11d
cmpq %r11, %r12
je 0x22a6b
movsd 0x70(%rsp,%r11,8), %xmm3
mulsd (%r9,%r11,8), %xmm3
movsd %xmm3, (%r9,%r11,8)
incq %r11
jmp 0x22a4e
incq %r10
addq %r14, %r9
jmp 0x22a46
decq %rax
addq %rsi, %rdx
addq %rsi, %rdi
addq %rsi, %r8
jmp 0x229ae
xorl %r15d, %r15d
movq 0x40(%rsp), %r13
cmpq %r15, %r12
je 0x22aca
movq 0x68(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
mulsd 0x10(%rsp), %xmm0
callq 0x80a0
movsd (%r13,%r15,8), %xmm1
mulsd 0x10(%rsp), %xmm1
divsd %xmm1, %xmm0
divsd (%rbx,%r15,8), %xmm0
movsd %xmm0, 0x70(%rsp,%r15,8)
incq %r15
jmp 0x22a8c
xorl %eax, %eax
cmpq %rbp, %rax
jg 0x22af5
xorl %ecx, %ecx
cmpq %rcx, %r12
je 0x22aed
movsd 0x70(%rsp,%rcx,8), %xmm0
mulsd (%rbx,%rcx,8), %xmm0
movsd %xmm0, (%rbx,%rcx,8)
incq %rcx
jmp 0x22ad3
incq %rax
addq %r14, %rbx
jmp 0x22acc
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq