// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../external/HyRec2020/hydrogen.c
// Function: rec_swift_hyrec_dxHIIdlna
double rec_swift_hyrec_dxHIIdlna(HYREC_DATA *data, double xe, double xHII, double nH, double H, double TM, double TR, double z){

  REC_COSMOPARAMS *cosmo = data-> cosmo;
  HYREC_ATOMIC *atomic = data->atomic;
  FIT_FUNC *fit = data->fit;
  int *error = &data->error;
  double fsR = cosmo->fsR, meR = cosmo->meR;
  double Alpha[2], DAlpha[2], Beta[2], R2p2s, RLya;
  double DK_K_fid=0., DK_K, fitted_RLya;
  double C_2s, C_2p, gamma_2s, gamma_2p, s, Dxe2;
  static double diff[3];
  unsigned i;
  double ratio;
  char sub_message[128];
  double T0fid_T0;
  if (*error == 1) return 0.;

  ratio = TM/TR;
  rescale_T(&TR, fsR, meR);
  TM = ratio * TR;   // This way ensure that TM<=TR is preserved
  T0fid_T0 = 2.7255 / (TR/kBoltz/(1.+z));

  /* The numbers in the following lines are fiducial parameters for correction function (Do not change) */
  diff[0] = (cosmo->ocbh2 - 0.14175)*pow(T0fid_T0,3);
  diff[1] = (cosmo->obh2*(1-cosmo->YHe) - 0.02242*(1-0.246738546372))*pow(T0fid_T0,3);
  diff[2] = cosmo->Neff-3.046;

  interpolate_rates(Alpha, DAlpha, Beta, &R2p2s, TR, TM/TR, atomic, fsR, meR, error, data->error_message);

  RLya = LYA_FACT(fsR, meR) *H/nH/(1.-xHII);   // 8 PI H/(3 nH x1s lambda_Lya^3)
  
  if (TR/kBoltz > fit->swift_func[0][DKK_SIZE-1]) DK_K = 0.;
  else {
    DK_K_fid = rec_interp1d(fit->swift_func[0][0], 10., fit->swift_func[1], DKK_SIZE, TR/kBoltz, error, data->error_message);

    for (i = 0; i < 3; i++) {
      DK_K_fid = DK_K_fid + diff[i]*rec_interp1d(fit->swift_func[0][0], 10., fit->swift_func[i+2],
                                                   DKK_SIZE, TR/kBoltz, error, data->error_message);
    }
  }

  DK_K = DK_K_fid;
  fitted_RLya = RLya / (1.+DK_K);
  gamma_2s = Beta[0] + 3.*R2p2s + L2s_rescaled(fsR, meR);
  gamma_2p = Beta[1] + R2p2s + fitted_RLya;
  C_2s = (L2s_rescaled(fsR, meR)+3.*R2p2s*fitted_RLya/gamma_2p)/(gamma_2s-3.*R2p2s*R2p2s/gamma_2p);
  C_2p = (fitted_RLya+R2p2s*L2s_rescaled(fsR, meR)/gamma_2s)/(gamma_2p-R2p2s*3.*R2p2s/gamma_2s);

  s    = SAHA_FACT(fsR, meR) *TR*sqrt(TR) *exp(-EI/TR)/nH;
  Dxe2 = xe*xHII - s*(1.-xHII); // xe^2 - xe^2[Saha eq with 1s] -- gives more compact expressions

  if (*error == 1) {
    sprintf(sub_message, "  called from rec_swift_hyrec_dxHIIdlna\n");
    strcat(data->error_message, sub_message);
    return 0.;
  }

  return -nH/H *( (s*(1.-xHII)*DAlpha[0] + Alpha[0]*Dxe2)*C_2s + (s*(1.-xHII)*DAlpha[1] + Alpha[1]*Dxe2)*C_2p)
          + (cosmo->inj_params->ion + (0.25*(1.-C_2s) + 0.75*(1.-C_2p))*cosmo->inj_params->exclya)/H ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
cmpl $0x1, 0x38(%rdi)
je 0xd60e7
movq %rdi, %rbx
movsd %xmm1, 0xb8(%rsp)
movsd %xmm0, 0xc0(%rsp)
movsd %xmm2, 0xc8(%rsp)
movsd %xmm3, 0xd0(%rsp)
movq (%rdi), %r15
movq 0x8(%rdi), %r12
movq 0x60(%rdi), %r13
leaq 0x38(%rdi), %r14
movsd 0x98(%r12), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0xa0(%r12), %xmm1
movsd %xmm1, 0x38(%rsp)
mulsd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
mulsd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
unpcklpd %xmm5, %xmm4            # xmm4 = xmm4[0],xmm5[0]
unpcklpd %xmm0, %xmm5            # xmm5 = xmm5[0],xmm0[0]
divpd %xmm5, %xmm4
movapd %xmm4, %xmm0
unpckhpd %xmm4, %xmm0            # xmm0 = xmm0[1],xmm4[1]
movapd %xmm0, 0x80(%rsp)
mulsd %xmm0, %xmm4
movapd %xmm4, 0x60(%rsp)
divsd 0x54572(%rip), %xmm0    # 0x12a368
movapd %xmm0, 0x50(%rsp)
addsd 0x1845c(%rip), %xmm6    # 0xee260
movapd %xmm0, %xmm1
divsd %xmm6, %xmm1
movsd 0x5459c(%rip), %xmm0    # 0x12a3b0
divsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rsp)
movsd 0x18(%r12), %xmm1
addsd 0x54588(%rip), %xmm1    # 0x12a3b8
movsd %xmm1, 0x10(%rsp)
movsd 0x19842(%rip), %xmm1    # 0xef680
callq 0x8620
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x7357f(%rip)    # 0x1493d0
movsd 0x18407(%rip), %xmm0    # 0xee260
subsd 0x90(%r12), %xmm0
mulsd 0x10(%r12), %xmm0
addsd 0x5454e(%rip), %xmm0    # 0x12a3c0
movsd %xmm0, 0x10(%rsp)
movsd 0x90(%rsp), %xmm0
movsd 0x197f7(%rip), %xmm1    # 0xef680
callq 0x8620
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x7353c(%rip)    # 0x1493d8
movsd 0x50(%r12), %xmm0
addsd 0x377fd(%rip), %xmm0    # 0x10d6a8
movsd %xmm0, 0x7352d(%rip)    # 0x1493e0
movapd 0x80(%rsp), %xmm0
movapd 0x60(%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0x48(%rbx), %rax
movq %rax, (%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
leaq 0xd8(%rsp), %rcx
movq %r15, %r8
movsd 0x18(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
movq %r14, %r9
callq 0xd572b
movaps 0x20(%rsp), %xmm0
callq 0xd3759
movaps %xmm0, 0x90(%rsp)
movq (%r13), %rax
movapd 0x50(%rsp), %xmm0
ucomisd 0x840(%rax), %xmm0
movsd 0x1832f(%rip), %xmm0    # 0xee260
ja 0xd5fd4
movsd (%rax), %xmm0
movq 0x8(%r13), %rdi
movq 0x48(%rbx), %rcx
movsd 0x188a5(%rip), %xmm1    # 0xee7f0
movl $0x109, %esi            # imm = 0x109
movapd 0x50(%rsp), %xmm2
movq %r14, %rdx
callq 0xd3a85
xorl %r15d, %r15d
leaq 0x73468(%rip), %rbp     # 0x1493d0
movapd %xmm0, 0x20(%rsp)
movsd (%r15,%rbp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq (%r13), %rax
movsd (%rax), %xmm0
movq 0x10(%r13,%r15), %rdi
movq 0x48(%rbx), %rcx
movsd 0x1885d(%rip), %xmm1    # 0xee7f0
movl $0x109, %esi            # imm = 0x109
movapd 0x50(%rsp), %xmm2
movq %r14, %rdx
callq 0xd3a85
mulsd 0x60(%rsp), %xmm0
movapd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movapd 0x20(%rsp), %xmm0
addq $0x8, %r15
cmpq $0x18, %r15
jne 0xd5f68
addsd 0x1828c(%rip), %xmm0    # 0xee260
movapd %xmm0, 0x20(%rsp)
movsd 0xe0(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x18(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
callq 0xd3754
movsd %xmm0, 0xa8(%rsp)
movsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0xd3754
movsd %xmm0, 0xb0(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0xd3754
movaps %xmm0, 0x40(%rsp)
movsd 0x18(%rsp), %xmm0
mulsd 0x38(%rsp), %xmm0
callq 0xd3759
movsd %xmm0, 0x18(%rsp)
xorpd %xmm0, %xmm0
movapd 0x80(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0xd6085
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0xd6097
movapd %xmm1, %xmm0
callq 0x82b0
movapd 0x80(%rsp), %xmm1
movsd %xmm0, 0x78(%rsp)
movsd 0x542db(%rip), %xmm0    # 0x12a380
divsd %xmm1, %xmm0
callq 0x8670
cmpl $0x1, (%r14)
jne 0xd60f0
movups 0x545fe(%rip), %xmm0    # 0x12a6b9
leaq 0x110(%rsp), %rsi
movups %xmm0, 0x19(%rsi)
movaps 0x545e2(%rip), %xmm0    # 0x12a6b0
movaps %xmm0, 0x10(%rsi)
movapd 0x545c6(%rip), %xmm0    # 0x12a6a0
movapd %xmm0, (%rsi)
movq 0x48(%rbx), %rdi
callq 0x8660
xorpd %xmm0, %xmm0
jmp 0xd62d8
movsd 0x54268(%rip), %xmm1    # 0x12a360
movapd 0x40(%rsp), %xmm8
mulsd %xmm1, %xmm8
movsd 0xb0(%rsp), %xmm11
mulsd %xmm1, %xmm11
movsd 0xa8(%rsp), %xmm3
mulsd %xmm1, %xmm3
movsd 0x38(%rsp), %xmm1
mulsd %xmm1, %xmm8
mulsd %xmm1, %xmm11
mulsd %xmm1, %xmm3
movsd 0x18(%rsp), %xmm1
mulsd 0x5420e(%rip), %xmm1    # 0x12a350
mulsd 0x80(%rsp), %xmm1
movsd 0x78(%rsp), %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm2, %xmm0
movapd 0x90(%rsp), %xmm7
mulsd 0x541ee(%rip), %xmm7    # 0x12a358
movsd 0xd0(%rsp), %xmm5
mulsd %xmm5, %xmm7
movsd 0xc8(%rsp), %xmm6
divsd %xmm6, %xmm7
movsd 0xb8(%rsp), %xmm1
movsd 0x180cb(%rip), %xmm2    # 0xee260
subsd %xmm1, %xmm2
divsd %xmm2, %xmm7
divsd %xmm6, %xmm0
mulsd %xmm2, %xmm0
movsd 0xc0(%rsp), %xmm4
mulsd %xmm1, %xmm4
movsd 0x50(%rsp), %xmm9
mulsd %xmm9, %xmm8
unpcklpd %xmm8, %xmm7            # xmm7 = xmm7[0],xmm8[0]
movsd 0x194b5(%rip), %xmm1    # 0xef680
mulsd %xmm9, %xmm1
movapd 0x60(%rsp), %xmm8
addsd %xmm1, %xmm8
addsd %xmm3, %xmm8
movapd 0x20(%rsp), %xmm2
unpcklpd %xmm8, %xmm2            # xmm2 = xmm2[0],xmm8[0]
divpd %xmm2, %xmm7
movsd 0x10(%rsp), %xmm10
addsd %xmm9, %xmm10
addsd %xmm7, %xmm10
mulsd %xmm1, %xmm9
movapd %xmm9, %xmm2
divsd %xmm8, %xmm2
movapd %xmm10, %xmm3
subsd %xmm2, %xmm3
movapd %xmm7, %xmm2
unpckhpd %xmm7, %xmm2            # xmm2 = xmm2[1],xmm7[1]
addsd %xmm7, %xmm2
divsd %xmm3, %xmm2
mulsd %xmm1, %xmm7
divsd %xmm10, %xmm7
addsd %xmm11, %xmm7
divsd %xmm10, %xmm9
subsd %xmm0, %xmm4
subsd %xmm9, %xmm8
divsd %xmm8, %xmm7
movsd 0x100(%rsp), %xmm1
mulsd %xmm4, %xmm1
movsd 0xf0(%rsp), %xmm3
mulsd %xmm0, %xmm3
mulsd 0x108(%rsp), %xmm4
mulsd 0xf8(%rsp), %xmm0
addsd %xmm1, %xmm3
addsd %xmm4, %xmm0
mulsd %xmm7, %xmm3
movsd 0x17fd6(%rip), %xmm4    # 0xee260
movapd %xmm4, %xmm1
subsd %xmm7, %xmm1
mulsd %xmm2, %xmm0
subsd %xmm2, %xmm4
mulsd 0x1c8b6(%rip), %xmm4    # 0xf2b58
mulsd 0x1b2d6(%rip), %xmm1    # 0xf1580
addsd %xmm0, %xmm3
addsd %xmm4, %xmm1
divsd %xmm5, %xmm6
movq 0xb8(%r12), %rax
mulsd 0x68(%rax), %xmm1
addsd 0x60(%rax), %xmm1
mulsd %xmm6, %xmm3
divsd %xmm5, %xmm1
subsd %xmm3, %xmm1
movapd %xmm1, %xmm0
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq