// File: /workspace/github_c_makefile_star2_O3/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
movl %r9d, %ebx
movq %r8, %r13
movq %rcx, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movapd %xmm0, %xmm9
movq 0x140(%rsp), %r12
xorpd %xmm0, %xmm0
movapd %xmm0, 0xe0(%rsp)
movapd %xmm0, 0xd0(%rsp)
movapd %xmm0, 0xc0(%rsp)
movapd %xmm0, 0xb0(%rsp)
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
movl %r9d, %r14d
testl %r9d, %r9d
movq %rsi, 0x8(%rsp)
movsd %xmm9, 0x20(%rsp)
jle 0x24e45
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
mulsd 0xcc324(%rip), %xmm0    # 0xf0fc8
movsd %xmm0, 0x48(%rsp)
movsd 0xc95e6(%rip), %xmm0    # 0xee298
addsd %xmm9, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x34(%rsp)
movl %ebx, %eax
movslq %esi, %rdx
leal 0x1(%rdx), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x60(%rsp)
imull %esi, %eax
movq %rdx, 0x68(%rsp)
leal -0x1(%rdx), %ecx
imull %ebx, %ecx
cltq
movslq %ecx, %rcx
leaq (%r12,%rax,8), %rax
movq %rax, 0x58(%rsp)
leaq (%r12,%rcx,8), %rax
movq %rax, 0x50(%rsp)
movl $0x1, %r15d
xorl %ebp, %ebp
movl %edi, (%rsp)
cmpl $0x1, %edi
jne 0x24d9b
ucomisd 0x48(%rsp), %xmm9
jbe 0x24d4d
movsd (%r13,%rbp,8), %xmm1
movl $0x1, %edi
movq 0x8(%rsp), %rsi
movapd %xmm9, %xmm0
leaq 0x10(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
callq 0x246ac
movl (%rsp), %edi
movsd 0x20(%rsp), %xmm9
movq 0x8(%rsp), %rsi
movl %eax, %r15d
cmpl $0x1, %r15d
jne 0x24df4
movq 0x38(%rsp), %rax
movsd (%rax,%rbp,8), %xmm0
movsd (%r13,%rbp,8), %xmm1
movsd %xmm1, 0x28(%rsp)
movl %esi, %edi
movl 0x34(%rsp), %esi
leaq 0x10(%rsp), %rdx
callq 0x24950
movsd 0x28(%rsp), %xmm1
movl (%rsp), %edi
movsd 0x20(%rsp), %xmm9
movq 0x8(%rsp), %rsi
movl $0x1, %r15d
jmp 0x24dfb
movsd (%r13,%rbp,8), %xmm1
movsd %xmm1, 0x28(%rsp)
movl (%rsp), %edi
movq 0x8(%rsp), %rsi
movapd %xmm9, %xmm0
leaq 0x10(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
callq 0x246ac
movl (%rsp), %edi
movsd 0x20(%rsp), %xmm9
movq 0x8(%rsp), %rsi
xorps %xmm0, %xmm0
cvtsi2sdl 0x1c(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x28(%rsp), %xmm1
jmp 0x24e03
movsd (%r13,%rbp,8), %xmm1
movsd 0xc945d(%rip), %xmm0    # 0xee260
mulsd 0x60(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd 0x10(%rsp), %xmm1
movq 0x138(%rsp), %rax
movq 0x68(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm1
movq 0x58(%rsp), %rax
movsd %xmm0, (%rax,%rbp,8)
movq 0x50(%rsp), %rax
movsd %xmm1, (%rax,%rbp,8)
incq %rbp
cmpq %rbp, %r14
jne 0x24d04
cmpl $0x2, %esi
jl 0x24fd8
movq 0x8(%rsp), %rsi
leal -0x2(%rsi), %eax
movslq %ebx, %rcx
leal 0x1(%rsi), %edx
movl %esi, %esi
movq %rsi, (%rsp)
movq %rcx, %rsi
imulq %rax, %rsi
leaq (%r12,%rsi,8), %r8
leaq (,%rcx,8), %r9
movq %r9, %r10
negq %r10
leaq 0x2(%rax), %rsi
imulq %rcx, %rsi
leaq (%r12,%rsi,8), %r11
leaq 0x1(%rax), %rsi
imulq %rcx, %rsi
leaq (%r12,%rsi,8), %r15
movapd 0xc9395(%rip), %xmm0    # 0xee230
movapd 0xc939d(%rip), %xmm1    # 0xee240
movsd 0xcc5ed(%rip), %xmm2    # 0xf1498
movsd 0xc93ad(%rip), %xmm3    # 0xee260
testl %ebx, %ebx
jle 0x24f69
movq 0x138(%rsp), %rsi
movsd 0x8(%rsi,%rax,8), %xmm4
leal 0x3(,%rax,2), %esi
xorps %xmm5, %xmm5
cvtsi2sd %esi, %xmm5
movq 0x130(%rsp), %rsi
movsd 0x10(%rsi,%rax,8), %xmm6
xorpd %xmm0, %xmm6
movq %rax, %rsi
imulq %rcx, %rsi
xorl %ebp, %ebp
movsd (%r13,%rbp,8), %xmm7
mulsd %xmm5, %xmm7
movsd (%r11,%rbp,8), %xmm8
mulsd %xmm6, %xmm8
mulsd (%r15,%rbp,8), %xmm7
addsd %xmm8, %xmm7
mulsd %xmm4, %xmm7
movsd %xmm7, (%r8,%rbp,8)
incq %rbp
cmpq %rbp, %r14
jne 0x24ef2
movsd (%r12,%rsi,8), %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm2, %xmm4
jbe 0x24fbf
testl %ebx, %ebx
jle 0x24f5b
xorl %esi, %esi
movapd %xmm3, %xmm4
divsd (%r8,%rsi,8), %xmm4
andpd %xmm1, %xmm4
movlpd %xmm4, 0x70(%rsp,%rsi,8)
incq %rsi
cmpq %rsi, %r14
jne 0x24f3f
movq %r8, %rbp
movq %rax, %rsi
cmpq (%rsp), %rax
jle 0x24f95
jmp 0x24fbf
movq %rax, %rsi
imulq %rcx, %rsi
movsd (%r12,%rsi,8), %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm2, %xmm4
setbe %sil
cmpq (%rsp), %rax
setg %dil
orb %sil, %dil
movq %r8, %rbp
movq %rax, %rsi
jne 0x24fbf
testl %ebx, %ebx
jle 0x24fb5
xorl %edi, %edi
movsd 0x70(%rsp,%rdi,8), %xmm4
mulsd (%rbp,%rdi,8), %xmm4
movsd %xmm4, (%rbp,%rdi,8)
incq %rdi
cmpq %rdi, %r14
jne 0x24f9b
incq %rsi
addq %r9, %rbp
cmpl %esi, %edx
jne 0x24f95
leaq -0x1(%rax), %rsi
addq %r10, %r8
addq %r10, %r11
addq %r10, %r15
testq %rax, %rax
movq %rsi, %rax
jg 0x24eb3
testl %ebx, %ebx
movq 0x38(%rsp), %r13
movq 0x40(%rsp), %rbp
jle 0x25026
xorl %r15d, %r15d
movsd (%rbp,%r15,8), %xmm0
mulsd %xmm9, %xmm0
callq 0x80a0
movsd 0x20(%rsp), %xmm9
movsd (%r13,%r15,8), %xmm1
mulsd %xmm9, %xmm1
divsd %xmm1, %xmm0
divsd (%r12,%r15,8), %xmm0
movsd %xmm0, 0x70(%rsp,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0x24fe9
movq 0x8(%rsp), %rsi
testl %esi, %esi
js 0x25066
incl %esi
leaq (,%r14,8), %rax
xorl %ecx, %ecx
testl %ebx, %ebx
jle 0x2505b
xorl %edx, %edx
movsd 0x70(%rsp,%rdx,8), %xmm0
mulsd (%r12,%rdx,8), %xmm0
movsd %xmm0, (%r12,%rdx,8)
incq %rdx
cmpq %rdx, %r14
jne 0x25041
incq %rcx
addq %rax, %r12
cmpq %rsi, %rcx
jne 0x2503b
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq