// File: /workspace/github_c_makefile_star2_O3/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 0xda7bf
divsd 0x14031(%rip), %xmm1    # 0xee7f0
movapd %xmm1, 0x50(%rsp)
movq 0x8(%rax), %r14
movapd %xmm0, %xmm2
addsd 0x13a8b(%rip), %xmm2    # 0xee260
movsd %xmm2, 0x18(%rsp)
movsd %xmm0, 0x38(%rsp)
movapd 0x13a47(%rip), %xmm0    # 0xee230
xorpd %xmm1, %xmm0
callq 0x8670
movsd 0x18(%rsp), %xmm1
mulsd %xmm1, %xmm0
addsd 0x13fe4(%rip), %xmm0    # 0xee7e8
movsd %xmm0, 0x8(%rsp)
movsd 0x88(%r12), %xmm0
movsd %xmm0, 0x20(%rsp)
movapd %xmm1, %xmm0
callq 0xd3759
movapd %xmm0, %xmm2
mulsd 0x20(%rsp), %xmm2
movq 0xb8(%r12), %rax
movsd 0x60(%rax), %xmm1
mulsd 0x14e3e(%rip), %xmm1    # 0xef680
mulsd %xmm2, %xmm1
mulsd 0x4ffa2(%rip), %xmm1    # 0x12a7f0
movsd 0x13a0a(%rip), %xmm0    # 0xee260
movsd 0x28(%rsp), %xmm3
subsd %xmm3, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
cmpl $0x1, 0x3c(%rbx)
jne 0xda8e7
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 0xda007
movsd 0x139b5(%rip), %xmm0    # 0xee260
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 0xda98b
notl %r14d
addl %r14d, %ebp
movsd 0x4fa73(%rip), %xmm0    # 0x12a368
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 0xd85d7
movsd (%r13), %xmm1
movsd 0x8(%r13), %xmm2
movsd 0x3012e(%rip), %xmm3    # 0x10aa78
mulsd %xmm1, %xmm3
movsd 0x4fe7a(%rip), %xmm4    # 0x12a7d0
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
mulsd 0x4fe72(%rip), %xmm2    # 0x12a7d8
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 0xd987f
movq 0x48(%rsp), %rax
movsd %xmm0, (%rax)
movsd (%r15), %xmm1
ucomisd %xmm1, %xmm1
jp 0xda9db
ucomisd 0x1389f(%rip), %xmm1    # 0xee260
ja 0xda9db
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
ja 0xda9db
cmpl $0x1, 0x38(%rbx)
movsd 0x8(%rsp), %xmm0
je 0xdaa10
jmp 0xdaa32
leaq 0x50844(%rip), %rsi     # 0x12b226
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x8090
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8660
movsd 0x8(%rsp), %xmm0
movl $0x1, 0x38(%rbx)
leaq 0x50847(%rip), %rsi     # 0x12b25e
leaq 0x70(%rsp), %r14
movq %r14, %rdi
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