// File: /workspace/github_c_makefile_star2_O3/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
movsd %xmm2, 0x40(%rsp)
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 0x50321(%rip), %xmm1    # 0x12a368
movsd 0x14211(%rip), %xmm2    # 0xee260
addsd %xmm0, %xmm2
mulsd %xmm2, %xmm1
movsd %xmm1, 0x38(%rsp)
movl $0x2, %r12d
cmpl $0x3, %esi
je 0xda0b6
movl %r15d, %r12d
cmpl $0x4, %r15d
jne 0xda0b6
movsd 0x38(%rsp), %xmm0
divsd 0x502e9(%rip), %xmm0    # 0x12a368
movsd 0x98(%r13), %xmm1
divsd %xmm1, %xmm0
divsd %xmm1, %xmm0
divsd 0xa0(%r13), %xmm0
movq 0x60(%rbx), %rax
movq (%rax), %rax
movl $0x4, %r12d
ucomisd 0x840(%rax), %xmm0
jbe 0xda0b6
movl $0x2, %r12d
movsd 0x88(%r13), %xmm0
movsd %xmm0, 0x30(%rsp)
movapd %xmm2, %xmm0
movsd %xmm2, 0x20(%rsp)
callq 0xd3759
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r13, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xd4334
movsd 0x14164(%rip), %xmm1    # 0xee260
movsd %xmm0, 0x50(%rsp)
subsd %xmm0, %xmm1
movsd %xmm1, 0x58(%rsp)
movsd 0x17364(%rip), %xmm0    # 0xf1478
addsd 0x10(%rsp), %xmm0
movq %r13, %rdi
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm1
callq 0xd4334
movsd %xmm0, 0x48(%rsp)
movsd 0x14b94(%rip), %xmm0    # 0xeecd0
addsd 0x10(%rsp), %xmm0
movq %r13, %rdi
movsd %xmm0, 0x28(%rsp)
movsd 0x8(%rsp), %xmm1
callq 0xd4334
xorpd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm3
ucomisd %xmm1, %xmm3
jne 0xda16c
jnp 0xda261
movq %r13, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xd4334
movsd %xmm0, 0x18(%rsp)
movq %r13, %rdi
movsd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xd4334
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 0x16df5(%rip), %xmm1    # 0xf0fc0
movsd %xmm1, 0x28(%rsp)
addsd 0x8(%rsp), %xmm1
movq %r13, %rdi
movsd 0x10(%rsp), %xmm0
callq 0xd4334
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm1
subsd 0x28(%rsp), %xmm1
movq %r13, %rdi
movsd 0x10(%rsp), %xmm0
callq 0xd4334
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x14ab9(%rip), %xmm1    # 0xeecd0
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 0xd44f6
movsd 0x8(%rsp), %xmm3
mulsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, 0x20(%rsp)
jmp 0xda27b
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 0xd85d7
movsd %xmm0, 0x28(%rsp)
movsd 0x16d01(%rip), %xmm0    # 0xf0fc0
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 0xd85d7
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 0xd85d7
movsd 0x28(%rsp), %xmm2
movsd 0x48(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x1496d(%rip), %xmm1    # 0xeecd0
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 0x13eb3(%rip), %xmm0    # 0xee240
movsd %xmm2, (%r14)
ucomisd 0x5044e(%rip), %xmm0    # 0x12a7e8
jbe 0xda3a3
movl $0x0, 0x3c(%rbx)
cmpl $0x3, %r15d
jne 0xda3f2
movsd 0x8(%rsp), %xmm0
movsd 0x13ea9(%rip), %xmm1    # 0xee260
addsd %xmm1, %xmm0
subsd %xmm2, %xmm0
subsd %xmm2, %xmm1
movq %rbx, %rdi
movl $0x3, %esi
movsd 0x30(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x38(%rsp), %xmm4
movaps %xmm4, %xmm5
movl %ebp, %edx
movsd 0x10(%rsp), %xmm6
callq 0xd85d7
movsd (%r14), %xmm2
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jae 0xda437
leaq 0x50d64(%rip), %rsi     # 0x12b167
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 0x8660
movsd 0x10(%rsp), %xmm0
movl $0x1, 0x38(%rbx)
jmp 0xda443
cmpl $0x1, 0x38(%rbx)
movsd 0x10(%rsp), %xmm0
jne 0xda465
leaq 0x50d4c(%rip), %rsi     # 0x12b196
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movb $0x1, %al
callq 0x8090
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8660
addq $0x868, %rsp            # imm = 0x868
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq