// File: /workspace/github_c_makefile_star2_O2/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 $0x178, %rsp            # imm = 0x178
cmpl $0x1, 0x38(%rdi)
je 0xce4fb
movq %rdi, %rbx
movsd %xmm1, 0x78(%rsp)
movsd %xmm0, 0x80(%rsp)
movsd %xmm2, 0x88(%rsp)
movsd %xmm3, 0x90(%rsp)
movq (%rdi), %r15
movq 0x8(%rdi), %r12
movq 0x60(%rdi), %r13
leaq 0x38(%rdi), %r14
movsd 0x98(%r12), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0xa0(%r12), %xmm1
movsd %xmm1, 0x10(%rsp)
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm0
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, 0x40(%rsp)
mulsd %xmm0, %xmm4
movapd %xmm4, 0x20(%rsp)
divsd 0x52fea(%rip), %xmm0    # 0x121208
movapd %xmm0, 0x50(%rsp)
addsd 0x17034(%rip), %xmm6    # 0xe5260
movapd %xmm0, %xmm1
divsd %xmm6, %xmm1
movsd 0x53014(%rip), %xmm0    # 0x121250
divsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%r12), %xmm1
addsd 0x53003(%rip), %xmm1    # 0x121258
movsd %xmm1, 0x30(%rsp)
movsd 0x184e5(%rip), %xmm1    # 0xe6748
callq 0x8650
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x7517a(%rip)    # 0x1433f0
movsd 0x16fe2(%rip), %xmm0    # 0xe5260
subsd 0x90(%r12), %xmm0
mulsd 0x10(%r12), %xmm0
addsd 0x52fc9(%rip), %xmm0    # 0x121260
movsd %xmm0, 0x30(%rsp)
movsd 0x18(%rsp), %xmm0
movsd 0x1849d(%rip), %xmm1    # 0xe6748
callq 0x8650
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x7513a(%rip)    # 0x1433f8
movsd 0x50(%r12), %xmm0
addsd 0x3629b(%rip), %xmm0    # 0x104568
movsd %xmm0, 0x7512b(%rip)    # 0x143400
movapd 0x40(%rsp), %xmm0
movapd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0x48(%rbx), %rax
movq %rax, (%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
leaq 0x98(%rsp), %rcx
movq %r15, %r8
movsd 0x8(%rsp), %xmm2
movsd 0x10(%rsp), %xmm3
movq %r14, %r9
callq 0xcdbf0
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0xcd110
movapd 0x50(%rsp), %xmm2
movaps %xmm0, 0x30(%rsp)
movq (%r13), %rax
ucomisd 0x840(%rax), %xmm2
movsd 0x16f0c(%rip), %xmm0    # 0xe5260
ja 0xce3f3
movsd (%rax), %xmm0
movq 0x8(%r13), %rdi
movq 0x48(%rbx), %rcx
movsd 0x17482(%rip), %xmm1    # 0xe57f0
movl $0x109, %esi            # imm = 0x109
movq %r14, %rdx
callq 0xcc0a7
xorl %r15d, %r15d
leaq 0x7506b(%rip), %rbp     # 0x1433f0
cmpq $0x18, %r15
je 0xce3eb
movsd (%r15,%rbp), %xmm1
movsd %xmm1, 0x18(%rsp)
movq (%r13), %rax
movapd %xmm0, 0x20(%rsp)
movsd (%rax), %xmm0
movq 0x10(%r13,%r15), %rdi
movq 0x48(%rbx), %rcx
movsd 0x1743a(%rip), %xmm1    # 0xe57f0
movl $0x109, %esi            # imm = 0x109
movapd 0x50(%rsp), %xmm2
movq %r14, %rdx
callq 0xcc0a7
mulsd 0x18(%rsp), %xmm0
movapd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movapd 0x20(%rsp), %xmm0
addq $0x8, %r15
jmp 0xce385
addsd 0x16e6d(%rip), %xmm0    # 0xe5260
movapd %xmm0, 0x20(%rsp)
movsd 0xa0(%rsp), %xmm0
movaps %xmm0, 0xe0(%rsp)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0xcd128
movsd %xmm0, 0x60(%rsp)
movsd 0xa8(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0xcd128
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0xcd128
movaps %xmm0, 0xd0(%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0xcd0fc
movsd %xmm0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movapd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0xce49c
sqrtsd %xmm1, %xmm0
jmp 0xce4ab
movapd %xmm1, %xmm0
callq 0x82d0
movapd 0x40(%rsp), %xmm1
movsd %xmm0, 0x8(%rsp)
movsd 0x52d67(%rip), %xmm0    # 0x121220
divsd %xmm1, %xmm0
callq 0x86a0
cmpl $0x1, (%r14)
jne 0xce504
movups 0x5305a(%rip), %xmm0    # 0x121529
leaq 0xf0(%rsp), %rsi
movups %xmm0, 0x19(%rsi)
movaps 0x5303e(%rip), %xmm0    # 0x121520
movaps %xmm0, 0x10(%rsi)
movapd 0x53022(%rip), %xmm0    # 0x121510
movapd %xmm0, (%rsi)
movq 0x48(%rbx), %rdi
callq 0x8690
xorpd %xmm0, %xmm0
jmp 0xce6a5
movsd 0x50(%rsp), %xmm8
mulsd 0x40(%rsp), %xmm8
mulsd 0x8(%rsp), %xmm8
mulsd %xmm0, %xmm8
movsd 0x90(%rsp), %xmm4
movapd 0x30(%rsp), %xmm6
mulsd %xmm4, %xmm6
movsd 0x88(%rsp), %xmm5
divsd %xmm5, %xmm6
movsd 0x78(%rsp), %xmm0
movsd 0x16d14(%rip), %xmm1    # 0xe5260
subsd %xmm0, %xmm1
divsd %xmm1, %xmm6
divsd %xmm5, %xmm8
mulsd %xmm1, %xmm8
movsd 0x80(%rsp), %xmm3
mulsd %xmm0, %xmm3
movsd 0x70(%rsp), %xmm10
movapd 0xd0(%rsp), %xmm0
mulsd %xmm10, %xmm0
unpcklpd %xmm0, %xmm6            # xmm6 = xmm6[0],xmm0[0]
movsd 0x181bc(%rip), %xmm0    # 0xe6748
mulsd %xmm10, %xmm0
movapd 0xe0(%rsp), %xmm9
addsd %xmm0, %xmm9
addsd 0x60(%rsp), %xmm9
movapd 0x20(%rsp), %xmm1
unpcklpd %xmm9, %xmm1            # xmm1 = xmm1[0],xmm9[0]
divpd %xmm1, %xmm6
movsd 0x68(%rsp), %xmm11
addsd %xmm10, %xmm11
addsd %xmm6, %xmm11
mulsd %xmm0, %xmm10
movapd %xmm10, %xmm1
divsd %xmm9, %xmm1
movapd %xmm11, %xmm2
subsd %xmm1, %xmm2
movapd %xmm6, %xmm1
unpckhpd %xmm6, %xmm1            # xmm1 = xmm1[1],xmm6[1]
addsd %xmm6, %xmm1
divsd %xmm2, %xmm1
mulsd %xmm0, %xmm6
divsd %xmm11, %xmm6
movsd 0x18(%rsp), %xmm7
addsd %xmm6, %xmm7
divsd %xmm11, %xmm10
subsd %xmm8, %xmm3
subsd %xmm10, %xmm9
divsd %xmm9, %xmm7
movsd 0xc0(%rsp), %xmm0
mulsd %xmm3, %xmm0
movsd 0xb0(%rsp), %xmm2
mulsd %xmm8, %xmm2
mulsd 0xc8(%rsp), %xmm3
mulsd 0xb8(%rsp), %xmm8
addsd %xmm0, %xmm2
addsd %xmm3, %xmm8
mulsd %xmm7, %xmm2
movsd 0x16c07(%rip), %xmm3    # 0xe5260
movapd %xmm3, %xmm0
subsd %xmm7, %xmm0
mulsd %xmm1, %xmm8
subsd %xmm1, %xmm3
mulsd 0x1b3a6(%rip), %xmm3    # 0xe9a18
mulsd 0x19e86(%rip), %xmm0    # 0xe8500
addsd %xmm8, %xmm2
addsd %xmm3, %xmm0
divsd %xmm4, %xmm5
movq 0xb8(%r12), %rax
mulsd 0x68(%rax), %xmm0
addsd 0x60(%rax), %xmm0
mulsd %xmm5, %xmm2
divsd %xmm4, %xmm0
subsd %xmm2, %xmm0
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq