// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../external/HyRec2020/hydrogen.c
// Function: rec_HMLA_2photon_dxHIIdlna
double rec_HMLA_2photon_dxHIIdlna(HYREC_DATA *data, double xe, double xHII, double nH, double H, double TM, double TR,
                                  unsigned iz, double z) {

  REC_COSMOPARAMS *cosmo = data->cosmo;
  HYREC_ATOMIC *atomic = data->atomic;
  int *error = &data->error;
  double **Dfminus_hist = data->rad->Dfminus_hist;
  double **Dfminus_Ly_hist = data->rad->Dfminus_Ly_hist;
  double **Dfnu_hist = data->rad->Dfnu_hist;
  double zstart = data->rad->z0;
  double fsR = cosmo->fsR, meR = cosmo->meR;

  double xr[2], xv[NVIRT], Dfplus[NVIRT], Dfplus_Ly[2]; /* Assume incoming radiation blueward of Ly-gamma is Blackbody */
  double dxedlna, one_minus_Pib, one_minus_exptau, Dfeq, s, x1s, Dxe2;
  unsigned b, i;

  double Trr[2][2];
  double *Trv[2];
  double *Tvr[2];
  double *Tvv[3];
  double sr[2];
  double sv[NVIRT];
  double Dtau[NVIRT];
  double Alpha[2], DAlpha[2], Beta[2];
  double ratio;
  char sub_message[128];
  if (*error == 1) return 0.;

  ratio = TM/TR;
  rescale_T(&TR, fsR, meR);
  TM    = ratio * TR;   /* This way ensure that TM<=TR is preserved */

  for (i = 0; i < 2; i++) Trv[i] = create_1D_array(NVIRT, error, data->error_message);
  for (i = 0; i < 2; i++) Tvr[i] = create_1D_array(NVIRT, error, data->error_message);
  for (i = 0; i < 3; i++) Tvv[i] = create_1D_array(NVIRT, error, data->error_message);

  /* Redshift photon occupation number from previous times and higher energy bins */
  fplus_from_fminus(Dfplus, Dfplus_Ly, Dfminus_hist, Dfminus_Ly_hist, TR, zstart, iz, z, atomic->Eb_tab);

  /* Compute real-real, real-virtual and virtual-virtual transition rates */
  populateTS_2photon(Trr, Trv, Tvr, Tvv, sr, sv, Dtau, xe, xHII, TM, TR, nH, H, atomic,
                     Dfplus, Dfplus_Ly, Alpha, DAlpha, Beta, fsR, meR, cosmo->inj_params->exclya, error, data->error_message);
  if (*error == 1) {
    sprintf(sub_message, "  called from rec_HMLA_2photon_dxHIIdlna\n");
    strcat(data->error_message, sub_message);
    return 0.;
  }

  /* Solve for the population of the real and virtual states
     (in fact, for the difference xi - xi[eq with 1s]) */
  solve_real_virt(xr, xv, Trr, Trv, Tvr, Tvv, sr, sv, error, data->error_message);

  /* Obtain xe_dot */
  x1s  = 1.-xHII;
  s    = SAHA_FACT(fsR, meR) *TR*sqrt(TR) *exp(-EI/TR)/nH;
  Dxe2 = xe*xHII - s*x1s;

  dxedlna = -(nH *(s*x1s*DAlpha[0] + Alpha[0]*Dxe2) - xr[0]*Beta[0]
             +nH *(s*x1s*DAlpha[1] + Alpha[1]*Dxe2) - xr[1]*Beta[1])/H
          + cosmo->inj_params->ion/H;     /* First term automatically includes the additional excitations
                          since x2s, x2p are computed accounting for them */

  /* Update fminuses */

  for (b = 0; b < NVIRT; b++) {
    if (Dtau[b] > 1e-30) {
      one_minus_Pib = Dtau[b] > 1e-6 ? 1.- (1.-exp(-Dtau[b]))/Dtau[b] : Dtau[b]/2. - square(Dtau[b])/6.;
      Dfeq  = -xr[0]*Tvr[0][b] - xr[1]*Tvr[1][b];
      Dfeq -=  (b == 0       ?  xv[1]*Tvv[2][0]:
                b == NVIRT-1 ?  xv[NVIRT-2]*Tvv[1][NVIRT-1]:
                xv[b+1]*Tvv[2][b] + xv[b-1]*Tvv[1][b]);
      Dfeq /= x1s*one_minus_Pib*Tvv[0][b];
      one_minus_exptau = Dtau[b] > 1e-6 ? 1.-exp(-Dtau[b]) : Dtau[b] - square(Dtau[b])/2.;

      Dfminus_hist[b][iz] = Dfplus[b] + (Dfeq - Dfplus[b])*one_minus_exptau;
    }
    else Dfminus_hist[b][iz] = Dfplus[b];
  }

  Dfminus_Ly_hist[0][iz] = xr[1]/3./x1s;
  Dfminus_Ly_hist[1][iz] = xr[0]/x1s*exp(-E32/TR);
  Dfminus_Ly_hist[2][iz] = xr[0]/x1s*exp(-E42/TR);

  /* Average radiation field in each bin */
  for (b = 0; b < NVIRT; b++) Dfnu_hist[b][iz] = xv[b]/x1s;

  for (i = 0; i < 2; i++) free(Trv[i]);
  for (i = 0; i < 2; i++) free(Tvr[i]);
  for (i = 0; i < 3; i++) free(Tvv[i]);

  return dxedlna;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28a8, %rsp           # imm = 0x28A8
movl %esi, 0x70(%rsp)
movsd %xmm4, 0x10(%rsp)
movsd %xmm3, 0x68(%rsp)
movsd %xmm2, 0x58(%rsp)
movsd %xmm0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
cmpl $0x1, 0x38(%rdi)
je 0xdbcbb
movq %rdi, %r15
movsd %xmm6, 0x38(%rsp)
movsd %xmm1, 0x8(%rsp)
movq (%rdi), %rbp
movq 0x8(%rdi), %rdx
leaq 0x38(%rdi), %r12
movq 0x58(%rdi), %rax
movq 0x10(%rax), %r14
movq 0x20(%rax), %rcx
movq %rcx, 0x98(%rsp)
movq 0x18(%rax), %rcx
movq %rcx, 0x110(%rsp)
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x98(%rdx), %xmm0
movq %rdx, 0x40(%rsp)
movsd 0xa0(%rdx), %xmm1
movsd %xmm0, 0xc0(%rsp)
mulsd %xmm0, %xmm0
movsd %xmm1, 0xb0(%rsp)
mulsd %xmm1, %xmm0
movsd %xmm5, 0x60(%rsp)
movapd %xmm5, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
xorl %ebx, %ebx
movq 0x48(%r15), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
callq 0xd6f5e
movq %rax, 0xf0(%rsp,%rbx,8)
incq %rbx
cmpq $0x1, %rbx
je 0xdb5a4
movsd 0x10(%rsp), %xmm0
divsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %ebx, %ebx
movq 0x48(%r15), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
callq 0xd6f5e
movq %rax, 0x80(%rsp,%rbx,8)
incq %rbx
cmpq $0x1, %rbx
je 0xdb5da
xorl %ebx, %ebx
movq 0x48(%r15), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
callq 0xd6f5e
movq %rax, 0xd0(%rsp,%rbx,8)
incq %rbx
cmpq $0x3, %rbx
jne 0xdb5fe
movsd 0x10(%rsp), %xmm0
mulsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x7b0(%rbp), %r9
leaq 0xb70(%rsp), %rbx
leaq 0x1a0(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq 0x98(%rsp), %rcx
movsd 0x48(%rsp), %xmm1
movl 0x70(%rsp), %r8d
movsd 0x38(%rsp), %xmm2
callq 0xdb1c1
movq 0x40(%rsp), %rax
movq 0xb8(%rax), %rax
movsd 0x68(%rax), %xmm0
movq 0x48(%r15), %rax
subq $0x50, %rsp
movq %rax, 0x48(%rsp)
movq %r12, 0x40(%rsp)
movsd %xmm0, 0x38(%rsp)
leaq 0x170(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x180(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x190(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movq %rbp, 0x8(%rsp)
leaq 0x1580(%rsp), %rax
movq %rax, (%rsp)
leaq 0x1d0(%rsp), %rdi
leaq 0x140(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
leaq 0x120(%rsp), %rcx
leaq 0x1c0(%rsp), %r13
leaq 0x1f40(%rsp), %rbx
movq %r13, %r8
movq %rbx, %r9
movsd 0xa0(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
movsd 0x78(%rsp), %xmm3
movsd 0xa8(%rsp), %xmm4
movsd 0xb8(%rsp), %xmm5
movsd 0x110(%rsp), %xmm6
movsd 0x100(%rsp), %xmm7
callq 0xda227
addq $0x50, %rsp
cmpl $0x1, 0x38(%r15)
jne 0xdb798
movups 0x51fb3(%rip), %xmm0    # 0x12d71a
leaq 0x1b0(%rsp), %rsi
movups %xmm0, 0x1a(%rsi)
movaps 0x51f96(%rip), %xmm0    # 0x12d710
movaps %xmm0, 0x10(%rsi)
movapd 0x51f7a(%rip), %xmm0    # 0x12d700
movapd %xmm0, (%rsi)
movq 0x48(%r15), %rdi
callq 0x8660
jmp 0xdbcbb
leaq 0x150(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
leaq 0x180(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
leaq 0x80(%rsp), %r8
leaq 0xd0(%rsp), %r9
pushq 0x48(%r15)
pushq %r12
pushq %rbx
pushq %r13
callq 0xdae01
addq $0x20, %rsp
movsd 0x15a7e(%rip), %xmm0    # 0xf1260
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0xc0(%rsp), %xmm0
mulsd 0xb0(%rsp), %xmm0
callq 0xd6f51
movapd %xmm0, %xmm2
mulsd 0x51b0f(%rip), %xmm2    # 0x12d320
movsd 0x28(%rsp), %xmm1
mulsd %xmm1, %xmm2
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jb 0xdb82e
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0xdb849
movapd %xmm1, %xmm0
movsd %xmm2, 0x10(%rsp)
callq 0x82b0
movsd 0x10(%rsp), %xmm2
movsd 0x28(%rsp), %xmm1
mulsd %xmm2, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x51af5(%rip), %xmm0    # 0x12d350
divsd %xmm1, %xmm0
callq 0x8670
movapd %xmm0, %xmm2
mulsd 0x10(%rsp), %xmm2
movsd 0x58(%rsp), %xmm3
divsd %xmm3, %xmm2
mulsd 0x38(%rsp), %xmm2
movsd 0x50(%rsp), %xmm4
mulsd 0x8(%rsp), %xmm4
subsd %xmm2, %xmm4
movsd 0x140(%rsp), %xmm0
mulsd %xmm4, %xmm0
movsd 0x130(%rsp), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x150(%rsp), %xmm5
movsd 0x158(%rsp), %xmm6
movapd 0x1596a(%rip), %xmm7    # 0xf1230
movapd %xmm5, %xmm0
xorpd %xmm7, %xmm0
movapd %xmm0, 0xb0(%rsp)
movsd 0x120(%rsp), %xmm0
movapd %xmm5, 0xa0(%rsp)
mulsd %xmm5, %xmm0
mulsd %xmm3, %xmm1
mulsd 0x148(%rsp), %xmm4
subsd %xmm0, %xmm1
mulsd 0x138(%rsp), %xmm2
addsd %xmm4, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
xorpd %xmm6, %xmm7
movapd %xmm7, 0xc0(%rsp)
movsd 0x128(%rsp), %xmm0
movapd %xmm6, 0x160(%rsp)
mulsd %xmm6, %xmm0
subsd %xmm0, %xmm2
movq 0x40(%rsp), %rax
movq 0xb8(%rax), %rax
movsd 0x60(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
divsd 0x68(%rsp), %xmm2
movsd %xmm2, 0x108(%rsp)
movq 0x80(%rsp), %r15
movq 0x88(%rsp), %r12
movsd 0xb58(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0xd0(%rsp), %r13
movq 0xd8(%rsp), %rax
movq %rax, 0x40(%rsp)
movsd 0x1b8(%rsp), %xmm0
movsd %xmm0, 0x118(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x48(%rsp)
movl 0x70(%rsp), %ebx
xorl %ebp, %ebp
movsd 0x1588f(%rip), %xmm0    # 0xf1250
movsd 0x1530(%rsp,%rbp,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xdba15
ucomisd 0x16318(%rip), %xmm1    # 0xf1cf0
movapd %xmm1, 0x10(%rsp)
jbe 0xdba23
movapd %xmm1, %xmm0
xorpd 0x15844(%rip), %xmm0    # 0xf1230
callq 0x8670
movapd 0x10(%rsp), %xmm3
movsd 0x15861(%rip), %xmm2    # 0xf1260
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
divsd %xmm3, %xmm1
movapd %xmm2, %xmm0
subsd %xmm1, %xmm0
jmp 0xdba52
movsd 0xb70(%rsp,%rbp,8), %xmm2
jmp 0xdbb77
movapd %xmm1, %xmm0
mulsd 0x162a1(%rip), %xmm0    # 0xf1cd0
movapd %xmm0, 0x70(%rsp)
movapd %xmm1, %xmm0
callq 0xd6f4c
movapd 0x10(%rsp), %xmm3
divsd 0x16c1c(%rip), %xmm0    # 0xf2668
addsd 0x70(%rsp), %xmm0
movsd (%r12,%rbp,8), %xmm1
mulsd 0xc0(%rsp), %xmm1
movsd %xmm1, 0x50(%rsp)
movsd (%r15,%rbp,8), %xmm2
mulsd 0xb0(%rsp), %xmm2
cmpl $0x136, %ebp            # imm = 0x136
movsd 0x38(%rsp), %xmm1
je 0xdba9c
testl %ebp, %ebp
jne 0xdbab7
movq 0x48(%rsp), %rax
movsd (%rax), %xmm4
mulsd 0x118(%rsp), %xmm4
jmp 0xdbaaf
movq 0x40(%rsp), %rax
movsd 0x9b0(%rax), %xmm4
mulsd 0x60(%rsp), %xmm4
movsd %xmm4, 0x8(%rsp)
jmp 0xdbae7
movsd 0x1a8(%rsp,%rbp,8), %xmm4
movq 0x40(%rsp), %rax
mulsd (%rax,%rbp,8), %xmm4
movsd 0x1b8(%rsp,%rbp,8), %xmm5
movq 0x48(%rsp), %rax
mulsd (%rax,%rbp,8), %xmm5
addsd %xmm4, %xmm5
movsd %xmm5, 0x8(%rsp)
movsd %xmm2, 0x70(%rsp)
ucomisd 0x161fb(%rip), %xmm3    # 0xf1cf0
mulsd %xmm1, %xmm0
mulsd (%r13,%rbp,8), %xmm0
movsd %xmm0, 0x58(%rsp)
jbe 0xdbb2b
xorpd 0x15720(%rip), %xmm3    # 0xf1230
movapd %xmm3, %xmm0
callq 0x8670
movapd %xmm0, %xmm1
movsd 0x1573b(%rip), %xmm0    # 0xf1260
subsd %xmm1, %xmm0
jmp 0xdbb42
movapd %xmm3, %xmm0
callq 0xd6f4c
mulsd 0x1892c(%rip), %xmm0    # 0xf4468
addsd 0x10(%rsp), %xmm0
movsd 0x70(%rsp), %xmm2
addsd 0x50(%rsp), %xmm2
subsd 0x8(%rsp), %xmm2
divsd 0x58(%rsp), %xmm2
movsd 0xb70(%rsp,%rbp,8), %xmm1
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd 0x156d9(%rip), %xmm0    # 0xf1250
movq (%r14,%rbp,8), %rax
movsd %xmm2, (%rax,%rbx,8)
incq %rbp
cmpq $0x137, %rbp            # imm = 0x137
jne 0xdb9c1
movsd 0x30(%rsp), %xmm0
divsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movapd 0x160(%rsp), %xmm0
divsd 0x16acd(%rip), %xmm0    # 0xf2680
movsd 0x38(%rsp), %xmm1
divsd %xmm1, %xmm0
movq 0x98(%rsp), %r14
movq (%r14), %rax
movsd %xmm0, (%rax,%rbx,8)
movapd 0xa0(%rsp), %xmm0
divsd %xmm1, %xmm0
movapd %xmm0, 0xa0(%rsp)
movsd 0x517cd(%rip), %xmm0    # 0x12d3b8
divsd 0x28(%rsp), %xmm0
callq 0x8670
mulsd 0xa0(%rsp), %xmm0
movq 0x8(%r14), %rax
movsd %xmm0, (%rax,%rbx,8)
movsd 0x517b0(%rip), %xmm0    # 0x12d3c0
divsd 0x28(%rsp), %xmm0
callq 0x8670
movsd 0x38(%rsp), %xmm1
mulsd 0xa0(%rsp), %xmm0
movq 0x10(%r14), %rax
movsd %xmm0, (%rax,%rbx,8)
xorl %eax, %eax
movq 0x110(%rsp), %rdx
movsd 0x1b0(%rsp,%rax,8), %xmm0
divsd %xmm1, %xmm0
movq (%rdx,%rax,8), %rcx
movsd %xmm0, (%rcx,%rbx,8)
incq %rax
cmpq $0x137, %rax            # imm = 0x137
jne 0xdbc3d
xorl %ebx, %ebx
movq 0xf0(%rsp,%rbx,8), %rdi
callq 0x8410
incq %rbx
cmpq $0x1, %rbx
je 0xdbc60
xorl %ebx, %ebx
movq 0x80(%rsp,%rbx,8), %rdi
callq 0x8410
incq %rbx
cmpq $0x1, %rbx
je 0xdbc78
xorl %ebx, %ebx
movq 0xd0(%rsp,%rbx,8), %rdi
callq 0x8410
incq %rbx
cmpq $0x3, %rbx
jne 0xdbc90
movsd 0x30(%rsp), %xmm0
subsd 0x108(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
addq $0x28a8, %rsp           # imm = 0x28A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq