// File: /workspace/github_c_makefile_star2_O0/PoulinV[P]AxiCLASS/build/../source/thermodynamics.c
// Function: thermodynamics_idm_quantities
int thermodynamics_idm_quantities(struct background * pba,
                                  double z,
                                  double * y,
                                  double * dy,
                                  struct thermodynamics * pth,
                                  struct thermo_workspace * ptw,
                                  double * pvecback){
  /** Summary: */

  /** Define local variables */
  struct thermo_diffeq_workspace * ptdw = ptw->ptdw;
  struct thermo_vector * ptv = ptdw->ptv;

  /* Thermo quantities */
  double T_g, Tmat, T_idr = 0.;
  double Vrms_idm_b2, m_b, T_diff_idm_b, FHe;

  T_g = ptw->Tcmb * (1.+z);
  Tmat = y[ptv->index_ti_D_Tmat] + T_g;

  /** - First deal with any required dark radiation */
  if (pba->has_idr == _TRUE_) {
    T_idr = pba->T_idr*(1.+z);
    ptdw->dmu_idr = pth->b_idr*pow((1.+z)/1.e7,pth->n_index_idm_dr)*pba->Omega0_idr*pow(pba->h,2);
  }

  /** - Now deal with any required dark matter (and its interactions) */
  if (pba->has_idm == _TRUE_) {
    /* First, set the IDM temperature in tight coupling */
    if (ptw->has_ap_idmtca == _TRUE_ && ptdw->ap_current == ptdw->index_ap_idmtca) {
      ptdw->T_idm = T_g;
      /* If we are coupling strongly to dark radiation instead */
      if ((pth->has_idm_dr == _TRUE_) && pth->n_index_idm_dr > 0)
        ptdw->T_idm = T_idr;
    }

    /* Also set idm temperature without tight coupling */
    else {
      ptdw->T_idm = y[ptv->index_ti_T_idm];
    }

    /* Compute idm temperature derivatives, starting with homogeneous expansion */
    ptdw->T_idm_prime = - 2. * ptdw->T_idm / (1.+z);

    /* Now add also coupling to photons*/
    if (pth->has_idm_g == _TRUE_) {
      /* - photon interaction rate with idm_g */
      ptdw->dmu_idm_g = 3./8./_PI_/_G_*pow(1.+z, 2+pth->n_index_idm_g)*pba->Omega0_idm*pba->H0*pba->H0*pth->u_idm_g*pow(_c_,4)*_sigma_/1.e11/_eV_/_Mpc_over_m_;
      ptdw->T_idm_prime += - 2.*4./3. * pvecback[pba->index_bg_rho_g]/pvecback[pba->index_bg_rho_idm] * ptdw->dmu_idm_g * (ptdw->T_idm  - T_g) / pvecback[pba->index_bg_H];
    }
    /* Now add also coupling to dark radiation */
    if (pth->has_idm_dr == _TRUE_) {
      /* - idr interaction rate with idm_dr */
      ptdw->dmu_idm_dr = pth->a_idm_dr*pow((1.+ z)/1.e7,pth->n_index_idm_dr)*pba->Omega0_idm*pow(pba->h,2);
      ptdw->Sinv_idm_dr  = 4./3.*pvecback[pba->index_bg_rho_idr]/pvecback[pba->index_bg_rho_idm];
      ptdw->T_idm_prime += - 2* ptdw->dmu_idm_dr * ptdw->Sinv_idm_dr * (ptdw->T_idm - T_idr) / pvecback[pba->index_bg_H];
    }
    /* Now add also coupling to baryons */
    /* Note that here we do a simplified calculation of the velocity, as described in 2010.04074. This will be adapted in future versions. */
    if (pth->has_idm_b == _TRUE_) {
      if (z > 1.e3)
        Vrms_idm_b2 = 1.e-8;
      else
        Vrms_idm_b2 = 1.e-8*pow(((1.+z)/1.e3),2);

      FHe = 1- ptw->YHe;
      m_b = _m_p_*_c_*_c_/_eV_; /* Note that for now we always assume scattering with protons. This will be adapted in future versions. */

      T_diff_idm_b = (Tmat*_k_B_/_eV_/m_b)+(ptdw->T_idm*_k_B_/_eV_/pth->m_idm)+(Vrms_idm_b2/3.0);

      ptdw->R_idm_b = (pvecback[pba->index_bg_a]*pvecback[pba->index_bg_rho_b]*pth->cross_idm_b*pth->n_coeff_idm_b/(m_b+pth->m_idm))
        *pow(T_diff_idm_b,(pth->n_index_idm_b+1.0)/2.0)*FHe
        *(3.e-4*pow(_c_,4.)/(8.*_PI_*_Mpc_over_m_*_G_*_eV_));

      ptdw->T_idm_prime += -2.*pth->m_idm/(pth->m_idm + m_b)*ptdw->R_idm_b*(ptdw->T_idm-Tmat) / pvecback[pba->index_bg_H];
    }

    /* Now conclude by computing the sound speed */
    ptdw->c2_idm = _k_B_ /(pth->m_idm*_eV_)  * (ptdw->T_idm - (1.+z)/3. * ptdw->T_idm_prime);
  }

  return _SUCCESS_;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movsd %xmm0, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq %rdx, 0x98(%rsp)
movq %rcx, 0x90(%rsp)
movq %r8, 0x88(%rsp)
movq %r9, 0x80(%rsp)
movq 0x88(%rsp), %rax
movq 0x80(%rax), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq 0xb8(%rax), %rax
movq %rax, 0x70(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0x88(%rsp), %rax
movsd 0x38(%rax), %xmm0
movsd 0x10cf65(%rip), %xmm1   # 0x1d2248
addsd 0xa8(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0xa0(%rsp), %rax
movq 0x70(%rsp), %rcx
movslq 0xc(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0xb0(%rsp), %rax
movswl 0x4c6(%rax), %eax
cmpl $0x1, %eax
jne 0xc53f7
movq 0xb0(%rsp), %rax
movsd 0x100(%rax), %xmm0
movsd 0x10cf00(%rip), %xmm1   # 0x1d2248
addsd 0xa8(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0x90(%rsp), %rax
movsd 0x1020(%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x10cecf(%rip), %xmm0   # 0x1d2248
addsd 0xa8(%rsp), %xmm0
movsd 0x12c13e(%rip), %xmm1   # 0x1f14c8
divsd %xmm1, %xmm0
movq 0x90(%rsp), %rax
movsd 0x1028(%rax), %xmm1
callq 0x8610
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0xb0(%rsp), %rax
mulsd 0xf8(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xb0(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd 0x10d8a5(%rip), %xmm1   # 0x1d2c80
callq 0x8610
movaps %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, 0x60(%rax)
movq 0xb0(%rsp), %rax
movswl 0x4b6(%rax), %eax
cmpl $0x1, %eax
jne 0xc5aaf
movq 0x88(%rsp), %rax
movswl 0x60(%rax), %eax
cmpl $0x1, %eax
jne 0xc5481
movq 0x78(%rsp), %rax
movl 0x90(%rax), %eax
movq 0x78(%rsp), %rcx
cmpl 0x70(%rcx), %eax
jne 0xc5481
movsd 0x68(%rsp), %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, 0x38(%rax)
movq 0x90(%rsp), %rax
movswl 0x38(%rax), %eax
cmpl $0x1, %eax
jne 0xc547f
movq 0x90(%rsp), %rax
movsd 0x1028(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xc547f
movsd 0x58(%rsp), %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, 0x38(%rax)
jmp 0xc54a1
movq 0xa0(%rsp), %rax
movq 0x70(%rsp), %rcx
movslq 0x10(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, 0x38(%rax)
movq 0x78(%rsp), %rax
movsd 0x10e2d2(%rip), %xmm0   # 0x1d3780
mulsd 0x38(%rax), %xmm0
movsd 0x10cd8d(%rip), %xmm1   # 0x1d2248
addsd 0xa8(%rsp), %xmm1
divsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, 0x40(%rax)
movq 0x90(%rsp), %rax
movswl 0x36(%rax), %eax
cmpl $0x1, %eax
jne 0xc5644
movsd 0x10cd59(%rip), %xmm0   # 0x1d2248
addsd 0xa8(%rsp), %xmm0
movq 0x90(%rsp), %rax
movl 0x1058(%rax), %eax
addl $0x2, %eax
cvtsi2sd %eax, %xmm1
callq 0x8610
movaps %xmm0, %xmm1
movsd 0x12bf83(%rip), %xmm0   # 0x1f14a0
mulsd %xmm1, %xmm0
movq 0xb0(%rsp), %rax
mulsd 0xf0(%rax), %xmm0
movq 0xb0(%rsp), %rax
mulsd (%rax), %xmm0
movq 0xb0(%rsp), %rax
mulsd (%rax), %xmm0
movq 0x90(%rsp), %rax
mulsd 0x1050(%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x1110c9(%rip), %xmm0   # 0x1d6630
movsd 0x10ff59(%rip), %xmm1   # 0x1d54c8
callq 0x8610
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd 0x11125f(%rip), %xmm1   # 0x1d67e8
mulsd %xmm1, %xmm0
movsd 0x11124b(%rip), %xmm1   # 0x1d67e0
divsd %xmm1, %xmm0
movsd 0x111257(%rip), %xmm1   # 0x1d67f8
divsd %xmm1, %xmm0
movsd 0x1110b3(%rip), %xmm1   # 0x1d6660
divsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, 0x48(%rax)
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq 0x38c(%rcx), %rcx
movsd 0x12bfd6(%rip), %xmm0   # 0x1f15b0
mulsd (%rax,%rcx,8), %xmm0
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq 0x398(%rcx), %rcx
divsd (%rax,%rcx,8), %xmm0
movq 0x78(%rsp), %rax
mulsd 0x48(%rax), %xmm0
movq 0x78(%rsp), %rax
movsd 0x38(%rax), %xmm1
subsd 0x68(%rsp), %xmm1
mulsd %xmm1, %xmm0
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq 0x384(%rcx), %rcx
divsd (%rax,%rcx,8), %xmm0
movq 0x78(%rsp), %rax
addsd 0x40(%rax), %xmm0
movsd %xmm0, 0x40(%rax)
movq 0x90(%rsp), %rax
movswl 0x38(%rax), %eax
cmpl $0x1, %eax
jne 0xc579a
movq 0x90(%rsp), %rax
movsd 0x1018(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x10cbd1(%rip), %xmm0   # 0x1d2248
addsd 0xa8(%rsp), %xmm0
movsd 0x12be40(%rip), %xmm1   # 0x1f14c8
divsd %xmm1, %xmm0
movq 0x90(%rsp), %rax
movsd 0x1028(%rax), %xmm1
callq 0x8610
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0xb0(%rsp), %rax
mulsd 0xf0(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0xb0(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd 0x10d5a7(%rip), %xmm1   # 0x1d2c80
callq 0x8610
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, 0x58(%rax)
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq 0x3b0(%rcx), %rcx
movsd 0x10fdfc(%rip), %xmm0   # 0x1d5510
mulsd (%rax,%rcx,8), %xmm0
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq 0x398(%rcx), %rcx
divsd (%rax,%rcx,8), %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, 0x68(%rax)
movq 0x78(%rsp), %rax
movsd 0x10e034(%rip), %xmm0   # 0x1d3780
mulsd 0x58(%rax), %xmm0
movq 0x78(%rsp), %rax
mulsd 0x68(%rax), %xmm0
movq 0x78(%rsp), %rax
movsd 0x38(%rax), %xmm1
subsd 0x58(%rsp), %xmm1
mulsd %xmm1, %xmm0
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq 0x384(%rcx), %rcx
divsd (%rax,%rcx,8), %xmm0
movq 0x78(%rsp), %rax
addsd 0x40(%rax), %xmm0
movsd %xmm0, 0x40(%rax)
movq 0x90(%rsp), %rax
movswl 0x34(%rax), %eax
cmpl $0x1, %eax
jne 0xc5a2d
movsd 0xa8(%rsp), %xmm0
movsd 0x110d10(%rip), %xmm1   # 0x1d64d0
ucomisd %xmm1, %xmm0
jbe 0xc57d6
movsd 0x12bcea(%rip), %xmm0   # 0x1f14b8
movsd %xmm0, 0x50(%rsp)
jmp 0xc5815
movsd 0x10ca6a(%rip), %xmm0   # 0x1d2248
addsd 0xa8(%rsp), %xmm0
movsd 0x110ce1(%rip), %xmm1   # 0x1d64d0
divsd %xmm1, %xmm0
movsd 0x10d485(%rip), %xmm1   # 0x1d2c80
callq 0x8610
movaps %xmm0, %xmm1
movsd 0x12bcad(%rip), %xmm0   # 0x1f14b8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x88(%rsp), %rax
movsd 0x10ca23(%rip), %xmm0   # 0x1d2248
subsd 0x18(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x12bc88(%rip), %xmm0   # 0x1f14c0
movsd %xmm0, 0x48(%rsp)
movsd 0x110dfa(%rip), %xmm0   # 0x1d6640
mulsd 0x60(%rsp), %xmm0
movsd 0x110fa4(%rip), %xmm1   # 0x1d67f8
divsd %xmm1, %xmm0
divsd 0x48(%rsp), %xmm0
movq 0x78(%rsp), %rax
movsd 0x110dd5(%rip), %xmm1   # 0x1d6640
mulsd 0x38(%rax), %xmm1
movsd 0x110f80(%rip), %xmm2   # 0x1d67f8
divsd %xmm2, %xmm1
movq 0x90(%rsp), %rax
divsd 0x1010(%rax), %xmm1
addsd %xmm1, %xmm0
movsd 0x50(%rsp), %xmm1
movsd 0x10ddfa(%rip), %xmm2   # 0x1d3698
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq 0x380(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq 0x390(%rcx), %rcx
mulsd (%rax,%rcx,8), %xmm0
movq 0x90(%rsp), %rax
mulsd 0x1030(%rax), %xmm0
movq 0x90(%rsp), %rax
mulsd 0x1040(%rax), %xmm0
movsd 0x48(%rsp), %xmm1
movq 0x90(%rsp), %rax
addsd 0x1010(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movsd 0x40(%rsp), %xmm0
movq 0x90(%rsp), %rax
cvtsi2sdl 0x1038(%rax), %xmm1
movsd 0x10c907(%rip), %xmm2   # 0x1d2248
addsd %xmm2, %xmm1
movsd 0x10d333(%rip), %xmm2   # 0x1d2c80
divsd %xmm2, %xmm1
callq 0x8610
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x110cba(%rip), %xmm0   # 0x1d6630
movsd 0x10fb4a(%rip), %xmm1   # 0x1d54c8
callq 0x8610
movaps %xmm0, %xmm2
movsd 0x8(%rsp), %xmm0
movsd 0x12bb1c(%rip), %xmm1   # 0x1f14b0
mulsd %xmm2, %xmm1
movsd 0x12bb08(%rip), %xmm2   # 0x1f14a8
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, 0x30(%rax)
movq 0x90(%rsp), %rax
movsd 0x10ddbe(%rip), %xmm0   # 0x1d3780
mulsd 0x1010(%rax), %xmm0
movq 0x90(%rsp), %rax
movsd 0x1010(%rax), %xmm1
addsd 0x48(%rsp), %xmm1
divsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
mulsd 0x30(%rax), %xmm0
movq 0x78(%rsp), %rax
movsd 0x38(%rax), %xmm1
subsd 0x60(%rsp), %xmm1
mulsd %xmm1, %xmm0
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq 0x384(%rcx), %rcx
divsd (%rax,%rcx,8), %xmm0
movq 0x78(%rsp), %rax
addsd 0x40(%rax), %xmm0
movsd %xmm0, 0x40(%rax)
movq 0x90(%rsp), %rax
movsd 0x110dbb(%rip), %xmm1   # 0x1d67f8
mulsd 0x1010(%rax), %xmm1
movsd 0x110bf3(%rip), %xmm0   # 0x1d6640
divsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movsd 0x38(%rax), %xmm2
movsd 0x10c7e5(%rip), %xmm1   # 0x1d2248
addsd 0xa8(%rsp), %xmm1
movsd 0x10dc24(%rip), %xmm3   # 0x1d3698
divsd %xmm3, %xmm1
movq 0x78(%rsp), %rax
movsd 0x40(%rax), %xmm3
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, 0x50(%rax)
xorl %eax, %eax
addq $0xb8, %rsp
retq
nopl (%rax)