// File: /workspace/github_c_makefile_star2_O1/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, %r14
movsd %xmm2, 0x40(%rsp)
movsd %xmm1, 0x20(%rsp)
movq %rdx, %rbp
movl %esi, 0xc(%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %r12
movq 0x58(%rdi), %rax
cmpl $0xa, 0x8b0(%rsp)
movsd 0xa8(%r12), %xmm1
movsd %xmm3, 0x28(%rsp)
je 0xddd30
divsd 0x13ac0(%rip), %xmm1    # 0xf17f0
movapd %xmm1, 0x50(%rsp)
movq 0x8(%rax), %r15
movapd %xmm0, %xmm2
addsd 0x1351a(%rip), %xmm2    # 0xf1260
movsd %xmm2, 0x30(%rsp)
movsd %xmm0, 0x38(%rsp)
movapd 0x134d6(%rip), %xmm0    # 0xf1230
xorpd %xmm1, %xmm0
callq 0x8670
movsd 0x30(%rsp), %xmm1
mulsd %xmm1, %xmm0
addsd 0x13a73(%rip), %xmm0    # 0xf17e8
movsd %xmm0, 0x10(%rsp)
movsd 0x88(%r12), %xmm0
movsd %xmm0, 0x18(%rsp)
movapd %xmm1, %xmm0
callq 0xd6f51
movapd %xmm0, %xmm2
mulsd 0x18(%rsp), %xmm2
movq 0xb8(%r12), %rax
movsd 0x60(%rax), %xmm1
mulsd 0x148cd(%rip), %xmm1    # 0xf2680
mulsd %xmm2, %xmm1
mulsd 0x4fa01(%rip), %xmm1    # 0x12d7c0
movsd 0x13499(%rip), %xmm0    # 0xf1260
movsd 0x20(%rsp), %xmm3
subsd %xmm3, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
cmpl $0x1, 0x3c(%rbx)
jne 0xdde4b
leaq 0x68(%rsp), %rax
movsd %xmm0, (%rax)
subl %r15d, %ebp
xorpd %xmm1, %xmm1
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movsd 0x10(%rsp), %xmm0
movq %rax, %r15
movq %rax, %rdx
movl %ebp, %ecx
movsd 0x28(%rsp), %xmm2
callq 0xdd58c
movsd 0x13447(%rip), %xmm0    # 0xf1260
subsd (%r15), %xmm0
movsd %xmm0, (%r14)
movsd (%r13), %xmm0
movsd %xmm0, 0x8(%r13)
movsd (%r14), %xmm0
subsd 0x20(%rsp), %xmm0
divsd 0x50(%rsp), %xmm0
movsd %xmm0, (%r13)
jmp 0xddeef
notl %r15d
addl %r15d, %ebp
movsd 0x4f4df(%rip), %xmm0    # 0x12d338
movsd 0x8(%r12), %xmm1
mulsd %xmm0, %xmm1
movsd 0x30(%rsp), %xmm5
mulsd %xmm1, %xmm5
movsd 0x40(%rsp), %xmm4
mulsd %xmm0, %xmm4
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movapd %xmm3, %xmm0
movapd %xmm3, %xmm1
movsd 0x28(%rsp), %xmm3
movl %ebp, %edx
movsd 0x38(%rsp), %xmm6
callq 0xdbd61
movsd (%r13), %xmm1
movsd 0x8(%r13), %xmm2
movsd 0x2fba2(%rip), %xmm3    # 0x10da50
mulsd %xmm1, %xmm3
movsd 0x4f8e6(%rip), %xmm4    # 0x12d7a0
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
mulsd 0x4f8de(%rip), %xmm2    # 0x12d7a8
addsd %xmm4, %xmm2
movsd %xmm1, 0x8(%r13)
movsd %xmm0, (%r13)
movapd 0x50(%rsp), %xmm0
mulsd %xmm2, %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, (%r14)
movsd (%r14), %xmm1
movsd 0x10(%rsp), %xmm0
movq %r12, %rdi
movsd 0x18(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
callq 0xdce04
movq 0x48(%rsp), %rax
movsd %xmm0, (%rax)
movsd (%r14), %xmm1
ucomisd %xmm1, %xmm1
jp 0xddf36
ucomisd 0x13336(%rip), %xmm1    # 0xf1260
ja 0xddf36
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xddf65
leaq 0x502b9(%rip), %rsi     # 0x12e1f6
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
movb $0x2, %al
callq 0x8090
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8660
movl $0x1, 0x38(%rbx)
cmpl $0x1, 0x38(%rbx)
jne 0xddf93
leaq 0x502bc(%rip), %rsi     # 0x12e22e
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x8090
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8660
addq $0x878, %rsp            # imm = 0x878
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq