// File: /workspace/github_c_makefile_star2_O3/lesgourg[P]class_public/build/../source/thermodynamics.c
// Function: thermodynamics_idm_initial_temperature
int thermodynamics_idm_initial_temperature(
                                           struct background* pba,
                                           struct thermodynamics* pth,
                                           double z_ini,
                                           struct thermo_diffeq_workspace * ptdw
                                           ) {

  /** - define local parameters */
  double* pvecback;
  int last_index;
  /* idm-b special parameters */
  double m_b, FHe, T_diff_idm_b;
  /* steady state factors ( = prefactors in temperature evolution equation) */
  double alpha=0.,beta=0.,epsilon=0.;

  /** - obtain necessary background information */
  class_alloc(pvecback,pba->bg_size*sizeof(double),pba->error_message);
  class_call(background_at_z(pba,
                             z_ini,
                             long_info,
                             inter_normal,
                             &last_index,
                             pvecback),
             pba->error_message,
             pth->error_message);

  /* idm-idr steady state */
  if ((pth->has_idm_dr == _TRUE_) && (pth->n_index_idm_dr == 0)) {
    ptdw->dmu_idm_dr = pth->a_idm_dr*pow((1.+ z_ini)/1.e7,pth->n_index_idm_dr)*pba->Omega0_idm*pow(pba->h,2); // constant
    ptdw->Sinv_idm_dr  = 4./3.*pvecback[pba->index_bg_rho_idr]/pvecback[pba->index_bg_rho_idm]; // propto (1+z_ini)
    epsilon = 2*ptdw->Sinv_idm_dr*ptdw->dmu_idm_dr / pvecback[pba->index_bg_H]*(1.+z_ini); // constant
  }
  /* idm_g steady state */
  else if (pth->has_idm_g == _TRUE_ && pth->n_index_idm_g == -2) {
    ptdw->dmu_idm_g =  3./8./_PI_/_G_*pow(1.+z_ini, 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_; // constant
    beta = 2.*4./3. * pvecback[pba->index_bg_rho_g]/pvecback[pba->index_bg_rho_idm] * ptdw->dmu_idm_g / pvecback[pba->index_bg_H] * (1+z_ini); // constant
  }
  /* idm_b steady state */
  else if (pth->has_idm_b == _TRUE_ && pth->n_index_idm_b == -3) {
    FHe = 1-pth->YHe;
    m_b = _m_p_*_c_*_c_/_eV_;
    /* This is super-highly approximated, and will not usually be correct. However, the small error we incur should be corrected by the evolution equation */
    T_diff_idm_b = (pba->T_cmb*(1.+z_ini)*_k_B_/_eV_/m_b)+(pba->T_cmb*(1.+z_ini)*_k_B_/_eV_/pth->m_idm)+(1.e-8/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_));
    alpha = 2.*pth->m_idm/(pth->m_idm + m_b)*ptdw->R_idm_b; // approximately constant
  }

  /* This formula (assuming alpha,beta,epsilon=const) approximates the steady-state solution of the IDM temperature evolution equation */
  ptdw->T_idm = (alpha + beta + epsilon * pba->T_idr/pba->T_cmb)/(1.+epsilon+alpha+beta) * pba->T_cmb * (1.+z_ini);

  free(pvecback);

  return _SUCCESS_;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x820, %rsp            # imm = 0x820
movq %rdx, %r14
movsd %xmm0, (%rsp)
movq %rsi, %r12
movq %rdi, %rbx
movslq 0x2b0(%rdi), %r13
leaq (,%r13,8), %rdi
callq 0x8460
testq %rax, %rax
je 0x659de
movq %rax, %r15
leaq 0x1c(%rsp), %rcx
movq %rbx, %rdi
movsd (%rsp), %xmm0
movl $0x2, %esi
xorl %edx, %edx
movq %rax, %r8
callq 0x54a8c
cmpl $0x1, %eax
jne 0x65a33
addq $0xb84, %rbx            # imm = 0xB84
leaq 0x79a4a(%rip), %rsi     # 0xdf3f0
leaq 0x99c79(%rip), %rdx     # 0xff626
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x1064, %r12           # imm = 0x1064
leaq 0x79667(%rip), %rsi     # 0xdf034
leaq 0x99c2b(%rip), %rdx     # 0xff5ff
movq %r12, %rdi
movl $0x1285, %ecx           # imm = 0x1285
jmp 0x65a1f
shll $0x3, %r13d
leaq 0x7961b(%rip), %rsi     # 0xdf004
leaq 0x9cb1c(%rip), %rdx     # 0x10250c
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x30af0
addq $0xb84, %rbx            # imm = 0xB84
leaq 0x79624(%rip), %rsi     # 0xdf034
leaq 0x99be8(%rip), %rdx     # 0xff5ff
movq %rbx, %rdi
movl $0x127d, %ecx           # imm = 0x127D
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
jmp 0x65d08
cmpw $0x1, 0x38(%r12)
jne 0x65b01
movsd 0x1028(%r12), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x65b01
jp 0x65b01
movsd 0x1018(%r12), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x797ea(%rip), %xmm0    # 0xdf260
addsd (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
divsd 0x94f3f(%rip), %xmm0    # 0xfa9c8
callq 0x8620
xorpd %xmm6, %xmm6
movsd (%rsp), %xmm5
mulsd 0x8(%rsp), %xmm0
mulsd 0x38(%rbx), %xmm0
movsd 0x8(%rbx), %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, 0x58(%r14)
movslq 0x230(%rbx), %rax
movsd (%r15,%rax,8), %xmm1
mulsd 0x7c9f6(%rip), %xmm1    # 0xe24c0
movslq 0x220(%rbx), %rax
divsd (%r15,%rax,8), %xmm1
movsd %xmm1, 0x68(%r14)
addsd %xmm1, %xmm1
mulsd %xmm2, %xmm1
movslq 0x20c(%rbx), %rax
divsd (%r15,%rax,8), %xmm1
mulsd 0x10(%rsp), %xmm1
xorpd %xmm0, %xmm0
jmp 0x65cb6
cmpw $0x1, 0x36(%r12)
movsd (%rsp), %xmm5
jne 0x65bcb
cmpl $-0x2, 0x1058(%r12)
jne 0x65bcb
movsd (%rbx), %xmm0
movsd 0x38(%rbx), %xmm1
mulsd 0x94e6d(%rip), %xmm1    # 0xfa9a0
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x1050(%r12), %xmm1
mulsd 0x94e5b(%rip), %xmm1    # 0xfa9a8
mulsd 0x7e053(%rip), %xmm1    # 0xe3ba8
divsd 0x7e053(%rip), %xmm1    # 0xe3bb0
movsd 0x796fb(%rip), %xmm2    # 0xdf260
divsd 0x7e00b(%rip), %xmm1    # 0xe3b78
movslq 0x214(%rbx), %rax
movsd (%r15,%rax,8), %xmm3
mulsd 0x94f1e(%rip), %xmm3    # 0xfaaa0
unpcklpd %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0]
movslq 0x220(%rbx), %rax
movapd 0x94fcb(%rip), %xmm0    # 0xfab60
movlpd (%r15,%rax,8), %xmm0    # xmm0 = mem[0],xmm0[1]
divpd %xmm0, %xmm3
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
movhpd %xmm3, 0x48(%r14)
mulsd %xmm3, %xmm0
movslq 0x20c(%rbx), %rax
divsd (%r15,%rax,8), %xmm0
addsd %xmm5, %xmm2
mulsd %xmm2, %xmm0
jmp 0x65cae
xorpd %xmm0, %xmm0
cmpw $0x1, 0x34(%r12)
jne 0x65cae
cmpl $-0x3, 0x1038(%r12)
jne 0x65cae
movsd 0x7966d(%rip), %xmm1    # 0xdf260
movapd %xmm1, %xmm2
subsd (%r12), %xmm2
addsd %xmm5, %xmm1
mulsd 0x18(%rbx), %xmm1
mulsd 0x7df62(%rip), %xmm1    # 0xe3b70
divsd 0x7df62(%rip), %xmm1    # 0xe3b78
movapd %xmm1, %xmm3
divsd 0x94d8e(%rip), %xmm3    # 0xfa9b0
movsd 0x1010(%r12), %xmm6
divsd %xmm6, %xmm1
movslq 0x208(%rbx), %rax
movsd (%r15,%rax,8), %xmm4
movslq 0x218(%rbx), %rax
mulsd (%r15,%rax,8), %xmm4
mulsd 0x1030(%r12), %xmm4
mulsd 0x1040(%r12), %xmm4
addsd %xmm3, %xmm1
unpcklpd %xmm6, %xmm1            # xmm1 = xmm1[0],xmm6[0]
addpd 0x94ed2(%rip), %xmm1    # 0xfab40
movapd 0x94eda(%rip), %xmm3    # 0xfab50
unpcklpd %xmm4, %xmm3            # xmm3 = xmm3[0],xmm4[0]
divpd %xmm1, %xmm3
movapd %xmm3, %xmm4
unpckhpd %xmm3, %xmm4            # xmm4 = xmm4[1],xmm3[1]
mulsd %xmm3, %xmm4
mulsd %xmm2, %xmm4
mulsd 0x94d2a(%rip), %xmm4    # 0xfa9c0
movsd %xmm4, 0x30(%r14)
addsd %xmm6, %xmm6
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
divsd %xmm1, %xmm6
mulsd %xmm4, %xmm6
jmp 0x65cb2
xorpd %xmm6, %xmm6
xorpd %xmm1, %xmm1
movapd %xmm6, %xmm2
addsd %xmm0, %xmm2
movsd 0x48(%rbx), %xmm3
mulsd %xmm1, %xmm3
movsd 0x18(%rbx), %xmm4
divsd %xmm4, %xmm3
addsd %xmm2, %xmm3
movsd 0x79584(%rip), %xmm2    # 0xdf260
addsd %xmm2, %xmm1
addsd %xmm6, %xmm1
addsd %xmm0, %xmm1
divsd %xmm1, %xmm3
mulsd %xmm4, %xmm3
addsd %xmm2, %xmm5
mulsd %xmm3, %xmm5
movsd %xmm5, 0x38(%r14)
movq %r15, %rdi
callq 0x8410
xorl %eax, %eax
addq $0x820, %rsp            # imm = 0x820
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq