// File: /workspace/github_c_makefile_star2_O1/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 0xd987f
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 0x53daa(%rip), %xmm0    # 0x12d338
movapd %xmm0, 0x50(%rsp)
addsd 0x17cc4(%rip), %xmm6    # 0xf1260
movapd %xmm0, %xmm1
divsd %xmm6, %xmm1
movsd 0x53dd4(%rip), %xmm0    # 0x12d380
divsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rsp)
movsd 0x18(%r12), %xmm1
addsd 0x53dc0(%rip), %xmm1    # 0x12d388
movsd %xmm1, 0x10(%rsp)
movsd 0x190aa(%rip), %xmm1    # 0xf2680
callq 0x8620
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x72de7(%rip)    # 0x14c3d0
movsd 0x17c6f(%rip), %xmm0    # 0xf1260
subsd 0x90(%r12), %xmm0
mulsd 0x10(%r12), %xmm0
addsd 0x53d86(%rip), %xmm0    # 0x12d390
movsd %xmm0, 0x10(%rsp)
movsd 0x90(%rsp), %xmm0
movsd 0x1905f(%rip), %xmm1    # 0xf2680
callq 0x8620
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x72da4(%rip)    # 0x14c3d8
movsd 0x50(%r12), %xmm0
addsd 0x37045(%rip), %xmm0    # 0x110688
movsd %xmm0, 0x72d95(%rip)    # 0x14c3e0
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 0xd8f27
movaps 0x20(%rsp), %xmm0
callq 0xd6f51
movaps %xmm0, 0x90(%rsp)
movq (%r13), %rax
movapd 0x50(%rsp), %xmm0
ucomisd 0x840(%rax), %xmm0
movsd 0x17b97(%rip), %xmm0    # 0xf1260
ja 0xd976c
movsd (%rax), %xmm0
movq 0x8(%r13), %rdi
movq 0x48(%rbx), %rcx
movsd 0x1810d(%rip), %xmm1    # 0xf17f0
movl $0x109, %esi            # imm = 0x109
movapd 0x50(%rsp), %xmm2
movq %r14, %rdx
callq 0xd727d
xorl %r15d, %r15d
leaq 0x72cd0(%rip), %rbp     # 0x14c3d0
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 0x180c5(%rip), %xmm1    # 0xf17f0
movl $0x109, %esi            # imm = 0x109
movapd 0x50(%rsp), %xmm2
movq %r14, %rdx
callq 0xd727d
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 0xd9700
addsd 0x17af4(%rip), %xmm0    # 0xf1260
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 0xd6f4c
movsd %xmm0, 0xa8(%rsp)
movsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0xd6f4c
movsd %xmm0, 0xb0(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0xd6f4c
movaps %xmm0, 0x40(%rsp)
movsd 0x18(%rsp), %xmm0
mulsd 0x38(%rsp), %xmm0
callq 0xd6f51
movsd %xmm0, 0x18(%rsp)
xorpd %xmm0, %xmm0
movapd 0x80(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0xd981d
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0xd982f
movapd %xmm1, %xmm0
callq 0x82b0
movapd 0x80(%rsp), %xmm1
movsd %xmm0, 0x78(%rsp)
movsd 0x53b13(%rip), %xmm0    # 0x12d350
divsd %xmm1, %xmm0
callq 0x8670
cmpl $0x1, (%r14)
jne 0xd9888
movups 0x53e36(%rip), %xmm0    # 0x12d689
leaq 0x110(%rsp), %rsi
movups %xmm0, 0x19(%rsi)
movaps 0x53e1a(%rip), %xmm0    # 0x12d680
movaps %xmm0, 0x10(%rsi)
movapd 0x53dfe(%rip), %xmm0    # 0x12d670
movapd %xmm0, (%rsi)
movq 0x48(%rbx), %rdi
callq 0x8660
xorpd %xmm0, %xmm0
jmp 0xd9a70
movsd 0x53aa0(%rip), %xmm1    # 0x12d330
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 0x53a46(%rip), %xmm1    # 0x12d320
mulsd 0x80(%rsp), %xmm1
movsd 0x78(%rsp), %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm2, %xmm0
movapd 0x90(%rsp), %xmm7
mulsd 0x53a26(%rip), %xmm7    # 0x12d328
movsd 0xd0(%rsp), %xmm5
mulsd %xmm5, %xmm7
movsd 0xc8(%rsp), %xmm6
divsd %xmm6, %xmm7
movsd 0xb8(%rsp), %xmm1
movsd 0x17933(%rip), %xmm2    # 0xf1260
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 0x18d1d(%rip), %xmm1    # 0xf2680
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 0x1783e(%rip), %xmm4    # 0xf1260
movapd %xmm4, %xmm1
subsd %xmm7, %xmm1
mulsd %xmm2, %xmm0
subsd %xmm2, %xmm4
mulsd 0x1c0ee(%rip), %xmm4    # 0xf5b28
mulsd 0x1ab2e(%rip), %xmm1    # 0xf4570
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