// File: /workspace/github_c_makefile_star2_O3/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, 0x78(%rsp)
movl %r8d, %ebp
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, 0x28(%rsp)
movslq 0x44(%rcx), %r15
movq %r15, %r14
shlq $0x3, %r14
movq %r14, %rdi
callq 0x8460
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0xa2d68
movq %r14, %rdi
callq 0x8460
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0xa2db2
cmpw $0x1, 0x50(%rbx)
jne 0xa28a7
movl $0x8d8, %eax            # imm = 0x8D8
cmpl %ebp, 0x54(%rbx)
je 0xa28c0
cmpw $0x1, 0x52(%rbx)
jne 0xa2dfc
movl $0x8dc, %eax            # imm = 0x8DC
cmpl %ebp, 0x58(%rbx)
jne 0xa2dfc
movl 0x1100(%rsp), %ecx
testl %ecx, %ecx
movq 0x28(%rsp), %r15
jle 0xa2d4d
movl (%r13,%rax), %eax
movl %eax, 0x24(%rsp)
movl %ecx, %eax
movq %rax, 0x88(%rsp)
xorl %ecx, %ecx
movq %r12, 0x68(%rsp)
movq %r13, 0x80(%rsp)
movw $0x1, 0xb2c(%r12)
movl 0x3c(%rbx), %esi
movq 0x80(%rbx), %rax
movq %rcx, 0x10(%rsp)
movsd (%rax,%rcx,8), %xmm0
movq %r12, %rdi
movl $0x1, %edx
movq 0x38(%rsp), %rcx
callq 0x943b4
cmpl $0x1, %eax
je 0xa2f27
movw $0x0, 0xb2c(%r12)
movl 0x40(%rbx), %r14d
xorpd %xmm3, %xmm3
testl %r14d, %r14d
jle 0xa2d21
xorl %r13d, %r13d
movq 0x78(%rsp), %r12
movsd %xmm3, 0x40(%rsp)
movq 0x80(%rsp), %rsi
movq 0xa38(%rsi), %rax
movslq 0x3c(%rbx), %r10
subq $0x8, %rsp
movq %r15, %rdi
movq %rbx, %rdx
movq 0x18(%rsp), %r15
movl %r15d, %ecx
movl %r13d, %r8d
movl 0x2c(%rsp), %r9d
leaq 0x8c8(%rsp), %r11
pushq %r11
pushq (%rax,%r10,8)
pushq %r12
callq 0xa3930
addq $0x20, %rsp
testl %eax, %eax
jne 0xa2e56
incl %r14d
imull %r13d, %r14d
leal 0x1(%r13), %ebp
imull %ebp, %r13d
shrl %r13d
subl %r13d, %r14d
movq 0x80(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
mulsd 0x4ccae(%rip), %xmm0    # 0xef680
callq 0x8670
movsd %xmm0, 0x50(%rsp)
movsd 0x8c0(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r15, %r13
movslq %r14d, %r15
movq 0x38(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
callq 0x8670
movsd 0x7891e(%rip), %xmm1    # 0x11b328
divsd 0x50(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm0, %xmm1
movq 0x30(%rsp), %rax
movsd %xmm1, (%rax,%r15,8)
movq 0x1110(%rsp), %r15
testq %r15, %r15
je 0xa2a61
movapd %xmm1, %xmm0
movsd %xmm1, 0x8(%rsp)
callq 0x82c0
movsd 0x8(%rsp), %xmm1
movl 0x44(%rbx), %eax
imull %r13d, %eax
addl %r14d, %eax
cltq
movsd %xmm0, (%r15,%rax,8)
movsd 0x40(%rsp), %xmm3
addsd %xmm1, %xmm3
movl 0x40(%rbx), %r14d
movl %ebp, %r13d
cmpl %r14d, %ebp
movq 0x28(%rsp), %r15
jl 0xa2954
testl %r14d, %r14d
jle 0xa2d1c
xorl %eax, %eax
movq %rbx, 0x70(%rsp)
movl %eax, %r13d
leal 0x1(%r13), %eax
cmpl %r14d, %eax
movl %eax, 0x48(%rsp)
jge 0xa2d08
movl %eax, %ebp
imull %r13d, %ebp
shrl %ebp
movl %eax, %edx
movq 0x1110(%rsp), %rcx
movq %r13, 0x90(%rsp)
movl %ebp, 0x4c(%rsp)
movl %edx, %r8d
cmpl %edx, %r13d
jbe 0xa2ae7
movl %r14d, %esi
imull %r8d, %esi
addl %r13d, %esi
leal 0x1(%r8), %edx
movl %edx, %r12d
imull %r8d, %r12d
shrl %r12d
subl %r12d, %esi
jmp 0xa2b03
movl %r14d, %eax
imull %r13d, %eax
movl %r8d, %esi
subl %ebp, %esi
addl %eax, %esi
leal 0x1(%r8), %edx
movl %edx, %r12d
imull %r8d, %r12d
shrl %r12d
movq 0x48(%rbx), %rax
movslq %esi, %rdi
cmpw $0x1, (%rax,%rdi,2)
jne 0xa2c41
movq %r8, 0x50(%rsp)
movq %rdi, 0x8(%rsp)
movl %esi, 0x1c(%rsp)
movl %edx, 0x20(%rsp)
movsd %xmm3, 0x40(%rsp)
movq %rbx, %rdx
movq 0x80(%rsp), %rbx
movq 0xa38(%rbx), %rax
movslq 0x3c(%rdx), %r10
subq $0x8, %rsp
movq %r15, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rcx
movl %r13d, %r8d
movl 0x2c(%rsp), %ebp
movl %ebp, %r9d
leaq 0x8c8(%rsp), %r11
pushq %r11
pushq (%rax,%r10,8)
movq 0x90(%rsp), %r13
pushq %r13
callq 0xa3930
addq $0x20, %rsp
testl %eax, %eax
jne 0xa2e9b
movq 0xa38(%rbx), %rax
movq 0x70(%rsp), %rdx
movslq 0x3c(%rdx), %r10
subq $0x8, %rsp
movq %r15, %rdi
movq %rbx, %rsi
movq %rdx, %rbx
movq 0x18(%rsp), %rcx
movq 0x58(%rsp), %r15
movl %r15d, %r8d
movl %ebp, %r9d
leaq 0xa0(%rsp), %r11
pushq %r11
pushq (%rax,%r10,8)
pushq %r13
callq 0xa3930
addq $0x20, %rsp
testl %eax, %eax
jne 0xa2ee5
incl %r14d
movl %r14d, %eax
movq 0x90(%rsp), %r13
imull %r13d, %eax
movl 0x4c(%rsp), %ebp
subl %ebp, %eax
imull %r15d, %r14d
xorpd %xmm5, %xmm5
cmpltsd 0x8c0(%rsp), %xmm5
subl %r12d, %r14d
xorpd %xmm4, %xmm4
cmpltsd 0x98(%rsp), %xmm4
movq 0x38(%rsp), %rcx
movq 0x8(%rsp), %rdi
movsd (%rcx,%rdi,8), %xmm6
cltq
movq 0x30(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movslq %r14d, %rax
mulsd (%rcx,%rax,8), %xmm0
ucomisd 0x4b61f(%rip), %xmm0    # 0xee258
jb 0xa2c4a
sqrtsd %xmm0, %xmm0
jmp 0xa2c84
xorpd %xmm4, %xmm4
jmp 0xa2ce5
movapd %xmm4, 0x50(%rsp)
movapd %xmm5, 0xb0(%rsp)
movapd %xmm6, 0xa0(%rsp)
callq 0x82b0
movapd 0xa0(%rsp), %xmm6
movapd 0xb0(%rsp), %xmm5
movapd 0x50(%rsp), %xmm4
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %r15
movq 0x1110(%rsp), %rcx
movsd 0x40(%rsp), %xmm3
movl 0x20(%rsp), %edx
movl 0x1c(%rsp), %esi
movapd %xmm5, %xmm1
andpd %xmm6, %xmm1
movapd 0x4b581(%rip), %xmm2    # 0xee230
xorpd %xmm2, %xmm6
andnpd %xmm6, %xmm5
orpd %xmm1, %xmm5
movapd %xmm4, %xmm1
andpd %xmm5, %xmm1
xorpd %xmm2, %xmm5
andnpd %xmm5, %xmm4
orpd %xmm1, %xmm4
mulsd %xmm4, %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax,%rdi,8)
addsd %xmm0, %xmm0
addsd %xmm0, %xmm3
testq %rcx, %rcx
je 0xa2cfb
movl 0x44(%rbx), %eax
imull 0x10(%rsp), %eax
addl %esi, %eax
cltq
movsd %xmm4, (%rcx,%rax,8)
movl 0x40(%rbx), %r14d
cmpl %r14d, %edx
jl 0xa2ac2
movl 0x48(%rsp), %eax
cmpl %r14d, %eax
movq 0x68(%rsp), %r12
jl 0xa2a90
jmp 0xa2d21
movq 0x68(%rsp), %r12
movapd %xmm3, %xmm0
callq 0x82c0
movq 0x1108(%rsp), %rax
movq 0x10(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq 0x88(%rsp), %rcx
jne 0xa28f6
movq 0x38(%rsp), %rdi
callq 0x8410
movq 0x30(%rsp), %rdi
callq 0x8410
xorl %eax, %eax
jmp 0xa2f7d
leal (,%r15,8), %ecx
leaq 0x4b28d(%rip), %rsi     # 0xee004
leaq 0x7ae8d(%rip), %rdx     # 0x11dc0b
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b296(%rip), %rsi     # 0xee034
leaq 0x7ae74(%rip), %rdx     # 0x11dc19
movq %rbx, %rdi
movl $0x983, %ecx            # imm = 0x983
jmp 0xa2f6e
leal (,%r15,8), %ecx
leaq 0x4b243(%rip), %rsi     # 0xee004
leaq 0x8c2e2(%rip), %rdx     # 0x12f0aa
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b24c(%rip), %rsi     # 0xee034
leaq 0x7ae2a(%rip), %rdx     # 0x11dc19
movq %rbx, %rdi
movl $0x985, %ecx            # imm = 0x985
jmp 0xa2f6e
leaq 0x7ae28(%rip), %rsi     # 0x11dc2b
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x4b769(%rip), %rsi     # 0xee585
leaq 0x8c0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30af0
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b1f5(%rip), %rsi     # 0xee034
leaq 0x7add3(%rip), %rdx     # 0x11dc19
movq %rbx, %rdi
movl $0x98e, %ecx            # imm = 0x98E
movq %r15, %r8
jmp 0xa2f71
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b58c(%rip), %rsi     # 0xee3f0
leaq 0x7ae67(%rip), %rdx     # 0x11dcd2
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x4b1ad(%rip), %rsi     # 0xee034
leaq 0x7ad8b(%rip), %rdx     # 0x11dc19
movq %rbx, %rdi
movl $0x9b8, %ecx            # imm = 0x9B8
jmp 0xa2f6e
movq 0x70(%rsp), %rbx
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b542(%rip), %rsi     # 0xee3f0
leaq 0x7ae1d(%rip), %rdx     # 0x11dcd2
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x4b163(%rip), %rsi     # 0xee034
leaq 0x7ad41(%rip), %rdx     # 0x11dc19
movq %rbx, %rdi
movl $0x9d9, %ecx            # imm = 0x9D9
jmp 0xa2f6e
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b4fd(%rip), %rsi     # 0xee3f0
leaq 0x7ae55(%rip), %rdx     # 0x11dd4f
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x4b11e(%rip), %rsi     # 0xee034
leaq 0x7acfc(%rip), %rdx     # 0x11dc19
movq %rbx, %rdi
movl $0x9e5, %ecx            # imm = 0x9E5
jmp 0xa2f6e
addq $0x32a, %r12            # imm = 0x32A
leaq 0x4b4bb(%rip), %rsi     # 0xee3f0
leaq 0x7ad35(%rip), %rdx     # 0x11dc71
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b0d5(%rip), %rsi     # 0xee034
leaq 0x7acb3(%rip), %rdx     # 0x11dc19
movq %rbx, %rdi
movl $0x998, %ecx            # imm = 0x998
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
addq $0x10c8, %rsp           # imm = 0x10C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq