// File: /workspace/github_c_makefile_star2_O3/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, %r12
movl %edx, %ebp
movq %rsi, %rbx
testq %r8, %r8
je 0x9f3ee
movq %r13, %rdi
callq 0xfcc32
testb %al, %al
jne 0x9f7c3
testq %r12, %r12
je 0x9f7be
callq 0x119160
testb %al, %al
je 0x9f419
leaq 0x2a9db8(%rip), %rdi    # 0x3491bf
callq 0x11c986
movq %rax, %r15
movq %rax, %rdi
callq 0x11c9e3
jmp 0x9f41c
xorl %r15d, %r15d
movzbl 0x58(%r12), %edi
movq 0x419b57(%rip), %rax    # 0x4b8f80
movq (%rax), %rdx
leaq 0x2a74a1(%rip), %rsi    # 0x3468d4
callq 0x103e40
movq %rax, %rsi
movslq %ebp, %rax
movq (%rbx,%rax,8), %rdi
movq %rsi, 0x8(%rsp)
movq %r13, %rdx
callq 0x12c8eb
testq %rax, %rax
movq %rax, 0x10(%rsp)
je 0x9f742
movq %rax, %rbx
movq %rax, %rdi
callq 0x12c10b
movq %rax, %r14
movq %rbx, %rdi
callq 0x12c110
movq %rax, %rbp
movq 0x10(%r12), %rdi
callq 0x11b0a1
leaq 0x2a9bdd(%rip), %rsi    # 0x349064
movq %rax, %rdi
callq 0x17a40
movq 0x48(%r12), %rcx
cmpq $-0x1, %rcx
je 0x9f4a4
movq %rcx, 0x40(%r12)
movq %rcx, 0x38(%r12)
movq 0x28(%r12), %rcx
cmpq $-0x1, %rcx
jne 0x9f4c9
cmpq $-0x1, 0x38(%r12)
jne 0x9f4c9
movq $0x0, 0x38(%r12)
leaq -0x1(%rbp), %rdx
movq %rdx, 0x40(%r12)
testl %eax, %eax
je 0x9f616
cmpq $-0x1, %rcx
je 0x9f67e
movq 0x18(%r12), %rdi
callq 0x11b0a1
movb (%rax), %bl
testq %r15, %r15
je 0x9f505
movq 0x419a8d(%rip), %rax    # 0x4b8f80
movq (%rax), %rdx
leaq 0x2a9d24(%rip), %rsi    # 0x349221
movq %r15, %rdi
callq 0x11cc90
movq 0x30(%r12), %rbp
cmpq %r14, %rbp
jae 0x9f70d
movq %r15, 0x28(%rsp)
movq 0x28(%r12), %r13
cmpq %rbp, %r13
ja 0x9f5fc
xorl %r15d, %r15d
movsbl %bl, %eax
movl %eax, 0x24(%rsp)
movq %rbp, 0x30(%rsp)
movq %rbp, %rbx
subq %r13, %rbx
cmpq $0x20001, %rbx          # imm = 0x20001
movq 0x10(%rsp), %r14
jb 0x9f572
leaq 0x20000(%r13), %rsi
movq %r14, %rdi
callq 0x12bb18
movq %r14, %rdi
movq %rax, %rsi
callq 0x12bb2e
movq %rax, %rbx
decq %rbx
subq %r13, %rbx
jbe 0x9f7b9
leaq (%rbx,%r13), %rdx
movq %r14, %rdi
movq %r13, 0x18(%rsp)
movq %r13, %rsi
movl 0x24(%rsp), %ecx
callq 0x12d5a2
testq %rax, %rax
je 0x9f7b4
movq %rbx, %rbp
incq %rbp
je 0x9f5e3
movq %rax, %r13
xorl %r14d, %r14d
movq 0x50(%r12), %rax
testq %rax, %rax
setne %cl
cmpq %rax, %r15
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0x9f5c9
movq (%r12), %rsi
movl $0xa, %edi
callq 0xff0af
xorl %r15d, %r15d
movsbl (%r13,%r14), %edi
movq (%r12), %rsi
callq 0xff0af
incq %r14
incq %r15
cmpq %r14, %rbp
jne 0x9f5a1
movq 0x18(%rsp), %r13
addq %rbx, %r13
incq %r13
movq 0x30(%rsp), %rbp
cmpq %rbp, %r13
jbe 0x9f535
movq (%r12), %rsi
movl $0xa, %edi
callq 0xff0af
xorl %ebp, %ebp
movq 0x28(%rsp), %r15
jmp 0x9f747
movq 0x38(%r12), %rsi
cmpq $-0x1, %rsi
je 0x9f4d1
movq 0x40(%r12), %rdx
cmpq %rbp, %rdx
jae 0x9f72e
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x12bb2e
movq %rax, 0x28(%r12)
movq 0x40(%r12), %rsi
movq %rbx, %rdi
callq 0x12bb2e
movq %rax, 0x18(%rsp)
movq 0x40(%r12), %rsi
movq %rbx, %rdi
callq 0x12bb4b
movq 0x18(%rsp), %rcx
addq %rcx, %rax
decq %rax
movq %rax, 0x30(%r12)
movq 0x28(%r12), %rcx
jmp 0x9f4d1
movq 0x38(%r12), %rbx
testq %r15, %r15
je 0x9f6a1
movq 0x4198f1(%rip), %rax    # 0x4b8f80
movq (%rax), %rdx
leaq 0x2a9c07(%rip), %rsi    # 0x3492a0
movq %r15, %rdi
callq 0x11cc90
movq 0x40(%r12), %r14
cmpq %rbp, %r14
jae 0x9f71f
xorl %ebp, %ebp
cmpq %r14, %rbx
ja 0x9f747
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
leaq 0x38(%rsp), %rsi
movq %rbx, %rdx
callq 0x12d638
movq %rax, %r13
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
movq %rbx, %rdx
callq 0x12bb9d
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rcx
movq (%r12), %r9
movq 0x50(%r12), %r8
movq %rax, %rdi
movq %r13, %rdx
callq 0xfe0d0
incq %rbx
cmpq %r14, %rbx
jbe 0x9f6bb
movq 0x8(%rsp), %r14
xorl %ebp, %ebp
jmp 0x9f74c
leaq 0x2a9b28(%rip), %rsi    # 0x34923c
movq %r13, %rdi
movq %rbp, %rdx
movq %r14, %rcx
jmp 0x9f73b
leaq 0x2a9aa8(%rip), %rsi    # 0x3491ce
movq %r13, %rdi
movq %r14, %rdx
jmp 0x9f738
leaq 0x2a9a99(%rip), %rsi    # 0x3491ce
movq %r13, %rdi
movq %rbp, %rcx
xorl %eax, %eax
callq 0xfcb67
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %r14
testq %r15, %r15
je 0x9f789
movq 0x419828(%rip), %rbx    # 0x4b8f80
movq (%rbx), %rdx
leaq 0x2a9b52(%rip), %rsi    # 0x3492b4
movq %r15, %rdi
callq 0x11cc90
movq 0x10(%rsp), %rdi
callq 0x12c3a7
movq %r14, %rdi
callq 0x1040e0
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x11cf39
jmp 0x9f79b
movq 0x10(%rsp), %rdi
callq 0x12c3a7
movq %r14, %rdi
callq 0x1040e0
movq %r15, %rdi
callq 0x11d054
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x193ee
callq 0x193b5
callq 0x19427
callq 0x1937c