// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rcx, %r12
movl %edx, %ebp
movq %rsi, %r14
testq %r8, %r8
je 0x20707
movq %rbx, %rdi
callq 0x89eb7
testb %al, %al
jne 0x20b46
testq %r12, %r12
je 0x20b18
callq 0xaaf34
testb %al, %al
je 0x20734
leaq 0x2c8a9f(%rip), %rdi    # 0x2e91bf
callq 0xaf4a5
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0xaf4d6
jmp 0x2073d
movq $0x0, 0x8(%rsp)
movzbl 0x58(%r12), %edi
movq 0x41781e(%rip), %rax    # 0x437f68
movq (%rax), %rdx
leaq 0x2c6180(%rip), %rsi    # 0x2e68d4
callq 0x92b50
movq %rax, %rsi
movslq %ebp, %rax
movq (%r14,%rax,8), %rdi
movq %rsi, 0x20(%rsp)
movq %rbx, %rdx
callq 0xc2100
movq %rax, %r13
testq %rax, %rax
je 0x20a49
movq %r13, %rdi
callq 0xc1778
movq %rax, %r14
movq %r13, %rdi
callq 0xc177d
movq %rax, %rbp
movq 0x10(%r12), %rdi
callq 0xad1fa
leaq 0x2c88c1(%rip), %rsi    # 0x2e9064
movq %rax, %rdi
callq 0x179e0
movq 0x48(%r12), %rcx
cmpq $-0x1, %rcx
je 0x207c0
movq %rcx, 0x40(%r12)
movq %rcx, 0x38(%r12)
movq 0x28(%r12), %rcx
cmpq $-0x1, %rcx
jne 0x207e2
cmpq $-0x1, 0x38(%r12)
jne 0x207e2
andq $0x0, 0x38(%r12)
leaq -0x1(%rbp), %rdx
movq %rdx, 0x40(%r12)
testl %eax, %eax
movq %r13, 0x10(%rsp)
je 0x2090c
cmpq $-0x1, %rcx
je 0x2096f
movq 0x18(%r12), %rdi
callq 0xad1fa
movb (%rax), %bpl
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x20826
movq 0x417751(%rip), %rax    # 0x437f68
movq (%rax), %rdx
leaq 0x2c8a00(%rip), %rsi    # 0x2e9221
callq 0xaf86f
movq 0x30(%r12), %rdx
cmpq %r14, %rdx
jae 0x209f1
movq %rdx, 0x28(%rsp)
movq 0x28(%r12), %r14
xorl %r15d, %r15d
movsbl %bpl, %eax
movl %eax, 0x1c(%rsp)
pushq $0xa
popq %rbx
movq 0x28(%rsp), %rbp
subq %r14, %rbp
jb 0x20a00
cmpq $0x20001, %rbp          # imm = 0x20001
jb 0x2088c
leaq 0x20000(%r14), %rsi
movq %r13, %rdi
callq 0xc1180
movq %r13, %rdi
movq %rax, %rsi
callq 0xc1196
movq %rax, %rbp
decq %rbp
subq %r14, %rbp
jbe 0x20aea
leaq (%r14,%rbp), %rdx
movq %r13, %rdi
movq %r14, %rsi
movl 0x1c(%rsp), %ecx
callq 0xc2df6
testq %rax, %rax
je 0x20ab9
movq %rax, %r13
addq %rbp, %r14
incq %r14
movq %r14, 0x30(%rsp)
incq %rbp
xorl %r14d, %r14d
cmpq %r14, %rbp
je 0x208fd
movq 0x50(%r12), %rax
testq %rax, %rax
setne %cl
cmpq %rax, %r15
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0x208e6
movq (%r12), %rsi
movl %ebx, %edi
callq 0x8d771
xorl %r15d, %r15d
movsbl (%r13,%r14), %edi
movq (%r12), %rsi
callq 0x8d771
incq %r14
incq %r15
jmp 0x208bc
movq 0x10(%rsp), %r13
movq 0x30(%rsp), %r14
jmp 0x2084c
movq 0x38(%r12), %rsi
cmpq $-0x1, %rsi
je 0x207ef
movq 0x40(%r12), %rdx
cmpq %rbp, %rdx
jae 0x20a35
movq %r13, %rdi
callq 0xc1196
movq %rax, 0x28(%r12)
movq 0x40(%r12), %rsi
movq %r13, %rdi
callq 0xc1196
movq %rax, %r13
movq 0x40(%r12), %rsi
movq 0x10(%rsp), %rdi
callq 0xc11b3
addq %r13, %rax
decq %rax
movq 0x10(%rsp), %r13
movq %rax, 0x30(%r12)
movq 0x28(%r12), %rcx
jmp 0x207ef
movq 0x38(%r12), %r14
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x20994
movq 0x4175e3(%rip), %rax    # 0x437f68
movq (%rax), %rdx
leaq 0x2c8911(%rip), %rsi    # 0x2e92a0
callq 0xaf86f
movq 0x40(%r12), %r13
cmpq %rbp, %r13
jae 0x20a10
leaq 0x40(%rsp), %rbp
movq 0x10(%rsp), %r15
cmpq %r13, %r14
ja 0x20a2c
movq %r15, %rdi
leaq 0x38(%rsp), %rsi
movq %r14, %rdx
callq 0xc2ebc
movq %rax, %rbx
movq %r15, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0xc11fb
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rcx
movq (%r12), %r9
movq 0x50(%r12), %r8
movq %rax, %rdi
movq %rbx, %rdx
callq 0x8c186
incq %r14
jmp 0x209a8
leaq 0x2c8844(%rip), %rsi    # 0x2e923c
movq %rbx, %rdi
movq %r14, %rcx
jmp 0x20a42
movq (%r12), %rsi
pushq $0xa
popq %rdi
callq 0x8d771
xorl %ebx, %ebx
jmp 0x20a4c
leaq 0x2c87b7(%rip), %rsi    # 0x2e91ce
movq %rbx, %rdi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x89dbb
pushq $-0x1
popq %rbx
jmp 0x20a2e
xorl %ebx, %ebx
movq 0x10(%rsp), %r13
jmp 0x20a4c
leaq 0x2c8792(%rip), %rsi    # 0x2e91ce
movq %rbx, %rdi
movq %rbp, %rcx
xorl %eax, %eax
callq 0x89dbb
pushq $-0x1
popq %rbx
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x20a8e
movq 0x41750b(%rip), %r14    # 0x437f68
movq (%r14), %rdx
leaq 0x2c884d(%rip), %rsi    # 0x2e92b4
movq %r15, %rdi
callq 0xaf86f
movq %r13, %rdi
callq 0xc1b0c
movq 0x20(%rsp), %rdi
callq 0x92fd0
movq (%r14), %rsi
movq %r15, %rdi
callq 0xafb49
jmp 0x20aa0
movq %r13, %rdi
callq 0xc1b0c
movq 0x20(%rsp), %rdi
callq 0x92fd0
movq %r15, %rdi
callq 0xafc5b
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4174a8(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2c4549(%rip), %rsi    # 0x2e5013
leaq 0x2e3488(%rip), %rdx    # 0x303f59
leaq 0x2c86cb(%rip), %rcx    # 0x2e91a3
leaq 0x2c83a4(%rip), %r8     # 0x2e8e83
movl $0x133, %r9d            # imm = 0x133
jmp 0x20b72
movq 0x417477(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2c4518(%rip), %rsi    # 0x2e5013
leaq 0x2c8789(%rip), %rdx    # 0x2e928b
leaq 0x2c869a(%rip), %rcx    # 0x2e91a3
leaq 0x2c8373(%rip), %r8     # 0x2e8e83
movl $0x129, %r9d            # imm = 0x129
jmp 0x20b72
movq 0x417449(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2c44ea(%rip), %rsi    # 0x2e5013
leaq 0x327b23(%rip), %rdx    # 0x348653
leaq 0x2c866c(%rip), %rcx    # 0x2e91a3
leaq 0x2c8345(%rip), %r8     # 0x2e8e83
movl $0xd8, %r9d
jmp 0x20b72
movq 0x41741b(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2c44bc(%rip), %rsi    # 0x2e5013
leaq 0x2c4661(%rip), %rdx    # 0x2e51bf
leaq 0x2c863e(%rip), %rcx    # 0x2e91a3
leaq 0x2c8317(%rip), %r8     # 0x2e8e83
movl $0xd7, %r9d
xorl %eax, %eax
callq 0x17a50
callq 0x17390
nop