// File: /workspace/github_c_makefile_star2_O2/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, 0x58(%rsp)
movsd %xmm4, 0x30(%rsp)
movsd %xmm3, 0x68(%rsp)
movsd %xmm2, 0x50(%rsp)
movsd %xmm0, 0x18(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
cmpl $0x1, 0x38(%rdi)
je 0xd088e
movq %rdi, %r15
movsd %xmm6, 0x10(%rsp)
movsd %xmm1, 0x70(%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, 0x100(%rsp)
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x98(%rdx), %xmm0
movq %rdx, 0x28(%rsp)
movsd 0xa0(%rdx), %xmm1
movsd %xmm0, 0xb0(%rsp)
mulsd %xmm0, %xmm0
movsd %xmm1, 0x20(%rsp)
mulsd %xmm1, %xmm0
movapd %xmm5, %xmm3
divsd %xmm0, %xmm3
xorl %ebx, %ebx
movsd %xmm3, (%rsp)
movsd %xmm5, 0x40(%rsp)
cmpq $0x2, %rbx
je 0xd019e
movq 0x48(%r15), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
callq 0xcbe5a
movsd 0x40(%rsp), %xmm5
movsd (%rsp), %xmm3
movq %rax, 0xe0(%rsp,%rbx,8)
incq %rbx
jmp 0xd016f
movsd 0x30(%rsp), %xmm0
divsd %xmm5, %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0xd01d9
movq 0x48(%r15), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
callq 0xcbe5a
movsd (%rsp), %xmm3
movq %rax, 0x80(%rsp,%rbx,8)
incq %rbx
jmp 0xd01b0
xorl %ebx, %ebx
cmpq $0x3, %rbx
je 0xd0204
movq 0x48(%r15), %rdx
movl $0x137, %edi            # imm = 0x137
movq %r12, %rsi
callq 0xcbe5a
movsd (%rsp), %xmm3
movq %rax, 0xc0(%rsp,%rbx,8)
incq %rbx
jmp 0xd01db
movsd 0x30(%rsp), %xmm0
mulsd %xmm3, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x7b0(%rbp), %r9
leaq 0xb60(%rsp), %rbx
leaq 0x190(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq 0x98(%rsp), %rcx
movsd 0x60(%rsp), %xmm1
movl 0x58(%rsp), %r8d
movsd 0x10(%rsp), %xmm2
callq 0xcfd8a
movq 0x28(%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 0x130(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
leaq 0x110(%rsp), %rcx
leaq 0x1b0(%rsp), %r13
leaq 0x1f30(%rsp), %rbx
movq %r13, %r8
movq %rbx, %r9
movsd 0x68(%rsp), %xmm0
movsd 0xc0(%rsp), %xmm1
movsd 0x80(%rsp), %xmm2
movsd 0x50(%rsp), %xmm3
movsd 0xa0(%rsp), %xmm4
movsd 0xb8(%rsp), %xmm5
movsd 0x100(%rsp), %xmm6
movsd 0x70(%rsp), %xmm7
callq 0xcee0a
addq $0x50, %rsp
cmpl $0x1, 0x38(%r15)
jne 0xd037a
movups 0x51271(%rip), %xmm0    # 0x1215ba
leaq 0x1a0(%rsp), %rsi
movups %xmm0, 0x1a(%rsi)
movaps 0x51254(%rip), %xmm0    # 0x1215b0
movaps %xmm0, 0x10(%rsi)
movapd 0x51238(%rip), %xmm0    # 0x1215a0
movapd %xmm0, (%rsi)
movq 0x48(%r15), %rdi
callq 0x8690
jmp 0xd088e
leaq 0x140(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
leaq 0x170(%rsp), %rdx
leaq 0xe0(%rsp), %rcx
leaq 0x80(%rsp), %r8
leaq 0xc0(%rsp), %r9
pushq 0x48(%r15)
pushq %r12
pushq %rbx
pushq %r13
callq 0xcf9c1
addq $0x20, %rsp
movsd 0x14e9c(%rip), %xmm0    # 0xe5260
subsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0xb0(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0xcd0fc
movsd (%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jb 0xd0403
sqrtsd %xmm1, %xmm0
jmp 0xd0411
movapd %xmm1, %xmm0
callq 0x82d0
movsd (%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, 0x40(%rsp)
movsd 0x50df7(%rip), %xmm0    # 0x121220
divsd %xmm1, %xmm0
callq 0x86a0
movapd %xmm0, %xmm2
mulsd 0x40(%rsp), %xmm2
movsd 0x50(%rsp), %xmm3
divsd %xmm3, %xmm2
mulsd 0x10(%rsp), %xmm2
movsd 0x18(%rsp), %xmm4
mulsd 0x70(%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 0x14d9c(%rip), %xmm7    # 0xe5230
movapd %xmm5, %xmm0
xorpd %xmm7, %xmm0
movapd %xmm0, 0xb0(%rsp)
movsd 0x110(%rsp), %xmm0
movapd %xmm5, 0xa0(%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, 0x70(%rsp)
movsd 0x118(%rsp), %xmm0
movapd %xmm6, 0x150(%rsp)
mulsd %xmm6, %xmm0
subsd %xmm0, %xmm2
movq 0x28(%rsp), %rax
movq 0xb8(%rax), %rax
movsd 0x60(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
divsd 0x68(%rsp), %xmm2
movsd %xmm2, 0xf8(%rsp)
movl 0x58(%rsp), %ebx
movq 0x80(%rsp), %r15
movq 0x88(%rsp), %r12
movsd 0xb48(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0xc0(%rsp), %r13
movq 0xc8(%rsp), %rax
movq %rax, 0x28(%rsp)
movsd 0x1a8(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
movsd 0x14cc4(%rip), %xmm0    # 0xe5250
cmpq $0x137, %rbp            # imm = 0x137
je 0xd075d
movsd 0x1520(%rsp,%rbp,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xd05ed
ucomisd 0x15720(%rip), %xmm1    # 0xe5cd0
movapd %xmm1, 0x40(%rsp)
jbe 0xd05fb
movapd %xmm1, %xmm0
xorpd 0x14c6c(%rip), %xmm0    # 0xe5230
callq 0x86a0
movapd 0x40(%rsp), %xmm3
movsd 0x14c89(%rip), %xmm2    # 0xe5260
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
divsd %xmm3, %xmm1
movapd %xmm2, %xmm0
subsd %xmm1, %xmm0
jmp 0xd062a
movsd 0xb60(%rsp,%rbp,8), %xmm2
jmp 0xd074c
movapd %xmm1, %xmm0
mulsd 0x156a9(%rip), %xmm0    # 0xe5cb0
movapd %xmm0, 0x30(%rsp)
movapd %xmm1, %xmm0
callq 0xcbe48
movapd 0x40(%rsp), %xmm3
divsd 0x16024(%rip), %xmm0    # 0xe6648
addsd 0x30(%rsp), %xmm0
movsd (%r12,%rbp,8), %xmm1
mulsd 0x70(%rsp), %xmm1
movsd %xmm1, 0x50(%rsp)
movsd (%r15,%rbp,8), %xmm2
mulsd 0xb0(%rsp), %xmm2
cmpl $0x136, %ebp            # imm = 0x136
movsd 0x10(%rsp), %xmm1
je 0xd0671
testl %ebp, %ebp
jne 0xd068c
movq 0x20(%rsp), %rax
movsd (%rax), %xmm4
mulsd 0x108(%rsp), %xmm4
jmp 0xd0684
movq 0x28(%rsp), %rax
movsd 0x9b0(%rax), %xmm4
mulsd 0x60(%rsp), %xmm4
movsd %xmm4, 0x18(%rsp)
jmp 0xd06bc
movsd 0x198(%rsp,%rbp,8), %xmm4
movq 0x28(%rsp), %rax
mulsd (%rax,%rbp,8), %xmm4
movsd 0x1a8(%rsp,%rbp,8), %xmm5
movq 0x20(%rsp), %rax
mulsd (%rax,%rbp,8), %xmm5
addsd %xmm4, %xmm5
movsd %xmm5, 0x18(%rsp)
movsd %xmm2, 0x30(%rsp)
ucomisd 0x15606(%rip), %xmm3    # 0xe5cd0
mulsd %xmm1, %xmm0
mulsd (%r13,%rbp,8), %xmm0
movsd %xmm0, 0x58(%rsp)
jbe 0xd0700
xorpd 0x14b4b(%rip), %xmm3    # 0xe5230
movapd %xmm3, %xmm0
callq 0x86a0
movapd %xmm0, %xmm1
movsd 0x14b66(%rip), %xmm0    # 0xe5260
subsd %xmm1, %xmm0
jmp 0xd0717
movapd %xmm3, %xmm0
callq 0xcbe48
mulsd 0x17d27(%rip), %xmm0    # 0xe8438
addsd 0x40(%rsp), %xmm0
movsd 0x30(%rsp), %xmm2
addsd 0x50(%rsp), %xmm2
subsd 0x18(%rsp), %xmm2
divsd 0x58(%rsp), %xmm2
movsd 0xb60(%rsp,%rbp,8), %xmm1
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd 0x14b04(%rip), %xmm0    # 0xe5250
movq (%r14,%rbp,8), %rax
movsd %xmm2, (%rax,%rbx,8)
incq %rbp
jmp 0xd058c
movsd 0x8(%rsp), %xmm0
divsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movapd 0x150(%rsp), %xmm0
divsd 0x15fc8(%rip), %xmm0    # 0xe6748
movsd 0x10(%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 0x50ad0(%rip), %xmm0    # 0x121288
divsd (%rsp), %xmm0
callq 0x86a0
mulsd 0xa0(%rsp), %xmm0
movq 0x8(%r14), %rax
movsd %xmm0, (%rax,%rbx,8)
movsd 0x50ab4(%rip), %xmm0    # 0x121290
divsd (%rsp), %xmm0
callq 0x86a0
movsd 0x10(%rsp), %xmm1
mulsd 0xa0(%rsp), %xmm0
movq 0x10(%r14), %rax
movsd %xmm0, (%rax,%rbx,8)
xorl %eax, %eax
movq 0x100(%rsp), %rdx
cmpq $0x137, %rax            # imm = 0x137
je 0xd082b
movsd 0x1a0(%rsp,%rax,8), %xmm0
divsd %xmm1, %xmm0
movq (%rdx,%rax,8), %rcx
movsd %xmm0, (%rcx,%rbx,8)
incq %rax
jmp 0xd0808
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0xd0845
movq 0xe0(%rsp,%rbx,8), %rdi
callq 0x8430
incq %rbx
jmp 0xd082d
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0xd085f
movq 0x80(%rsp,%rbx,8), %rdi
callq 0x8430
incq %rbx
jmp 0xd0847
xorl %ebx, %ebx
cmpq $0x3, %rbx
je 0xd0879
movq 0xc0(%rsp,%rbx,8), %rdi
callq 0x8430
incq %rbx
jmp 0xd0861
movsd 0x8(%rsp), %xmm0
subsd 0xf8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
addq $0x2898, %rsp           # imm = 0x2898
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq