// File: /workspace/github_c_makefile_star2_O1/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 $0xe8, %rsp
movl %r9d, %ebx
movq %r8, %r13
movq %rcx, 0x30(%rsp)
movq %rdx, 0x40(%rsp)
movapd %xmm0, %xmm9
movq 0x130(%rsp), %r12
xorpd %xmm0, %xmm0
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)
movapd %xmm0, 0x60(%rsp)
movslq %esi, %rax
movq %rax, 0x38(%rsp)
movl %r9d, %r14d
testl %r9d, %r9d
movq %rsi, (%rsp)
movsd %xmm9, 0x18(%rsp)
jle 0x24f68
movl %edi, %ebp
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
mulsd 0xcf1b7(%rip), %xmm0    # 0xf3fb8
movsd %xmm0, 0x48(%rsp)
movsd 0xcc489(%rip), %xmm0    # 0xf1298
addsd %xmm9, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x2c(%rsp)
movl %ebx, %eax
leal 0x1(%rsi), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x20(%rsp)
imull %esi, %eax
leal -0x1(%rsi), %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, 0x10(%rsp)
xorl %r15d, %r15d
cmpl $0x1, %ebp
jne 0x24ed8
ucomisd 0x48(%rsp), %xmm9
jbe 0x24e9a
movsd (%r13,%r15,8), %xmm1
movl $0x1, %edi
movq (%rsp), %rsi
movapd %xmm9, %xmm0
leaq 0x8(%rsp), %rdx
leaq 0x14(%rsp), %rcx
callq 0x24806
movsd 0x18(%rsp), %xmm9
movq (%rsp), %rsi
movl %eax, 0x10(%rsp)
cmpl $0x1, 0x10(%rsp)
jne 0x24ece
movq 0x30(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
movsd (%r13,%r15,8), %xmm1
movl %esi, %edi
movl 0x2c(%rsp), %esi
leaq 0x8(%rsp), %rdx
callq 0x24aaa
movsd 0x18(%rsp), %xmm9
movq (%rsp), %rsi
movsd 0xcc38a(%rip), %xmm0    # 0xf1260
jmp 0x24f1d
movsd (%r13,%r15,8), %xmm1
movl %ebp, %edi
movq (%rsp), %rsi
movapd %xmm9, %xmm0
leaq 0x8(%rsp), %rdx
leaq 0x14(%rsp), %rcx
callq 0x24806
movsd 0x18(%rsp), %xmm9
movq (%rsp), %rsi
xorps %xmm0, %xmm0
cvtsi2sdl 0x14(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd (%r13,%r15,8), %xmm1
mulsd 0x20(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd 0x8(%rsp), %xmm1
movq 0x128(%rsp), %rax
movq 0x38(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm1
movq 0x58(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
movq 0x50(%rsp), %rax
movsd %xmm1, (%rax,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0x24e59
cmpl $0x2, %esi
jl 0x250ca
movq 0x38(%rsp), %rsi
leaq -0x2(%rsi), %rax
movq (%rsp), %rdx
leal 0x1(%rdx), %ecx
movl %edx, %edx
movq %rdx, 0x20(%rsp)
movslq %ebx, %rdi
movq %rdi, %rdx
imulq %rax, %rdx
leaq (%r12,%rdx,8), %r8
leaq (,%rdi,8), %r9
movq %r9, %r10
negq %r10
movq %rsi, %rdx
imulq %rdi, %rdx
leaq (%r12,%rdx,8), %r11
decq %rsi
imulq %rdi, %rsi
leaq (%r12,%rsi,8), %r15
movapd 0xcc26e(%rip), %xmm0    # 0xf1230
movapd 0xcc276(%rip), %xmm1    # 0xf1240
movsd 0xcf4b6(%rip), %xmm2    # 0xf4488
movsd 0xcc286(%rip), %xmm3    # 0xf1260
testl %ebx, %ebx
jle 0x25041
leal 0x3(,%rax,2), %edx
xorps %xmm4, %xmm4
cvtsi2sd %edx, %xmm4
movq 0x128(%rsp), %rdx
movsd 0x8(%rdx,%rax,8), %xmm5
movq 0x120(%rsp), %rdx
movsd 0x10(%rdx,%rax,8), %xmm6
xorpd %xmm0, %xmm6
xorl %esi, %esi
movsd (%r13,%rsi,8), %xmm7
mulsd %xmm4, %xmm7
movsd (%r11,%rsi,8), %xmm8
mulsd %xmm6, %xmm8
mulsd (%r15,%rsi,8), %xmm7
addsd %xmm8, %xmm7
mulsd %xmm5, %xmm7
movsd %xmm7, (%r8,%rsi,8)
incq %rsi
cmpq %rsi, %r14
jne 0x2500e
movq %rax, %rdx
imulq %rdi, %rdx
movsd (%r12,%rdx,8), %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm2, %xmm4
jbe 0x250b1
testl %ebx, %ebx
jle 0x2507a
xorl %esi, %esi
movapd %xmm3, %xmm4
divsd (%r8,%rsi,8), %xmm4
andpd %xmm1, %xmm4
movlpd %xmm4, 0x60(%rsp,%rsi,8)
incq %rsi
cmpq %rsi, %r14
jne 0x2505e
movq %r8, %rbp
movq %rax, %rsi
cmpq 0x20(%rsp), %rax
jg 0x250b1
testl %ebx, %ebx
jle 0x250a7
xorl %edx, %edx
movsd 0x60(%rsp,%rdx,8), %xmm4
mulsd (%rbp,%rdx,8), %xmm4
movsd %xmm4, (%rbp,%rdx,8)
incq %rdx
cmpq %rdx, %r14
jne 0x2508d
incq %rsi
addq %r9, %rbp
cmpl %esi, %ecx
jne 0x25087
leaq -0x1(%rax), %rdx
addq %r10, %r8
addq %r10, %r11
addq %r10, %r15
testq %rax, %rax
movq %rdx, %rax
jg 0x24fda
testl %ebx, %ebx
movq 0x30(%rsp), %r13
movq 0x40(%rsp), %rbp
jle 0x25118
xorl %r15d, %r15d
movsd (%rbp,%r15,8), %xmm0
mulsd %xmm9, %xmm0
callq 0x80a0
movsd 0x18(%rsp), %xmm9
movsd (%r13,%r15,8), %xmm1
mulsd %xmm9, %xmm1
divsd %xmm1, %xmm0
divsd (%r12,%r15,8), %xmm0
movsd %xmm0, 0x60(%rsp,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0x250db
movq (%rsp), %rsi
testl %esi, %esi
js 0x25157
incl %esi
leaq (,%r14,8), %rax
xorl %ecx, %ecx
testl %ebx, %ebx
jle 0x2514c
xorl %edx, %edx
movsd 0x60(%rsp,%rdx,8), %xmm0
mulsd (%r12,%rdx,8), %xmm0
movsd %xmm0, (%r12,%rdx,8)
incq %rdx
cmpq %rdx, %r14
jne 0x25132
incq %rcx
addq %rax, %r12
cmpq %rsi, %rcx
jne 0x2512c
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq