// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../external/HyRec2020/history.c
// Function: get_rec_next2_HHe
void get_rec_next2_HHe(HYREC_DATA *data, int model, double z_in, long iz, double *xH1, double *xHeII,
                       double dxHIIdlna_prev[2], double dxHeIIdlna_prev[2], double H) {

  REC_COSMOPARAMS *cosmo = data->cosmo;
  int *error = &data->error;
  double Tm = data->Tm_output[iz-1];
  long iz_rad = iz-1-data->rad->iz_rad_0;

  double dxHeIIdlna, dxHIIdlna=0., z_out, xe;
  double nH, TR, DLNA;
  char sub_message[SIZE_ErrorM];
  DLNA = cosmo->dlna;
  xe = *xHeII + 1.- (*xH1);
  nH = cosmo->nH0 *cube(1.+z_in);
  TR = kBoltz * cosmo->T0 *(1.+z_in);
  /* Evolve HeII by solving ODE */
  dxHeIIdlna  = rec_helium_dxHeIIdlna(data, z_in, *xH1, *xHeII, H);
  *xHeII     += DLNA * hyrec_integrator(dxHeIIdlna, dxHeIIdlna_prev, z_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){
    z_out = (1.+z_in)*exp(-DLNA)-1.;
    rec_xH1_stiff(data, model, z_out, *xHeII, xH1, iz_rad+1, H);
    hyrec_integrator(dxHIIdlna, dxHIIdlna_prev, z_in);
  }

    /* Otherwise use second-order explicit solver */
  else {
    dxHIIdlna = rec_dxHIIdlna(data, model, xe, 1.-(*xH1), nH, H, kBoltz*Tm, TR, iz_rad, z_in);
    *xH1 -= DLNA * hyrec_integrator(dxHIIdlna, dxHIIdlna_prev, z_in);
  }

    /* Checking for errors */
  if (*xH1 < 0. || *xH1 > 1. || *xH1 != *xH1) {
    sprintf(sub_message, "xH1 < 0 or xH1 > 1 in get_rec_next2_HHe: at z = %f, xH1 = %E\n", z_out, *xH1);
    strcat(data->error_message, sub_message);
    *error = 1;
  }
  if (*error == 1) {
    sprintf(sub_message, "  called from get_rec_next2_HHe 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
movsd %xmm1, 0x18(%rsp)
movq %r9, 0x20(%rsp)
movq %r8, %r13
movq %rcx, %r14
movq %rdx, %r12
movapd %xmm0, %xmm1
movsd %xmm0, 0x28(%rsp)
movl %esi, 0x14(%rsp)
movq %rdi, %rbx
movq 0x8b0(%rsp), %rbp
movq 0x8(%rdi), %r15
movq 0x30(%rdi), %rax
movsd -0x8(%rax,%rdx,8), %xmm0
movsd %xmm0, 0x68(%rsp)
decq %r12
movq 0x58(%rdi), %rax
subq 0x8(%rax), %r12
movsd 0x88(%r15), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0xa8(%r15), %xmm0
movaps %xmm0, 0x30(%rsp)
movsd (%r8), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd (%rcx), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x137d9(%rip), %xmm0    # 0xf1260
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0xd6f51
movsd %xmm0, 0x48(%rsp)
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd (%r14), %xmm1
movsd (%r13), %xmm2
movq %rbx, %rdi
movsd 0x28(%rsp), %xmm0
movsd 0x18(%rsp), %xmm3
callq 0xd7cf2
movsd (%rbp), %xmm1
movsd 0x8(%rbp), %xmm2
movsd 0x2ff77(%rip), %xmm3    # 0x10da50
mulsd %xmm1, %xmm3
movsd 0x4fcbb(%rip), %xmm4    # 0x12d7a0
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
mulsd 0x4fcb3(%rip), %xmm2    # 0x12d7a8
addsd %xmm4, %xmm2
movsd %xmm1, 0x8(%rbp)
movsd %xmm0, (%rbp)
mulsd 0x30(%rsp), %xmm2
addsd (%r13), %xmm2
movsd %xmm2, (%r13)
cmpl $0x1, 0x3c(%rbx)
jne 0xddb85
movapd 0x30(%rsp), %xmm0
xorpd 0x13707(%rip), %xmm0    # 0xf1230
callq 0x8670
movsd 0x8(%rsp), %xmm2
mulsd %xmm0, %xmm2
addsd 0x13ca8(%rip), %xmm2    # 0xf17e8
movsd (%r13), %xmm1
incl %r12d
movq %rbx, %rdi
movl 0x14(%rsp), %esi
movsd %xmm2, 0x8(%rsp)
movapd %xmm2, %xmm0
movq %r14, %rdx
movl %r12d, %ecx
movsd 0x18(%rsp), %xmm2
callq 0xdd58c
movq 0x20(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rax)
movq $0x0, (%rax)
jmp 0xddc46
movsd 0x4f7ab(%rip), %xmm3    # 0x12d338
movsd 0x40(%rsp), %xmm0
mulsd %xmm3, %xmm0
movsd 0x8(%rsp), %xmm5
mulsd %xmm0, %xmm5
movsd 0x60(%rsp), %xmm2
mulsd 0x48(%rsp), %xmm2
movsd 0x136ab(%rip), %xmm1    # 0xf1260
movsd 0x58(%rsp), %xmm0
addsd %xmm1, %xmm0
subsd 0x50(%rsp), %xmm0
subsd (%r14), %xmm1
movsd 0x68(%rsp), %xmm4
mulsd %xmm3, %xmm4
movq %rbx, %rdi
movl 0x14(%rsp), %esi
movsd 0x18(%rsp), %xmm3
movl %r12d, %edx
movsd 0x28(%rsp), %xmm6
callq 0xdbd61
movq 0x20(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x8(%rax), %xmm2
movsd 0x2fe4b(%rip), %xmm3    # 0x10da50
mulsd %xmm1, %xmm3
movsd 0x4fb8f(%rip), %xmm4    # 0x12d7a0
mulsd %xmm0, %xmm4
mulsd 0x4fb8b(%rip), %xmm2    # 0x12d7a8
addsd %xmm3, %xmm4
addsd %xmm4, %xmm2
movsd %xmm1, 0x8(%rax)
movsd %xmm0, (%rax)
movsd (%r14), %xmm0
movapd 0x30(%rsp), %xmm1
mulsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, (%r14)
movsd (%r14), %xmm1
ucomisd %xmm1, %xmm1
jp 0xddc65
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
ja 0xddc65
ucomisd 0x135fd(%rip), %xmm1    # 0xf1260
jbe 0xddc94
leaq 0x50521(%rip), %rsi     # 0x12e18d
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
movl $0x1, 0x38(%rbx)
cmpl $0x1, 0x38(%rbx)
movsd 0x8(%rsp), %xmm0
jne 0xddcc2
leaq 0x50524(%rip), %rsi     # 0x12e1cb
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