// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../external/HyRec2020/history.c
// Function: rec_get_xe_next1_H
void rec_get_xe_next1_H(HYREC_DATA *data, int model, double z_in, long iz, double xe_in, double Tm_in,
                        double *xe_out, double *Tm_out, double dxedlna_prev[2], double H, int flag) {

  REC_COSMOPARAMS *cosmo = data->cosmo;
  int *error = &data->error;
  long iz_rad = iz-1-data->rad->iz_rad_0;

  double dxedlna, z_out;
  double nH, TR, xH1, dEdtdV, DLNA;
  char sub_message[SIZE_ErrorM];
  if (flag==10) DLNA = cosmo->dlna;
  else DLNA = cosmo->dlna/10.;

  z_out   = (1.+z_in)*exp(-DLNA)-1.;
  nH = cosmo->nH0 *cube(1.+z_in);
  TR = kBoltz *cosmo->T0 *(1.+z_in);

  dEdtdV = cosmo->inj_params->ion*3*nH*EI / (1-xe_in);
  /* Compute dxHII/dlna. This also correctly updates the radiation field at z_in,
     which is required even when using the stiff approximation */

  /* If system is stiff use the quasi-equilibrium solution */
  if (data->quasi_eq == 1) {
    xH1 = 1.-xe_in;
    rec_xH1_stiff(data, model, z_out, 0, &xH1, iz_rad+1, H);
    *xe_out = 1.-xH1;
    dxedlna_prev[1] = dxedlna_prev[0];
    dxedlna_prev[0] = (*xe_out-xe_in)/DLNA;
  }
    /* Otherwise use second-order explicit solver */
  else {
    dxedlna = rec_dxHIIdlna(data, model, xe_in, xe_in, nH, H, kBoltz*Tm_in, TR, iz_rad, z_in);
    *xe_out = xe_in + DLNA * hyrec_integrator(dxedlna, dxedlna_prev, z_in);
  }

  /* Quasi-steady state solution for Tm */
  *Tm_out = rec_Tmss(z_out, *xe_out, cosmo, dEdtdV, H);

  // Test that the outcome is sensible
  if (*xe_out > 1. || *xe_out < 0. || *xe_out != *xe_out) {
    sprintf(sub_message, "xe > 1 or xe < 0 in get_rec_next1_H at z = %E, xe = %E\n", z_out, *xe_out);
    strcat(data->error_message, sub_message);
    *error = 1;
  }
  if (*error == 1) {
    sprintf(sub_message, "  called from get_rec_next1_H at z = %f\n", z_out);
    strcat(data->error_message, sub_message);
    return;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x878, %rsp            # imm = 0x878
movq %r9, %r13
movq %r8, 0x48(%rsp)
movq %rcx, %r15
movsd %xmm2, 0x40(%rsp)
movsd %xmm1, 0x28(%rsp)
movq %rdx, %rbp
movl %esi, 0x14(%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %r12
movq 0x58(%rdi), %rax
cmpl $0xa, 0x8b0(%rsp)
movsd 0xa8(%r12), %xmm1
movsd %xmm3, 0x30(%rsp)
je 0xd27e6
divsd 0x1300a(%rip), %xmm1    # 0xe57f0
movapd %xmm1, 0x50(%rsp)
movq 0x8(%rax), %r14
movapd %xmm0, %xmm2
addsd 0x12a64(%rip), %xmm2    # 0xe5260
movsd %xmm2, 0x18(%rsp)
movsd %xmm0, 0x38(%rsp)
movapd 0x12a20(%rip), %xmm0    # 0xe5230
xorpd %xmm1, %xmm0
callq 0x86a0
movsd 0x18(%rsp), %xmm1
mulsd %xmm1, %xmm0
addsd 0x12fbd(%rip), %xmm0    # 0xe57e8
movsd %xmm0, 0x8(%rsp)
movsd 0x88(%r12), %xmm0
movsd %xmm0, 0x20(%rsp)
movapd %xmm1, %xmm0
callq 0xcbe4d
movapd %xmm0, %xmm2
mulsd 0x20(%rsp), %xmm2
movq 0xb8(%r12), %rax
movsd 0x60(%rax), %xmm1
mulsd 0x13edf(%rip), %xmm1    # 0xe6748
mulsd %xmm2, %xmm1
mulsd 0x4edeb(%rip), %xmm1    # 0x121660
movsd 0x129e3(%rip), %xmm0    # 0xe5260
movsd 0x28(%rsp), %xmm3
subsd %xmm3, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
cmpl $0x1, 0x3c(%rbx)
jne 0xd290e
movq %r15, 0x18(%rsp)
leaq 0x68(%rsp), %r15
movsd %xmm0, (%r15)
subl %r14d, %ebp
xorpd %xmm1, %xmm1
movq %rbx, %rdi
movl 0x14(%rsp), %esi
movsd 0x8(%rsp), %xmm0
movq %r15, %rdx
movl %ebp, %ecx
movsd 0x30(%rsp), %xmm2
callq 0xd203c
movsd 0x1298e(%rip), %xmm0    # 0xe5260
subsd (%r15), %xmm0
movq 0x18(%rsp), %r15
movsd %xmm0, (%r15)
movsd (%r13), %xmm0
movsd %xmm0, 0x8(%r13)
movsd (%r15), %xmm0
subsd 0x28(%rsp), %xmm0
divsd 0x50(%rsp), %xmm0
movsd %xmm0, (%r13)
movsd (%r15), %xmm1
jmp 0xd29b2
notl %r14d
addl %r14d, %ebp
movsd 0x4e8ec(%rip), %xmm0    # 0x121208
movsd 0x8(%r12), %xmm1
mulsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm5
mulsd %xmm1, %xmm5
movsd 0x40(%rsp), %xmm4
mulsd %xmm0, %xmm4
movq %rbx, %rdi
movl 0x14(%rsp), %esi
movapd %xmm3, %xmm0
movapd %xmm3, %xmm1
movsd 0x30(%rsp), %xmm3
movl %ebp, %edx
movsd 0x38(%rsp), %xmm6
callq 0xd0930
movsd (%r13), %xmm1
movsd 0x8(%r13), %xmm2
movsd 0x2efcf(%rip), %xmm3    # 0x101940
mulsd %xmm1, %xmm3
movsd 0x4ecc3(%rip), %xmm4    # 0x121640
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
mulsd 0x4ecbb(%rip), %xmm2    # 0x121648
addsd %xmm4, %xmm2
movsd %xmm1, 0x8(%r13)
movsd %xmm0, (%r13)
movapd 0x50(%rsp), %xmm1
mulsd %xmm2, %xmm1
addsd 0x28(%rsp), %xmm1
movsd %xmm1, (%r15)
movsd 0x8(%rsp), %xmm0
movq %r12, %rdi
movsd 0x20(%rsp), %xmm2
movsd 0x30(%rsp), %xmm3
callq 0xd18ba
movq 0x48(%rsp), %rax
movsd %xmm0, (%rax)
movsd (%r15), %xmm1
ucomisd %xmm1, %xmm1
jp 0xd2a02
ucomisd 0x12878(%rip), %xmm1    # 0xe5260
ja 0xd2a02
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
ja 0xd2a02
cmpl $0x1, 0x38(%rbx)
movsd 0x8(%rsp), %xmm0
je 0xd2a37
jmp 0xd2a59
leaq 0x4f68d(%rip), %rsi     # 0x122096
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x8090
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8690
movsd 0x8(%rsp), %xmm0
movl $0x1, 0x38(%rbx)
leaq 0x4f690(%rip), %rsi     # 0x1220ce
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movb $0x1, %al
callq 0x8090
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8690
addq $0x878, %rsp            # imm = 0x878
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq