// File: /workspace/github_c_makefile_star2_O2/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 0x12d28(%rip), %xmm0    # 0xe5260
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0xcbe4d
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 0xccaf5
movsd (%rbp), %xmm1
movsd 0x8(%rbp), %xmm2
movsd 0x2f3b6(%rip), %xmm3    # 0x101940
mulsd %xmm1, %xmm3
movsd 0x4f0aa(%rip), %xmm4    # 0x121640
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
mulsd 0x4f0a2(%rip), %xmm2    # 0x121648
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 0xd2638
movapd 0x30(%rsp), %xmm0
xorpd 0x12c56(%rip), %xmm0    # 0xe5230
callq 0x86a0
movsd 0x8(%rsp), %xmm2
mulsd %xmm0, %xmm2
addsd 0x131f7(%rip), %xmm2    # 0xe57e8
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 0xd203c
movq 0x20(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rax)
andq $0x0, (%rax)
movsd (%r14), %xmm1
jmp 0xd26f9
movsd 0x4ebc8(%rip), %xmm3    # 0x121208
movsd 0x40(%rsp), %xmm0
mulsd %xmm3, %xmm0
movsd 0x8(%rsp), %xmm5
mulsd %xmm0, %xmm5
movsd 0x60(%rsp), %xmm2
mulsd 0x48(%rsp), %xmm2
movsd 0x12bf8(%rip), %xmm1    # 0xe5260
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 0xd0930
movq 0x20(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x8(%rax), %xmm2
movsd 0x2f288(%rip), %xmm3    # 0x101940
mulsd %xmm1, %xmm3
movsd 0x4ef7c(%rip), %xmm4    # 0x121640
mulsd %xmm0, %xmm4
mulsd 0x4ef78(%rip), %xmm2    # 0x121648
addsd %xmm3, %xmm4
addsd %xmm4, %xmm2
movsd %xmm1, 0x8(%rax)
movsd %xmm0, (%rax)
movsd (%r14), %xmm1
movapd 0x30(%rsp), %xmm0
mulsd %xmm2, %xmm0
subsd %xmm0, %xmm1
movsd %xmm1, (%r14)
ucomisd %xmm1, %xmm1
jp 0xd2721
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
ja 0xd2721
ucomisd 0x12b4f(%rip), %xmm1    # 0xe5260
ja 0xd2721
cmpl $0x1, 0x38(%rbx)
movsd 0x8(%rsp), %xmm0
je 0xd2756
jmp 0xd2778
leaq 0x4f905(%rip), %rsi     # 0x12202d
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 0x4f90e(%rip), %rsi     # 0x12206b
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