// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../external/HyRec2020/helium.c
// Function: rec_saha_xH1s
double rec_saha_xH1s(REC_COSMOPARAMS *cosmo, double z, double xHeII) {

  double s, Tr, nH, ainv;
  double nH0 = cosmo->nH0, T0 = cosmo->T0;
  double fsR = cosmo->fsR, meR = cosmo->meR;

  Tr = T0 * (ainv=1.+z) /fsR/fsR/meR; /* current (rescaled) radiation temperature */
  nH = nH0*ainv*ainv*ainv;

  /* Obtain Saha ratio, xe xHII/xH1s, with xe = xHII + xHeII and xHII = 1-xH1s
   * Constants:
   * reduced mass Rydberg = 157801.37882 Kelvin (no relativistic corrections)
   * prefactor = (2*pi*m*k/h^2)^1.5  */

  s = fsR*fsR*fsR*meR*meR*meR *2.4127161187130e15*Tr*sqrt(Tr)*exp(-157801.37882/Tr)/nH;
  if      (s == 0.) return 1.;
  else if (s > 1e5) return (1.+xHeII)/s - (xHeII*xHeII + 3.*xHeII + 2.)/s/s;  /* Second-order value for xHII ~ 1 */
  else              return 1.-2./(1.+ xHeII/s + sqrt((1.+ xHeII/s)*(1.+ xHeII/s) +4./s));

}

// Assembly:
subq $0x68, %rsp
movsd 0x88(%rdi), %xmm2
movaps %xmm2, 0x40(%rsp)
movsd 0x98(%rdi), %xmm3
movsd 0xa0(%rdi), %xmm2
addsd 0x19707(%rip), %xmm0    # 0xf1260
movsd 0x8(%rdi), %xmm4
movapd %xmm0, 0x50(%rsp)
mulsd %xmm0, %xmm4
divsd %xmm3, %xmm4
divsd %xmm3, %xmm4
movapd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
mulsd 0x55608(%rip), %xmm0    # 0x12d198
movapd %xmm0, 0x30(%rsp)
divsd %xmm2, %xmm4
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm4
movaps %xmm1, (%rsp)
movapd %xmm4, 0x20(%rsp)
jb 0xd7bb7
xorps %xmm0, %xmm0
sqrtsd %xmm4, %xmm0
jmp 0xd7bc6
movapd %xmm4, %xmm0
callq 0x82b0
movapd 0x20(%rsp), %xmm4
movapd %xmm0, 0x10(%rsp)
movsd 0x555cc(%rip), %xmm0    # 0x12d1a0
divsd %xmm4, %xmm0
callq 0x8670
movapd 0x50(%rsp), %xmm1
movapd 0x30(%rsp), %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
movapd 0x20(%rsp), %xmm3
unpcklpd 0x40(%rsp), %xmm3       # xmm3 = xmm3[0],mem[0]
mulpd %xmm2, %xmm3
movapd 0x10(%rsp), %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
mulpd %xmm3, %xmm2
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
mulpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
divsd %xmm1, %xmm0
ucomisd 0x19631(%rip), %xmm0    # 0xf1258
jne 0xd7c38
jp 0xd7c38
movsd 0x1962d(%rip), %xmm0    # 0xf1260
jmp 0xd7ced
ucomisd 0x1df78(%rip), %xmm0    # 0xf5bb8
jbe 0xd7c8d
movsd 0x1aa36(%rip), %xmm1    # 0xf2680
movapd (%rsp), %xmm3
mulsd %xmm3, %xmm1
movapd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
addpd 0x55615(%rip), %xmm3    # 0x12d280
movapd %xmm0, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
divpd %xmm1, %xmm3
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
divsd %xmm0, %xmm1
subsd %xmm1, %xmm3
movapd %xmm3, %xmm0
jmp 0xd7ced
movapd (%rsp), %xmm2
divsd %xmm0, %xmm2
addsd 0x195c2(%rip), %xmm2    # 0xf1260
movsd 0x1c782(%rip), %xmm1    # 0xf4428
divsd %xmm0, %xmm1
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xd7cc6
sqrtsd %xmm0, %xmm0
jmp 0xd7cd5
movapd %xmm2, (%rsp)
callq 0x82b0
movapd (%rsp), %xmm2
addsd %xmm0, %xmm2
movsd 0x1aa77(%rip), %xmm0    # 0xf2758
divsd %xmm2, %xmm0
addsd 0x19573(%rip), %xmm0    # 0xf1260
addq $0x68, %rsp
retq