// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/match/rdj-contigpaths.c
// Function: gt_contigpaths_to_fasta
int gt_contigpaths_to_fasta(const char *indexname,
    const char *contigpaths_suffix, const char *fasta_suffix,
    const GtEncseq *encseq, GtUword min_contig_length, bool showpaths,
    bool astat, double coverage, bool load_copynum, size_t buffersize,
    GtLogger *logger, GtError *err)
{
  GtUword nofchars, seqnum, contig_length = 0;
  GtFile *infp = NULL, *outfp = NULL;
  FILE *depthinfo_fp = NULL;
  int nvalues, i;
  GtContigsWriter *cw = NULL;
  GtContigpathElem *buffer = NULL;
  unsigned char *rcn = NULL;
  int had_err = 0;

  if (buffersize == 0)
  {
    buffersize = GT_CONTIGPATHS_BUFFERSIZE * sizeof (GtContigpathElem);
    gt_log_log("buffersize = default ("GT_ZU" bytes)", buffersize);
  }
  else
  {
    size_t bsmod = buffersize % sizeof (GtContigpathElem);
    buffersize -= bsmod;
    gt_log_log("buffersize = "GT_ZU" bytes", buffersize);
  }
  gt_assert(buffersize > 0);
  gt_assert(buffersize % sizeof (GtContigpathElem) == 0);
  buffer = gt_malloc(buffersize);

  gt_assert(encseq != NULL);
  gt_error_check(err);
  gt_assert(buffer != NULL);

  infp = gt_contigpaths_get_file(indexname, contigpaths_suffix, "r", err);
  if (infp == NULL)
    had_err = -1;
  if (!had_err)
  {
    outfp = gt_contigpaths_get_file(indexname, fasta_suffix, "w", err);
    if (outfp == NULL)
    {
      gt_file_delete(infp);
      had_err = -1;
    }
  }
  if (!had_err && load_copynum)
  {
    GtFile *rcnfp = NULL;
    size_t nbytes;
    rcnfp = gt_contigpaths_get_file(indexname,
        GT_READJOINER_SUFFIX_READSCOPYNUM, "r", err);
    if (rcnfp == NULL)
    {
      had_err = -1;
    }
    else
    {
      gt_log_log("load reads copy number from file");
      nbytes = sizeof (*rcn) * gt_encseq_num_of_sequences(encseq);
      if (gt_encseq_is_mirrored(encseq))
        nbytes = GT_DIV2(nbytes);
      rcn = gt_malloc(nbytes);
      (void)gt_file_xread(rcnfp, rcn, nbytes);
      gt_file_delete(rcnfp);
    }
  }
  if (!had_err)
  {
    cw = gt_contigs_writer_new(encseq, outfp);
    if (showpaths)
      gt_contigs_writer_enable_complete_path_output(cw);
    if (astat)
    {
      depthinfo_fp = gt_fa_fopen_with_suffix(indexname,
          GT_READJOINER_SUFFIX_DEPTHINFO, "w", err);
      if (depthinfo_fp == NULL)
      {
        had_err = -1;
      }
      if (!had_err)
      {
        gt_contigs_writer_enable_astat_calculation(cw, coverage, rcn,
            depthinfo_fp);
      }
    }
  }
  if (!had_err)
  {
    while ((nvalues = gt_file_xread(infp, buffer, buffersize)) > 0)
    {
      gt_assert((size_t)nvalues <= buffersize);
      nvalues /= (sizeof (GtContigpathElem) << 1);
      for (i = 0; i < nvalues; i++)
      {
        nofchars = (GtUword)buffer[(i << 1)];
        seqnum = (GtUword)buffer[(i << 1) + 1];
        if (nofchars == 0)
        {
          /* end of contig */
          if (contig_length >= min_contig_length)
            gt_contigs_writer_write(cw);
          else
            gt_contigs_writer_abort(cw);
          gt_contigs_writer_start(cw, seqnum);
          contig_length = gt_encseq_seqlength(encseq, seqnum);
        }
        else
        {
          contig_length += nofchars;
          gt_contigs_writer_append(cw, seqnum, nofchars);
        }
      }
    }

    if (contig_length >= min_contig_length)
      gt_contigs_writer_write(cw);
    else
      gt_contigs_writer_abort(cw);
    gt_contigs_writer_show_stats(cw, logger);
  }
  if (depthinfo_fp != NULL)
    gt_fa_fclose(depthinfo_fp);
  gt_contigs_writer_delete(cw);
  gt_file_delete(infp);
  gt_file_delete(outfp);
  gt_free(buffer);
  gt_free(rcn);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movsd %xmm0, 0x10(%rsp)
movl %r9d, %r13d
movq %r8, 0x30(%rsp)
movq %rcx, %r15
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, %r14
movq 0x80(%rsp), %rbx
testq %rbx, %rbx
je 0x175fa5
leaq 0x1d7567(%rip), %rdi    # 0x34d4cb
movq %rbx, %rsi
andq $-0x4, %rsi
xorl %eax, %eax
callq 0x92a82
andq $-0x4, %rbx
jne 0x175fbd
movq 0x2c1fe9(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x16f08a(%rip), %rsi    # 0x2e5013
leaq 0x1d7552(%rip), %rdx    # 0x34d4e2
leaq 0x1d755a(%rip), %rcx    # 0x34d4f1
leaq 0x1d756b(%rip), %r8     # 0x34d509
pushq $0x46
jmp 0x17636c
leaq 0x1d74fe(%rip), %rdi    # 0x34d4aa
movl $0x40000, %ebx          # imm = 0x40000
movl $0x40000, %esi          # imm = 0x40000
xorl %eax, %eax
callq 0x92a82
leaq 0x1d7545(%rip), %rsi    # 0x34d509
pushq $0x48
popq %rdx
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
callq 0x93160
movq %rax, 0x18(%rsp)
testq %r15, %r15
je 0x1762f0
movq 0x90(%rsp), %rbx
testq %rbx, %rbx
je 0x175fff
movq %rbx, %rdi
callq 0x89eb7
testb %al, %al
jne 0x176344
cmpq $0x0, 0x18(%rsp)
je 0x17631a
leaq 0x184e1b(%rip), %rdx    # 0x2fae2d
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rcx
callq 0x17637a
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x1760e6
leaq 0x1bd8d9(%rip), %rdx    # 0x33390e
movq %r14, %rdi
movq %rbp, %rsi
movq %rbx, %rcx
callq 0x17637a
testq %rax, %rax
je 0x1760dc
movq %rax, %rbx
cmpb $0x0, 0x78(%rsp)
je 0x176141
leaq 0x17e7b5(%rip), %rsi    # 0x2f4816
leaq 0x184dc5(%rip), %rdx    # 0x2fae2d
movq %r14, %rdi
movq 0x90(%rsp), %rcx
callq 0x17637a
testq %rax, %rax
je 0x1760e8
movq %rax, %r12
movl %r13d, 0x8(%rsp)
movq %r14, (%rsp)
leaq 0x1d7495(%rip), %rdi    # 0x34d525
xorl %eax, %eax
callq 0x92a82
movq %r15, %rdi
callq 0x705a1
movq %rax, %r14
movq %r15, %rdi
callq 0x81dea
movl %eax, %ecx
shrq %cl, %r14
leaq 0x1d7453(%rip), %rsi    # 0x34d509
pushq $0x6a
popq %rdx
movq %r14, %rdi
callq 0x93160
movq %rax, %r13
movq %r12, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x8d861
movq %r12, %rdi
callq 0x8da06
jmp 0x17614d
movq 0x20(%rsp), %rdi
callq 0x8da06
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0x1788c2
movq 0x20(%rsp), %rdi
callq 0x8da06
movq %rbx, %rdi
callq 0x8da06
leaq 0x1d73fb(%rip), %r14    # 0x34d509
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movl $0xaa, %edx
callq 0x936f9
movq %r13, %rdi
movq %r14, %rsi
movl $0xab, %edx
callq 0x936f9
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, 0x8(%rsp)
movq %r14, (%rsp)
xorl %r13d, %r13d
movb 0x70(%rsp), %r14b
movq %r15, %rdi
movq %rbx, %rsi
callq 0x17872c
movq %rax, %rbp
cmpb $0x0, 0x8(%rsp)
je 0x17616f
movq %rbp, %rdi
callq 0x178815
testb %r14b, %r14b
je 0x1761ce
leaq 0x17d1f6(%rip), %rsi    # 0x2f3371
leaq 0x1bd78c(%rip), %rdx    # 0x33390e
leaq 0x1d7380(%rip), %rcx    # 0x34d509
pushq $0x77
popq %r8
movq (%rsp), %rdi
movq 0x90(%rsp), %r9
callq 0x8a449
testq %rax, %rax
je 0x1760ed
movq %rbx, 0x8(%rsp)
movq %r15, %rbx
movq %rbp, %rdi
movsd 0x10(%rsp), %xmm0
movq %r13, 0x10(%rsp)
movq %r13, %rsi
movq %rax, (%rsp)
movq %rax, %rdx
callq 0x17881a
jmp 0x1761e3
movq %r13, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
movq %r15, %rbx
movq $0x0, (%rsp)
xorl %r13d, %r13d
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
callq 0x8d861
testl %eax, %eax
jle 0x176275
movl %eax, %r12d
movl %eax, %eax
cmpq %rax, %r14
jb 0x1762c2
shrl $0x3, %r12d
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x1761e6
movq 0x18(%rsp), %rax
movl (%rax,%r15,8), %edx
movl 0x4(%rax,%r15,8), %r14d
testq %rdx, %rdx
je 0x17623e
addq %rdx, %r13
movq %rbp, %rdi
movq %r14, %rsi
callq 0x178c88
jmp 0x176270
cmpq 0x30(%rsp), %r13
jae 0x17624f
movq %rbp, %rdi
callq 0x178934
jmp 0x176257
movq %rbp, %rdi
callq 0x17899d
movq %rbp, %rdi
movq %r14, %rsi
callq 0x178e88
movq %rbx, %rdi
movq %r14, %rsi
callq 0x75173
movq %rax, %r13
incq %r15
jmp 0x176216
cmpq 0x30(%rsp), %r13
jae 0x176286
movq %rbp, %rdi
callq 0x178934
jmp 0x17628e
movq %rbp, %rdi
callq 0x17899d
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %r13
movq (%rsp), %r14
movq %rbp, %rdi
movq 0x88(%rsp), %rsi
callq 0x179022
testq %r14, %r14
je 0x1760ed
movq %r14, %rdi
callq 0x8a4fd
jmp 0x1760ed
movq 0x2c1c9f(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x16ed40(%rip), %rsi    # 0x2e5013
leaq 0x1d726c(%rip), %rdx    # 0x34d546
leaq 0x1d7210(%rip), %rcx    # 0x34d4f1
leaq 0x1d7221(%rip), %r8     # 0x34d509
movl $0x87, %r9d
jmp 0x17636e
movq 0x2c1c71(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x16ed12(%rip), %rsi    # 0x2e5013
leaq 0x1c9faa(%rip), %rdx    # 0x3402b2
leaq 0x1d71e2(%rip), %rcx    # 0x34d4f1
leaq 0x1d71f3(%rip), %r8     # 0x34d509
pushq $0x4a
jmp 0x17636c
movq 0x2c1c47(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x16ece8(%rip), %rsi    # 0x2e5013
leaq 0x18dc27(%rip), %rdx    # 0x303f59
leaq 0x1d71b8(%rip), %rcx    # 0x34d4f1
leaq 0x1d71c9(%rip), %r8     # 0x34d509
pushq $0x4c
jmp 0x17636c
movq 0x2c1c1d(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x16ecbe(%rip), %rsi    # 0x2e5013
leaq 0x16ee63(%rip), %rdx    # 0x2e51bf
leaq 0x1d718e(%rip), %rcx    # 0x34d4f1
leaq 0x1d719f(%rip), %r8     # 0x34d509
pushq $0x4b
popq %r9
xorl %eax, %eax
callq 0x17a50
callq 0x17390