// File: /workspace/github_c_makefile_star2_O3/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 $0x34a8, %rsp           # imm = 0x34A8
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r13
leaq 0x1560(%rsp), %rdi
movl $0x1f40, %edx           # imm = 0x1F40
xorl %esi, %esi
callq 0x8200
movslq 0x848(%r14), %rax
movq %rax, (%rsp)
movl 0x40c(%rbx), %edx
cmpl $0x1, %edx
jne 0xea04c
cmpl $0x2, 0x248(%r13)
jl 0xe9fe6
leaq 0x4556b(%rip), %rsi     # 0x12f4fa
leaq 0x160(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x40da(%rip), %rsi      # 0xee082
leaq 0x45653(%rip), %rdx     # 0x12f602
leaq 0xd60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x4062(%rip), %rsi      # 0xee034
leaq 0x45637(%rip), %rdx     # 0x12f610
movq %rbx, %rdi
movl $0x421, %ecx            # imm = 0x421
jmp 0xea661
cmpw $0x1, 0x36(%r14)
jne 0xea04c
leaq 0x45625(%rip), %rsi     # 0x12f61a
leaq 0x160(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x4074(%rip), %rsi      # 0xee082
leaq 0x10d25(%rip), %rdx     # 0xfad3a
leaq 0xd60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x3ffc(%rip), %rsi      # 0xee034
leaq 0x455d1(%rip), %rdx     # 0x12f610
movq %rbx, %rdi
movl $0x425, %ecx            # imm = 0x425
jmp 0xea661
leaq 0x1560(%rsp), %rcx
movq %r13, %rdi
movq %r14, %rsi
callq 0x72aaa
cmpl $0x1, %eax
jne 0xea0b0
addq $0xd1c, %r13            # imm = 0xD1C
leaq 0x437e(%rip), %rsi      # 0xee3f0
leaq 0x456b7(%rip), %rdx     # 0x12f730
leaq 0x160(%rsp), %r14
movq %r14, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x3f98(%rip), %rsi      # 0xee034
leaq 0x4556d(%rip), %rdx     # 0x12f610
movq %rbx, %rdi
movl $0x42b, %ecx            # imm = 0x42B
jmp 0xea6b1
leaq 0x1560(%rsp), %rdi
callq 0x30c32
movq 0x870(%r14), %rdx
movq 0x9c8(%r14), %rcx
movq (%rsp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl %eax, 0x34(%rsp)
movslq %eax, %rbp
imulq %rcx, %rbp
movslq (%rdx,%rsi,4), %r12
movq %rbp, %rdi
imulq %r12, %rdi
shlq $0x3, %rdi
callq 0x8460
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0xea5cd
movl 0xe0(%rbx), %eax
testl %eax, %eax
jle 0xea5bc
movq %rbp, %rcx
shlq $0x3, %rcx
movq %rcx, 0x50(%rsp)
xorl %ecx, %ecx
movq %rbp, 0x58(%rsp)
movq %rbx, 0x38(%rsp)
movq %r14, 0x48(%rsp)
movq %r13, 0x20(%rsp)
movsd 0xe8(%rbx,%rcx,8), %xmm1
movsd 0x818(%r14), %xmm0
movsd %xmm1, 0x10(%rsp)
ucomisd %xmm0, %xmm1
ja 0xea6d2
cmpl $0x1, %eax
movq %rcx, 0x40(%rsp)
jne 0xea169
movb $0x0, 0x19(%rsp)
movsd 0x10(%rsp), %xmm0
jmp 0xea1a6
leal 0x1(%rcx), %ebp
xorl %edi, %edi
xorl %esi, %esi
leaq 0x44fd3(%rip), %r15     # 0x12f14a
movq %r15, %rdx
movq %rcx, %r12
movl %ebp, %ecx
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
leaq 0x19(%rsp), %rdi
movq %r15, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x8550
movsd 0xe8(%rbx,%r12,8), %xmm0
movl 0x40c(%rbx), %edx
movq %r13, %rdi
movq %r14, %rsi
movl 0x34(%rsp), %ecx
movq 0x28(%rsp), %r8
callq 0x71d20
cmpl $0x1, %eax
je 0xea736
movq 0x870(%r14), %rax
movq (%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jle 0xea59f
movq 0x28(%rsp), %r13
xorl %ebp, %ebp
movq %r14, %rdi
movl %ebp, %esi
leaq 0x960(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x73341
cmpl $0x1, %eax
je 0xea61a
cmpw $0x1, 0x14(%r14)
jne 0xea26a
movq 0x870(%r14), %rax
movq (%rsp), %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0xea26a
xorl %edi, %edi
xorl %esi, %esi
leaq 0x45665(%rip), %r14     # 0x12f88e
movq %r14, %rdx
movq %rbx, %rcx
leaq 0x19(%rsp), %r12
movq %r12, %r8
leaq 0x8e5d(%rip), %r15      # 0xf309b
movq %r15, %r9
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %rbx, %rcx
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rdx
movq %r12, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x8550
jmp 0xea2e8
xorl %edi, %edi
xorl %esi, %esi
movq %rbp, %r12
leaq 0x45612(%rip), %rbp     # 0x12f88a
movq %rbp, %rdx
movq %rbx, %rcx
leaq 0x19(%rsp), %r15
movq %r15, %r8
movq %r13, %r14
leaq 0x45605(%rip), %r13     # 0x12f895
movq %r13, %r9
xorl %eax, %eax
leaq 0x8e47(%rip), %r10      # 0xf30e3
pushq %r10
leaq 0x14(%rsp), %r10
pushq %r10
callq 0x8550
addq $0x10, %rsp
incl %eax
movslq %eax, %rsi
movq %rbx, %rcx
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
movq %r12, %rbp
movq %r15, %r8
movq %r13, %r9
movq %r14, %r13
xorl %eax, %eax
leaq 0x8e0d(%rip), %r10      # 0xf30e3
pushq %r10
leaq 0x14(%rsp), %r10
pushq %r10
callq 0x8550
addq $0x10, %rsp
movq %rbx, %rdi
leaq 0x712f(%rip), %rsi      # 0xf1421
callq 0x8400
testq %rax, %rax
je 0xea666
movq %rax, %r12
movq 0x38(%rsp), %rbx
cmpw $0x1, 0x408(%rbx)
movq 0x48(%rsp), %r14
jne 0xea55f
movl 0x40c(%rbx), %eax
cmpl $0x1, %eax
je 0xea478
testl %eax, %eax
jne 0xea55f
movq %r12, %rdi
leaq 0x45564(%rip), %rsi     # 0x12f8a0
leaq 0x960(%rsp), %rdx
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x84e0
movq 0x9c8(%r14), %rax
movq 0x9d0(%r14), %rcx
movq (%rsp), %r15
movq (%rcx,%r15,8), %rcx
movsd (%rcx), %xmm0
movq 0x20(%rsp), %rdx
movsd 0x8(%rdx), %xmm2
divsd %xmm2, %xmm0
movslq (%rax,%r15,4), %rax
movsd -0x8(%rcx,%rax,8), %xmm1
divsd %xmm2, %xmm1
movq %r12, %rdi
leaq 0x4553f(%rip), %rsi     # 0x12f8d0
movb $0x2, %al
callq 0x84e0
movq 0x9c8(%r14), %rax
movl (%rax,%r15,4), %edx
movq %r12, %rdi
leaq 0x4553c(%rip), %rsi     # 0x12f8e9
xorl %eax, %eax
callq 0x84e0
cmpw $0x1, 0x34(%r14)
jne 0xea420
movl $0x46, %esi
movl $0x1, %edx
leaq 0x45541(%rip), %rdi     # 0x12f90e
movq %r12, %rcx
callq 0x86d0
movl $0x58, %esi
movl $0x1, %edx
leaq 0x4556f(%rip), %rdi     # 0x12f955
movq %r12, %rcx
callq 0x86d0
movl $0x64, %esi
movl $0x1, %edx
leaq 0x455af(%rip), %rdi     # 0x12f9ae
movq %r12, %rcx
callq 0x86d0
movl $0x4f, %esi
movl $0x1, %edx
leaq 0x455fb(%rip), %rdi     # 0x12fa13
movq %r12, %rcx
callq 0x86d0
cmpw $0x1, 0x36(%r14)
jne 0xea45a
movl $0x3a, %esi
movl $0x1, %edx
leaq 0x4562a(%rip), %rdi     # 0x12fa63
movq %r12, %rcx
callq 0x86d0
movl $0x49, %esi
movl $0x1, %edx
leaq 0x4564c(%rip), %rdi     # 0x12fa9e
movq %r12, %rcx
callq 0x86d0
movl $0x2, %esi
movl $0x1, %edx
leaq 0x2006a(%rip), %rdi     # 0x10a4d5
movq %r12, %rcx
callq 0x86d0
jmp 0xea55f
movq %r12, %rdi
leaq 0x45666(%rip), %rsi     # 0x12fae8
leaq 0x960(%rsp), %rdx
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x84e0
movq 0x9c8(%r14), %rax
movq 0x9d0(%r14), %rcx
movq (%rsp), %r15
movq (%rcx,%r15,8), %rcx
movsd (%rcx), %xmm0
movq 0x20(%rsp), %rdx
movsd 0x8(%rdx), %xmm2
divsd %xmm2, %xmm0
movslq (%rax,%r15,4), %rax
movsd -0x8(%rcx,%rax,8), %xmm1
divsd %xmm2, %xmm1
movq %r12, %rdi
leaq 0x453f9(%rip), %rsi     # 0x12f8d0
movb $0x2, %al
callq 0x84e0
movq 0x9c8(%r14), %rax
movl (%rax,%r15,4), %edx
movq %r12, %rdi
leaq 0x453f6(%rip), %rsi     # 0x12f8e9
xorl %eax, %eax
callq 0x84e0
movl $0x46, %esi
movl $0x1, %edx
leaq 0x45624(%rip), %rdi     # 0x12fb2f
movq %r12, %rcx
callq 0x86d0
movl $0x64, %esi
movl $0x1, %edx
leaq 0x45652(%rip), %rdi     # 0x12fb76
movq %r12, %rcx
callq 0x86d0
movl $0x2, %esi
movl $0x1, %edx
leaq 0x1ff98(%rip), %rdi     # 0x10a4d5
movq %r12, %rcx
callq 0x86d0
movl $0x23, %edi
movq %r12, %rsi
callq 0x8440
movl $0xa, %edi
movq %r12, %rsi
callq 0x8440
movq %r12, %rdi
leaq 0x1560(%rsp), %rsi
movq %r13, %rdx
movq 0x58(%rsp), %rcx
callq 0xed1c2
movq %r12, %rdi
callq 0x83a0
incq %rbp
movq 0x870(%r14), %rax
movq (%rsp), %rcx
movslq (%rax,%rcx,4), %rax
addq 0x50(%rsp), %r13
cmpq %rax, %rbp
jl 0xea1e5
movq 0x40(%rsp), %rcx
incq %rcx
movslq 0xe0(%rbx), %rax
cmpq %rax, %rcx
movq 0x20(%rsp), %r13
jl 0xea130
movq 0x28(%rsp), %rdi
callq 0x8410
xorl %eax, %eax
jmp 0xea6c0
imull %ebp, %r12d
shll $0x3, %r12d
leaq 0x3a28(%rip), %rsi      # 0xee004
leaq 0x40d9a(%rip), %rdx     # 0x12b37d
leaq 0x160(%rsp), %r14
movq %r14, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x3a2e(%rip), %rsi      # 0xee034
leaq 0x45003(%rip), %rdx     # 0x12f610
movq %rbx, %rdi
movl $0x42f, %ecx            # imm = 0x42F
jmp 0xea6b1
addq $0x6c8a, %r14           # imm = 0x6C8A
leaq 0x3dc8(%rip), %rsi      # 0xee3f0
leaq 0x45208(%rip), %rdx     # 0x12f837
leaq 0x160(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x39e2(%rip), %rsi      # 0xee034
leaq 0x44fb7(%rip), %rdx     # 0x12f610
movq %rbx, %rdi
movl $0x44f, %ecx            # imm = 0x44F
movq %r15, %r8
jmp 0xea6b4
leaq 0x637b(%rip), %rsi      # 0xf09e8
leaq 0x45225(%rip), %rdx     # 0x12f899
leaq 0x1fdb1(%rip), %r8      # 0x10a42c
leaq 0x160(%rsp), %r14
leaq 0x60(%rsp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
movq 0x38(%rsp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x398f(%rip), %rsi      # 0xee034
leaq 0x44f64(%rip), %rdx     # 0x12f610
movl $0x456, %ecx            # imm = 0x456
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
addq $0x34a8, %rsp           # imm = 0x34A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45096(%rip), %rsi     # 0x12f76f
leaq 0x160(%rsp), %r14
movq %r14, %rdi
movsd 0x10(%rsp), %xmm1
movb $0x2, %al
callq 0x30af0
leaq 0x398a(%rip), %rsi      # 0xee082
leaq 0x44a26(%rip), %rdx     # 0x12f125
leaq 0xd60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x3912(%rip), %rsi      # 0xee034
leaq 0x44ee7(%rip), %rdx     # 0x12f610
movq %rbx, %rdi
movl $0x439, %ecx            # imm = 0x439
jmp 0xea661
addq $0x6c8a, %r14           # imm = 0x6C8A
leaq 0x3cac(%rip), %rsi      # 0xee3f0
leaq 0x45082(%rip), %rdx     # 0x12f7cd
leaq 0x160(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x38c6(%rip), %rsi      # 0xee034
leaq 0x44e9b(%rip), %rdx     # 0x12f610
movq %rbx, %rdi
movl $0x44a, %ecx            # imm = 0x44A
jmp 0xea661