// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../source/background.c
// Function: background_ncdm_M_from_Omega
int background_ncdm_M_from_Omega(
                                 struct precision *ppr,
                                 struct background *pba,
                                 int n_ncdm
                                 ) {
  double rho0,rho,n,M,deltaM,drhodM;
  int iter,maxiter=50;

  rho0 = pba->H0*pba->H0*pba->Omega0_ncdm[n_ncdm]; /*Remember that rho is defined such that H^2=sum(rho_i) */
  M = 0.0;

  background_ncdm_momenta(pba->q_ncdm_bg[n_ncdm],
                          pba->w_ncdm_bg[n_ncdm],
                          pba->q_size_ncdm_bg[n_ncdm],
                          M,
                          pba->factor_ncdm[n_ncdm],
                          0.,
                          &n,
                          &rho,
                          NULL,
                          NULL,
                          NULL);

  /* Is the value of Omega less than a massless species?*/
  class_test(rho0<rho,pba->error_message,
             "The value of Omega for the %dth species, %g, is less than for a massless species! It should be atleast %g. Check your input.",
             n_ncdm,pba->Omega0_ncdm[n_ncdm],pba->Omega0_ncdm[n_ncdm]*rho/rho0);

  /* In the strict NR limit we have rho = n*(M) today, giving a zeroth order guess: */
  M = rho0/n; /* This is our guess for M. */
  for (iter=1; iter<=maxiter; iter++) {

    /* Newton iteration. First get relevant quantities at M: */
    background_ncdm_momenta(pba->q_ncdm_bg[n_ncdm],
                            pba->w_ncdm_bg[n_ncdm],
                            pba->q_size_ncdm_bg[n_ncdm],
                            M,
                            pba->factor_ncdm[n_ncdm],
                            0.,
                            NULL,
                            &rho,
                            NULL,
                            &drhodM,
                            NULL);

    deltaM = (rho0-rho)/drhodM; /* By definition of the derivative */
    if ((M+deltaM)<0.0) deltaM = -M/2.0; /* Avoid overshooting to negative M value. */
    M += deltaM; /* Update value of M.. */
    if (fabs(deltaM/M)<ppr->tol_M_ncdm) {
      /* Accuracy reached.. */
      pba->M_ncdm[n_ncdm] = M;
      break;
    }
  }
  class_test(iter>=maxiter,pba->error_message,
             "Newton iteration could not converge on a mass for some reason.");
  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1068, %rsp           # imm = 0x1068
movq %rdi, 0x40(%rsp)
movsd (%rsi), %xmm0
mulsd %xmm0, %xmm0
movq 0x280(%rsi), %rax
movslq %edx, %r14
mulsd (%rax,%r14,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x500(%rsi), %rax
movslq (%rax,%r14,4), %r12
movq 0x510(%rsi), %rax
movsd (%rax,%r14,8), %xmm2
testq %r12, %r12
movq %rsi, 0x8(%rsp)
jle 0x660fc
movq 0x4d8(%rsi), %rax
movq (%rax,%r14,8), %r15
movq 0x4e0(%rsi), %rax
movq (%rax,%r14,8), %rbx
xorpd %xmm3, %xmm3
xorl %r13d, %r13d
xorpd %xmm4, %xmm4
movsd %xmm2, 0x10(%rsp)
movsd (%r15,%r13,8), %xmm1
mulsd %xmm1, %xmm1
ucomisd %xmm4, %xmm1
jb 0x660ad
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0x660d8
movapd %xmm1, %xmm0
movapd %xmm3, 0x30(%rsp)
movapd %xmm1, 0x20(%rsp)
callq 0x82b0
movapd 0x20(%rsp), %xmm1
xorpd %xmm4, %xmm4
movapd 0x30(%rsp), %xmm3
movsd 0x10(%rsp), %xmm2
mulsd %xmm1, %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movsd (%rbx,%r13,8), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm0, %xmm1
addpd %xmm1, %xmm3
incq %r13
cmpq %r13, %r12
jne 0x66094
jmp 0x66100
xorpd %xmm3, %xmm3
movapd %xmm2, %xmm1
mulsd %xmm3, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x66193
movq 0x8(%rsp), %rbx
movq 0x280(%rbx), %rax
movapd %xmm0, %xmm2
movsd (%rax,%r14,8), %xmm0
mulsd %xmm0, %xmm1
divsd %xmm2, %xmm1
leaq 0xa8be6(%rip), %rsi     # 0x10ed1f
leaq 0x860(%rsp), %r15
movq %r15, %rdi
movl %r14d, %edx
movb $0x2, %al
callq 0x30c2c
leaq 0x8af2d(%rip), %rsi     # 0xf1082
leaq 0xa8c40(%rip), %rdx     # 0x10ed9c
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0xd1c, %rbx            # imm = 0xD1C
leaq 0x8aeb8(%rip), %rsi     # 0xf1034
leaq 0xa8c22(%rip), %rdx     # 0x10eda5
movq %rbx, %rdi
movl $0x80a, %ecx            # imm = 0x80A
movq %r14, %r8
jmp 0x66375
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
mulsd %xmm3, %xmm2
movapd %xmm0, %xmm4
divsd %xmm2, %xmm4
movl $0x1, %ebp
xorpd %xmm5, %xmm5
movq 0x8(%rsp), %rbx
movq 0x500(%rbx), %rax
movslq (%rax,%r14,4), %r12
movq 0x510(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
movapd %xmm0, 0x50(%rsp)
testq %r12, %r12
jle 0x66284
movq 0x4d8(%rbx), %rax
movq 0x4e0(%rbx), %rcx
movq (%rax,%r14,8), %r13
movq (%rcx,%r14,8), %r15
movapd %xmm4, %xmm3
mulsd %xmm4, %xmm3
xorpd %xmm2, %xmm2
xorl %ebx, %ebx
movsd %xmm4, 0x10(%rsp)
movsd %xmm3, 0x48(%rsp)
movsd (%r13,%rbx,8), %xmm6
mulsd %xmm6, %xmm6
movapd %xmm3, %xmm0
addsd %xmm6, %xmm0
ucomisd %xmm5, %xmm0
jb 0x66227
sqrtsd %xmm0, %xmm0
jmp 0x66254
movapd %xmm2, 0x30(%rsp)
movapd %xmm6, 0x20(%rsp)
callq 0x82b0
movapd 0x20(%rsp), %xmm6
movsd 0x48(%rsp), %xmm3
movapd 0x30(%rsp), %xmm2
xorpd %xmm5, %xmm5
movsd 0x10(%rsp), %xmm4
movapd %xmm4, %xmm1
mulsd %xmm6, %xmm1
mulsd %xmm0, %xmm6
divsd %xmm0, %xmm1
unpcklpd %xmm1, %xmm6            # xmm6 = xmm6[0],xmm1[0]
movsd (%r15,%rbx,8), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm6, %xmm0
addpd %xmm0, %xmm2
incq %rbx
cmpq %rbx, %r12
jne 0x66208
jmp 0x66288
xorpd %xmm2, %xmm2
movapd 0x50(%rsp), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm2, %xmm1
movsd 0x18(%rsp), %xmm0
subsd %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
divsd %xmm1, %xmm0
movapd %xmm4, %xmm1
addsd %xmm0, %xmm1
movapd %xmm4, %xmm2
mulsd 0x8e1ac(%rip), %xmm2    # 0xf4468
cmpltsd %xmm5, %xmm1
movapd %xmm1, %xmm3
andnpd %xmm0, %xmm3
andpd %xmm2, %xmm1
orpd %xmm3, %xmm1
addsd %xmm1, %xmm4
divsd %xmm4, %xmm1
andpd 0x8af5f(%rip), %xmm1    # 0xf1240
movq 0x40(%rsp), %rax
movsd 0x28(%rax), %xmm0
ucomisd %xmm1, %xmm0
ja 0x66303
incl %ebp
cmpl $0x33, %ebp
movq 0x8(%rsp), %rbx
jne 0x661b1
jmp 0x6631c
movq 0x8(%rsp), %rbx
movq 0x270(%rbx), %rax
movsd %xmm4, (%rax,%r14,8)
xorl %eax, %eax
cmpl $0x31, %ebp
jbe 0x66381
leaq 0xa8a9f(%rip), %rsi     # 0x10edc2
leaq 0x860(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
leaq 0x8ad46(%rip), %rsi     # 0xf1082
leaq 0xa8abe(%rip), %rdx     # 0x10ee01
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0xd1c, %rbx            # imm = 0xD1C
leaq 0x8acd1(%rip), %rsi     # 0xf1034
leaq 0xa8a3b(%rip), %rdx     # 0x10eda5
movq %rbx, %rdi
movl $0x827, %ecx            # imm = 0x827
movq %r15, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
addq $0x1068, %rsp           # imm = 0x1068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq