// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movsd %xmm0, 0x30(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %rbp
movq 0x90(%rsp), %r14
testq %r14, %r14
movl %r9d, 0x10(%rsp)
je 0x1c5cf7
leaq 0x1e749d(%rip), %rdi    # 0x3ad17b
movq %r14, %rsi
andq $-0x4, %rsi
xorl %eax, %eax
callq 0x103d72
andq $-0x4, %r14
jne 0x1c5d10
callq 0x69c67
leaq 0x1e745c(%rip), %rdi    # 0x3ad15a
movl $0x40000, %r14d         # imm = 0x40000
movl $0x40000, %esi          # imm = 0x40000
xorl %eax, %eax
callq 0x103d72
leaq 0x1e74a2(%rip), %rsi    # 0x3ad1b9
movq %r14, %rdi
movl $0x48, %edx
callq 0x104226
testq %r12, %r12
je 0x1c6059
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x1c5d4a
callq 0xfcc32
testb %al, %al
jne 0x1c6063
testq %rbx, %rbx
je 0x1c605e
leaq 0x1950fb(%rip), %rdx    # 0x35ae55
movq %rbp, %rdi
movq %r13, %rsi
movq 0xa0(%rsp), %r13
movq %r13, %rcx
callq 0x1c6068
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x1c5e44
leaq 0x1cd830(%rip), %rdx    # 0x3935b5
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rcx
callq 0x1c6068
testq %rax, %rax
je 0x1c5e3a
movq %rax, %r15
cmpb $0x0, 0x88(%rsp)
movq %rax, 0x8(%rsp)
je 0x1c5e51
leaq 0x18ea4d(%rip), %rsi    # 0x354806
leaq 0x195095(%rip), %rdx    # 0x35ae55
movq %rbp, %rdi
movq %r13, %rcx
callq 0x1c6068
testq %rax, %rax
je 0x1c5ff2
movq %rax, %r15
movq %rbp, 0x20(%rsp)
movq %r14, %r13
leaq 0x1e73ef(%rip), %rdi    # 0x3ad1d5
xorl %eax, %eax
callq 0x103d72
movq %r12, %rdi
callq 0xe7bac
movq %rax, %r14
movq %r12, %rdi
callq 0xf6567
movl %eax, %ecx
shrq %cl, %r14
leaq 0x1e73ad(%rip), %rsi    # 0x3ad1b9
movq %r14, %rdi
movl $0x6a, %edx
callq 0x104226
movq %r15, %rdi
movq %rax, (%rsp)
movq %rax, %rsi
movq %r14, %rdx
callq 0xff139
movq %r15, %rdi
callq 0xff22c
movq 0x8(%rsp), %r15
jmp 0x1c5e61
movq 0x18(%rsp), %rdi
callq 0xff22c
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %ebp, %ebp
jmp 0x1c6002
movq %rbp, 0x20(%rsp)
movq %r14, %r13
movq $0x0, (%rsp)
movb 0x80(%rsp), %r14b
movq %r12, 0x40(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x1c7fb4
movq %rax, %rbp
cmpb $0x0, 0x10(%rsp)
je 0x1c5e8b
movq %rbp, %rdi
callq 0x1c806c
testb %r14b, %r14b
je 0x1c5ee5
leaq 0x18d4ca(%rip), %rsi    # 0x353361
leaq 0x1cd717(%rip), %rdx    # 0x3935b5
leaq 0x1e7314(%rip), %rcx    # 0x3ad1b9
movq 0x20(%rsp), %rdi
movl $0x77, %r8d
movq 0xa0(%rsp), %r9
callq 0xfcf97
testq %rax, %rax
je 0x1c5ffe
movq %r13, %r14
movq %rbp, %rdi
movsd 0x30(%rsp), %xmm0
movq (%rsp), %rsi
movq %rax, 0x10(%rsp)
movq %rax, %rdx
callq 0x1c8071
jmp 0x1c5ef1
movq $0x0, 0x10(%rsp)
movq %r13, %r14
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xff139
testl %eax, %eax
jle 0x1c5fa9
movl %eax, %r15d
xorl %r13d, %r13d
movq %r14, 0x38(%rsp)
movl %r15d, %eax
cmpq %rax, %r14
jb 0x1c6054
cmpl $0x8, %r15d
jb 0x1c5f87
shrl $0x3, %r15d
xorl %r12d, %r12d
movl (%rbx,%r12,8), %edx
movl 0x4(%rbx,%r12,8), %r14d
testq %rdx, %rdx
je 0x1c5f4b
addq %rdx, %r13
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1c84b8
jmp 0x1c5f7f
cmpq 0x28(%rsp), %r13
jae 0x1c5f5c
movq %rbp, %rdi
callq 0x1c8192
jmp 0x1c5f64
movq %rbp, %rdi
callq 0x1c81ca
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1c865e
movq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0xeb9d2
movq %rax, %r13
incq %r12
cmpq %r12, %r15
jne 0x1c5f2d
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq 0x38(%rsp), %r14
movq %r14, %rdx
callq 0xff139
movl %eax, %r15d
testl %eax, %eax
jg 0x1c5f14
jmp 0x1c5fac
xorl %r13d, %r13d
movq 0x98(%rsp), %r14
cmpq 0x28(%rsp), %r13
jae 0x1c5fc5
movq %rbp, %rdi
callq 0x1c8192
jmp 0x1c5fcd
movq %rbp, %rdi
callq 0x1c81ca
movq 0x8(%rsp), %r15
movq (%rsp), %r12
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1c879e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1c6002
callq 0xfd018
jmp 0x1c6002
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x8(%rsp), %r15
jmp 0x1c6002
movq (%rsp), %r12
movq %rbp, %rdi
callq 0x1c8119
movq 0x18(%rsp), %rdi
callq 0xff22c
movq %r15, %rdi
callq 0xff22c
leaq 0x1e7196(%rip), %r14    # 0x3ad1b9
movq %rbx, %rdi
movq %r14, %rsi
movl $0xaa, %edx
callq 0x1045eb
movq %r12, %rdi
movq %r14, %rsi
movl $0xab, %edx
callq 0x1045eb
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x69cd5
callq 0x69d45
callq 0x69d0e
callq 0x69c9e