// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../source/background.c
// Function: background_ncdm_momenta
int background_ncdm_momenta(
                            /* Only calculate for non-NULL pointers: */
                            double * qvec,
                            double * wvec,
                            int qsize,
                            double M,
                            double factor,
                            double z,
                            double * n,
                            double * rho, // density
                            double * p,   // pressure
                            double * drho_dM,  // d rho / d M used in next function
                            double * pseudo_p  // pseudo-p used in ncdm fluid approx
                            ) {

  int index_q;
  double epsilon;
  double q2;
  double factor2;
  /** Summary: */

  /** - rescale normalization at given redshift */
  factor2 = factor*pow(1+z,4);

  /** - initialize quantities */
  if (n!=NULL) *n = 0.;
  if (rho!=NULL) *rho = 0.;
  if (p!=NULL) *p = 0.;
  if (drho_dM!=NULL) *drho_dM = 0.;
  if (pseudo_p!=NULL) *pseudo_p = 0.;

  /** - loop over momenta */
  for (index_q=0; index_q<qsize; index_q++) {

    /* squared momentum */
    q2 = qvec[index_q]*qvec[index_q];

    /* energy */
    epsilon = sqrt(q2+M*M/(1.+z)/(1.+z));

    /* integrand of the various quantities */
    if (n!=NULL) *n += q2*wvec[index_q];
    if (rho!=NULL) *rho += q2*epsilon*wvec[index_q];
    if (p!=NULL) *p += q2*q2/3./epsilon*wvec[index_q];
    if (drho_dM!=NULL) *drho_dM += q2*M/(1.+z)/(1.+z)/epsilon*wvec[index_q];
    if (pseudo_p!=NULL) *pseudo_p += pow(q2/epsilon,3)/3.0*wvec[index_q];
  }

  /** - adjust normalization */

  if (n!=NULL) *n *= factor2/(1.+z);
  if (rho!=NULL) *rho *= factor2;
  if (p!=NULL) *p *= factor2;
  if (drho_dM!=NULL) *drho_dM *= factor2;
  if (pseudo_p!=NULL) *pseudo_p *=factor2;

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %r15
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, 0x30(%rsp)
addsd 0x90d2a(%rip), %xmm2    # 0xf1260
movsd 0x93eea(%rip), %xmm1    # 0xf4428
movsd %xmm2, (%rsp)
movapd %xmm2, %xmm0
callq 0x8620
testq %r15, %r15
je 0x60558
movq $0x0, (%r15)
testq %r14, %r14
je 0x60564
movq $0x0, (%r14)
movq 0x70(%rsp), %rcx
testq %rbx, %rbx
je 0x60575
movq $0x0, (%rbx)
movq 0x78(%rsp), %rax
testq %rcx, %rcx
je 0x60586
movq $0x0, (%rcx)
movsd %xmm0, 0x18(%rsp)
testq %rax, %rax
je 0x60598
movq $0x0, (%rax)
testl %ebp, %ebp
jle 0x606d7
movsd 0x8(%rsp), %xmm1
mulsd %xmm1, %xmm1
movsd (%rsp), %xmm0
divsd %xmm0, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movl %ebp, %ebp
xorl %r13d, %r13d
movq 0x30(%rsp), %rdx
movsd (%rdx,%r13,8), %xmm3
mulsd %xmm3, %xmm3
movsd 0x28(%rsp), %xmm0
addsd %xmm3, %xmm0
ucomisd 0x90c75(%rip), %xmm0    # 0xf1258
jb 0x605eb
sqrtsd %xmm0, %xmm0
jmp 0x60606
movsd %xmm3, 0x20(%rsp)
callq 0x82b0
movsd 0x20(%rsp), %xmm3
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
testq %r15, %r15
je 0x6061f
movsd (%r12,%r13,8), %xmm1
mulsd %xmm3, %xmm1
addsd (%r15), %xmm1
movsd %xmm1, (%r15)
testq %r14, %r14
je 0x6063c
movapd %xmm3, %xmm1
mulsd %xmm0, %xmm1
mulsd (%r12,%r13,8), %xmm1
addsd (%r14), %xmm1
movsd %xmm1, (%r14)
testq %rbx, %rbx
je 0x60663
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
divsd 0x9202f(%rip), %xmm1    # 0xf2680
divsd %xmm0, %xmm1
mulsd (%r12,%r13,8), %xmm1
addsd (%rbx), %xmm1
movsd %xmm1, (%rbx)
testq %rcx, %rcx
je 0x60691
movapd %xmm3, %xmm1
mulsd 0x8(%rsp), %xmm1
movsd (%rsp), %xmm2
divsd %xmm2, %xmm1
divsd %xmm2, %xmm1
divsd %xmm0, %xmm1
mulsd (%r12,%r13,8), %xmm1
addsd (%rcx), %xmm1
movsd %xmm1, (%rcx)
testq %rax, %rax
je 0x606cb
divsd %xmm0, %xmm3
movapd %xmm3, %xmm0
movsd 0x91fda(%rip), %xmm1    # 0xf2680
callq 0x8620
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
divsd 0x91fc3(%rip), %xmm0    # 0xf2680
mulsd (%r12,%r13,8), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
incq %r13
cmpq %r13, %rbp
jne 0x605c2
movsd 0x18(%rsp), %xmm1
mulsd 0x10(%rsp), %xmm1
testq %r15, %r15
je 0x606fb
movapd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd (%r15), %xmm0
movsd %xmm0, (%r15)
testq %r14, %r14
je 0x6070e
movsd (%r14), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r14)
testq %rbx, %rbx
je 0x6071f
movsd (%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rbx)
testq %rcx, %rcx
je 0x60730
movsd (%rcx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rcx)
testq %rax, %rax
je 0x6073d
mulsd (%rax), %xmm1
movsd %xmm1, (%rax)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq