// File: /workspace/github_c_makefile_star2_O3/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 $0x2898, %rsp           # imm = 0x2898
movl %esi, 0x80(%rsp)
movsd %xmm3, 0x78(%rsp)
movsd %xmm2, 0x58(%rsp)
movsd %xmm0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
cmpl $0x1, 0x38(%rdi)
je 0xd8531
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, 0xa8(%rsp)
movq 0x18(%rax), %rcx
movq %rcx, 0x100(%rsp)
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x98(%rdx), %xmm0
movq %rdx, 0x40(%rsp)
movsd 0xa0(%rdx), %xmm1
movsd %xmm0, 0xd0(%rsp)
mulsd %xmm0, %xmm0
movsd %xmm1, 0xc0(%rsp)
mulsd %xmm1, %xmm0
movapd %xmm5, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movq 0x48(%rdi), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
movsd %xmm4, 0x10(%rsp)
movsd %xmm5, 0x70(%rsp)
callq 0xd3766
movq %rax, 0x90(%rsp)
movq 0x48(%r15), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
callq 0xd3766
movq %rax, 0x98(%rsp)
movsd 0x10(%rsp), %xmm0
divsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x48(%r15), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
callq 0xd3766
movq %rax, 0x60(%rsp)
movq 0x48(%r15), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
callq 0xd3766
movq %rax, 0x68(%rsp)
xorl %ebx, %ebx
movq 0x48(%r15), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
callq 0xd3766
movq %rax, 0xe0(%rsp,%rbx,8)
incq %rbx
cmpq $0x3, %rbx
jne 0xd7e6d
movsd 0x10(%rsp), %xmm0
mulsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x7b0(%rbp), %r9
leaq 0xb60(%rsp), %rbx
leaq 0x190(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq 0xa8(%rsp), %rcx
movsd 0x48(%rsp), %xmm1
movl 0x80(%rsp), %r8d
movsd 0x38(%rsp), %xmm2
callq 0xd7a17
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 0x160(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x170(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x180(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movq %rbp, 0x8(%rsp)
leaq 0x1570(%rsp), %rax
movq %rax, (%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
leaq 0x130(%rsp), %rcx
leaq 0x1b0(%rsp), %r13
leaq 0x1f30(%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 0xc8(%rsp), %xmm5
movsd 0x120(%rsp), %xmm6
movsd 0x110(%rsp), %xmm7
callq 0xd6a8f
addq $0x50, %rsp
cmpl $0x1, 0x38(%r15)
jne 0xd800a
movups 0x52771(%rip), %xmm0    # 0x12a74a
leaq 0x1a0(%rsp), %rsi
movups %xmm0, 0x1a(%rsi)
movaps 0x52754(%rip), %xmm0    # 0x12a740
movaps %xmm0, 0x10(%rsi)
movapd 0x52738(%rip), %xmm0    # 0x12a730
movapd %xmm0, (%rsi)
movq 0x48(%r15), %rdi
callq 0x8660
jmp 0xd8531
leaq 0x140(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
leaq 0x170(%rsp), %rdx
leaq 0x90(%rsp), %rcx
leaq 0x60(%rsp), %r8
leaq 0xe0(%rsp), %r9
pushq 0x48(%r15)
pushq %r12
pushq %rbx
pushq %r13
callq 0xd764d
addq $0x20, %rsp
movsd 0x1620f(%rip), %xmm0    # 0xee260
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0xd0(%rsp), %xmm0
mulsd 0xc0(%rsp), %xmm0
callq 0xd3759
movapd %xmm0, %xmm2
mulsd 0x522d0(%rip), %xmm2    # 0x12a350
movsd 0x28(%rsp), %xmm1
mulsd %xmm1, %xmm2
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jb 0xd809d
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0xd80b8
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 0x522b6(%rip), %xmm0    # 0x12a380
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 0x130(%rsp), %xmm0
mulsd %xmm4, %xmm0
movsd 0x120(%rsp), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x140(%rsp), %xmm5
movsd 0x148(%rsp), %xmm6
movapd 0x160fb(%rip), %xmm7    # 0xee230
movapd %xmm5, %xmm0
xorpd %xmm7, %xmm0
movapd %xmm0, 0xc0(%rsp)
movsd 0x110(%rsp), %xmm0
movapd %xmm5, 0xb0(%rsp)
mulsd %xmm5, %xmm0
mulsd %xmm3, %xmm1
mulsd 0x138(%rsp), %xmm4
subsd %xmm0, %xmm1
mulsd 0x128(%rsp), %xmm2
addsd %xmm4, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
xorpd %xmm6, %xmm7
movapd %xmm7, 0xd0(%rsp)
movsd 0x118(%rsp), %xmm0
movapd %xmm6, 0x150(%rsp)
mulsd %xmm6, %xmm0
subsd %xmm0, %xmm2
movq 0x40(%rsp), %rax
movq 0xb8(%rax), %rax
movsd 0x60(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
divsd 0x78(%rsp), %xmm2
movsd %xmm2, 0xf8(%rsp)
movl 0x80(%rsp), %ebx
movq 0x60(%rsp), %r15
movq 0x68(%rsp), %r12
movsd 0xb48(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movq 0xe0(%rsp), %r13
movq 0xe8(%rsp), %rax
movq %rax, 0x40(%rsp)
movsd 0x1a8(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x48(%rsp)
xorl %ebp, %ebp
movsd 0x16023(%rip), %xmm0    # 0xee250
movsd 0x1520(%rsp,%rbp,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xd8281
ucomisd 0x16aac(%rip), %xmm1    # 0xeecf0
movapd %xmm1, 0x10(%rsp)
jbe 0xd828f
movapd %xmm1, %xmm0
xorpd 0x15fd8(%rip), %xmm0    # 0xee230
callq 0x8670
movapd 0x10(%rsp), %xmm3
movsd 0x15ff5(%rip), %xmm2    # 0xee260
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
divsd %xmm3, %xmm1
movapd %xmm2, %xmm0
subsd %xmm1, %xmm0
jmp 0xd82c4
movsd 0xb60(%rsp,%rbp,8), %xmm2
jmp 0xd83ef
movapd %xmm1, %xmm0
mulsd 0x16a35(%rip), %xmm0    # 0xeecd0
movapd %xmm0, 0x80(%rsp)
movapd %xmm1, %xmm0
callq 0xd3754
movapd 0x10(%rsp), %xmm3
divsd 0x173ad(%rip), %xmm0    # 0xef668
addsd 0x80(%rsp), %xmm0
movsd (%r12,%rbp,8), %xmm1
mulsd 0xd0(%rsp), %xmm1
movsd %xmm1, 0x50(%rsp)
movsd (%r15,%rbp,8), %xmm2
mulsd 0xc0(%rsp), %xmm2
cmpl $0x136, %ebp            # imm = 0x136
movsd 0x38(%rsp), %xmm1
je 0xd830e
testl %ebp, %ebp
jne 0xd8329
movq 0x48(%rsp), %rax
movsd (%rax), %xmm4
mulsd 0x108(%rsp), %xmm4
jmp 0xd8321
movq 0x40(%rsp), %rax
movsd 0x9b0(%rax), %xmm4
mulsd 0x70(%rsp), %xmm4
movsd %xmm4, 0x8(%rsp)
jmp 0xd8359
movsd 0x198(%rsp,%rbp,8), %xmm4
movq 0x40(%rsp), %rax
mulsd (%rax,%rbp,8), %xmm4
movsd 0x1a8(%rsp,%rbp,8), %xmm5
movq 0x48(%rsp), %rax
mulsd (%rax,%rbp,8), %xmm5
addsd %xmm4, %xmm5
movsd %xmm5, 0x8(%rsp)
movsd %xmm2, 0x80(%rsp)
ucomisd 0x16986(%rip), %xmm3    # 0xeecf0
mulsd %xmm1, %xmm0
mulsd (%r13,%rbp,8), %xmm0
movsd %xmm0, 0x58(%rsp)
jbe 0xd83a0
xorpd 0x15eab(%rip), %xmm3    # 0xee230
movapd %xmm3, %xmm0
callq 0x8670
movapd %xmm0, %xmm1
movsd 0x15ec6(%rip), %xmm0    # 0xee260
subsd %xmm1, %xmm0
jmp 0xd83b7
movapd %xmm3, %xmm0
callq 0xd3754
mulsd 0x190c7(%rip), %xmm0    # 0xf1478
addsd 0x10(%rsp), %xmm0
movsd 0x80(%rsp), %xmm2
addsd 0x50(%rsp), %xmm2
subsd 0x8(%rsp), %xmm2
divsd 0x58(%rsp), %xmm2
movsd 0xb60(%rsp,%rbp,8), %xmm1
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd 0x15e61(%rip), %xmm0    # 0xee250
movq (%r14,%rbp,8), %rax
movsd %xmm2, (%rax,%rbx,8)
incq %rbp
cmpq $0x137, %rbp            # imm = 0x137
jne 0xd822d
movsd 0x30(%rsp), %xmm0
divsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movapd 0x150(%rsp), %xmm0
divsd 0x17255(%rip), %xmm0    # 0xef680
movsd 0x38(%rsp), %xmm1
divsd %xmm1, %xmm0
movq 0xa8(%rsp), %r14
movq (%r14), %rax
movsd %xmm0, (%rax,%rbx,8)
movapd 0xb0(%rsp), %xmm0
divsd %xmm1, %xmm0
movapd %xmm0, 0xb0(%rsp)
movsd 0x51f85(%rip), %xmm0    # 0x12a3e8
divsd 0x28(%rsp), %xmm0
callq 0x8670
mulsd 0xb0(%rsp), %xmm0
movq 0x8(%r14), %rax
movsd %xmm0, (%rax,%rbx,8)
movsd 0x51f68(%rip), %xmm0    # 0x12a3f0
divsd 0x28(%rsp), %xmm0
callq 0x8670
movsd 0x38(%rsp), %xmm1
mulsd 0xb0(%rsp), %xmm0
movq 0x10(%r14), %rax
movsd %xmm0, (%rax,%rbx,8)
xorl %eax, %eax
movq 0x100(%rsp), %rdx
movsd 0x1a0(%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 0xd84b5
movq 0x90(%rsp), %rdi
callq 0x8410
movq 0x98(%rsp), %rdi
callq 0x8410
movq 0x60(%rsp), %rdi
callq 0x8410
movq 0x68(%rsp), %rdi
callq 0x8410
xorl %ebx, %ebx
movq 0xe0(%rsp,%rbx,8), %rdi
callq 0x8410
incq %rbx
cmpq $0x3, %rbx
jne 0xd8506
movsd 0x30(%rsp), %xmm0
subsd 0xf8(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
addq $0x2898, %rsp           # imm = 0x2898
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq