// File: /workspace/github_c_makefile_star2_O3/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 0x903e3(%rip), %xmm2    # 0xee260
movsd 0x935b3(%rip), %xmm1    # 0xf1438
movsd %xmm2, (%rsp)
movapd %xmm2, %xmm0
callq 0x8620
testq %r15, %r15
je 0x5de9f
movq $0x0, (%r15)
testq %r14, %r14
je 0x5deab
movq $0x0, (%r14)
movq 0x70(%rsp), %rcx
testq %rbx, %rbx
je 0x5debc
movq $0x0, (%rbx)
movq 0x78(%rsp), %rax
testq %rcx, %rcx
je 0x5decd
movq $0x0, (%rcx)
movsd %xmm0, 0x18(%rsp)
testq %rax, %rax
je 0x5dedf
movq $0x0, (%rax)
testl %ebp, %ebp
jle 0x5e01e
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 0x9032e(%rip), %xmm0    # 0xee258
jb 0x5df32
sqrtsd %xmm0, %xmm0
jmp 0x5df4d
movsd %xmm3, 0x20(%rsp)
callq 0x82b0
movsd 0x20(%rsp), %xmm3
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
testq %r15, %r15
je 0x5df66
movsd (%r12,%r13,8), %xmm1
mulsd %xmm3, %xmm1
addsd (%r15), %xmm1
movsd %xmm1, (%r15)
testq %r14, %r14
je 0x5df83
movapd %xmm3, %xmm1
mulsd %xmm0, %xmm1
mulsd (%r12,%r13,8), %xmm1
addsd (%r14), %xmm1
movsd %xmm1, (%r14)
testq %rbx, %rbx
je 0x5dfaa
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
divsd 0x916e8(%rip), %xmm1    # 0xef680
divsd %xmm0, %xmm1
mulsd (%r12,%r13,8), %xmm1
addsd (%rbx), %xmm1
movsd %xmm1, (%rbx)
testq %rcx, %rcx
je 0x5dfd8
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 0x5e012
divsd %xmm0, %xmm3
movapd %xmm3, %xmm0
movsd 0x91693(%rip), %xmm1    # 0xef680
callq 0x8620
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
divsd 0x9167c(%rip), %xmm0    # 0xef680
mulsd (%r12,%r13,8), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
incq %r13
cmpq %r13, %rbp
jne 0x5df09
movsd 0x18(%rsp), %xmm1
mulsd 0x10(%rsp), %xmm1
testq %r15, %r15
je 0x5e042
movapd %xmm1, %xmm0
divsd (%rsp), %xmm0
mulsd (%r15), %xmm0
movsd %xmm0, (%r15)
testq %r14, %r14
je 0x5e055
movsd (%r14), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r14)
testq %rbx, %rbx
je 0x5e066
movsd (%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rbx)
testq %rcx, %rcx
je 0x5e077
movsd (%rcx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rcx)
testq %rax, %rax
je 0x5e084
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