// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../source/thermodynamics.c
// Function: thermodynamics_calculate_idm_and_idr_quantities
int thermodynamics_calculate_idm_and_idr_quantities(struct precision* ppr,
                                                    struct background * pba,
                                                    struct thermodynamics * pth,
                                                    double* pvecback){

  /** Summary: **/

  /** - Define local variables **/
  int index_tau_fs;
  int index_tau;

  /** - Calculate optical functions tau_idm_dr, tau_idr, g_idm_dr */
  if (pth->has_idm_dr == _TRUE_) {
    /* - second derivative of idm_dr interaction rate (with idr), [Sinv*dmu_idm_dr]'', stored temporarily in column dddmu */
    class_call(array_spline_table_line_to_line(pth->tau_table,
                                               pth->tt_size,
                                               pth->thermodynamics_table,
                                               pth->th_size,
                                               pth->index_th_ddmu_idm_dr,
                                               pth->index_th_dddmu_idm_dr,
                                               _SPLINE_EST_DERIV_,
                                               pth->error_message),
               pth->error_message,
               pth->error_message);

    /* - compute optical depth of idm, tau_idm_dr = [int_{tau_today}^{tau} dtau [Sinv*dmu_idm_dr] ].*/
    /*    This step gives -tau_idm_dr. The resulty is mutiplied by -1 later on. */
    class_call(array_integrate_spline_table_line_to_line(pth->tau_table,
                                                         pth->tt_size,
                                                         pth->thermodynamics_table,
                                                         pth->th_size,
                                                         pth->index_th_ddmu_idm_dr,
                                                         pth->index_th_dddmu_idm_dr,
                                                         pth->index_th_tau_idm_dr,
                                                         pth->error_message),
               pth->error_message,
               pth->error_message);

    /* - second derivative of idr interaction rate (with idm_dr), [dmu_idm_idr]'', stored temporarily in column dddmu */
    class_call(array_spline_table_line_to_line(pth->tau_table,
                                               pth->tt_size,
                                               pth->thermodynamics_table,
                                               pth->th_size,
                                               pth->index_th_dmu_idm_dr,
                                               pth->index_th_dddmu_idm_dr,
                                               _SPLINE_EST_DERIV_,
                                               pth->error_message),
               pth->error_message,
               pth->error_message);

    /* - compute optical depth of idr, tau_idr = [int_{tau_today}^{tau} dtau [dmu_idm_idr] ]. */
    /*   This step gives -tau_idr. The resulty is mutiplied by -1 later on. */
    class_call(array_integrate_spline_table_line_to_line(pth->tau_table,
                                                         pth->tt_size,
                                                         pth->thermodynamics_table,
                                                         pth->th_size,
                                                         pth->index_th_dmu_idm_dr,
                                                         pth->index_th_dddmu_idm_dr,
                                                         pth->index_th_tau_idr,
                                                         pth->error_message),
               pth->error_message,
               pth->error_message);


    /* - restore correct sign for idm_dr and idr optical depth, and calculate idm_dr visibility function */
    /* loop on z (decreasing z, increasing time) */

    for (index_tau=pth->tt_size-1; index_tau>=0; index_tau--) {
      /* - --> restore the correct sign for tau_idm_dr */
      pth->thermodynamics_table[index_tau*pth->th_size+pth->index_th_tau_idm_dr] *= -1.;

      /* - --> restore the correct sign for tau_idr */
      pth->thermodynamics_table[index_tau*pth->th_size+pth->index_th_tau_idr] *= -1.;

      /* - --> visibility function for idm_dr : g_idm_dr = [Sinv*dmu_idm_dr] * exp(-tau_idm_dr) */
      pth->thermodynamics_table[index_tau*pth->th_size+pth->index_th_g_idm_dr] =
        pth->thermodynamics_table[index_tau*pth->th_size+pth->index_th_ddmu_idm_dr]
        * exp(-pth->thermodynamics_table[index_tau*pth->th_size+pth->index_th_tau_idm_dr]);
    }

    /* - fill columns for ddmu_idm_dr and dddmu_idm_dr with true values, and compute idm_dr temperature and sound speed */
    /* - --> second derivative with respect to tau of dmu_idm_dr (in view of spline interpolation) */
    class_call(array_spline_table_line_to_line(pth->tau_table,
                                               pth->tt_size,
                                               pth->thermodynamics_table,
                                               pth->th_size,
                                               pth->index_th_dmu_idm_dr,
                                               pth->index_th_dddmu_idm_dr,
                                               _SPLINE_EST_DERIV_,
                                               pth->error_message),
               pth->error_message,
               pth->error_message);

    /* - --> first derivative with respect to tau of dmu_idm_dr (using spline interpolation) */
    class_call(array_spline_table_line_to_line(pth->tau_table,
                                               pth->tt_size,
                                               pth->thermodynamics_table,
                                               pth->th_size,
                                               pth->index_th_dmu_idm_dr,
                                               pth->index_th_dddmu_idm_dr,
                                               _SPLINE_EST_DERIV_,
                                               pth->error_message),
               pth->error_message,
               pth->error_message);

    /* - --> first derivative with respect to tau of dmu_idm_dr (using spline interpolation) */
    class_call(array_derive_spline_table_line_to_line(pth->tau_table,
                                                      pth->tt_size,
                                                      pth->thermodynamics_table,
                                                      pth->th_size,
                                                      pth->index_th_dmu_idm_dr,
                                                      pth->index_th_dddmu_idm_dr,
                                                      pth->index_th_ddmu_idm_dr,
                                                      pth->error_message),
               pth->error_message,
               pth->error_message);

  }

  /** - Find interacting dark radiation free-streaming time */
  /* First, find index of recombination, or free streaming for ordinary radiation */
  index_tau = pth->tt_size - 1;
  while(1./pth->thermodynamics_table[(index_tau)*pth->th_size+pth->index_th_dkappa]/pth->tau_table[index_tau] < ppr->radiation_streaming_trigger_tau_c_over_tau && index_tau > 0)
    index_tau--;
  index_tau_fs = index_tau;

  /** - Search after the above free-streaming time for idr free-streaming as well */
  if (pth->has_idm_dr == _TRUE_) {

    if (pth->n_index_idm_dr>=2) {
      index_tau=index_tau_fs-1;
      while ((1./pth->thermodynamics_table[(index_tau)*pth->th_size+pth->index_th_dmu_idm_dr]/pth->tau_table[index_tau]
              < ppr->idr_streaming_trigger_tau_c_over_tau) && index_tau > 0)
        index_tau--;
    }
    else {
      index_tau=0;
      while ((1./pth->thermodynamics_table[(index_tau)*pth->th_size+pth->index_th_dmu_idm_dr]/pth->tau_table[index_tau]
              < ppr->idr_streaming_trigger_tau_c_over_tau) && index_tau < pth->tt_size-1)
        index_tau++;
    }

    /* tau_idm_dr_fs = tau; */
    pth->tau_idr_free_streaming = pth->tau_table[index_tau];
  }
  /* case of idr alone without idm_dr: Set idr free streaming simply to normal free-streaming */
  else {
    index_tau= (index_tau_fs > 0 ? index_tau_fs - 1: 0);
    pth->tau_idr_free_streaming = pth->tau_table[index_tau];
  }

  if (pth->has_idm_b == _TRUE_) {
    /** - --> second derivative with respect to tau of R_idm_b (in view of spline interpolation) */
    class_call(array_spline_table_line_to_line(pth->tau_table,
                                               pth->tt_size,
                                               pth->thermodynamics_table,
                                               pth->th_size,
                                               pth->index_th_R_idm_b,
                                               pth->index_th_ddR_idm_b,
                                               _SPLINE_EST_DERIV_,
                                               pth->error_message),
               pth->error_message,
               pth->error_message);

    /** - --> first derivative with respect to tau of R_idm_b (using spline interpolation) */
    class_call(array_derive_spline_table_line_to_line(pth->tau_table,
                                                      pth->tt_size,
                                                      pth->thermodynamics_table,
                                                      pth->th_size,
                                                      pth->index_th_R_idm_b,
                                                      pth->index_th_ddR_idm_b,
                                                      pth->index_th_dR_idm_b,
                                                      pth->error_message),
               pth->error_message,
               pth->error_message);
  }

  return _SUCCESS_;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x818, %rsp            # imm = 0x818
movq %rdx, %rbx
movq %rdi, %r15
cmpw $0x1, 0x38(%rdx)
jne 0x7184d
movq 0xf18(%rbx), %rdi
movl 0xf08(%rbx), %esi
movq 0xf20(%rbx), %rdx
movl 0xf04(%rbx), %ecx
movl 0xeb0(%rbx), %r8d
movl 0xeb4(%rbx), %r9d
leaq 0x1064(%rbx), %r14
pushq %r14
pushq $0x1
callq 0x13c30
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x714c1
leaq 0x7ff63(%rip), %rsi     # 0xf13f0
leaq 0xa2d14(%rip), %rdx     # 0x1141a8
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x7fb87(%rip), %rsi     # 0xf1034
leaq 0xa2da9(%rip), %rdx     # 0x11425d
movq %r14, %rdi
movl $0xdf7, %ecx            # imm = 0xDF7
jmp 0x71a82
movq 0xf18(%rbx), %rdi
movl 0xf08(%rbx), %esi
movq 0xf20(%rbx), %rdx
movl 0xf04(%rbx), %ecx
movl 0xeb0(%rbx), %r8d
movl 0xeb4(%rbx), %r9d
movl 0xebc(%rbx), %eax
pushq %r14
pushq %rax
callq 0x1337c
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x7153b
leaq 0x7fee9(%rip), %rsi     # 0xf13f0
leaq 0xa2d7f(%rip), %rdx     # 0x11428d
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x7fb0d(%rip), %rsi     # 0xf1034
leaq 0xa2d2f(%rip), %rdx     # 0x11425d
movq %r14, %rdi
movl $0xe04, %ecx            # imm = 0xE04
jmp 0x71a82
movq 0xf18(%rbx), %rdi
movl 0xf08(%rbx), %esi
movq 0xf20(%rbx), %rdx
movl 0xf04(%rbx), %ecx
movl 0xeac(%rbx), %r8d
movl 0xeb4(%rbx), %r9d
pushq %r14
pushq $0x1
callq 0x13c30
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x715b0
leaq 0x7fe74(%rip), %rsi     # 0xf13f0
leaq 0xa2de0(%rip), %rdx     # 0x114363
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x7fa98(%rip), %rsi     # 0xf1034
leaq 0xa2cba(%rip), %rdx     # 0x11425d
movq %r14, %rdi
movl $0xe10, %ecx            # imm = 0xE10
jmp 0x71a82
movq 0xf18(%rbx), %rdi
movl 0xf08(%rbx), %esi
movq 0xf20(%rbx), %rdx
movl 0xf04(%rbx), %ecx
movl 0xeac(%rbx), %r8d
movl 0xeb4(%rbx), %r9d
movl 0xec0(%rbx), %eax
pushq %r14
pushq %rax
callq 0x1337c
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x7162a
leaq 0x7fdfa(%rip), %rsi     # 0xf13f0
leaq 0xa2e1a(%rip), %rdx     # 0x114417
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x7fa1e(%rip), %rsi     # 0xf1034
leaq 0xa2c40(%rip), %rdx     # 0x11425d
movq %r14, %rdi
movl $0xe1d, %ecx            # imm = 0xE1D
jmp 0x71a82
movl 0xf08(%rbx), %r12d
testl %r12d, %r12d
jle 0x716e9
incl %r12d
leal -0x2(%r12), %eax
movq 0xf20(%rbx), %rcx
movslq 0xf04(%rbx), %rdx
movslq %eax, %r13
imulq %r13, %rdx
movslq 0xebc(%rbx), %rax
addq %rdx, %rax
movsd (%rcx,%rax,8), %xmm0
movapd 0x7fbc2(%rip), %xmm1    # 0xf1230
xorpd %xmm1, %xmm0
movlpd %xmm0, (%rcx,%rax,8)
movslq 0xec0(%rbx), %rsi
movslq %edx, %rdx
addq %rdx, %rsi
movsd (%rcx,%rsi,8), %xmm0
xorpd %xmm1, %xmm0
movlpd %xmm0, (%rcx,%rsi,8)
movslq 0xeb0(%rbx), %rsi
addq %rdx, %rsi
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%rcx,%rax,8), %xmm0
xorpd %xmm1, %xmm0
callq 0x8670
mulsd 0x8(%rsp), %xmm0
movq 0xf20(%rbx), %rax
movslq 0xf04(%rbx), %rcx
imulq %r13, %rcx
movslq 0xec4(%rbx), %rdx
addq %rcx, %rdx
movsd %xmm0, (%rax,%rdx,8)
decl %r12d
cmpl $0x1, %r12d
jg 0x7163d
movq 0xf18(%rbx), %rdi
movl 0xf08(%rbx), %esi
movq 0xf20(%rbx), %rdx
movl 0xf04(%rbx), %ecx
movl 0xeac(%rbx), %r8d
movl 0xeb4(%rbx), %r9d
pushq %r14
pushq $0x1
callq 0x13c30
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x7175e
leaq 0x7fcc6(%rip), %rsi     # 0xf13f0
leaq 0xa2c32(%rip), %rdx     # 0x114363
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x7f8ea(%rip), %rsi     # 0xf1034
leaq 0xa2b0c(%rip), %rdx     # 0x11425d
movq %r14, %rdi
movl $0xe3b, %ecx            # imm = 0xE3B
jmp 0x71a82
movq 0xf18(%rbx), %rdi
movl 0xf08(%rbx), %esi
movq 0xf20(%rbx), %rdx
movl 0xf04(%rbx), %ecx
movl 0xeac(%rbx), %r8d
movl 0xeb4(%rbx), %r9d
pushq %r14
pushq $0x1
callq 0x13c30
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x717d3
leaq 0x7fc51(%rip), %rsi     # 0xf13f0
leaq 0xa2bbd(%rip), %rdx     # 0x114363
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x7f875(%rip), %rsi     # 0xf1034
leaq 0xa2a97(%rip), %rdx     # 0x11425d
movq %r14, %rdi
movl $0xe47, %ecx            # imm = 0xE47
jmp 0x71a82
movq 0xf18(%rbx), %rdi
movl 0xf08(%rbx), %esi
movq 0xf20(%rbx), %rdx
movl 0xf04(%rbx), %ecx
movl 0xeb4(%rbx), %r9d
movl 0xeac(%rbx), %r8d
movl 0xeb0(%rbx), %eax
pushq %r14
pushq %rax
callq 0x12be6
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x7184d
leaq 0x7fbd7(%rip), %rsi     # 0xf13f0
leaq 0xa2cc9(%rip), %rdx     # 0x1144e9
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x7f7fb(%rip), %rsi     # 0xf1034
leaq 0xa2a1d(%rip), %rdx     # 0x11425d
movq %r14, %rdi
movl $0xe53, %ecx            # imm = 0xE53
jmp 0x71a82
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
movslq 0xf08(%rbx), %rsi
movq 0xf18(%rbx), %rdi
movq 0xf20(%rbx), %rdx
movslq 0xf04(%rbx), %rcx
movslq 0xe80(%rbx), %rax
movsd 0x630(%r15), %xmm1
leal -0x1(%rsi), %r9d
movq %rsi, %r10
shlq $0x20, %r10
addq %r11, %r10
leaq -0x1(%rsi), %r8
imulq %rcx, %r8
shlq $0x3, %rax
leaq (%rax,%r8,8), %r14
addq %rdx, %r14
leaq (,%rcx,8), %rax
movq %rax, %r8
negq %r8
movsd 0x7f9a6(%rip), %xmm0    # 0xf1260
movq %rsi, %r13
movq %r13, %r12
decl %r9d
addq %r11, %r10
cmpq $0x2, %r13
jl 0x718ea
movapd %xmm0, %xmm2
divsd (%r14), %xmm2
divsd -0x8(%rdi,%r12,8), %xmm2
leaq -0x1(%r12), %r13
addq %r8, %r14
ucomisd %xmm2, %xmm1
ja 0x718bd
cmpw $0x1, 0x38(%rbx)
jne 0x7194a
movsd 0x1028(%rbx), %xmm1
ucomisd 0x803ff(%rip), %xmm1    # 0xf1d00
movslq 0xeac(%rbx), %r11
movsd 0x648(%r15), %xmm1
jae 0x7195a
leal -0x1(%rsi), %r8d
movslq %r8d, %r8
leaq (%rdx,%r11,8), %r10
xorl %r11d, %r11d
movapd %xmm0, %xmm2
divsd (%r10), %xmm2
divsd (%rdi,%r11,8), %xmm2
leaq 0x1(%r11), %r9
ucomisd %xmm2, %xmm1
jbe 0x71945
addq %rax, %r10
cmpq %r8, %r11
movq %r9, %r11
jl 0x71921
decq %r9
jmp 0x7198e
sarq $0x20, %r10
xorl %eax, %eax
cmpq $0x2, %r12
cmovgeq %r10, %rax
jmp 0x71991
movslq %r9d, %r10
leaq (%rdx,%r11,8), %r9
imulq %r10, %rax
addq %r9, %rax
leaq -0x1(%r10), %r9
testq %r10, %r10
jle 0x7198b
movapd %xmm0, %xmm2
divsd (%rax), %xmm2
divsd (%rdi,%r10,8), %xmm2
addq %r8, %rax
ucomisd %xmm2, %xmm1
movq %r9, %r10
ja 0x71968
incq %r9
movslq %r9d, %rax
leaq (%rdi,%rax,8), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0xfe0(%rbx)
xorl %ebp, %ebp
cmpw $0x1, 0x34(%rbx)
jne 0x71a91
movl 0xed8(%rbx), %r8d
movl 0xee0(%rbx), %r9d
leaq 0x1064(%rbx), %r14
pushq %r14
pushq $0x1
callq 0x13c30
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x71a0d
leaq 0x7fa14(%rip), %rsi     # 0xf13f0
leaq 0xa2bd9(%rip), %rdx     # 0x1145bc
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x7f638(%rip), %rsi     # 0xf1034
leaq 0xa285a(%rip), %rdx     # 0x11425d
movq %r14, %rdi
movl $0xe82, %ecx            # imm = 0xE82
jmp 0x71a82
movq 0xf18(%rbx), %rdi
movl 0xf08(%rbx), %esi
movq 0xf20(%rbx), %rdx
movl 0xf04(%rbx), %ecx
movl 0xee0(%rbx), %r9d
movl 0xed8(%rbx), %r8d
movl 0xedc(%rbx), %eax
pushq %r14
pushq %rax
callq 0x12be6
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x71a91
leaq 0x7f99d(%rip), %rsi     # 0xf13f0
leaq 0xa2c10(%rip), %rdx     # 0x11466a
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x7f5c1(%rip), %rsi     # 0xf1034
leaq 0xa27e3(%rip), %rdx     # 0x11425d
movq %r14, %rdi
movl $0xe8e, %ecx            # imm = 0xE8E
movq %rbx, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %ebp
movl %ebp, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq