// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
movsd %xmm0, 0x20(%rsp)
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, 0x30(%rsp)
addsd 0x8b39f(%rip), %xmm2    # 0xe5260
movsd 0x8e52f(%rip), %xmm1    # 0xe83f8
movsd %xmm2, 0x10(%rsp)
movapd %xmm2, %xmm0
callq 0x8650
movsd %xmm0, 0x8(%rsp)
testq %r15, %r15
je 0x59ee7
andq $0x0, (%r15)
testq %r14, %r14
je 0x59ef0
andq $0x0, (%r14)
movq 0x70(%rsp), %rcx
testq %rbx, %rbx
je 0x59efe
andq $0x0, (%rbx)
movq 0x78(%rsp), %rax
testq %rcx, %rcx
je 0x59f0c
andq $0x0, (%rcx)
testq %rax, %rax
je 0x59f15
andq $0x0, (%rax)
movsd 0x8(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x20(%rsp), %xmm1
mulsd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm0, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
xorl %ebp, %ebp
testl %r12d, %r12d
cmovlel %ebp, %r12d
cmpq %rbp, %r12
je 0x5a06d
movq 0x30(%rsp), %rdx
movsd (%rdx,%rbp,8), %xmm3
mulsd %xmm3, %xmm3
movsd 0x18(%rsp), %xmm0
addsd %xmm3, %xmm0
ucomisd 0x8b2e1(%rip), %xmm0    # 0xe5258
jb 0x59f7f
sqrtsd %xmm0, %xmm0
jmp 0x59f9a
movsd %xmm3, 0x28(%rsp)
callq 0x82d0
movsd 0x28(%rsp), %xmm3
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
testq %r15, %r15
je 0x59fb4
movsd (%r13,%rbp,8), %xmm1
mulsd %xmm3, %xmm1
addsd (%r15), %xmm1
movsd %xmm1, (%r15)
testq %r14, %r14
je 0x59fd2
movapd %xmm3, %xmm1
mulsd %xmm0, %xmm1
mulsd (%r13,%rbp,8), %xmm1
addsd (%r14), %xmm1
movsd %xmm1, (%r14)
testq %rbx, %rbx
je 0x59ffa
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
divsd 0x8c761(%rip), %xmm1    # 0xe6748
divsd %xmm0, %xmm1
mulsd (%r13,%rbp,8), %xmm1
addsd (%rbx), %xmm1
movsd %xmm1, (%rbx)
testq %rcx, %rcx
je 0x5a02a
movapd %xmm3, %xmm1
mulsd 0x20(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
divsd %xmm2, %xmm1
divsd %xmm2, %xmm1
divsd %xmm0, %xmm1
mulsd (%r13,%rbp,8), %xmm1
addsd (%rcx), %xmm1
movsd %xmm1, (%rcx)
testq %rax, %rax
je 0x5a065
divsd %xmm0, %xmm3
movapd %xmm3, %xmm0
movsd 0x8c709(%rip), %xmm1    # 0xe6748
callq 0x8650
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
divsd 0x8c6f2(%rip), %xmm0    # 0xe6748
mulsd (%r13,%rbp,8), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
incq %rbp
jmp 0x59f4e
testq %r15, %r15
je 0x5a088
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
mulsd (%r15), %xmm0
movsd %xmm0, (%r15)
testq %r14, %r14
je 0x5a09d
movsd (%r14), %xmm0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, (%r14)
testq %rbx, %rbx
je 0x5a0b0
movsd (%rbx), %xmm0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rbx)
testq %rcx, %rcx
je 0x5a0c3
movsd (%rcx), %xmm0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rcx)
testq %rax, %rax
je 0x5a0d6
movsd 0x8(%rsp), %xmm0
mulsd (%rax), %xmm0
movsd %xmm0, (%rax)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq