// File: /workspace/github_c_makefile_star2_O1/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 $0x10c8, %rsp           # imm = 0x10C8
movq %r9, 0x18(%rsp)
movl %r8d, %ebp
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, 0x20(%rsp)
movslq 0x44(%rcx), %r15
movq %r15, %r14
shlq $0x3, %r14
movq %r14, %rdi
callq 0x8460
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0xa5c38
movq %r14, %rdi
callq 0x8460
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0xa5c7f
cmpw $0x1, 0x50(%r13)
jne 0xa573e
movl $0x8d8, %eax            # imm = 0x8D8
cmpl %ebp, 0x54(%r13)
je 0xa5759
cmpw $0x1, 0x52(%r13)
jne 0xa5cc9
movl $0x8dc, %eax            # imm = 0x8DC
cmpl %ebp, 0x58(%r13)
jne 0xa5cc9
movl 0x1100(%rsp), %ecx
testl %ecx, %ecx
jle 0xa5c1d
movl (%rbx,%rax), %r14d
movl %ecx, %eax
movq %rax, 0x68(%rsp)
xorl %r15d, %r15d
movl %r14d, 0xc(%rsp)
movq %r12, 0x70(%rsp)
movq %rbx, 0x48(%rsp)
movw $0x1, 0xb2c(%r12)
movl 0x3c(%r13), %esi
movq 0x80(%r13), %rax
movsd (%rax,%r15,8), %xmm0
movq %r12, %rdi
movl $0x1, %edx
movq 0x38(%rsp), %rcx
callq 0x97030
cmpl $0x1, %eax
je 0xa5e0b
movw $0x0, 0xb2c(%r12)
movq %r13, %r12
movl 0x40(%r13), %ebp
xorpd %xmm0, %xmm0
testl %ebp, %ebp
jle 0xa5916
xorl %r13d, %r13d
movq 0x18(%rsp), %r11
movq 0x20(%rsp), %rdi
movsd %xmm0, 0x50(%rsp)
movq 0x48(%rsp), %rsi
movq 0xa38(%rsi), %rax
movslq 0x3c(%r12), %r10
subq $0x8, %rsp
movq %r12, %rdx
movl %r15d, %ecx
movl %r13d, %r8d
movl %r14d, %r9d
leaq 0x8c8(%rsp), %rbx
pushq %rbx
pushq (%rax,%r10,8)
pushq %r11
callq 0xa67cd
addq $0x20, %rsp
testl %eax, %eax
jne 0xa5d3c
incl %ebp
imull %r13d, %ebp
leal 0x1(%r13), %r14d
imull %r14d, %r13d
shrl %r13d
subl %r13d, %ebp
movq 0x80(%r12), %rax
movsd (%rax,%r15,8), %xmm0
mulsd 0x4ce28(%rip), %xmm0    # 0xf2680
callq 0x8670
movsd %xmm0, 0x30(%rsp)
movsd 0x8c0(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r15, %rbx
movslq %ebp, %r15
movq 0x38(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
callq 0x8670
movsd 0x78a58(%rip), %xmm1    # 0x11e2e8
divsd 0x30(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
mulsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm0, %xmm1
movq 0x40(%rsp), %rax
movsd %xmm1, (%rax,%r15,8)
movq 0x1110(%rsp), %r15
testq %r15, %r15
je 0xa58e7
movapd %xmm1, %xmm0
movsd %xmm1, 0x10(%rsp)
callq 0x82c0
movsd 0x10(%rsp), %xmm1
movl 0x44(%r12), %eax
imull %ebx, %eax
addl %ebp, %eax
cltq
movsd %xmm0, (%r15,%rax,8)
movsd 0x50(%rsp), %xmm0
addsd %xmm1, %xmm0
movl 0x40(%r12), %ebp
movl %r14d, %r13d
cmpl %ebp, %r14d
movq 0x18(%rsp), %r11
movq 0x20(%rsp), %rdi
movl 0xc(%rsp), %r14d
movq %rbx, %r15
jl 0xa57e7
jmp 0xa5920
movq 0x18(%rsp), %r11
movq 0x20(%rsp), %rdi
cmpl $0x0, 0x40(%r12)
movq %r12, %r13
jle 0xa5bf2
movl $0x2, %eax
movl $0x0, 0x28(%rsp)
xorl %edx, %edx
movq 0x48(%rsp), %rbx
movq 0x1110(%rsp), %rcx
movl %eax, 0x60(%rsp)
movl %edx, %r12d
leal 0x1(%r12), %edx
movl 0x40(%r13), %r14d
cmpl %r14d, %edx
movl %edx, 0x5c(%rsp)
jge 0xa5bd9
movl 0x28(%rsp), %eax
shrl %eax
negl %eax
movq %rax, 0x80(%rsp)
movl %edx, %eax
imull %r12d, %eax
shrl %eax
movl %eax, 0x64(%rsp)
movl %edx, %esi
movq %r12, 0x78(%rsp)
movl %esi, %ebp
cmpl %esi, %r12d
jbe 0xa59a7
movl %r14d, %edx
imull %ebp, %edx
addl %r12d, %edx
leal 0x1(%rbp), %eax
imull %ebp, %eax
shrl %eax
subl %eax, %edx
jmp 0xa59ba
movl %r12d, %edx
imull %r14d, %edx
movq 0x80(%rsp), %rax
addl %ebp, %eax
addl %eax, %edx
leal 0x1(%rbp), %esi
movq 0x48(%r13), %rax
movslq %edx, %r8
cmpw $0x1, (%rax,%r8,2)
jne 0xa5aec
movq %r8, 0x30(%rsp)
movl %esi, 0x10(%rsp)
movl %edx, 0x2c(%rsp)
movsd %xmm0, 0x50(%rsp)
movq 0xa38(%rbx), %rax
movslq 0x3c(%r13), %r10
subq $0x8, %rsp
movq %r13, %rdx
movq %rdi, %r13
movq %rbx, %rsi
movl %r15d, %ecx
movl %r12d, %r8d
movl 0x14(%rsp), %r9d
movq %rbx, %r12
leaq 0x8c8(%rsp), %rbx
pushq %rbx
pushq (%rax,%r10,8)
pushq %r11
movq %rdx, %rbx
callq 0xa67cd
addq $0x20, %rsp
testl %eax, %eax
jne 0xa5d81
movq 0xa38(%r12), %rax
movslq 0x3c(%rbx), %r10
subq $0x8, %rsp
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %r13
movq %rbx, %rdx
movq %r15, %rbx
movl %r15d, %ecx
movl %ebp, %r8d
movl 0x14(%rsp), %r9d
leaq 0x90(%rsp), %r11
pushq %r11
pushq (%rax,%r10,8)
pushq 0x30(%rsp)
callq 0xa67cd
addq $0x20, %rsp
testl %eax, %eax
jne 0xa5dc6
incl %r14d
movl %r14d, %eax
movq 0x78(%rsp), %r12
imull %r12d, %eax
subl 0x64(%rsp), %eax
imull %ebp, %r14d
movl 0x10(%rsp), %esi
imull %esi, %ebp
shrl %ebp
xorpd %xmm4, %xmm4
cmpltsd 0x8c0(%rsp), %xmm4
subl %ebp, %r14d
xorpd %xmm3, %xmm3
cmpltsd 0x88(%rsp), %xmm3
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
movsd (%rcx,%r8,8), %xmm5
cltq
movq 0x40(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movslq %r14d, %rax
mulsd (%rcx,%rax,8), %xmm0
ucomisd 0x4b774(%rip), %xmm0    # 0xf1258
jb 0xa5b18
sqrtsd %xmm0, %xmm0
jmp 0xa5b5c
xorpd %xmm3, %xmm3
testq %rcx, %rcx
je 0xa5b06
movl 0x44(%r13), %eax
imull %r15d, %eax
addl %edx, %eax
cltq
movsd %xmm3, (%rcx,%rax,8)
movl 0x40(%r13), %r14d
cmpl %r14d, %esi
jl 0xa598b
jmp 0xa5bd9
movapd %xmm3, 0xb0(%rsp)
movapd %xmm4, 0xa0(%rsp)
movapd %xmm5, 0x90(%rsp)
callq 0x82b0
movapd 0x90(%rsp), %xmm5
movapd 0xa0(%rsp), %xmm4
movapd 0xb0(%rsp), %xmm3
movq 0x30(%rsp), %r8
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %r11
movq 0x20(%rsp), %rdi
movq %rbx, %r15
movl 0x2c(%rsp), %edx
movapd %xmm4, %xmm1
andpd %xmm5, %xmm1
movapd 0x4b6b3(%rip), %xmm2    # 0xf1230
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 0x40(%rsp), %rax
movsd %xmm0, (%rax,%r8,8)
addsd %xmm0, %xmm0
movsd 0x50(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movq 0x1110(%rsp), %rcx
testq %rcx, %rcx
movq 0x48(%rsp), %rbx
jne 0xa5af5
jmp 0xa5b06
movl 0x60(%rsp), %eax
addl %eax, 0x28(%rsp)
addl $0x2, %eax
movl 0x5c(%rsp), %edx
cmpl 0x40(%r13), %edx
jl 0xa594b
callq 0x82c0
movq 0x1108(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
cmpq 0x68(%rsp), %r15
movq 0x70(%rsp), %r12
movl 0xc(%rsp), %r14d
jne 0xa5785
movq 0x38(%rsp), %rdi
callq 0x8410
movq 0x40(%rsp), %rdi
callq 0x8410
xorl %eax, %eax
jmp 0xa5d2a
leal (,%r15,8), %ecx
leaq 0x4b3bd(%rip), %rsi     # 0xf1004
leaq 0x7af7d(%rip), %rdx     # 0x120bcb
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x192, %r13            # imm = 0x192
leaq 0x4b3c6(%rip), %rsi     # 0xf1034
leaq 0x7af64(%rip), %rdx     # 0x120bd9
movq %r13, %rdi
movl $0x983, %ecx            # imm = 0x983
jmp 0xa5cc4
leal (,%r15,8), %ecx
leaq 0x4b376(%rip), %rsi     # 0xf1004
leaq 0x8c3e5(%rip), %rdx     # 0x13207a
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x192, %r13            # imm = 0x192
leaq 0x4b37f(%rip), %rsi     # 0xf1034
leaq 0x7af1d(%rip), %rdx     # 0x120bd9
movq %r13, %rdi
movl $0x985, %ecx            # imm = 0x985
movq %r14, %r8
jmp 0xa5d1e
leaq 0x7af1b(%rip), %rsi     # 0x120beb
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
leaq 0x4b89c(%rip), %rsi     # 0xf1585
leaq 0x8c0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30c2c
addq $0x192, %r13            # imm = 0x192
leaq 0x4b328(%rip), %rsi     # 0xf1034
leaq 0x7aec6(%rip), %rdx     # 0x120bd9
movq %r13, %rdi
movl $0x98e, %ecx            # imm = 0x98E
movq %r15, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
addq $0x10c8, %rsp           # imm = 0x10C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x192, %r12            # imm = 0x192
leaq 0x4b6a6(%rip), %rsi     # 0xf13f0
leaq 0x7af41(%rip), %rdx     # 0x120c92
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x4b2c7(%rip), %rsi     # 0xf1034
leaq 0x7ae65(%rip), %rdx     # 0x120bd9
movq %r12, %rdi
movl $0x9b8, %ecx            # imm = 0x9B8
jmp 0xa5cc4
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b661(%rip), %rsi     # 0xf13f0
leaq 0x7aefc(%rip), %rdx     # 0x120c92
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x4b282(%rip), %rsi     # 0xf1034
leaq 0x7ae20(%rip), %rdx     # 0x120bd9
movq %rbx, %rdi
movl $0x9d9, %ecx            # imm = 0x9D9
jmp 0xa5cc4
addq $0x192, %r13            # imm = 0x192
leaq 0x4b61c(%rip), %rsi     # 0xf13f0
leaq 0x7af34(%rip), %rdx     # 0x120d0f
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x4b23d(%rip), %rsi     # 0xf1034
leaq 0x7addb(%rip), %rdx     # 0x120bd9
movq %r13, %rdi
movl $0x9e5, %ecx            # imm = 0x9E5
jmp 0xa5cc4
addq $0x32a, %r12            # imm = 0x32A
leaq 0x4b5d7(%rip), %rsi     # 0xf13f0
leaq 0x7ae11(%rip), %rdx     # 0x120c31
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0x192, %r13            # imm = 0x192
leaq 0x4b1f1(%rip), %rsi     # 0xf1034
leaq 0x7ad8f(%rip), %rdx     # 0x120bd9
movq %r13, %rdi
movl $0x998, %ecx            # imm = 0x998
jmp 0xa5cc4