// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../external/HyRec2020/history.c
// Function: rec_get_xe_next1_He
void rec_get_xe_next1_He(HYREC_DATA *data, double z_in, double *xHeII, double dxHeIIdlna_prev[2],
                         double *hubble_array, int flag) {

  REC_COSMOPARAMS *cosmo = data->cosmo;
  double Nz = data->Nz, dz = data->zmax/Nz;
  int *error = &data->error;

  double xH1, xH1_p, xH1_m, xHeIISaha, dxHeIISaha_dlna, DdxHeIIdlna_Dxe, dxHeIIdlna, z_out, Dxe, DLNA;
  char sub_message[SIZE_ErrorM];
  double H;
  if (flag==10) DLNA = cosmo->dlna;
  else DLNA = cosmo->dlna/10.;

  if (hubble_array[0]==-1.) H  = rec_HubbleRate(cosmo, z_in);
  else H = rec_interp1d(.0, dz, hubble_array, Nz, z_in, error, sub_message);

  xH1        = rec_saha_xH1s(cosmo, z_in, *xHeII);
  dxHeIIdlna = rec_helium_dxHeIIdlna(data, z_in, xH1, *xHeII, H);
  /* Post-Saha approximation during the early phase of HeII->HeI recombination */
  if (data->quasi_eq == 1) {
    z_out     = (1.+z_in)*exp(-DLNA)-1.;
    xHeIISaha = rec_saha_xHeII(cosmo, z_out);

    dxHeIISaha_dlna  = (1.+z_out)*(rec_saha_xHeII(cosmo, z_out-0.5)
                                  -rec_saha_xHeII(cosmo, z_out+0.5));

    Dxe    = 0.01*(cosmo->fHe - xHeIISaha);
    xH1_p = rec_saha_xH1s(cosmo, z_out, xHeIISaha+Dxe);
    xH1_m = rec_saha_xH1s(cosmo, z_out, xHeIISaha-Dxe);

    if (hubble_array[0]==-1.) H  = rec_HubbleRate(cosmo, z_out);
    else H = rec_interp1d(.0, dz, hubble_array, Nz, z_out, error, sub_message);

    DdxHeIIdlna_Dxe  = (rec_helium_dxHeIIdlna(data, z_out, xH1_p, xHeIISaha+Dxe, H)
                       -rec_helium_dxHeIIdlna(data, z_out, xH1_m, xHeIISaha-Dxe, H))/2./Dxe;

    *xHeII = xHeIISaha + dxHeIISaha_dlna/DdxHeIIdlna_Dxe;
    /* Check that the post-Saha approximation is still valid. If not, switch it off for future iterations */
    if (fabs(*xHeII - xHeIISaha) > DXHEII_MAX) data->quasi_eq = 0;
  }

  /* Otherwise integrate ODE */
  else *xHeII += DLNA * hyrec_integrator(dxHeIIdlna, dxHeIIdlna_prev,z_in);

  if (*error == 1) {
    sprintf(sub_message, "  called from rec_get_xe_next1_He at z = %f\n", z_in);
    strcat(data->error_message, sub_message);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x888, %rsp            # imm = 0x888
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %r14
movapd %xmm0, %xmm2
movq %rdi, %rbx
movq 0x20(%rdi), %r13
cvtsi2sd %r13, %xmm0
movq 0x8(%rdi), %rbp
movsd 0x10(%rdi), %xmm1
movsd 0xa8(%rbp), %xmm3
cmpl $0xa, %r8d
je 0xd1d13
divsd 0x13add(%rip), %xmm3    # 0xe57f0
movapd %xmm3, 0x10(%rsp)
divsd %xmm0, %xmm1
leaq 0x38(%rbx), %rdx
movsd (%r12), %xmm0
ucomisd 0x13ab9(%rip), %xmm0    # 0xe57e8
movsd %xmm2, 0x28(%rsp)
movq %rdx, 0x38(%rsp)
movsd %xmm1, 0x30(%rsp)
jne 0xd1d52
jp 0xd1d52
movq %rbp, %rdi
movapd %xmm2, %xmm0
callq 0xd0bdc
jmp 0xd1d69
leaq 0x80(%rsp), %rcx
xorpd %xmm0, %xmm0
movq %r12, %rdi
movl %r13d, %esi
callq 0xcc0a7
movsd %xmm0, (%rsp)
movsd (%r14), %xmm1
movq %rbp, %rdi
movsd 0x28(%rsp), %xmm0
callq 0xcc936
movaps %xmm0, %xmm1
movsd (%r14), %xmm2
movq %rbx, %rdi
movsd 0x28(%rsp), %xmm0
movsd (%rsp), %xmm3
callq 0xccaf5
cmpl $0x1, 0x3c(%rbx)
jne 0xd1ed9
movsd 0x134b2(%rip), %xmm0    # 0xe5260
movsd %xmm0, 0x8(%rsp)
movsd 0x28(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movapd 0x10(%rsp), %xmm0
xorpd 0x1345f(%rip), %xmm0    # 0xe5230
callq 0x86a0
mulsd (%rsp), %xmm0
addsd 0x13a05(%rip), %xmm0    # 0xe57e8
movsd %xmm0, 0x10(%rsp)
movq %rbp, %rdi
callq 0xcc7c5
movsd %xmm0, (%rsp)
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x16624(%rip), %xmm0    # 0xe8438
addsd %xmm1, %xmm0
movq %rbp, %rdi
callq 0xcc7c5
movapd %xmm0, 0x40(%rsp)
movsd 0x13e82(%rip), %xmm0    # 0xe5cb0
addsd 0x10(%rsp), %xmm0
movq %rbp, %rdi
callq 0xcc7c5
movapd 0x40(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x8(%rsp), %xmm1
movapd %xmm1, 0x40(%rsp)
movsd 0x80(%rbp), %xmm0
movsd (%rsp), %xmm1
subsd %xmm1, %xmm0
mulsd 0x16115(%rip), %xmm0    # 0xe7f80
movsd %xmm0, 0x8(%rsp)
addsd %xmm0, %xmm1
movq %rbp, %rdi
movsd 0x10(%rsp), %xmm0
movsd %xmm1, 0x78(%rsp)
callq 0xcc936
movsd %xmm0, 0x68(%rsp)
movsd (%rsp), %xmm1
subsd 0x8(%rsp), %xmm1
movq %rbp, %rdi
movsd 0x10(%rsp), %xmm0
movsd %xmm1, 0x70(%rsp)
callq 0xcc936
movsd %xmm0, 0x60(%rsp)
movsd (%r12), %xmm0
ucomisd 0x13926(%rip), %xmm0    # 0xe57e8
jne 0xd1f35
jp 0xd1f35
movq %rbp, %rdi
movsd 0x10(%rsp), %xmm0
callq 0xd0bdc
jmp 0xd1f5d
movsd (%r15), %xmm1
movsd 0x8(%r15), %xmm2
movsd 0x2fa54(%rip), %xmm3    # 0x101940
mulsd %xmm1, %xmm3
movapd %xmm0, %xmm4
mulsd 0x4f744(%rip), %xmm4    # 0x121640
mulsd 0x4f744(%rip), %xmm2    # 0x121648
addsd %xmm3, %xmm4
addsd %xmm4, %xmm2
movsd %xmm1, 0x8(%r15)
movsd %xmm0, (%r15)
movapd 0x10(%rsp), %xmm0
mulsd %xmm2, %xmm0
addsd (%r14), %xmm0
movsd %xmm0, (%r14)
movq 0x38(%rsp), %rax
jmp 0xd1ffa
leaq 0x80(%rsp), %rcx
xorpd %xmm0, %xmm0
movsd 0x30(%rsp), %xmm1
movq %r12, %rdi
movl %r13d, %esi
movsd 0x10(%rsp), %xmm2
movq 0x38(%rsp), %rdx
callq 0xcc0a7
movapd %xmm0, %xmm3
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x68(%rsp), %xmm1
movsd 0x78(%rsp), %xmm2
movsd %xmm3, 0x58(%rsp)
callq 0xccaf5
movsd %xmm0, 0x30(%rsp)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
movsd 0x70(%rsp), %xmm2
movsd 0x58(%rsp), %xmm3
callq 0xccaf5
movsd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x13cf7(%rip), %xmm1    # 0xe5cb0
divsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm0
movapd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd (%rsp), %xmm0
addsd %xmm0, %xmm1
movsd %xmm1, (%r14)
subsd %xmm0, %xmm1
andpd 0x13259(%rip), %xmm1    # 0xe5240
ucomisd 0x4f661(%rip), %xmm1    # 0x121650
movq 0x38(%rsp), %rax
jbe 0xd1ffa
andl $0x0, 0x3c(%rbx)
cmpl $0x1, (%rax)
movsd 0x28(%rsp), %xmm0
jne 0xd202a
leaq 0x4ff9e(%rip), %rsi     # 0x121faa
leaq 0x80(%rsp), %r14
movq %r14, %rdi
movb $0x1, %al
callq 0x8090
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8690
addq $0x888, %rsp            # imm = 0x888
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq