// File: /workspace/github_c_makefile_star2_O2/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 0x6a7c3
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 0x12065
popq %rcx
popq %rdx
cmpl $0x1, %eax
jne 0x6a453
leaq 0x7afd1(%rip), %rsi     # 0xe53f0
leaq 0x9dc72(%rip), %rdx     # 0x108098
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7abf5(%rip), %rsi     # 0xe5034
leaq 0x9dd07(%rip), %rdx     # 0x10814d
movq %r14, %rdi
movl $0xdf7, %ecx            # imm = 0xDF7
jmp 0x6a9f4
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 0x117fe
popq %rcx
popq %rdx
cmpl $0x1, %eax
jne 0x6a4cb
leaq 0x7af59(%rip), %rsi     # 0xe53f0
leaq 0x9dcdf(%rip), %rdx     # 0x10817d
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7ab7d(%rip), %rsi     # 0xe5034
leaq 0x9dc8f(%rip), %rdx     # 0x10814d
movq %r14, %rdi
movl $0xe04, %ecx            # imm = 0xE04
jmp 0x6a9f4
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 0x12065
popq %rcx
popq %rdx
cmpl $0x1, %eax
jne 0x6a53e
leaq 0x7aee6(%rip), %rsi     # 0xe53f0
leaq 0x9dd42(%rip), %rdx     # 0x108253
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7ab0a(%rip), %rsi     # 0xe5034
leaq 0x9dc1c(%rip), %rdx     # 0x10814d
movq %r14, %rdi
movl $0xe10, %ecx            # imm = 0xE10
jmp 0x6a9f4
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 0x117fe
popq %rcx
popq %rdx
cmpl $0x1, %eax
jne 0x6a5b6
leaq 0x7ae6e(%rip), %rsi     # 0xe53f0
leaq 0x9dd7e(%rip), %rdx     # 0x108307
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7aa92(%rip), %rsi     # 0xe5034
leaq 0x9dba4(%rip), %rdx     # 0x10814d
movq %r14, %rdi
movl $0xe1d, %ecx            # imm = 0xE1D
jmp 0x6a9f4
movl 0xf08(%rbx), %ebp
testl %ebp, %ebp
jle 0x6a665
decl %ebp
movq 0xf20(%rbx), %rax
movslq 0xf04(%rbx), %rcx
movslq %ebp, %r12
imulq %r12, %rcx
movslq 0xebc(%rbx), %rdx
addq %rcx, %rdx
movsd (%rax,%rdx,8), %xmm0
movapd 0x7ac3e(%rip), %xmm1    # 0xe5230
xorpd %xmm1, %xmm0
movlpd %xmm0, (%rax,%rdx,8)
movslq 0xec0(%rbx), %rsi
movslq %ecx, %rcx
addq %rcx, %rsi
movsd (%rax,%rsi,8), %xmm0
xorpd %xmm1, %xmm0
movlpd %xmm0, (%rax,%rsi,8)
movslq 0xeb0(%rbx), %rsi
addq %rcx, %rsi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%rax,%rdx,8), %xmm0
xorpd %xmm1, %xmm0
callq 0x86a0
mulsd 0x8(%rsp), %xmm0
movq 0xf20(%rbx), %rax
movslq 0xf04(%rbx), %rcx
imulq %r12, %rcx
movslq 0xec4(%rbx), %rdx
addq %rcx, %rdx
movsd %xmm0, (%rax,%rdx,8)
jmp 0x6a5bc
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 0x12065
popq %rcx
popq %rdx
cmpl $0x1, %eax
jne 0x6a6d8
leaq 0x7ad4c(%rip), %rsi     # 0xe53f0
leaq 0x9dba8(%rip), %rdx     # 0x108253
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7a970(%rip), %rsi     # 0xe5034
leaq 0x9da82(%rip), %rdx     # 0x10814d
movq %r14, %rdi
movl $0xe3b, %ecx            # imm = 0xE3B
jmp 0x6a9f4
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 0x12065
popq %rcx
popq %rdx
cmpl $0x1, %eax
jne 0x6a74b
leaq 0x7acd9(%rip), %rsi     # 0xe53f0
leaq 0x9db35(%rip), %rdx     # 0x108253
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7a8fd(%rip), %rsi     # 0xe5034
leaq 0x9da0f(%rip), %rdx     # 0x10814d
movq %r14, %rdi
movl $0xe47, %ecx            # imm = 0xE47
jmp 0x6a9f4
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 0x110a3
popq %rcx
popq %rdx
cmpl $0x1, %eax
jne 0x6a7c3
leaq 0x7ac61(%rip), %rsi     # 0xe53f0
leaq 0x9dc43(%rip), %rdx     # 0x1083d9
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7a885(%rip), %rsi     # 0xe5034
leaq 0x9d997(%rip), %rdx     # 0x10814d
movq %r14, %rdi
movl $0xe53, %ecx            # imm = 0xE53
jmp 0x6a9f4
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 0x7aa30(%rip), %xmm0    # 0xe5260
movq %rsi, %r13
movq %r13, %r12
decl %r9d
addq %r11, %r10
cmpq $0x2, %r13
jl 0x6a860
movapd %xmm0, %xmm2
divsd (%r14), %xmm2
divsd -0x8(%rdi,%r12,8), %xmm2
leaq -0x1(%r12), %r13
addq %r8, %r14
ucomisd %xmm2, %xmm1
ja 0x6a833
cmpw $0x1, 0x38(%rbx)
jne 0x6a8c0
movsd 0x1028(%rbx), %xmm1
ucomisd 0x7b469(%rip), %xmm1    # 0xe5ce0
movslq 0xeac(%rbx), %r11
movsd 0x648(%r15), %xmm1
jae 0x6a8d0
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 0x6a8bb
addq %rax, %r10
cmpq %r8, %r11
movq %r9, %r11
jl 0x6a897
decq %r9
jmp 0x6a904
sarq $0x20, %r10
xorl %eax, %eax
cmpq $0x2, %r12
cmovgeq %r10, %rax
jmp 0x6a907
movslq %r9d, %r10
leaq (%rdx,%r11,8), %r9
imulq %r10, %rax
addq %r9, %rax
leaq -0x1(%r10), %r9
testq %r10, %r10
jle 0x6a901
movapd %xmm0, %xmm2
divsd (%rax), %xmm2
divsd (%rdi,%r10,8), %xmm2
addq %r8, %rax
ucomisd %xmm2, %xmm1
movq %r9, %r10
ja 0x6a8de
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 0x6aa01
movl 0xed8(%rbx), %r8d
movl 0xee0(%rbx), %r9d
leaq 0x1064(%rbx), %r14
pushq %r14
pushq $0x1
callq 0x12065
popq %rcx
popq %rdx
cmpl $0x1, %eax
jne 0x6a981
leaq 0x7aaa0(%rip), %rsi     # 0xe53f0
leaq 0x9db55(%rip), %rdx     # 0x1084ac
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7a6c4(%rip), %rsi     # 0xe5034
leaq 0x9d7d6(%rip), %rdx     # 0x10814d
movq %r14, %rdi
movl $0xe82, %ecx            # imm = 0xE82
jmp 0x6a9f4
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 0x110a3
popq %rcx
popq %rdx
cmpl $0x1, %eax
jne 0x6aa01
leaq 0x7aa2b(%rip), %rsi     # 0xe53f0
leaq 0x9db8e(%rip), %rdx     # 0x10855a
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7a64f(%rip), %rsi     # 0xe5034
leaq 0x9d761(%rip), %rdx     # 0x10814d
movq %r14, %rdi
movl $0xe8e, %ecx            # imm = 0xE8E
movq %rbx, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq