// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../external/HyRec2020/history.c
// Function: rec_xH1_stiff
void rec_xH1_stiff(HYREC_DATA *data, int model, double z, double xHeII, double *xH1, unsigned iz_rad, double H){

  REC_COSMOPARAMS *cosmo = data->cosmo;
  int *error = &data->error;

  double ainv, xH1sSaha, xHIISaha, dxH1sSaha_dlna, dxH1sdlna_Saha, DdxH1sdlna_DxH1s, T, nH, Dxe;
  int model_stiff;	// To use EMLA2p2s model for PostSaha in FULL and SWIFT mode
  char sub_message[SIZE_ErrorM];

  // Set model for rec_xH1_stiff. FULL mode uses EMLA2s2p for stiff.
  // SWIFT mode uses EMLA2s2p for stiff when z is not in the range of redshifts for SWIFT fitting function.

  T = kBoltz*cosmo->T0 * (ainv=1.+z);

  if (model == FULL) {
    model_stiff = EMLA2s2p;
  }
  else{
    model_stiff = model;
    if (model == SWIFT){
      if (T/kBoltz/cosmo->fsR/cosmo->fsR/cosmo->meR > data->fit->swift_func[0][DKK_SIZE-1] ) model_stiff = EMLA2s2p;
    }
  }

  nH = cosmo->nH0 *cube(1.+z);
  xH1sSaha = rec_saha_xH1s(cosmo, z, xHeII);
  xHIISaha = 1.-xH1sSaha;

  dxH1sSaha_dlna = (1.+z)*(rec_saha_xH1s(cosmo, z-0.5, xHeII)
                          -rec_saha_xH1s(cosmo, z+0.5, xHeII));
                  /* (partial xHII)/(partial lna). Use xH1s = 1-xHII for better accuracy. */
  if (xHeII != 0.) {
    dxH1sSaha_dlna = (1.+z)*(rec_saha_xH1s(cosmo, z-0.5, xHeII)
                            -rec_saha_xH1s(cosmo, z+0.5, xHeII));
    Dxe = 0.01*(cosmo->fHe - xHeII);
    dxH1sSaha_dlna += (rec_saha_xH1s(cosmo, z, xHeII+Dxe)
                      -rec_saha_xH1s(cosmo, z, xHeII-Dxe))/2./Dxe
                      *rec_helium_dxHeIIdlna(data, z, xH1sSaha, xHeII, H);
                   /* (partial xHII)/(partial xHeII).dxHeII/dlna */
  }

  dxH1sdlna_Saha = -rec_dxHIIdlna(data, model_stiff, xHIISaha + xHeII, xHIISaha, nH, H, T, T, iz_rad, z);
  Dxe            = 0.01*xH1sSaha;
  DdxH1sdlna_DxH1s = (rec_dxHIIdlna(data, model_stiff, xHIISaha+Dxe + xHeII, xHIISaha+Dxe, nH, H, T, T, iz_rad, z)
                       -rec_dxHIIdlna(data, model_stiff, xHIISaha-Dxe + xHeII, xHIISaha-Dxe, nH, H, T, T, iz_rad, z))/2./Dxe;
  *xH1 = xH1sSaha + (dxH1sSaha_dlna - dxH1sdlna_Saha)/DdxH1sdlna_DxH1s;


  if (fabs(*xH1 - xH1sSaha) > DXHII_MAX)  data->quasi_eq = 0;
  //if (z<1700.) *stiff = 0;   /* Used when calculating the correction function for SWIFT mode. */

  /* Update photon population when MODEL = FULL */
  if (model == FULL) rec_dxHIIdlna(data, model, xHeII + 1.-*xH1, 1.-*xH1, nH, H, T, T, iz_rad, z);

  if (*xH1 < 0. || *xH1 != *xH1) {
    sprintf(sub_message, "xH1 < 0 in rec_xH1_stiff: at z = %f, xH1 = %E\n", z, *xH1);
    strcat(data->error_message, sub_message);
    *error = 1;
  }

  if (*error == 1) {
    sprintf(sub_message, "  called from rec_xH1_stiff at z = %f\n", z);
    strcat(data->error_message, sub_message);
    return;
  }
  return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x868, %rsp            # imm = 0x868
movl %ecx, %ebp
movq %rdx, %r14
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
movl %esi, %r15d
movq %rdi, %rbx
movq 0x8(%rdi), %r13
movsd 0x8(%r13), %xmm1
mulsd 0x4f192(%rip), %xmm1    # 0x121208
movsd 0x131e2(%rip), %xmm3    # 0xe5260
addsd %xmm0, %xmm3
mulsd %xmm3, %xmm1
movsd %xmm1, 0x38(%rsp)
pushq $0x2
popq %rax
cmpl $0x3, %esi
jne 0xd2099
movl %eax, %r12d
jmp 0xd20df
movl %r15d, %r12d
cmpl $0x4, %r15d
jne 0xd20df
movsd 0x38(%rsp), %xmm0
divsd 0x4f158(%rip), %xmm0    # 0x121208
movsd 0x98(%r13), %xmm1
divsd %xmm1, %xmm0
divsd %xmm1, %xmm0
divsd 0xa0(%r13), %xmm0
movq 0x60(%rbx), %rcx
movq (%rcx), %rcx
ucomisd 0x840(%rcx), %xmm0
ja 0xd2094
pushq $0x4
popq %r12
movsd %xmm2, 0x40(%rsp)
movsd 0x88(%r13), %xmm0
movsd %xmm0, 0x30(%rsp)
movapd %xmm3, %xmm0
movsd %xmm3, 0x20(%rsp)
callq 0xcbe4d
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r13, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xcc936
movsd 0x13135(%rip), %xmm1    # 0xe5260
movsd %xmm0, 0x50(%rsp)
subsd %xmm0, %xmm1
movsd %xmm1, 0x58(%rsp)
movsd 0x162f5(%rip), %xmm0    # 0xe8438
addsd 0x10(%rsp), %xmm0
movq %r13, %rdi
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm1
callq 0xcc936
movsd %xmm0, 0x48(%rsp)
movsd 0x13b45(%rip), %xmm0    # 0xe5cb0
addsd 0x10(%rsp), %xmm0
movq %r13, %rdi
movsd %xmm0, 0x28(%rsp)
movsd 0x8(%rsp), %xmm1
callq 0xcc936
xorpd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm3
ucomisd %xmm1, %xmm3
jne 0xd219b
jnp 0xd2290
movq %r13, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xcc936
movsd %xmm0, 0x18(%rsp)
movq %r13, %rdi
movsd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xcc936
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x80(%r13), %xmm1
subsd 0x8(%rsp), %xmm1
mulsd 0x15d86(%rip), %xmm1    # 0xe7f80
movsd %xmm1, 0x28(%rsp)
addsd 0x8(%rsp), %xmm1
movq %r13, %rdi
movsd 0x10(%rsp), %xmm0
callq 0xcc936
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm1
subsd 0x28(%rsp), %xmm1
movq %r13, %rdi
movsd 0x10(%rsp), %xmm0
callq 0xcc936
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x13a6a(%rip), %xmm1    # 0xe5cb0
divsd 0x28(%rsp), %xmm1
movsd %xmm1, 0x18(%rsp)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
callq 0xccaf5
movsd 0x8(%rsp), %xmm3
mulsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, 0x20(%rsp)
jmp 0xd22aa
movsd 0x48(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x58(%rsp), %xmm1
movapd %xmm1, %xmm0
addsd %xmm3, %xmm0
movq %rbx, %rdi
movl %r12d, %esi
movsd 0x30(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x38(%rsp), %xmm4
movaps %xmm4, %xmm5
movl %ebp, %edx
movsd 0x10(%rsp), %xmm6
callq 0xd0930
movsd %xmm0, 0x28(%rsp)
movsd 0x15c92(%rip), %xmm0    # 0xe7f80
mulsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x58(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
addsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
movl %r12d, %esi
movsd 0x30(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x38(%rsp), %xmm4
movaps %xmm4, %xmm5
movl %ebp, %edx
movsd 0x10(%rsp), %xmm6
callq 0xd0930
movsd %xmm0, 0x48(%rsp)
movsd 0x58(%rsp), %xmm1
subsd 0x18(%rsp), %xmm1
movapd %xmm1, %xmm0
addsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
movl %r12d, %esi
movsd 0x30(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x38(%rsp), %xmm4
movaps %xmm4, %xmm5
movl %ebp, %edx
movsd 0x10(%rsp), %xmm6
callq 0xd0930
movsd 0x28(%rsp), %xmm2
movsd 0x48(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x1391e(%rip), %xmm1    # 0xe5cb0
divsd 0x18(%rsp), %xmm1
addsd 0x20(%rsp), %xmm2
divsd %xmm1, %xmm2
movsd 0x50(%rsp), %xmm1
addsd %xmm1, %xmm2
movapd %xmm2, %xmm0
subsd %xmm1, %xmm0
andpd 0x12e84(%rip), %xmm0    # 0xe5240
movsd %xmm2, (%r14)
ucomisd 0x4f28f(%rip), %xmm0    # 0x121658
jbe 0xd23cf
andl $0x0, 0x3c(%rbx)
cmpl $0x3, %r15d
jne 0xd241c
movsd 0x8(%rsp), %xmm0
movsd 0x12e7d(%rip), %xmm1    # 0xe5260
addsd %xmm1, %xmm0
subsd %xmm2, %xmm0
subsd %xmm2, %xmm1
pushq $0x3
popq %rsi
movq %rbx, %rdi
movsd 0x30(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x38(%rsp), %xmm4
movaps %xmm4, %xmm5
movl %ebp, %edx
movsd 0x10(%rsp), %xmm6
callq 0xd0930
movsd (%r14), %xmm2
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jae 0xd2461
leaq 0x4fbaa(%rip), %rsi     # 0x121fd7
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x8090
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8690
movsd 0x10(%rsp), %xmm0
movl $0x1, 0x38(%rbx)
jmp 0xd246d
cmpl $0x1, 0x38(%rbx)
movsd 0x10(%rsp), %xmm0
jne 0xd248f
leaq 0x4fb92(%rip), %rsi     # 0x122006
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movb $0x1, %al
callq 0x8090
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8690
addq $0x868, %rsp            # imm = 0x868
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq