// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x8d8, %rsp            # imm = 0x8D8
movq %rdi, 0x8d0(%rsp)
movl %esi, 0x8cc(%rsp)
movsd %xmm0, 0x8c0(%rsp)
movsd %xmm1, 0x8b8(%rsp)
movq %rdx, 0x8b0(%rsp)
movl %ecx, 0x8ac(%rsp)
movsd %xmm2, 0x8a0(%rsp)
movq 0x8d0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x898(%rsp)
movq 0x8d0(%rsp), %rax
addq $0x38, %rax
movq %rax, 0x890(%rsp)
movq 0x898(%rsp), %rax
movsd 0x5eca0(%rip), %xmm0    # 0x20e8f8
mulsd 0x8(%rax), %xmm0
movsd 0x225e3(%rip), %xmm1    # 0x1d2248
addsd 0x8c0(%rsp), %xmm1
movsd %xmm1, 0x888(%rsp)
mulsd %xmm1, %xmm0
movsd %xmm0, 0x858(%rsp)
cmpl $0x3, 0x8cc(%rsp)
jne 0x1afc9e
movl $0x2, 0x844(%rsp)
jmp 0x1afd23
movl 0x8cc(%rsp), %eax
movl %eax, 0x844(%rsp)
cmpl $0x4, 0x8cc(%rsp)
jne 0x1afd21
movsd 0x858(%rsp), %xmm0
movsd 0x5ec31(%rip), %xmm1    # 0x20e8f8
divsd %xmm1, %xmm0
movq 0x898(%rsp), %rax
divsd 0x98(%rax), %xmm0
movq 0x898(%rsp), %rax
divsd 0x98(%rax), %xmm0
movq 0x898(%rsp), %rax
divsd 0xa0(%rax), %xmm0
movq 0x8d0(%rsp), %rax
movq 0x60(%rax), %rax
movq (%rax), %rax
ucomisd 0x840(%rax), %xmm0
jbe 0x1afd1f
movl $0x2, 0x844(%rsp)
jmp 0x1afd21
jmp 0x1afd23
movq 0x898(%rsp), %rax
movsd 0x88(%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x22507(%rip), %xmm0    # 0x1d2248
addsd 0x8c0(%rsp), %xmm0
callq 0x1a5670
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x850(%rsp)
movq 0x898(%rsp), %rdi
movsd 0x8c0(%rsp), %xmm0
movsd 0x8b8(%rsp), %xmm1
callq 0x1a6c20
movsd %xmm0, 0x880(%rsp)
movsd 0x224b3(%rip), %xmm0    # 0x1d2248
subsd 0x880(%rsp), %xmm0
movsd %xmm0, 0x878(%rsp)
movsd 0x22499(%rip), %xmm0    # 0x1d2248
addsd 0x8c0(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x898(%rsp), %rdi
movsd 0x8c0(%rsp), %xmm0
movsd 0x22eb1(%rip), %xmm1    # 0x1d2c88
subsd %xmm1, %xmm0
movsd 0x8b8(%rsp), %xmm1
callq 0x1a6c20
movsd %xmm0, 0x30(%rsp)
movq 0x898(%rsp), %rdi
movsd 0x22e89(%rip), %xmm0    # 0x1d2c88
addsd 0x8c0(%rsp), %xmm0
movsd 0x8b8(%rsp), %xmm1
callq 0x1a6c20
movsd 0x30(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x38(%rsp), %xmm0
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x870(%rsp)
movsd 0x8b8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1afe4f
jp 0x1afe4f
jmp 0x1affde
movsd 0x223f1(%rip), %xmm0    # 0x1d2248
addsd 0x8c0(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x898(%rsp), %rdi
movsd 0x8c0(%rsp), %xmm0
movsd 0x22e09(%rip), %xmm1    # 0x1d2c88
subsd %xmm1, %xmm0
movsd 0x8b8(%rsp), %xmm1
callq 0x1a6c20
movsd %xmm0, 0x8(%rsp)
movq 0x898(%rsp), %rdi
movsd 0x22de1(%rip), %xmm0    # 0x1d2c88
addsd 0x8c0(%rsp), %xmm0
movsd 0x8b8(%rsp), %xmm1
callq 0x1a6c20
movsd 0x8(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x10(%rsp), %xmm0
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x870(%rsp)
movq 0x898(%rsp), %rax
movsd 0x80(%rax), %xmm1
subsd 0x8b8(%rsp), %xmm1
movsd 0x250d1(%rip), %xmm0    # 0x1d4fd0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x848(%rsp)
movq 0x898(%rsp), %rdi
movsd 0x8c0(%rsp), %xmm0
movsd 0x8b8(%rsp), %xmm1
addsd 0x848(%rsp), %xmm1
callq 0x1a6c20
movsd %xmm0, 0x18(%rsp)
movq 0x898(%rsp), %rdi
movsd 0x8c0(%rsp), %xmm0
movsd 0x8b8(%rsp), %xmm1
subsd 0x848(%rsp), %xmm1
callq 0x1a6c20
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd 0x22d09(%rip), %xmm1    # 0x1d2c80
divsd %xmm1, %xmm0
divsd 0x848(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x8d0(%rsp), %rdi
movsd 0x8c0(%rsp), %xmm0
movsd 0x880(%rsp), %xmm1
movsd 0x8b8(%rsp), %xmm2
movsd 0x8a0(%rsp), %xmm3
callq 0x1a6e90
movaps %xmm0, %xmm2
movsd 0x20(%rsp), %xmm0
movsd 0x870(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x870(%rsp)
movq 0x8d0(%rsp), %rdi
movl 0x844(%rsp), %esi
movsd 0x878(%rsp), %xmm0
addsd 0x8b8(%rsp), %xmm0
movsd 0x878(%rsp), %xmm1
movsd 0x850(%rsp), %xmm2
movsd 0x8a0(%rsp), %xmm3
movsd 0x858(%rsp), %xmm4
movsd 0x858(%rsp), %xmm5
movl 0x8ac(%rsp), %edx
movsd 0x8c0(%rsp), %xmm6
callq 0x1ad910
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x868(%rsp)
movsd 0x24f67(%rip), %xmm0    # 0x1d4fd0
mulsd 0x880(%rsp), %xmm0
movsd %xmm0, 0x848(%rsp)
movq 0x8d0(%rsp), %rdi
movl 0x844(%rsp), %esi
movsd 0x878(%rsp), %xmm0
addsd 0x848(%rsp), %xmm0
addsd 0x8b8(%rsp), %xmm0
movsd 0x878(%rsp), %xmm1
addsd 0x848(%rsp), %xmm1
movsd 0x850(%rsp), %xmm2
movsd 0x8a0(%rsp), %xmm3
movsd 0x858(%rsp), %xmm4
movsd 0x858(%rsp), %xmm5
movl 0x8ac(%rsp), %edx
movsd 0x8c0(%rsp), %xmm6
callq 0x1ad910
movsd %xmm0, (%rsp)
movq 0x8d0(%rsp), %rdi
movl 0x844(%rsp), %esi
movsd 0x878(%rsp), %xmm0
subsd 0x848(%rsp), %xmm0
addsd 0x8b8(%rsp), %xmm0
movsd 0x878(%rsp), %xmm1
subsd 0x848(%rsp), %xmm1
movsd 0x850(%rsp), %xmm2
movsd 0x8a0(%rsp), %xmm3
movsd 0x858(%rsp), %xmm4
movsd 0x858(%rsp), %xmm5
movl 0x8ac(%rsp), %edx
movsd 0x8c0(%rsp), %xmm6
callq 0x1ad910
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movsd 0x22b02(%rip), %xmm1    # 0x1d2c80
divsd %xmm1, %xmm0
divsd 0x848(%rsp), %xmm0
movsd %xmm0, 0x860(%rsp)
movsd 0x880(%rsp), %xmm0
movsd 0x870(%rsp), %xmm1
subsd 0x868(%rsp), %xmm1
divsd 0x860(%rsp), %xmm1
addsd %xmm1, %xmm0
movq 0x8b0(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x8b0(%rsp), %rax
movsd (%rax), %xmm0
subsd 0x880(%rsp), %xmm0
movaps 0x2204c(%rip), %xmm1    # 0x1d2230
pand %xmm1, %xmm0
movsd 0x412c0(%rip), %xmm1    # 0x1f14b0
ucomisd %xmm1, %xmm0
jbe 0x1b0205
movq 0x8d0(%rsp), %rax
movl $0x0, 0x3c(%rax)
cmpl $0x3, 0x8cc(%rsp)
jne 0x1b0288
movq 0x8d0(%rsp), %rdi
movl 0x8cc(%rsp), %esi
movsd 0x22022(%rip), %xmm0    # 0x1d2248
addsd 0x8b8(%rsp), %xmm0
movq 0x8b0(%rsp), %rax
subsd (%rax), %xmm0
movq 0x8b0(%rsp), %rax
movsd 0x21ffd(%rip), %xmm1    # 0x1d2248
subsd (%rax), %xmm1
movsd 0x850(%rsp), %xmm2
movsd 0x8a0(%rsp), %xmm3
movsd 0x858(%rsp), %xmm4
movsd 0x858(%rsp), %xmm5
movl 0x8ac(%rsp), %edx
movsd 0x8c0(%rsp), %xmm6
callq 0x1ad910
movq 0x8b0(%rsp), %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
ja 0x1b02b7
movq 0x8b0(%rsp), %rax
movsd (%rax), %xmm0
movq 0x8b0(%rsp), %rax
ucomisd (%rax), %xmm0
jne 0x1b02b7
jp 0x1b02b7
jmp 0x1b0303
leaq 0x40(%rsp), %rdi
movsd 0x8c0(%rsp), %xmm0
movq 0x8b0(%rsp), %rax
movsd (%rax), %xmm1
leaq 0x5f34f(%rip), %rsi     # 0x20f627
movb $0x2, %al
callq 0x8090
movq 0x8d0(%rsp), %rax
movq 0x48(%rax), %rdi
leaq 0x40(%rsp), %rsi
callq 0x8660
movq 0x890(%rsp), %rax
movl $0x1, (%rax)
movq 0x890(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x1b0344
leaq 0x40(%rsp), %rdi
movsd 0x8c0(%rsp), %xmm0
leaq 0x5f331(%rip), %rsi     # 0x20f656
movb $0x1, %al
callq 0x8090
movq 0x8d0(%rsp), %rax
movq 0x48(%rax), %rdi
leaq 0x40(%rsp), %rsi
callq 0x8660
jmp 0x1b0346
jmp 0x1b0346
addq $0x8d8, %rsp            # imm = 0x8D8
retq
nop