// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/tools/gt_condenseq_extract.c
// Function: gt_condenseq_extract_runner
static int gt_condenseq_extract_runner(GT_UNUSED int argc,
                                       const char **argv,
                                       int parsed_args,
                                       void *tool_arguments,
                                       GtError *err)
{
  int had_err = 0;
  GtCondenserExtractArguments *arguments = tool_arguments;
  GtCondenseq *condenseq = NULL;
  GtLogger *logger = NULL;
  GtTimer *timer = NULL;

  gt_error_check(err);
  gt_assert(arguments);

  if (gt_showtime_enabled()) {
    timer = gt_timer_new_with_progress_description("load condenseq");
    gt_timer_start(timer);
  }

  logger = gt_logger_new(arguments->verbose, GT_LOGGER_DEFLT_PREFIX, stderr);

  if (!had_err) {
    condenseq = gt_condenseq_new_from_file(argv[parsed_args], logger, err);
    if (condenseq == NULL) {
      had_err = -1;
    }
  }

  if (!had_err) {
    const char *buffer = NULL;
    const char *desc = NULL;
    GtUword desclen,
            seqlen,
            rend = gt_condenseq_total_length(condenseq),
            send = gt_condenseq_num_of_sequences(condenseq);
    bool concat = strcmp(gt_str_get(arguments->mode), "concat") == 0;
    /* single sequence to extract = range of length 1 */
    if (arguments->seq != GT_UNDEF_UWORD) {
      arguments->seqrange.start = arguments->seqrange.end = arguments->seq;
    }
    /* no range given at all: extract all seqs */
    if (arguments->range.start == GT_UNDEF_UWORD &&
        arguments->seqrange.start == GT_UNDEF_UWORD) {
      arguments->seqrange.start = 0;
      arguments->seqrange.end = send - 1;
    }
    /* if seqs are specified, and concat is given, switch to posrange */
    if (concat && arguments->seqrange.start != GT_UNDEF_UWORD) {
      if (arguments->seqrange.end >= send) {
        had_err = -1;
        gt_error_set(err, "range end " GT_WU " excedes number of sequences "
                     GT_WU " (ranges are zero based sequence ids)",
                     arguments->seqrange.end, send);
      }
      else {
        arguments->range.start =
          gt_condenseq_seqstartpos(condenseq, arguments->seqrange.start);
        arguments->range.end =
          gt_condenseq_seqstartpos(condenseq, arguments->seqrange.end) +
          gt_condenseq_seqlength(condenseq, arguments->seqrange.end) - 1;
      }
    }
    /* extract sequence region */
    if (!had_err && arguments->range.start != GT_UNDEF_UWORD) {
      const GtUword maxbuffsize = ((GtUword) 1) << 17; /* ~ 100000byte */
      GtUword clen,
              rstart,
              current_length = 0, i;
      const char sepchar = gt_str_get(arguments->sepchar)[0];

      if (timer)
        gt_timer_show_progress(timer, "extract sequence region(s)", stderr);

      if (arguments->range.end >= rend) {
        had_err = -1;
        gt_error_set(err, "range end " GT_WU " excedes length of sequence "
                     GT_WU " (ranges are zero based positions)",
                     arguments->range.end, rend);
      }
      if (!had_err) {
        rstart = arguments->range.start;
        rend = arguments->range.end;
        /* nextlength = gt_condenseq_seqlength(condenseq, seqnum); */
        /* seqstart = gt_condenseq_seqstartpos(condenseq, seqnum); */
        /* gt_assert(rstart >= seqstart); */
        /* nextlength -= rstart - seqstart; [> handle first seq <] */
        while (rstart <= rend) {
          GtRange cur_range;
          if (rend - rstart > maxbuffsize) {
            GtUword seqnum = gt_condenseq_pos2seqnum(condenseq,
                                                     rstart + maxbuffsize),
                    closest_sep = gt_condenseq_seqstartpos(condenseq,
                                                           seqnum) - 1;
            gt_assert(closest_sep > rstart);
            clen = closest_sep - rstart + 1;
          }
          else
            clen = rend - rstart + 1;

          cur_range.start = rstart;
          cur_range.end = rstart + clen - 1;
          buffer = gt_condenseq_extract_decoded_range(condenseq, cur_range,
                                                      sepchar);
          gt_assert(buffer != NULL);
          for (i = 0; i < clen; i++, current_length++) {
            if (arguments->width && current_length == arguments->width) {
              gt_file_xfputc('\n', arguments->outfp);
              current_length = 0;
            }
            gt_file_xfputc(buffer[i], arguments->outfp);
          }
          rstart += clen;
        }
        gt_file_xfputc('\n', arguments->outfp);
      }
    }
    else if (!had_err) { /* extract seqwise and always fasta */
      GtUword seqnum,
              sstart = arguments->seqrange.start;

      if (timer)
        gt_timer_show_progress(timer, "extract sequence(s)", stderr);
      if (arguments->seqrange.end >= send) {
        had_err = -1;
        gt_error_set(err, "range end " GT_WU " excedes number of sequences "
                     GT_WU " (ranges are zero based sequence ids)",
                     arguments->seqrange.end, send);
      }
      send = arguments->seqrange.end;
      for (seqnum = sstart;
           !had_err && seqnum <= send;
           ++seqnum) {
        buffer = gt_condenseq_extract_decoded(condenseq, &seqlen, seqnum);
        desc = gt_condenseq_description(condenseq, &desclen, seqnum);
        gt_fasta_show_entry_nt(desc, desclen,
                               buffer, seqlen,
                               arguments->width,
                               arguments->outfp);
      }
    }
  }
  if (timer)
    gt_timer_show_progress(timer, "cleanup", stderr);
  gt_condenseq_delete(condenseq);
  gt_logger_delete(logger);
  if (timer)
    gt_timer_show_progress_final(timer, stderr);
  gt_timer_delete(timer);
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %r13
movq %rcx, %r14
movl %edx, %ebp
movq %rsi, %r15
testq %r8, %r8
je 0xa1572
movq %r13, %rdi
callq 0x101a9a
testb %al, %al
jne 0xa19ab
testq %r14, %r14
je 0xa19a1
callq 0x11ed94
testb %al, %al
je 0xa159d
leaq 0x2b0c44(%rip), %rdi    # 0x3521cf
callq 0x1226d6
movq %rax, %r12
movq %rax, %rdi
callq 0x122733
jmp 0xa15a0
xorl %r12d, %r12d
movzbl 0x58(%r14), %edi
movq 0x4229d4(%rip), %rax    # 0x4c3f80
movq (%rax), %rdx
leaq 0x2ae31e(%rip), %rsi    # 0x34f8d4
callq 0x108ed0
movq %rax, %rsi
movslq %ebp, %rax
movq (%r15,%rax,8), %rdi
movq %rsi, 0x28(%rsp)
movq %r13, %rdx
callq 0x132916
movq %rax, %r15
testq %rax, %rax
je 0xa17d1
movq %r15, %rdi
callq 0x13212a
movq %rax, 0x10(%rsp)
movq %r15, %rdi
callq 0x13212f
movq %rax, %rbx
movq 0x10(%r14), %rdi
callq 0x120d23
leaq 0x2b0a6e(%rip), %rsi    # 0x352074
movq %rax, %rdi
callq 0x17a40
movq 0x48(%r14), %rcx
cmpq $-0x1, %rcx
je 0xa1620
movq %rcx, 0x40(%r14)
movq %rcx, 0x38(%r14)
cmpq $-0x1, 0x28(%r14)
jne 0xa163e
cmpq $-0x1, 0x38(%r14)
jne 0xa163e
movq $0x0, 0x38(%r14)
leaq -0x1(%rbx), %rcx
movq %rcx, 0x40(%r14)
movb $0x1, %bpl
testl %eax, %eax
je 0xa17db
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
testb %bpl, %bpl
je 0xa1915
cmpq $-0x1, 0x28(%r14)
movq %r15, 0x8(%rsp)
je 0xa1836
movq 0x18(%r14), %rdi
callq 0x120d23
movb (%rax), %bpl
testq %r12, %r12
je 0xa1694
movq 0x4228fe(%rip), %rax    # 0x4c3f80
movq (%rax), %rdx
leaq 0x2b0ba5(%rip), %rsi    # 0x352231
movq %r12, %rdi
callq 0x1229c8
movq 0x30(%r14), %rbx
movl $0x0, 0x4(%rsp)
movq 0x10(%rsp), %rcx
cmpq %rcx, %rbx
jb 0xa16cb
leaq 0x2b0b9b(%rip), %rsi    # 0x35224c
movq %r13, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1019cf
movq 0x10(%rsp), %rcx
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
cmpq %rcx, %rbx
jae 0xa1915
movq %r12, 0x18(%rsp)
movq 0x28(%r14), %rbx
movq 0x30(%r14), %r13
cmpq %r13, %rbx
ja 0xa17ba
xorl %r12d, %r12d
movsbl %bpl, %eax
movl %eax, 0x24(%rsp)
movq %r13, 0x30(%rsp)
subq %rbx, %r13
cmpq $0x20001, %r13          # imm = 0x20001
jb 0xa172f
leaq 0x20000(%rbx), %rsi
movq %r15, %rdi
callq 0x131b64
movq %r15, %rdi
movq %rax, %rsi
callq 0x131b7a
movq %rax, %r13
decq %r13
subq %rbx, %r13
jbe 0xa19a6
leaq (%rbx,%r13), %rdx
movq %r15, %rdi
movq %rbx, 0x10(%rsp)
movq %rbx, %rsi
movl 0x24(%rsp), %ecx
callq 0x1335fa
testq %rax, %rax
je 0xa199c
movq %r13, %rbp
incq %rbp
je 0xa179c
movq %rax, %rbx
xorl %r15d, %r15d
movq 0x50(%r14), %rax
testq %rax, %rax
setne %cl
cmpq %rax, %r12
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0xa1784
movq (%r14), %rsi
movl $0xa, %edi
callq 0x103f7f
xorl %r12d, %r12d
movsbl (%rbx,%r15), %edi
movq (%r14), %rsi
callq 0x103f7f
incq %r15
incq %r12
cmpq %r15, %rbp
jne 0xa175e
movq 0x10(%rsp), %rbx
addq %r13, %rbx
incq %rbx
movq 0x30(%rsp), %r13
cmpq %r13, %rbx
movq 0x8(%rsp), %r15
jbe 0xa16fa
movq (%r14), %rsi
movl $0xa, %edi
callq 0x103f7f
movq 0x18(%rsp), %r12
jmp 0xa1915
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xa1919
movq 0x38(%r14), %rsi
cmpq $-0x1, %rsi
je 0xa1649
movq 0x40(%r14), %rdx
cmpq %rbx, %rdx
jae 0xa1981
movq %r15, %rdi
callq 0x131b7a
movq %rax, 0x28(%r14)
movq 0x40(%r14), %rsi
movq %r15, %rdi
callq 0x131b7a
movq %rbx, 0x8(%rsp)
movq %rax, %rbx
movq 0x40(%r14), %rsi
movq %r15, %rdi
callq 0x131b97
addq %rbx, %rax
decq %rax
movq 0x8(%rsp), %rbx
movq %rax, 0x30(%r14)
jmp 0xa1649
testb %bpl, %bpl
je 0xa1915
movq 0x38(%r14), %rbp
testq %r12, %r12
je 0xa1861
movq 0x422731(%rip), %rax    # 0x4c3f80
movq (%rax), %rdx
leaq 0x2b0a57(%rip), %rsi    # 0x3522b0
movq %r12, %rdi
callq 0x1229c8
movq %r12, 0x18(%rsp)
movq 0x40(%r14), %r12
movl $0x0, 0x4(%rsp)
cmpq %rbx, %r12
jb 0xa1896
leaq 0x2b0960(%rip), %rsi    # 0x3521de
movq %r13, %rdi
movq %r12, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1019cf
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
cmpq %rbx, %r12
setb %al
movq 0x40(%r14), %rcx
movq %rcx, 0x10(%rsp)
cmpq %rcx, %rbp
setbe %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xa190b
movq 0x8(%rsp), %r13
movq %r13, %rdi
leaq 0x38(%rsp), %rsi
movq %rbp, %rdx
callq 0x13368e
movq %rbx, %r15
movq %rax, %rbx
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
movq %rbp, %rdx
callq 0x131be9
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rcx
movq (%r14), %r9
movq 0x50(%r14), %r8
movq %rax, %rdi
movq %rbx, %rdx
movq %r15, %rbx
callq 0x102f8a
cmpq %r15, %r12
jae 0xa190b
incq %rbp
cmpq 0x10(%rsp), %rbp
jbe 0xa18b7
movq 0x18(%rsp), %r12
movq 0x8(%rsp), %r15
movl 0x4(%rsp), %ebp
testq %r12, %r12
je 0xa1956
movq 0x42265b(%rip), %rbx    # 0x4c3f80
movq (%rbx), %rdx
leaq 0x2b0995(%rip), %rsi    # 0x3522c4
movq %r12, %rdi
callq 0x1229c8
movq %r15, %rdi
callq 0x1323d6
movq 0x28(%rsp), %rdi
callq 0x10916a
movq (%rbx), %rsi
movq %r12, %rdi
callq 0x122c67
jmp 0xa1968
movq %r15, %rdi
callq 0x1323d6
movq 0x28(%rsp), %rdi
callq 0x10916a
movq %r12, %rdi
callq 0x122d79
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2b0856(%rip), %rsi    # 0x3521de
xorl %ebp, %ebp
movq %r13, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1019cf
jmp 0xa1649
callq 0x19460
callq 0x19499
callq 0x19427
callq 0x193ee