// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../source/fourier.c
// Function: fourier_pk_linear
int fourier_pk_linear(
                      struct background *pba,
                      struct perturbations *ppt,
                      struct primordial *ppm,
                      struct fourier *pfo,
                      int index_pk,
                      int index_tau,
                      int k_size,
                      double * lnpk,    //lnpk[index_k]
                      double * lnpk_ic  //lnpk[index_k * pfo->ic_ic_size + index_ic1_ic2]
                      ) {

  int index_k;
  int index_tp;
  int index_ic1,index_ic2,index_ic1_ic1,index_ic1_ic2,index_ic2_ic2;
  double * primordial_pk;
  double pk;
  double * pk_ic;
  double source_ic1;
  double source_ic2;
  double cosine_correlation;

  /** - allocate temporary vector where the primordial spectrum will be stored */

  class_alloc(primordial_pk,pfo->ic_ic_size*sizeof(double),pfo->error_message);

  class_alloc(pk_ic,pfo->ic_ic_size*sizeof(double),pfo->error_message);

  if ((pfo->has_pk_m == _TRUE_) && (index_pk == pfo->index_pk_m)) {
    index_tp = ppt->index_tp_delta_m;
  }
  else if ((pfo->has_pk_cb == _TRUE_) && (index_pk == pfo->index_pk_cb)) {
    index_tp = ppt->index_tp_delta_cb;
  }
  else {
    class_stop(pfo->error_message,"P(k) is set neither to total matter nor to cold dark matter + baryons");
  }

  /** - loop over k values */
  for (index_k=0; index_k<k_size; index_k++) {

    /** --> get primordial spectrum */
    ppm->calling_from_pk = _TRUE_;
    class_call(primordial_spectrum_at_k(ppm,pfo->index_md_scalars,logarithmic,pfo->ln_k[index_k],primordial_pk),
               ppm->error_message,
               pfo->error_message);
    ppm->calling_from_pk = _FALSE_;

    /** --> initialize a local variable for P_m(k) and P_cb(k) to zero */
    pk = 0.;

    /** --> here we recall the relations relevant for the nomalization fo the power spectrum:
        For adiabatic modes, the curvature primordial spectrum thnat we just read was:
        P_R(k) = 1/(2pi^2) k^3 < R R >
        Thus the primordial curvature correlator is given by:
        < R R > = (2pi^2) k^-3 P_R(k)
        So the delta_m correlator reads:
        P(k) = < delta_m delta_m > = (source_m)^2 < R R > = (2pi^2) k^-3 (source_m)^2 P_R(k)

        For isocurvature or cross adiabatic-isocurvature parts,
        one would just replace one or two 'R' by 'S_i's */

    /** --> get contributions to P(k) diagonal in the initial conditions */
    for (index_ic1 = 0; index_ic1 < pfo->ic_size; index_ic1++) {

      index_ic1_ic1 = index_symmetric_matrix(index_ic1,index_ic1,pfo->ic_size);

      class_call(fourier_get_source(pba,
                                    ppt,
                                    pfo,
                                    index_k,
                                    index_ic1,
                                    index_tp,
                                    index_tau,
                                    ppt->sources[pfo->index_md_scalars],
                                    &source_ic1),
                 pfo->error_message,
                 pfo->error_message);

      pk_ic[index_ic1_ic1] = 2.*_PI_*_PI_/exp(3.*pfo->ln_k[index_k])
        *source_ic1*source_ic1
        *exp(primordial_pk[index_ic1_ic1]);

      pk += pk_ic[index_ic1_ic1];

      if (lnpk_ic != NULL) {
        lnpk_ic[index_k * pfo->ic_ic_size + index_ic1_ic1] = log(pk_ic[index_ic1_ic1]);
      }
    }

    /** --> get contributions to P(k) non-diagonal in the initial conditions */
    for (index_ic1 = 0; index_ic1 < pfo->ic_size; index_ic1++) {
      for (index_ic2 = index_ic1+1; index_ic2 < pfo->ic_size; index_ic2++) {

        index_ic1_ic2 = index_symmetric_matrix(index_ic1,index_ic2,pfo->ic_size);
        index_ic1_ic1 = index_symmetric_matrix(index_ic1,index_ic1,pfo->ic_size);
        index_ic2_ic2 = index_symmetric_matrix(index_ic2,index_ic2,pfo->ic_size);

        if (pfo->is_non_zero[index_ic1_ic2] == _TRUE_) {

          class_call(fourier_get_source(pba,
                                        ppt,
                                        pfo,
                                        index_k,
                                        index_ic1,
                                        index_tp,
                                        index_tau,
                                        ppt->sources[pfo->index_md_scalars],
                                        &source_ic1),
                     pfo->error_message,
                     pfo->error_message);

          class_call(fourier_get_source(pba,
                                        ppt,
                                        pfo,
                                        index_k,
                                        index_ic2,
                                        index_tp,
                                        index_tau,
                                        ppt->sources[pfo->index_md_scalars],
                                        &source_ic2),
                     pfo->error_message,
                     pfo->error_message);

          cosine_correlation = primordial_pk[index_ic1_ic2]*SIGN(source_ic1)*SIGN(source_ic2);

          pk_ic[index_ic1_ic2] = cosine_correlation * sqrt(pk_ic[index_ic1_ic1]*pk_ic[index_ic2_ic2]);

          pk += 2.*pk_ic[index_ic1_ic2];

          if (lnpk_ic != NULL) {
            lnpk_ic[index_k * pfo->ic_ic_size + index_ic1_ic2] = cosine_correlation;
          }
        }
        else {
          if (lnpk_ic != NULL) {
            lnpk_ic[index_k * pfo->ic_ic_size + index_ic1_ic2] = 0.;
          }
        }
      }
    }

    lnpk[index_k] = log(pk);
  }

  free(primordial_pk);
  free(pk_ic);

  return _SUCCESS_;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10b8, %rsp           # imm = 0x10B8
movq %r9, 0x38(%rsp)
movl %r8d, %r14d
movq %rcx, %rbx
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, 0x10(%rsp)
movslq 0x44(%rcx), %r12
movq %r12, %r15
shlq $0x3, %r15
movq %r15, %rdi
callq 0x8490
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x9dbbe
movq %r15, %rdi
callq 0x8490
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x9dc08
cmpw $0x1, 0x50(%rbx)
jne 0x9d729
movl $0x8d8, %eax            # imm = 0x8D8
cmpl %r14d, 0x54(%rbx)
je 0x9d743
cmpw $0x1, 0x52(%rbx)
jne 0x9dc52
movl $0x8dc, %eax            # imm = 0x8DC
cmpl %r14d, 0x58(%rbx)
jne 0x9dc52
movl 0x10f0(%rsp), %ecx
xorl %r15d, %r15d
testl %ecx, %ecx
cmovlel %r15d, %ecx
movl (%rbp,%rax), %eax
pushq $0x1
popq %rdx
cmpq %rcx, %r15
je 0x9dd97
movl %eax, 0x4(%rsp)
movq %rcx, 0x80(%rsp)
movw $0x1, 0xb2c(%r13)
movl 0x3c(%rbx), %esi
movq 0x80(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
movq %r13, %rdi
movq 0x20(%rsp), %rcx
callq 0x8f820
cmpl $0x1, %eax
je 0x9ddaf
movq %r15, 0x48(%rsp)
movq %rbp, 0x40(%rsp)
movq %r13, 0x78(%rsp)
andw $0x0, 0xb2c(%r13)
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movq 0x38(%rsp), %r13
movl 0x40(%rbx), %ebp
cmpl %ebp, %r15d
jge 0x9d8e8
movsd %xmm0, 0x50(%rsp)
movq 0x40(%rsp), %rsi
movq 0xa38(%rsi), %rax
movslq 0x3c(%rbx), %r10
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq %rbx, %rdx
movq 0x50(%rsp), %r12
movl %r12d, %ecx
movl %r15d, %r8d
movl 0xc(%rsp), %r9d
leaq 0x8b8(%rsp), %r11
pushq %r11
pushq (%rax,%r10,8)
pushq %r13
callq 0x9e75c
addq $0x20, %rsp
testl %eax, %eax
jne 0x9dcac
incl %ebp
imull %r15d, %ebp
leal 0x1(%r15), %r14d
imull %r14d, %r15d
shrl %r15d
subl %r15d, %ebp
movq 0x80(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
mulsd 0x48efd(%rip), %xmm0    # 0xe6748
callq 0x86a0
movsd %xmm0, 0x60(%rsp)
movsd 0x8b0(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movslq %ebp, %r15
movq 0x20(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
callq 0x86a0
movsd 0x74948(%rip), %xmm1    # 0x1121c8
divsd 0x60(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm0, %xmm1
movq 0x28(%rsp), %rax
movsd %xmm1, (%rax,%r15,8)
movq 0x1100(%rsp), %r15
testq %r15, %r15
je 0x9d8d6
movapd %xmm1, %xmm0
movsd %xmm1, 0x8(%rsp)
callq 0x82e0
movsd 0x8(%rsp), %xmm1
movl 0x44(%rbx), %eax
imull %r12d, %eax
addl %ebp, %eax
cltq
movsd %xmm0, (%r15,%rax,8)
movsd 0x50(%rsp), %xmm0
addsd %xmm1, %xmm0
movl %r14d, %r15d
jmp 0x9d7c3
xorl %r8d, %r8d
movq 0x10(%rsp), %rdi
movq 0x1100(%rsp), %rcx
movq 0x48(%rsp), %r15
pushq $0x1
popq %r12
movq %rbx, 0x30(%rsp)
cmpl %ebp, %r8d
jge 0x9db8a
leal 0x1(%r8), %eax
movl %eax, %r12d
imull %r8d, %r12d
shrl %r12d
movl %eax, 0x58(%rsp)
movl %eax, %r13d
movq %r8, 0x70(%rsp)
movl %r12d, 0x5c(%rsp)
cmpl %ebp, %r13d
jge 0x9db7a
cmpl %r13d, %r8d
jbe 0x9d958
movl %ebp, %edx
imull %r13d, %edx
addl %r8d, %edx
leal 0x1(%r13), %esi
movl %esi, %r14d
imull %r13d, %r14d
shrl %r14d
subl %r14d, %edx
jmp 0x9d974
movl %ebp, %eax
imull %r8d, %eax
movl %r13d, %edx
subl %r12d, %edx
addl %eax, %edx
leal 0x1(%r13), %esi
movl %esi, %r14d
imull %r13d, %r14d
shrl %r14d
movq 0x48(%rbx), %rax
movslq %edx, %r9
cmpw $0x1, (%rax,%r9,2)
jne 0x9daa7
movq %r9, 0x8(%rsp)
movl %esi, 0x18(%rsp)
movl %edx, 0x1c(%rsp)
movsd %xmm0, 0x50(%rsp)
movq 0x40(%rsp), %r12
movq 0xa38(%r12), %rax
movq %rax, 0x60(%rsp)
movslq 0x3c(%rbx), %r10
subq $0x8, %rsp
movq %r12, %rsi
movq %rbx, %rdx
movl %r15d, %ecx
movl 0xc(%rsp), %r15d
movl %r15d, %r9d
leaq 0x8b8(%rsp), %r11
pushq %r11
movq 0x70(%rsp), %r11
pushq (%r11,%r10,8)
pushq 0x50(%rsp)
callq 0x9e75c
addq $0x20, %rsp
testl %eax, %eax
jne 0x9dcf1
movq 0xa38(%r12), %rax
movslq 0x3c(%rbx), %r10
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq 0x50(%rsp), %rbx
movl %ebx, %ecx
movl %r13d, %r8d
movl %r15d, %r9d
leaq 0x90(%rsp), %r11
pushq %r11
pushq (%rax,%r10,8)
pushq 0x50(%rsp)
callq 0x9e75c
addq $0x20, %rsp
testl %eax, %eax
jne 0x9dd33
movq %rbx, %r15
incl %ebp
movl %ebp, %eax
movq 0x70(%rsp), %r8
imull %r8d, %eax
movl 0x5c(%rsp), %r12d
subl %r12d, %eax
imull %r13d, %ebp
xorpd %xmm4, %xmm4
cmpltsd 0x8b0(%rsp), %xmm4
subl %r14d, %ebp
xorpd %xmm3, %xmm3
cmpltsd 0x88(%rsp), %xmm3
movq 0x20(%rsp), %rcx
movq 0x8(%rsp), %r9
movsd (%rcx,%r9,8), %xmm5
cltq
movq 0x28(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movslq %ebp, %rax
mulsd (%rcx,%rax,8), %xmm0
ucomisd 0x477b9(%rip), %xmm0    # 0xe5258
jb 0x9dab0
sqrtsd %xmm0, %xmm0
jmp 0x9daef
xorpd %xmm3, %xmm3
jmp 0x9db5a
movapd %xmm3, 0x60(%rsp)
movapd %xmm4, 0xa0(%rsp)
movapd %xmm5, 0x90(%rsp)
callq 0x82d0
movapd 0x90(%rsp), %xmm5
movapd 0xa0(%rsp), %xmm4
movapd 0x60(%rsp), %xmm3
movq 0x8(%rsp), %r9
movq 0x70(%rsp), %r8
movq 0x30(%rsp), %rbx
movq 0x10(%rsp), %rdi
movq 0x1100(%rsp), %rcx
movl 0x1c(%rsp), %edx
movl 0x18(%rsp), %esi
movapd %xmm4, %xmm1
andpd %xmm5, %xmm1
movapd 0x47717(%rip), %xmm2    # 0xe5230
xorpd %xmm2, %xmm5
andnpd %xmm5, %xmm4
orpd %xmm1, %xmm4
movapd %xmm3, %xmm1
andpd %xmm4, %xmm1
xorpd %xmm2, %xmm4
andnpd %xmm4, %xmm3
orpd %xmm1, %xmm3
mulsd %xmm3, %xmm0
movq 0x28(%rsp), %rax
movsd %xmm0, (%rax,%r9,8)
addsd %xmm0, %xmm0
movsd 0x50(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
testq %rcx, %rcx
je 0x9db6f
movl 0x44(%rbx), %eax
imull %r15d, %eax
addl %edx, %eax
cltq
movsd %xmm3, (%rcx,%rax,8)
movl 0x40(%rbx), %ebp
movl %esi, %r13d
jmp 0x9d92e
movl 0x58(%rsp), %eax
movl %eax, %r8d
pushq $0x1
popq %r12
jmp 0x9d906
callq 0x82e0
movl %r12d, %edx
movq 0x10f8(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movq 0x78(%rsp), %r13
movq 0x40(%rsp), %rbp
movq 0x80(%rsp), %rcx
movl 0x4(%rsp), %eax
jmp 0x9d75a
leal (,%r12,8), %ecx
leaq 0x47437(%rip), %rsi     # 0xe5004
leaq 0x76ed7(%rip), %rdx     # 0x114aab
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0x47440(%rip), %rsi     # 0xe5034
leaq 0x76ebe(%rip), %rdx     # 0x114ab9
movq %rbx, %rdi
movl $0x983, %ecx            # imm = 0x983
jmp 0x9dd78
leal (,%r12,8), %ecx
leaq 0x473ed(%rip), %rsi     # 0xe5004
leaq 0x882fc(%rip), %rdx     # 0x125f1a
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0x473f6(%rip), %rsi     # 0xe5034
leaq 0x76e74(%rip), %rdx     # 0x114ab9
movq %rbx, %rdi
movl $0x985, %ecx            # imm = 0x985
jmp 0x9dd78
leaq 0x76e72(%rip), %rsi     # 0x114acb
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0x47913(%rip), %rsi     # 0xe5585
leaq 0x8b0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0x4739f(%rip), %rsi     # 0xe5034
leaq 0x76e1d(%rip), %rdx     # 0x114ab9
movq %rbx, %rdi
movl $0x98e, %ecx            # imm = 0x98E
movq %r15, %r8
jmp 0x9dd7b
addq $0x192, %rbx            # imm = 0x192
leaq 0x47736(%rip), %rsi     # 0xe53f0
leaq 0x76eb1(%rip), %rdx     # 0x114b72
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x47357(%rip), %rsi     # 0xe5034
leaq 0x76dd5(%rip), %rdx     # 0x114ab9
movq %rbx, %rdi
movl $0x9b8, %ecx            # imm = 0x9B8
jmp 0x9dd78
addq $0x192, %rbx            # imm = 0x192
leaq 0x476f1(%rip), %rsi     # 0xe53f0
leaq 0x76e6c(%rip), %rdx     # 0x114b72
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x47312(%rip), %rsi     # 0xe5034
leaq 0x76d90(%rip), %rdx     # 0x114ab9
movq %rbx, %rdi
movl $0x9d9, %ecx            # imm = 0x9D9
jmp 0x9dd78
movq 0x30(%rsp), %rbx
addq $0x192, %rbx            # imm = 0x192
leaq 0x476aa(%rip), %rsi     # 0xe53f0
leaq 0x76ea2(%rip), %rdx     # 0x114bef
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x472cb(%rip), %rsi     # 0xe5034
leaq 0x76d49(%rip), %rdx     # 0x114ab9
movq %rbx, %rdi
movl $0x9e5, %ecx            # imm = 0x9E5
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
addq $0x10b8, %rsp           # imm = 0x10B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rdi
callq 0x8430
movq 0x28(%rsp), %rdi
callq 0x8430
xorl %eax, %eax
jmp 0x9dd85
addq $0x32a, %r13            # imm = 0x32A
leaq 0x47633(%rip), %rsi     # 0xe53f0
leaq 0x76d4d(%rip), %rdx     # 0x114b11
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0x4724d(%rip), %rsi     # 0xe5034
leaq 0x76ccb(%rip), %rdx     # 0x114ab9
movq %rbx, %rdi
movl $0x998, %ecx            # imm = 0x998
jmp 0x9dd78