// File: /workspace/github_c_makefile_star2_O3/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 0x6ed6e
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 0x13d65
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x6e9ef
leaq 0x7fa35(%rip), %rsi     # 0xee3f0
leaq 0xa2836(%rip), %rdx     # 0x1111f8
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x7f659(%rip), %rsi     # 0xee034
leaq 0xa28cb(%rip), %rdx     # 0x1112ad
movq %r14, %rdi
movl $0xdf7, %ecx            # imm = 0xDF7
jmp 0x6efa3
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 0x134f5
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x6ea69
leaq 0x7f9bb(%rip), %rsi     # 0xee3f0
leaq 0xa28a1(%rip), %rdx     # 0x1112dd
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x7f5df(%rip), %rsi     # 0xee034
leaq 0xa2851(%rip), %rdx     # 0x1112ad
movq %r14, %rdi
movl $0xe04, %ecx            # imm = 0xE04
jmp 0x6efa3
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 0x13d65
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x6eade
leaq 0x7f946(%rip), %rsi     # 0xee3f0
leaq 0xa2902(%rip), %rdx     # 0x1113b3
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x7f56a(%rip), %rsi     # 0xee034
leaq 0xa27dc(%rip), %rdx     # 0x1112ad
movq %r14, %rdi
movl $0xe10, %ecx            # imm = 0xE10
jmp 0x6efa3
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 0x134f5
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x6eb58
leaq 0x7f8cc(%rip), %rsi     # 0xee3f0
leaq 0xa293c(%rip), %rdx     # 0x111467
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x7f4f0(%rip), %rsi     # 0xee034
leaq 0xa2762(%rip), %rdx     # 0x1112ad
movq %r14, %rdi
movl $0xe1d, %ecx            # imm = 0xE1D
jmp 0x6efa3
movl 0xf04(%rbx), %ecx
movl 0xf08(%rbx), %r12d
movq 0xf20(%rbx), %rdx
testl %r12d, %r12d
jle 0x6ec1a
incl %r12d
leal -0x2(%r12), %ebp
imull %ebp, %ecx
movslq 0xebc(%rbx), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movsd (%rdx,%rax,8), %xmm0
movapd 0x7f696(%rip), %xmm1    # 0xee230
xorpd %xmm1, %xmm0
movlpd %xmm0, (%rdx,%rax,8)
movslq 0xec0(%rbx), %rsi
addq %rcx, %rsi
movsd (%rdx,%rsi,8), %xmm0
xorpd %xmm1, %xmm0
movlpd %xmm0, (%rdx,%rsi,8)
movslq 0xeb0(%rbx), %rsi
addq %rcx, %rsi
movsd (%rdx,%rsi,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%rdx,%rax,8), %xmm0
xorpd %xmm1, %xmm0
callq 0x8670
mulsd 0x8(%rsp), %xmm0
movq 0xf20(%rbx), %rdx
movl 0xf04(%rbx), %ecx
imull %ecx, %ebp
movslq 0xec4(%rbx), %rax
movslq %ebp, %rsi
addq %rax, %rsi
movsd %xmm0, (%rdx,%rsi,8)
decl %r12d
cmpl $0x1, %r12d
ja 0x6eb78
movl 0xf08(%rbx), %r12d
movq 0xf18(%rbx), %rdi
movl 0xeac(%rbx), %r8d
movl 0xeb4(%rbx), %r9d
movl %r12d, %esi
pushq %r14
pushq $0x1
callq 0x13d65
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x6ec7f
leaq 0x7f7a5(%rip), %rsi     # 0xee3f0
leaq 0xa2761(%rip), %rdx     # 0x1113b3
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x7f3c9(%rip), %rsi     # 0xee034
leaq 0xa263b(%rip), %rdx     # 0x1112ad
movq %r14, %rdi
movl $0xe3b, %ecx            # imm = 0xE3B
jmp 0x6efa3
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 0x13d65
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x6ecf4
leaq 0x7f730(%rip), %rsi     # 0xee3f0
leaq 0xa26ec(%rip), %rdx     # 0x1113b3
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x7f354(%rip), %rsi     # 0xee034
leaq 0xa25c6(%rip), %rdx     # 0x1112ad
movq %r14, %rdi
movl $0xe47, %ecx            # imm = 0xE47
jmp 0x6efa3
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 0x12d5d
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x6ed6e
leaq 0x7f6b6(%rip), %rsi     # 0xee3f0
leaq 0xa27f8(%rip), %rdx     # 0x111539
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x7f2da(%rip), %rsi     # 0xee034
leaq 0xa254c(%rip), %rdx     # 0x1112ad
movq %r14, %rdi
movl $0xe53, %ecx            # imm = 0xE53
jmp 0x6efa3
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 0x7f485(%rip), %xmm0    # 0xee260
movq %rsi, %r13
movq %r13, %r12
decl %r9d
addq %r11, %r10
cmpq $0x2, %r13
jl 0x6ee0b
movapd %xmm0, %xmm2
divsd (%r14), %xmm2
divsd -0x8(%rdi,%r12,8), %xmm2
leaq -0x1(%r12), %r13
addq %r8, %r14
ucomisd %xmm2, %xmm1
ja 0x6edde
cmpw $0x1, 0x38(%rbx)
jne 0x6ee6b
movsd 0x1028(%rbx), %xmm1
ucomisd 0x7fede(%rip), %xmm1    # 0xeed00
movslq 0xeac(%rbx), %r11
movsd 0x648(%r15), %xmm1
jae 0x6ee7b
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 0x6ee66
addq %rax, %r10
cmpq %r8, %r11
movq %r9, %r11
jl 0x6ee42
decq %r9
jmp 0x6eeaf
sarq $0x20, %r10
xorl %eax, %eax
cmpq $0x2, %r12
cmovgeq %r10, %rax
jmp 0x6eeb2
movslq %r9d, %r10
leaq (%rdx,%r11,8), %r9
imulq %r10, %rax
addq %r9, %rax
leaq -0x1(%r10), %r9
testq %r10, %r10
jle 0x6eeac
movapd %xmm0, %xmm2
divsd (%rax), %xmm2
divsd (%rdi,%r10,8), %xmm2
addq %r8, %rax
ucomisd %xmm2, %xmm1
movq %r9, %r10
ja 0x6ee89
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 0x6efb2
movl 0xed8(%rbx), %r8d
movl 0xee0(%rbx), %r9d
leaq 0x1064(%rbx), %r14
pushq %r14
pushq $0x1
callq 0x13d65
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x6ef2e
leaq 0x7f4f3(%rip), %rsi     # 0xee3f0
leaq 0xa2708(%rip), %rdx     # 0x11160c
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x7f117(%rip), %rsi     # 0xee034
leaq 0xa2389(%rip), %rdx     # 0x1112ad
movq %r14, %rdi
movl $0xe82, %ecx            # imm = 0xE82
jmp 0x6efa3
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 0x12d5d
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x6efb2
leaq 0x7f47c(%rip), %rsi     # 0xee3f0
leaq 0xa273f(%rip), %rdx     # 0x1116ba
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x7f0a0(%rip), %rsi     # 0xee034
leaq 0xa2312(%rip), %rdx     # 0x1112ad
movq %r14, %rdi
movl $0xe8e, %ecx            # imm = 0xE8E
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %ebp
movl %ebp, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq