// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %rbx
subq $0x1000, %rsp           # imm = 0x1000
movq %rsi, %rbx
movsd (%rsi), %xmm2
mulsd %xmm2, %xmm2
movq 0x280(%rsi), %rcx
movslq %edx, %rax
movsd (%rcx,%rax,8), %xmm0
mulsd %xmm0, %xmm2
movq 0x4d8(%rsi), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x4e0(%rsi), %rsi
movq (%rsi,%rax,8), %rsi
movq 0x500(%rbx), %r8
movl (%r8,%rax,4), %r8d
movq 0x510(%rbx), %r9
movsd (%r9,%rax,8), %xmm3
xorpd %xmm4, %xmm4
testl %r8d, %r8d
jle 0x6392a
xorl %r9d, %r9d
movsd (%rcx,%r9,8), %xmm1
mulsd %xmm1, %xmm1
xorps %xmm5, %xmm5
sqrtsd %xmm1, %xmm5
mulsd %xmm1, %xmm5
unpcklpd %xmm1, %xmm5            # xmm5 = xmm5[0],xmm1[0]
movsd (%rsi,%r9,8), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm5, %xmm1
addpd %xmm1, %xmm4
incq %r9
cmpq %r9, %r8
jne 0x638f7
movapd %xmm3, %xmm1
mulsd %xmm4, %xmm1
ucomisd %xmm2, %xmm1
jbe 0x63999
mulsd %xmm0, %xmm1
divsd %xmm2, %xmm1
leaq 0xa83f8(%rip), %rsi     # 0x10bd3f
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movb $0x2, %al
callq 0x30af0
leaq 0x8a722(%rip), %rsi     # 0xee082
leaq 0xa8455(%rip), %rdx     # 0x10bdbc
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0xd1c, %rbx            # imm = 0xD1C
leaq 0x8a6af(%rip), %rsi     # 0xee034
leaq 0xa8439(%rip), %rdx     # 0x10bdc5
movq %rbx, %rdi
movl $0x80a, %ecx            # imm = 0x80A
jmp 0x63aff
unpckhpd %xmm4, %xmm4            # xmm4 = xmm4[1,1]
mulsd %xmm3, %xmm4
movapd %xmm2, %xmm0
divsd %xmm4, %xmm0
movsd 0x28(%rdi), %xmm1
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
movl $0x1, %edx
movsd 0x8dab9(%rip), %xmm4    # 0xf1478
xorpd %xmm5, %xmm5
movapd 0x8a875(%rip), %xmm6    # 0xee240
testl %r8d, %r8d
jle 0x63a32
movapd %xmm0, %xmm8
mulsd %xmm0, %xmm8
xorpd %xmm7, %xmm7
xorl %edi, %edi
movsd (%rcx,%rdi,8), %xmm9
mulsd %xmm9, %xmm9
movapd %xmm8, %xmm10
addsd %xmm9, %xmm10
sqrtsd %xmm10, %xmm10
movapd %xmm0, %xmm11
mulsd %xmm9, %xmm11
mulsd %xmm10, %xmm9
divsd %xmm10, %xmm11
movsd (%rsi,%rdi,8), %xmm10
unpcklpd %xmm10, %xmm10          # xmm10 = xmm10[0,0]
unpcklpd %xmm11, %xmm9           # xmm9 = xmm9[0],xmm11[0]
mulpd %xmm9, %xmm10
addpd %xmm10, %xmm7
incq %rdi
cmpq %rdi, %r8
jne 0x639e0
jmp 0x63a36
xorpd %xmm7, %xmm7
mulpd %xmm3, %xmm7
movapd %xmm2, %xmm8
subsd %xmm7, %xmm8
unpckhpd %xmm7, %xmm7            # xmm7 = xmm7[1,1]
divsd %xmm7, %xmm8
movapd %xmm0, %xmm7
addsd %xmm8, %xmm7
movapd %xmm0, %xmm9
mulsd %xmm4, %xmm9
cmpltsd %xmm5, %xmm7
movapd %xmm7, %xmm10
andnpd %xmm8, %xmm10
andpd %xmm9, %xmm7
orpd %xmm10, %xmm7
addsd %xmm7, %xmm0
divsd %xmm0, %xmm7
andpd %xmm6, %xmm7
ucomisd %xmm7, %xmm1
ja 0x63a98
incl %edx
cmpl $0x33, %edx
jne 0x639cb
jmp 0x63aab
movq 0x270(%rbx), %rcx
movsd %xmm0, (%rcx,%rax,8)
xorl %eax, %eax
cmpl $0x32, %edx
jne 0x63b0e
leaq 0xa8330(%rip), %rsi     # 0x10bde2
leaq 0x800(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x8a5b7(%rip), %rsi     # 0xee082
leaq 0xa834f(%rip), %rdx     # 0x10be21
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0xd1c, %rbx            # imm = 0xD1C
leaq 0x8a544(%rip), %rsi     # 0xee034
leaq 0xa82ce(%rip), %rdx     # 0x10bdc5
movq %rbx, %rdi
movl $0x827, %ecx            # imm = 0x827
movq %r15, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r14
popq %r15
retq