// File: /workspace/github_c_makefile_star2_O1/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
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
movq 0x8(%rdi), %rbp
movsd 0x10(%rdi), %xmm1
movsd 0xa8(%rbp), %xmm3
cmpl $0xa, %r8d
je 0xdd260
divsd 0x14590(%rip), %xmm3    # 0xf17f0
movapd %xmm3, 0x10(%rsp)
divsd %xmm0, %xmm1
leaq 0x38(%rbx), %rdx
movsd (%r12), %xmm0
ucomisd 0x1456c(%rip), %xmm0    # 0xf17e8
movsd %xmm2, 0x28(%rsp)
movq %rdx, 0x38(%rsp)
movsd %xmm1, 0x30(%rsp)
jne 0xdd29f
jp 0xdd29f
movq %rbp, %rdi
movapd %xmm2, %xmm0
callq 0xdc084
jmp 0xdd2b6
leaq 0x80(%rsp), %rcx
xorpd %xmm0, %xmm0
movq %r12, %rdi
movl %r13d, %esi
callq 0xd727d
movsd %xmm0, (%rsp)
movsd (%r14), %xmm1
movq %rbp, %rdi
movsd 0x28(%rsp), %xmm0
callq 0xd7b30
movaps %xmm0, %xmm1
movsd (%r14), %xmm2
movq %rbx, %rdi
movsd 0x28(%rsp), %xmm0
movsd (%rsp), %xmm3
callq 0xd7cf2
cmpl $0x1, 0x3c(%rbx)
jne 0xdd426
movsd 0x13f65(%rip), %xmm0    # 0xf1260
movsd %xmm0, 0x8(%rsp)
movsd 0x28(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movapd 0x10(%rsp), %xmm0
xorpd 0x13f12(%rip), %xmm0    # 0xf1230
callq 0x8670
mulsd (%rsp), %xmm0
addsd 0x144b8(%rip), %xmm0    # 0xf17e8
movsd %xmm0, 0x10(%rsp)
movq %rbp, %rdi
callq 0xd79bc
movsd %xmm0, (%rsp)
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x17107(%rip), %xmm0    # 0xf4468
addsd %xmm1, %xmm0
movq %rbp, %rdi
callq 0xd79bc
movapd %xmm0, 0x40(%rsp)
movsd 0x14955(%rip), %xmm0    # 0xf1cd0
addsd 0x10(%rsp), %xmm0
movq %rbp, %rdi
callq 0xd79bc
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 0x16bf8(%rip), %xmm0    # 0xf3fb0
movsd %xmm0, 0x8(%rsp)
addsd %xmm0, %xmm1
movq %rbp, %rdi
movsd 0x10(%rsp), %xmm0
movsd %xmm1, 0x78(%rsp)
callq 0xd7b30
movsd %xmm0, 0x68(%rsp)
movsd (%rsp), %xmm1
subsd 0x8(%rsp), %xmm1
movq %rbp, %rdi
movsd 0x10(%rsp), %xmm0
movsd %xmm1, 0x70(%rsp)
callq 0xd7b30
movsd %xmm0, 0x60(%rsp)
movsd (%r12), %xmm0
ucomisd 0x143d9(%rip), %xmm0    # 0xf17e8
jne 0xdd482
jp 0xdd482
movq %rbp, %rdi
movsd 0x10(%rsp), %xmm0
callq 0xdc084
jmp 0xdd4aa
movsd (%r15), %xmm1
movsd 0x8(%r15), %xmm2
movsd 0x30617(%rip), %xmm3    # 0x10da50
mulsd %xmm1, %xmm3
movapd %xmm0, %xmm4
mulsd 0x50357(%rip), %xmm4    # 0x12d7a0
mulsd 0x50357(%rip), %xmm2    # 0x12d7a8
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 0xdd54a
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 0xd727d
movapd %xmm0, %xmm3
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x68(%rsp), %xmm1
movsd 0x78(%rsp), %xmm2
movsd %xmm3, 0x58(%rsp)
callq 0xd7cf2
movsd %xmm0, 0x30(%rsp)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
movsd 0x70(%rsp), %xmm2
movsd 0x58(%rsp), %xmm3
callq 0xd7cf2
movsd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x147ca(%rip), %xmm1    # 0xf1cd0
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 0x13d0c(%rip), %xmm1    # 0xf1240
ucomisd 0x50274(%rip), %xmm1    # 0x12d7b0
movq 0x38(%rsp), %rax
jbe 0xdd54a
movl $0x0, 0x3c(%rbx)
cmpl $0x1, (%rax)
movsd 0x28(%rsp), %xmm0
jne 0xdd57a
leaq 0x50bae(%rip), %rsi     # 0x12e10a
leaq 0x80(%rsp), %r14
movq %r14, %rdi
movb $0x1, %al
callq 0x8090
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8660
addq $0x888, %rsp            # imm = 0x888
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq