// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../source/output.c
// Function: output_tk
int output_tk(
              struct background * pba,
              struct perturbations * ppt,
              struct output * pop
              ) {

  /** Summary: */

  /** - define local variables */
  char titles[_MAXTITLESTRINGLENGTH_]={0};
  double * data;
  int size_data, number_of_titles;

  FILE * tkfile;

  int index_md;
  int index_ic;
  int index_z;

  double z;

  FileName file_name;
  char redshift_suffix[7]; // 7 is enough to write "z%d_" as long as there are at most 10'000 bins
  char first_line[_LINE_LENGTH_MAX_];
  char ic_suffix[_SUFFIXNAMESIZE_];   // 4 is enough to write "ad", "bi", "cdi", "nid", "niv", ...


  index_md=ppt->index_md_scalars;

  if (pop->output_format == camb_format) {

    class_test(pba->N_ncdm>1,
               pop->error_message,
               "you wish to output the transfer functions in CMBFAST/CAMB format but you have more than one non-cold dark matter (ncdm) species. The two are not compatible (since CMBFAST/CAMB only have one ncdm species): switch to CLASS output format or keep only on ncdm species");

    class_test(ppt->has_velocity_transfers == _TRUE_,
               pop->error_message,
               "you wish to output the transfer functions in CMBFAST/CAMB format, but you requested velocity transfer functions. The two are not compatible (since CMBFAST/CAMB do not compute velocity transfer functions): switch to CLASS output format, or ask only for density transfer function");
  }


  class_call(perturbations_output_titles(pba,ppt,pop->output_format,titles),
             pba->error_message,
             pop->error_message);
  number_of_titles = get_number_of_titles(titles);
  size_data = number_of_titles*ppt->k_size[index_md];

  class_alloc(data, sizeof(double)*ppt->ic_size[index_md]*size_data, pop->error_message);

  for (index_z = 0; index_z < pop->z_pk_num; index_z++) {

    z = pop->z_pk[index_z];

    /** - first, check that requested redshift z_pk is consistent */

    class_test((pop->z_pk[index_z] > ppt->z_max_pk),
               pop->error_message,
               "T_i(k,z) computed up to z=%f but requested at z=%f. Must increase z_max_pk in precision file.",ppt->z_max_pk,pop->z_pk[index_z]);

    if (pop->z_pk_num == 1)
      redshift_suffix[0]='\0';
    else
      class_sprintf(redshift_suffix,"z%d_",index_z+1);

    /** - second, open only the relevant files, and write a heading in each of them */

    class_call(perturbations_output_data_at_z(pba,
                                              ppt,
                                              pop->output_format,
                                              pop->z_pk[index_z],
                                              number_of_titles,
                                              data
                                              ),
               ppt->error_message,
               pop->error_message);

    for (index_ic = 0; index_ic < ppt->ic_size[index_md]; index_ic++) {

      class_call(perturbations_output_firstline_and_ic_suffix(ppt, index_ic, first_line, ic_suffix),
                 ppt->error_message, pop->error_message);

      if ((ppt->has_ad == _TRUE_) && (ppt->ic_size[index_md] == 1) )
        class_sprintf(file_name,"%s%s%s",pop->root,redshift_suffix,"tk.dat");
      else
        class_sprintf(file_name,"%s%s%s%s%s",pop->root,redshift_suffix,"tk_",ic_suffix,".dat");

      class_open(tkfile, file_name, "w", pop->error_message);

      if (pop->write_header == _TRUE_) {
        if (pop->output_format == class_format) {
          fprintf(tkfile,"# Transfer functions T_i(k) %sat redshift z=%g\n",first_line,z);
          fprintf(tkfile,"# for k=%g to %g h/Mpc,\n",ppt->k[index_md][0]/pba->h,ppt->k[index_md][ppt->k_size[index_md]-1]/pba->h);
          fprintf(tkfile,"# number of wavenumbers equal to %d\n",ppt->k_size[index_md]);
          if (ppt->has_density_transfers == _TRUE_) {
            fprintf(tkfile,"# d_i   stands for (delta rho_i/rho_i)(k,z) with above normalization \n");
            fprintf(tkfile,"# d_tot stands for (delta rho_tot/rho_tot)(k,z) with rho_Lambda NOT included in rho_tot\n");
            fprintf(tkfile,"# (note that this differs from the transfer function output from CAMB/CMBFAST, which gives the same\n");
            fprintf(tkfile,"#  quantities divided by -k^2 with k in Mpc^-1; use format=camb to match CAMB)\n");
          }
          if (ppt->has_velocity_transfers == _TRUE_) {
            fprintf(tkfile,"# t_i   stands for theta_i(k,z) with above normalization \n");
            fprintf(tkfile,"# t_tot stands for (sum_i [rho_i+p_i] theta_i)/(sum_i [rho_i+p_i]))(k,z)\n");
          }
          fprintf(tkfile,"#\n");
        }
        else if (pop->output_format == camb_format) {

          fprintf(tkfile,"# Rescaled matter transfer functions [-T_i(k)/k^2] %sat redshift z=%g\n",first_line,z);
          fprintf(tkfile,"# for k=%g to %g h/Mpc,\n",ppt->k[index_md][0]/pba->h,ppt->k[index_md][ppt->k_size[index_md]-1]/pba->h);
          fprintf(tkfile,"# number of wavenumbers equal to %d\n",ppt->k_size[index_md]);
          fprintf(tkfile,"# T_i   stands for (delta rho_i/rho_i)(k,z) with above normalization \n");
          fprintf(tkfile,"# The rescaling factor [-1/k^2] with k in 1/Mpc is here to match the CMBFAST/CAMB output convention\n");
          fprintf(tkfile,"#\n");
          fprintf(tkfile,"#");
          fprintf(tkfile,"\n");

        }
      }

      output_print_data(tkfile,
                        titles,
                        data+index_ic*size_data,
                        size_data);

      /** - free memory and close files */
      fclose(tkfile);

    }

  }

  free(data);

  return _SUCCESS_;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x34b8, %rsp           # imm = 0x34B8
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r13
leaq 0x1570(%rsp), %rdi
movl $0x1f40, %edx           # imm = 0x1F40
xorl %esi, %esi
callq 0x8220
movslq 0x848(%r14), %rax
movq %rax, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
movl 0x40c(%rbx), %edx
cmpl $0x1, %edx
jne 0xe1985
cmpl $0x2, 0x248(%r13)
jl 0xe191d
leaq 0x44aa6(%rip), %rsi     # 0x12636a
leaq 0x170(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0x37a5(%rip), %rsi      # 0xe5082
leaq 0x44b8e(%rip), %rdx     # 0x126472
leaq 0xd70(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
movq 0x8(%rsp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x3728(%rip), %rsi      # 0xe5034
leaq 0x44b6d(%rip), %rdx     # 0x126480
movl $0x421, %ecx            # imm = 0x421
jmp 0xe1f73
cmpw $0x1, 0x36(%r14)
jne 0xe1985
leaq 0x44b5e(%rip), %rsi     # 0x12648a
leaq 0x170(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0x373d(%rip), %rsi      # 0xe5082
leaq 0x102b6(%rip), %rdx     # 0xf1c02
leaq 0xd70(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
movq 0x8(%rsp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x36c0(%rip), %rsi      # 0xe5034
leaq 0x44b05(%rip), %rdx     # 0x126480
movl $0x425, %ecx            # imm = 0x425
jmp 0xe1f73
leaq 0x1570(%rsp), %rcx
movq %r13, %rdi
movq %r14, %rsi
callq 0x6e45b
cmpl $0x1, %eax
jne 0xe19eb
addq $0xd1c, %r13            # imm = 0xD1C
leaq 0x3a45(%rip), %rsi      # 0xe53f0
leaq 0x44bee(%rip), %rdx     # 0x1265a0
leaq 0x170(%rsp), %r14
movq %r14, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x2e014
movq 0x8(%rsp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x365a(%rip), %rsi      # 0xe5034
leaq 0x44a9f(%rip), %rdx     # 0x126480
movl $0x42b, %ecx            # imm = 0x42B
jmp 0xe1fc3
leaq 0x1570(%rsp), %rdi
callq 0x2e156
movq 0x870(%r14), %rdx
movq 0x9c8(%r14), %rcx
movq 0x10(%rsp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl %eax, 0x3c(%rsp)
movslq %eax, %rbp
imulq %rcx, %rbp
movslq (%rdx,%rsi,4), %r15
movq %rbp, %rdi
imulq %r15, %rdi
shlq $0x3, %rdi
callq 0x8490
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0xe1edb
movq %rbp, %rax
shlq $0x3, %rax
movq %rax, 0x58(%rsp)
xorl %edx, %edx
movq %r14, 0x50(%rsp)
movq %r13, 0x30(%rsp)
movq %rbp, 0x60(%rsp)
movq 0x8(%rsp), %rax
movslq 0xe0(%rax), %rax
cmpq %rax, %rdx
jge 0xe1fe2
movq 0x8(%rsp), %rcx
movsd 0xe8(%rcx,%rdx,8), %xmm1
movsd 0x818(%r14), %xmm0
movsd %xmm1, 0x28(%rsp)
ucomisd %xmm0, %xmm1
ja 0xe1ff0
cmpl $0x1, %eax
movq %rdx, 0x48(%rsp)
jne 0xe1aac
movb $0x0, 0x21(%rsp)
movsd 0x28(%rsp), %xmm0
jmp 0xe1aee
leal 0x1(%rdx), %ebp
xorl %edi, %edi
xorl %esi, %esi
leaq 0x44500(%rip), %rbx     # 0x125fba
movq %rdx, %r15
movq %rbx, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
leaq 0x21(%rsp), %rdi
movq %rbx, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x8580
movq 0x8(%rsp), %rax
movsd 0xe8(%rax,%r15,8), %xmm0
movq 0x8(%rsp), %rax
movl 0x40c(%rax), %edx
movq %r13, %rdi
movq %r14, %rsi
movl 0x3c(%rsp), %ecx
movq 0x40(%rsp), %r15
movq %r15, %r8
callq 0x6d6d6
cmpl $0x1, %eax
je 0xe2056
movq %r15, %r13
xorl %ebx, %ebx
movq 0x870(%r14), %rax
movq 0x10(%rsp), %rcx
movslq (%rax,%rcx,4), %rax
cmpq %rax, %rbx
jge 0xe1ec9
movq %r14, %rdi
movl %ebx, %esi
leaq 0x970(%rsp), %rdx
leaq 0x1d(%rsp), %rcx
callq 0x6ecd5
cmpl $0x1, %eax
je 0xe1f2a
movq %rbx, 0x68(%rsp)
cmpw $0x1, 0x14(%r14)
jne 0xe1bc6
movq 0x870(%r14), %rax
movq 0x10(%rsp), %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0xe1bc6
xorl %edi, %edi
xorl %esi, %esi
leaq 0x44b7d(%rip), %r15     # 0x1266fe
movq %r15, %rdx
movq 0x8(%rsp), %rbx
movq %rbx, %rcx
leaq 0x21(%rsp), %r8
leaq 0x83cb(%rip), %rbp      # 0xe9f63
movq %rbp, %r9
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
leaq 0x70(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
movq %rbx, %rcx
leaq 0x21(%rsp), %r8
movq %rbp, %r9
xorl %eax, %eax
callq 0x8580
jmp 0xe1c39
xorl %edi, %edi
xorl %esi, %esi
leaq 0x44b29(%rip), %rdx     # 0x1266fa
movq 0x8(%rsp), %r14
movq %r14, %rcx
leaq 0x21(%rsp), %r15
movq %r15, %r8
movq %r13, %rbx
leaq 0x44b1a(%rip), %r13     # 0x126705
movq %r13, %r9
xorl %eax, %eax
leaq 0x83b4(%rip), %rbp      # 0xe9fab
pushq %rbp
leaq 0x25(%rsp), %r10
pushq %r10
callq 0x8580
addq $0x10, %rsp
incl %eax
movslq %eax, %rsi
leaq 0x70(%rsp), %r12
movq %r12, %rdi
leaq 0x44ade(%rip), %rdx     # 0x1266fa
movq %r14, %rcx
movq %r15, %r8
movq %r13, %r9
movq %rbx, %r13
xorl %eax, %eax
pushq %rbp
leaq 0x25(%rsp), %r10
pushq %r10
callq 0x8580
popq %rcx
popq %rdx
movq %r12, %rdi
leaq 0x679e(%rip), %rsi      # 0xe83e1
callq 0x8420
testq %rax, %rax
je 0xe1f78
movq %rax, %r15
movq 0x8(%rsp), %rax
cmpw $0x1, 0x408(%rax)
movq 0x50(%rsp), %r14
jne 0xe1e97
movq 0x8(%rsp), %rax
movl 0x40c(%rax), %eax
cmpl $0x1, %eax
je 0xe1dbb
testl %eax, %eax
jne 0xe1e97
movq %r15, %rdi
leaq 0x44a7e(%rip), %rsi     # 0x126710
leaq 0x970(%rsp), %rdx
movsd 0x28(%rsp), %xmm0
movb $0x1, %al
callq 0x8510
movq 0x9c8(%r14), %rax
movq 0x9d0(%r14), %rcx
movq 0x10(%rsp), %r12
movq (%rcx,%r12,8), %rcx
movsd (%rcx), %xmm0
movq 0x30(%rsp), %rdx
movsd 0x8(%rdx), %xmm2
divsd %xmm2, %xmm0
movslq (%rax,%r12,4), %rax
movsd -0x8(%rcx,%rax,8), %xmm1
divsd %xmm2, %xmm1
movq %r15, %rdi
leaq 0x44a58(%rip), %rsi     # 0x126740
movb $0x2, %al
callq 0x8510
movq 0x9c8(%r14), %rax
movl (%rax,%r12,4), %edx
movq %r15, %rdi
leaq 0x44a55(%rip), %rsi     # 0x126759
xorl %eax, %eax
callq 0x8510
cmpw $0x1, 0x34(%r14)
jne 0xe1d6b
leaq 0x44a64(%rip), %rdi     # 0x12677e
pushq $0x46
popq %rsi
pushq $0x1
popq %r12
movq %r12, %rdx
movq %r15, %rcx
callq 0x8700
leaq 0x44a92(%rip), %rdi     # 0x1267c5
pushq $0x58
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x8700
leaq 0x44ad6(%rip), %rdi     # 0x12681e
pushq $0x64
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x8700
leaq 0x44b26(%rip), %rdi     # 0x126883
pushq $0x4f
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x8700
cmpw $0x1, 0x36(%r14)
jne 0xe1da1
leaq 0x44b59(%rip), %rdi     # 0x1268d3
pushq $0x3a
popq %rsi
pushq $0x1
popq %r12
movq %r12, %rdx
movq %r15, %rcx
callq 0x8700
leaq 0x44b7b(%rip), %rdi     # 0x12690e
pushq $0x49
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x8700
leaq 0x1f5f5(%rip), %rdi     # 0x10139d
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x8700
jmp 0xe1e97
movq %r15, %rdi
leaq 0x44b93(%rip), %rsi     # 0x126958
leaq 0x970(%rsp), %rdx
movsd 0x28(%rsp), %xmm0
movb $0x1, %al
callq 0x8510
movq 0x9c8(%r14), %rax
movq 0x9d0(%r14), %rcx
movq 0x10(%rsp), %r12
movq (%rcx,%r12,8), %rcx
movsd (%rcx), %xmm0
movq 0x30(%rsp), %rdx
movsd 0x8(%rdx), %xmm2
divsd %xmm2, %xmm0
movslq (%rax,%r12,4), %rax
movsd -0x8(%rcx,%rax,8), %xmm1
divsd %xmm2, %xmm1
movq %r15, %rdi
leaq 0x44925(%rip), %rsi     # 0x126740
movb $0x2, %al
callq 0x8510
movq 0x9c8(%r14), %rax
movl (%rax,%r12,4), %edx
movq %r15, %rdi
leaq 0x44922(%rip), %rsi     # 0x126759
xorl %eax, %eax
callq 0x8510
leaq 0x44b5a(%rip), %rdi     # 0x12699f
pushq $0x46
popq %rsi
pushq $0x1
popq %r12
movq %r12, %rdx
movq %r15, %rcx
callq 0x8700
leaq 0x44b88(%rip), %rdi     # 0x1269e6
pushq $0x64
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x8700
leaq 0x1f52a(%rip), %rdi     # 0x10139d
pushq $0x2
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x8700
pushq $0x23
popq %rdi
movq %r15, %rsi
callq 0x8460
pushq $0xa
popq %rdi
movq %r15, %rsi
callq 0x8460
movq %r15, %rdi
leaq 0x1570(%rsp), %rsi
movq %r13, %rdx
movq 0x60(%rsp), %rcx
callq 0xe4991
movq %r15, %rdi
callq 0x83c0
movq 0x68(%rsp), %rbx
incq %rbx
addq 0x58(%rsp), %r13
jmp 0xe1b1e
movq 0x48(%rsp), %rdx
incq %rdx
movq 0x30(%rsp), %r13
jmp 0xe1a59
imull %ebp, %r15d
shll $0x3, %r15d
leaq 0x311a(%rip), %rsi      # 0xe5004
leaq 0x402fc(%rip), %rdx     # 0x1221ed
leaq 0x170(%rsp), %r14
movq %r14, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2e014
movq 0x8(%rsp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x311b(%rip), %rsi      # 0xe5034
leaq 0x44560(%rip), %rdx     # 0x126480
movl $0x42f, %ecx            # imm = 0x42F
jmp 0xe1fc3
addq $0x6c8a, %r14           # imm = 0x6C8A
leaq 0x34b8(%rip), %rsi      # 0xe53f0
leaq 0x44768(%rip), %rdx     # 0x1266a7
leaq 0x170(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
movq 0x8(%rsp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x30cd(%rip), %rsi      # 0xe5034
leaq 0x44512(%rip), %rdx     # 0x126480
movl $0x44f, %ecx            # imm = 0x44F
movq %r15, %r8
jmp 0xe1fc6
leaq 0x5a29(%rip), %rsi      # 0xe79a8
leaq 0x44783(%rip), %rdx     # 0x126709
leaq 0x1f367(%rip), %r8      # 0x1012f4
leaq 0x170(%rsp), %r14
leaq 0x70(%rsp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
movq 0x8(%rsp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x307d(%rip), %rsi      # 0xe5034
leaq 0x444c2(%rip), %rdx     # 0x126480
movl $0x456, %ecx            # imm = 0x456
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
addq $0x34b8, %rsp           # imm = 0x34B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%rsp), %rdi
callq 0x8430
xorl %eax, %eax
jmp 0xe1fd0
leaq 0x445e8(%rip), %rsi     # 0x1265df
leaq 0x170(%rsp), %r14
movq %r14, %rdi
movsd 0x28(%rsp), %xmm1
movb $0x2, %al
callq 0x2e014
leaq 0x306c(%rip), %rsi      # 0xe5082
leaq 0x43f78(%rip), %rdx     # 0x125f95
leaq 0xd70(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
movq 0x8(%rsp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x2fef(%rip), %rsi      # 0xe5034
leaq 0x44434(%rip), %rdx     # 0x126480
movl $0x439, %ecx            # imm = 0x439
jmp 0xe1f73
addq $0x6c8a, %r14           # imm = 0x6C8A
leaq 0x338c(%rip), %rsi      # 0xe53f0
leaq 0x445d2(%rip), %rdx     # 0x12663d
leaq 0x170(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
movq 0x8(%rsp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x2fa1(%rip), %rsi      # 0xe5034
leaq 0x443e6(%rip), %rdx     # 0x126480
movl $0x44a, %ecx            # imm = 0x44A
jmp 0xe1f73