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

  /** Summary: */

  /** Define local variables */
  double R;
  /* Initial time and dkappa/dtau */
  double tau_ini,dkappa_ini;
  double* tau_table_growing;
  int index_tau;
  int last_index_back;

  class_alloc(tau_table_growing,pth->tt_size*sizeof(double),pth->error_message);

  /* find the value of last_index_back for
     tau_table[pth->tt_size-1] = tau_table_growing[0] in order to
     speed up subsequent interpolations in the loop */
  class_call(background_at_tau(pba,
                               pth->tau_table[pth->tt_size-1],
                               normal_info,
                               inter_normal,
                               &last_index_back,
                               pvecback),
             pba->error_message,
             pth->error_message);

  /* compute integrand and store temporarily in column "ddkappa" */
  for (index_tau=0; index_tau < pth->tt_size; index_tau++) {

    tau_table_growing[index_tau] = pth->tau_table[pth->tt_size-1-index_tau];

    class_call(background_at_tau(pba,
                                 tau_table_growing[index_tau],
                                 normal_info,
                                 inter_closeby,
                                 &last_index_back,
                                 pvecback),
               pba->error_message,
               pth->error_message);

    R = 3./4.*pvecback[pba->index_bg_rho_b]/pvecback[pba->index_bg_rho_g];

    pth->thermodynamics_table[index_tau*pth->th_size+pth->index_th_ddkappa] =
      1./6./pth->thermodynamics_table[(pth->tt_size-1-index_tau)*pth->th_size+pth->index_th_dkappa]
      *(R*R/(1+R)+16./15.)/(1.+R);

  }

  /* compute second derivative of integrand, and store temporarily in column "dddkappa" */
  class_call(array_spline_table_line_to_line(tau_table_growing,
                                             pth->tt_size,
                                             pth->thermodynamics_table,
                                             pth->th_size,
                                             pth->index_th_ddkappa,
                                             pth->index_th_dddkappa,
                                             _SPLINE_EST_DERIV_,
                                             pth->error_message),
             pth->error_message,
             pth->error_message);

  /* compute integratal and store temporarily in column "g" */
  class_call(array_integrate_spline_table_line_to_line(tau_table_growing,
                                                       pth->tt_size,
                                                       pth->thermodynamics_table,
                                                       pth->th_size,
                                                       pth->index_th_ddkappa,
                                                       pth->index_th_dddkappa,
                                                       pth->index_th_g,
                                                       pth->error_message),
             pth->error_message,
             pth->error_message);

  free(tau_table_growing);

  /* we could now write the result as r_d = 2pi * sqrt(integral),
   *  but we will first better acount for the contribution frokm the tau_ini boundary.
   *  Close to this boundary, R=0 and the integrand is just 16/(15*6)/kappa'
   *  Using kappa' propto 1/a^2 and tau propro a during RD, we get the analytic result:
   *  int_0^{tau_ini} dtau / kappa' = tau_ini / 3 / kappa'_ini
   *  Thus r_d = 2pi * sqrt( 16/(15*6*3) * (tau_ini/ kappa'_ini) * integral)
   */

  tau_ini = pth->tau_table[pth->tt_size-1];
  dkappa_ini = pth->thermodynamics_table[(pth->tt_size-1)*pth->th_size+pth->index_th_dkappa];

  for (index_tau=0; index_tau < pth->tt_size; index_tau++) {

    pth->thermodynamics_table[index_tau*pth->th_size+pth->index_th_r_d] =
      2.*_PI_*sqrt(16./(15.*6.*3.)*tau_ini/dkappa_ini
                   +pth->thermodynamics_table[(pth->tt_size-1-index_tau)*pth->th_size+pth->index_th_g]);

  }

  return _SUCCESS_;
}

// Assembly:
subq $0x2868, %rsp           # imm = 0x2868
movq %rdi, 0x2858(%rsp)
movq %rsi, 0x2850(%rsp)
movq %rdx, 0x2848(%rsp)
movq 0x2850(%rsp), %rax
movslq 0xf08(%rax), %rdi
shlq $0x3, %rdi
callq 0x8460
movq %rax, 0x2828(%rsp)
cmpq $0x0, 0x2828(%rsp)
jne 0xc0399
movq 0x2850(%rsp), %rax
movslq 0xf08(%rax), %rax
shlq $0x3, %rax
movl %eax, 0x281c(%rsp)
leaq 0x2010(%rsp), %rdi
movl 0x281c(%rsp), %ecx
leaq 0x111cba(%rip), %rsi    # 0x1d2004
leaq 0x13440c(%rip), %rdx    # 0x1f475d
movb $0x0, %al
callq 0x5b9c0
movq 0x2850(%rsp), %rdi
addq $0x1064, %rdi           # imm = 0x1064
leaq 0x2010(%rsp), %r8
leaq 0x111cbe(%rip), %rsi    # 0x1d2034
leaq 0x1343f2(%rip), %rdx    # 0x1f476f
movl $0xcbc, %ecx            # imm = 0xCBC
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2864(%rsp)
jmp 0xc09f8
movq 0x2858(%rsp), %rdi
movq 0x2850(%rsp), %rax
movq 0xf18(%rax), %rax
movq 0x2850(%rsp), %rcx
movl 0xf08(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x2848(%rsp), %r8
movl $0x1, %esi
xorl %edx, %edx
leaq 0x2820(%rsp), %rcx
callq 0x9e9b0
cmpl $0x1, %eax
jne 0xc0457
leaq 0x1810(%rsp), %rdi
movq 0x2858(%rsp), %rcx
addq $0xd1c, %rcx            # imm = 0xD1C
leaq 0x111fd0(%rip), %rsi    # 0x1d23d8
leaq 0x134387(%rip), %rdx    # 0x1f4796
movb $0x0, %al
callq 0x5b9c0
movq 0x2850(%rsp), %rdi
addq $0x1064, %rdi           # imm = 0x1064
leaq 0x1810(%rsp), %r8
leaq 0x111c00(%rip), %rsi    # 0x1d2034
leaq 0x134334(%rip), %rdx    # 0x1f476f
movl $0xcc8, %ecx            # imm = 0xCC8
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2864(%rsp)
jmp 0xc09f8
movl $0x0, 0x2824(%rsp)
movl 0x2824(%rsp), %eax
movq 0x2850(%rsp), %rcx
cmpl 0xf08(%rcx), %eax
jge 0xc06a6
movq 0x2850(%rsp), %rax
movq 0xf18(%rax), %rax
movq 0x2850(%rsp), %rcx
movl 0xf08(%rcx), %ecx
subl $0x1, %ecx
subl 0x2824(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x2828(%rsp), %rax
movslq 0x2824(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x2858(%rsp), %rdi
movq 0x2828(%rsp), %rax
movslq 0x2824(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x2848(%rsp), %r8
movl $0x1, %edx
leaq 0x2820(%rsp), %rcx
movl %edx, %esi
callq 0x9e9b0
cmpl $0x1, %eax
jne 0xc056c
leaq 0x1010(%rsp), %rdi
movq 0x2858(%rsp), %rcx
addq $0xd1c, %rcx            # imm = 0xD1C
leaq 0x111ebb(%rip), %rsi    # 0x1d23d8
leaq 0x1342e0(%rip), %rdx    # 0x1f4804
movb $0x0, %al
callq 0x5b9c0
movq 0x2850(%rsp), %rdi
addq $0x1064, %rdi           # imm = 0x1064
leaq 0x1010(%rsp), %r8
leaq 0x111aeb(%rip), %rsi    # 0x1d2034
leaq 0x13421f(%rip), %rdx    # 0x1f476f
movl $0xcd6, %ecx            # imm = 0xCD6
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2864(%rsp)
jmp 0xc09f8
movq 0x2848(%rsp), %rax
movq 0x2858(%rsp), %rcx
movslq 0x390(%rcx), %rcx
movsd 0x11273d(%rip), %xmm0   # 0x1d2cc8
mulsd (%rax,%rcx,8), %xmm0
movq 0x2848(%rsp), %rax
movq 0x2858(%rsp), %rcx
movslq 0x38c(%rcx), %rcx
divsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x2840(%rsp)
movq 0x2850(%rsp), %rax
movq 0xf20(%rax), %rax
movq 0x2850(%rsp), %rcx
movl 0xf08(%rcx), %ecx
subl $0x1, %ecx
subl 0x2824(%rsp), %ecx
movq 0x2850(%rsp), %rdx
imull 0xf04(%rdx), %ecx
movq 0x2850(%rsp), %rdx
addl 0xe80(%rdx), %ecx
movslq %ecx, %rcx
movsd 0x114f1c(%rip), %xmm0   # 0x1d5520
divsd (%rax,%rcx,8), %xmm0
movsd 0x2840(%rsp), %xmm1
mulsd 0x2840(%rsp), %xmm1
movsd 0x111c25(%rip), %xmm2   # 0x1d2248
addsd 0x2840(%rsp), %xmm2
divsd %xmm2, %xmm1
movsd 0x130f50(%rip), %xmm2   # 0x1f1588
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x111c00(%rip), %xmm1   # 0x1d2248
addsd 0x2840(%rsp), %xmm1
divsd %xmm1, %xmm0
movq 0x2850(%rsp), %rax
movq 0xf20(%rax), %rax
movl 0x2824(%rsp), %ecx
movq 0x2850(%rsp), %rdx
imull 0xf04(%rdx), %ecx
movq 0x2850(%rsp), %rdx
addl 0xe88(%rdx), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x2824(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2824(%rsp)
jmp 0xc0462
movq 0x2828(%rsp), %rdi
movq 0x2850(%rsp), %rax
movl 0xf08(%rax), %esi
movq 0x2850(%rsp), %rax
movq 0xf20(%rax), %rdx
movq 0x2850(%rsp), %rax
movl 0xf04(%rax), %ecx
movq 0x2850(%rsp), %rax
movl 0xe88(%rax), %r8d
movq 0x2850(%rsp), %rax
movl 0xe8c(%rax), %r9d
movq 0x2850(%rsp), %rax
addq $0x1064, %rax           # imm = 0x1064
movl $0x1, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x1c1c0
cmpl $0x1, %eax
jne 0xc0788
leaq 0x810(%rsp), %rdi
movq 0x2850(%rsp), %rcx
addq $0x1064, %rcx           # imm = 0x1064
leaq 0x111c9f(%rip), %rsi    # 0x1d23d8
leaq 0x134131(%rip), %rdx    # 0x1f4871
movb $0x0, %al
callq 0x5b9c0
movq 0x2850(%rsp), %rdi
addq $0x1064, %rdi           # imm = 0x1064
leaq 0x810(%rsp), %r8
leaq 0x1118cf(%rip), %rsi    # 0x1d2034
leaq 0x134003(%rip), %rdx    # 0x1f476f
movl $0xcea, %ecx            # imm = 0xCEA
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2864(%rsp)
jmp 0xc09f8
movq 0x2828(%rsp), %rdi
movq 0x2850(%rsp), %rax
movl 0xf08(%rax), %esi
movq 0x2850(%rsp), %rax
movq 0xf20(%rax), %rdx
movq 0x2850(%rsp), %rax
movl 0xf04(%rax), %ecx
movq 0x2850(%rsp), %rax
movl 0xe88(%rax), %r8d
movq 0x2850(%rsp), %rax
movl 0xe8c(%rax), %r9d
movq 0x2850(%rsp), %rax
movl 0xe94(%rax), %r10d
movq 0x2850(%rsp), %rax
addq $0x1064, %rax           # imm = 0x1064
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x1ac60
cmpl $0x1, %eax
jne 0xc0870
leaq 0x10(%rsp), %rdi
movq 0x2850(%rsp), %rcx
addq $0x1064, %rcx           # imm = 0x1064
leaq 0x111bb4(%rip), %rsi    # 0x1d23d8
leaq 0x1340f6(%rip), %rdx    # 0x1f4921
movb $0x0, %al
callq 0x5b9c0
movq 0x2850(%rsp), %rdi
addq $0x1064, %rdi           # imm = 0x1064
leaq 0x10(%rsp), %r8
leaq 0x1117e7(%rip), %rsi    # 0x1d2034
leaq 0x133f1b(%rip), %rdx    # 0x1f476f
movl $0xcf6, %ecx            # imm = 0xCF6
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2864(%rsp)
jmp 0xc09f8
movq 0x2828(%rsp), %rdi
callq 0x8420
movq 0x2850(%rsp), %rax
movq 0xf18(%rax), %rax
movq 0x2850(%rsp), %rcx
movl 0xf08(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x2838(%rsp)
movq 0x2850(%rsp), %rax
movq 0xf20(%rax), %rax
movq 0x2850(%rsp), %rcx
movl 0xf08(%rcx), %ecx
subl $0x1, %ecx
movq 0x2850(%rsp), %rdx
imull 0xf04(%rdx), %ecx
movq 0x2850(%rsp), %rdx
addl 0xe80(%rdx), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x2830(%rsp)
movl $0x0, 0x2824(%rsp)
movl 0x2824(%rsp), %eax
movq 0x2850(%rsp), %rcx
cmpl 0xf08(%rcx), %eax
jge 0xc09ed
movsd 0x130c56(%rip), %xmm0   # 0x1f1580
mulsd 0x2838(%rsp), %xmm0
divsd 0x2830(%rsp), %xmm0
movq 0x2850(%rsp), %rax
movq 0xf20(%rax), %rax
movq 0x2850(%rsp), %rcx
movl 0xf08(%rcx), %ecx
subl $0x1, %ecx
subl 0x2824(%rsp), %ecx
movq 0x2850(%rsp), %rdx
imull 0xf04(%rdx), %ecx
movq 0x2850(%rsp), %rdx
addl 0xe94(%rdx), %ecx
movslq %ecx, %rcx
addsd (%rax,%rcx,8), %xmm0
callq 0x82e0
movaps %xmm0, %xmm1
movsd 0x114af0(%rip), %xmm0   # 0x1d5488
mulsd %xmm1, %xmm0
movq 0x2850(%rsp), %rax
movq 0xf20(%rax), %rax
movl 0x2824(%rsp), %ecx
movq 0x2850(%rsp), %rdx
imull 0xf04(%rdx), %ecx
movq 0x2850(%rsp), %rdx
addl 0xf00(%rdx), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x2824(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2824(%rsp)
jmp 0xc0907
movl $0x0, 0x2864(%rsp)
movl 0x2864(%rsp), %eax
addq $0x2868, %rsp           # imm = 0x2868
retq
nopw (%rax,%rax)