// File: /workspace/github_c_makefile_star2_O2/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 $0x1048, %rsp           # imm = 0x1048
movq %rsi, %rbx
movq %rdi, %r15
movsd (%rsi), %xmm0
mulsd %xmm0, %xmm0
movq 0x280(%rsi), %rax
movslq %edx, %r14
mulsd (%rax,%r14,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x4d8(%rsi), %rax
movq (%rax,%r14,8), %rdi
movq 0x4e0(%rsi), %rax
movq (%rax,%r14,8), %rsi
movq 0x500(%rbx), %rax
movl (%rax,%r14,4), %edx
movq 0x510(%rbx), %rax
movsd (%rax,%r14,8), %xmm1
xorpd %xmm0, %xmm0
movupd %xmm0, (%rsp)
leaq 0x38(%rsp), %rcx
leaq 0x20(%rsp), %r12
xorpd %xmm0, %xmm0
xorpd %xmm2, %xmm2
movq %r12, %r8
xorl %r9d, %r9d
callq 0x59e8b
movsd 0x18(%rsp), %xmm3
movsd (%r12), %xmm1
ucomisd %xmm3, %xmm1
jbe 0x5f989
movq 0x280(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
mulsd %xmm0, %xmm1
divsd %xmm3, %xmm1
leaq 0xa32d0(%rip), %rsi     # 0x102bff
leaq 0x840(%rsp), %r15
movq %r15, %rdi
movl %r14d, %edx
movb $0x2, %al
callq 0x2e014
leaq 0x85737(%rip), %rsi     # 0xe5082
leaq 0xa332a(%rip), %rdx     # 0x102c7c
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2e014
addq $0xd1c, %rbx            # imm = 0xD1C
leaq 0x856c2(%rip), %rsi     # 0xe5034
leaq 0xa330c(%rip), %rdx     # 0x102c85
movq %rbx, %rdi
movl $0x80a, %ecx            # imm = 0x80A
movq %r14, %r8
jmp 0x5faca
movapd %xmm3, %xmm0
divsd 0x38(%rsp), %xmm0
pushq $0x32
popq %rbp
leaq 0x20(%rsp), %r12
movl %ebp, %r13d
subl $0x1, %ebp
jb 0x5fa71
movq 0x4d8(%rbx), %rax
movq 0x4e0(%rbx), %rcx
movq (%rax,%r14,8), %rdi
movq (%rcx,%r14,8), %rsi
movq 0x500(%rbx), %rax
movl (%rax,%r14,4), %edx
movq 0x510(%rbx), %rax
movsd (%rax,%r14,8), %xmm1
leaq 0x30(%rsp), %rax
movq %rax, (%rsp)
andq $0x0, 0x8(%rsp)
xorpd %xmm2, %xmm2
xorl %ecx, %ecx
movq %r12, %r8
xorl %r9d, %r9d
movsd %xmm0, 0x28(%rsp)
callq 0x59e8b
movsd 0x28(%rsp), %xmm0
movsd 0x18(%rsp), %xmm4
subsd 0x20(%rsp), %xmm4
divsd 0x30(%rsp), %xmm4
movapd %xmm0, %xmm1
addsd %xmm4, %xmm1
movapd %xmm0, %xmm2
mulsd 0x88a11(%rip), %xmm2    # 0xe8438
cmpltsd 0x85828(%rip), %xmm1    # 0xe5258
andpd %xmm1, %xmm2
andnpd %xmm4, %xmm1
orpd %xmm2, %xmm1
addsd %xmm1, %xmm0
divsd %xmm0, %xmm1
andpd 0x857f4(%rip), %xmm1    # 0xe5240
movsd 0x28(%r15), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x5f99b
movq 0x270(%rbx), %rax
movsd %xmm0, (%rax,%r14,8)
xorl %eax, %eax
cmpl $0x1, %r13d
jne 0x5fad4
leaq 0xa322a(%rip), %rsi     # 0x102ca2
leaq 0x840(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0x855f1(%rip), %rsi     # 0xe5082
leaq 0xa3249(%rip), %rdx     # 0x102ce1
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
addq $0xd1c, %rbx            # imm = 0xD1C
leaq 0x8557c(%rip), %rsi     # 0xe5034
leaq 0xa31c6(%rip), %rdx     # 0x102c85
movq %rbx, %rdi
movl $0x827, %ecx            # imm = 0x827
movq %r15, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
addq $0x1048, %rsp           # imm = 0x1048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq