// File: /workspace/github_c_makefile_star2_O1/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, (%rsp)
movl %r9d, 0x8(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rbp
movq 0x80(%rsp), %rbx
testq %rbx, %rbx
je 0x1cef94
andq $-0x4, %rbx
leaq 0x1e77ec(%rip), %rdi    # 0x3b677b
movq %rbx, %rsi
jmp 0x1cefa5
leaq 0x1e77bf(%rip), %rdi    # 0x3b675a
movl $0x40000, %ebx          # imm = 0x40000
movl $0x40000, %esi          # imm = 0x40000
xorl %eax, %eax
callq 0x108e02
testq %rbx, %rbx
je 0x1cf2da
leaq 0x1e77fd(%rip), %rsi    # 0x3b67b9
movq %rbx, %rdi
movl $0x48, %edx
callq 0x1092b2
cmpq $0x0, 0x18(%rsp)
je 0x1cf2df
movq %rax, %r14
movq 0x90(%rsp), %r15
testq %r15, %r15
je 0x1ceff5
movq %r15, %rdi
callq 0x101a9a
testb %al, %al
jne 0x1cf2e9
movq %rbx, 0x20(%rsp)
testq %r14, %r14
je 0x1cf2e4
movb 0x78(%rsp), %bl
leaq 0x194ebb(%rip), %rdx    # 0x363ec9
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rcx
callq 0x1cf2ee
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x1cf051
leaq 0x1cda04(%rip), %rdx    # 0x39ca31
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rcx
callq 0x1cf2ee
testq %rax, %rax
je 0x1cf047
movq %rax, %r13
movb $0x1, %al
jmp 0x1cf056
movq 0x10(%rsp), %rdi
callq 0x1040fc
xorl %r13d, %r13d
xorl %eax, %eax
andb %al, %bl
cmpb $0x1, %bl
jne 0x1cf0e4
leaq 0x18e7d6(%rip), %rsi    # 0x35d83e
leaq 0x194e5a(%rip), %rdx    # 0x363ec9
movq %rbp, %rdi
movq %r15, %rcx
callq 0x1cf2ee
movq %rax, %r12
testq %rax, %rax
setne %al
je 0x1cf0e4
leaq 0x1e7749(%rip), %rdi    # 0x3b67d5
xorl %eax, %eax
callq 0x108e02
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0xec1e8
movq %rax, %rbx
movq %r15, %rdi
callq 0xfac80
movl %eax, %ecx
shrq %cl, %rbx
leaq 0x1e7702(%rip), %rsi    # 0x3b67b9
movq %rbx, %rdi
movl $0x6a, %edx
callq 0x1092b2
movq %rax, %r15
movq %r12, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x104009
movq %r12, %rdi
movq %r15, %r12
callq 0x1040fc
movb $0x1, %al
jmp 0x1cf0e7
xorl %r12d, %r12d
testb %al, %al
je 0x1cf161
movq %rbp, %r15
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x1d1210
movq %rax, %rbp
cmpb $0x0, 0x8(%rsp)
je 0x1cf10d
movq %rbp, %rdi
callq 0x1d12c8
movb $0x1, %bl
cmpb $0x0, 0x70(%rsp)
je 0x1cf169
leaq 0x18d27c(%rip), %rsi    # 0x35c399
leaq 0x1cd90d(%rip), %rdx    # 0x39ca31
leaq 0x1e768e(%rip), %rcx    # 0x3b67b9
movq %r15, %rdi
movl $0x77, %r8d
movq 0x90(%rsp), %r9
callq 0x101dff
testq %rax, %rax
je 0x1cf165
movq %rbp, %rdi
movsd (%rsp), %xmm0
movq %r12, %rsi
movq %rax, %rdx
movq %rax, %r15
callq 0x1d12cd
movq %r15, %rax
jmp 0x1cf16b
xorl %eax, %eax
xorl %ebp, %ebp
xorl %ebx, %ebx
jmp 0x1cf16b
xorl %eax, %eax
testb %bl, %bl
je 0x1cf276
movq %rax, 0x30(%rsp)
movq %r12, (%rsp)
movq %r13, 0x8(%rsp)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movq 0x20(%rsp), %rbx
movq %rbx, %rdx
callq 0x104009
testl %eax, %eax
jle 0x1cf239
movl %eax, %r13d
xorl %r12d, %r12d
movl %r13d, %eax
cmpq %rax, %rbx
jb 0x1cf2d5
cmpl $0x8, %r13d
jb 0x1cf217
shrl $0x3, %r13d
xorl %r15d, %r15d
movl (%r14,%r15,8), %edx
movl 0x4(%r14,%r15,8), %ebx
testq %rdx, %rdx
je 0x1cf1db
addq %rdx, %r12
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1d1714
jmp 0x1cf20f
cmpq 0x28(%rsp), %r12
jae 0x1cf1ec
movq %rbp, %rdi
callq 0x1d13ee
jmp 0x1cf1f4
movq %rbp, %rdi
callq 0x1d1426
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1d18b4
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0xeffd3
movq %rax, %r12
incq %r15
cmpq %r15, %r13
jne 0x1cf1bd
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movq 0x20(%rsp), %rbx
movq %rbx, %rdx
callq 0x104009
movl %eax, %r13d
testl %eax, %eax
jg 0x1cf1a4
jmp 0x1cf23c
xorl %r12d, %r12d
movq 0x88(%rsp), %rbx
cmpq 0x28(%rsp), %r12
jae 0x1cf255
movq %rbp, %rdi
callq 0x1d13ee
jmp 0x1cf25d
movq %rbp, %rdi
callq 0x1d1426
movq 0x8(%rsp), %r13
movq (%rsp), %r12
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1d19ed
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x1cf283
movq %rax, %rdi
callq 0x101e80
movq %rbp, %rdi
callq 0x1d1375
movq 0x10(%rsp), %rdi
callq 0x1040fc
movq %r13, %rdi
callq 0x1040fc
leaq 0x1e7515(%rip), %rbx    # 0x3b67b9
movq %r14, %rdi
movq %rbx, %rsi
movl $0xaa, %edx
callq 0x109670
movq %r12, %rdi
movq %rbx, %rsi
movl $0xab, %edx
callq 0x109670
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6b53f
callq 0x6b5e6
callq 0x6b5af
callq 0x6b578
callq 0x6b508