// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/tools/gt_condenseq_compress.c
// Function: gt_condenseq_compress_runner
static int gt_condenseq_compress_runner(GT_UNUSED int argc, const char **argv,
                                        int parsed_args, void *tool_arguments,
                                        GtError *err)
{
  GtCondenseqCompressArguments *arguments = tool_arguments;
  GtLogger *logger,
           *kdb_logger;
  FILE *kmer_fp = NULL;
  int had_err = 0;

  gt_error_check(err);
  gt_assert(arguments);

  logger = gt_logger_new(arguments->verbose, GT_LOGGER_DEFLT_PREFIX, stderr);
  kdb_logger = gt_logger_new(arguments->kdb, GT_LOGGER_DEFLT_PREFIX, stderr);
  if (arguments->kdb) {
    kmer_fp = gt_fa_fopen("kmer_db.out", "w", err);
    gt_logger_set_target(kdb_logger, kmer_fp);
  }

  if (gt_str_length(arguments->indexname) == 0UL) {
    char *basenameptr;
    basenameptr = gt_basename(argv[parsed_args]);
    gt_str_set(arguments->indexname, basenameptr);
    gt_free(basenameptr);
  }

  if (!had_err) {
    GtEncseqLoader *es_l = gt_encseq_loader_new();
    arguments->input_es = gt_encseq_loader_load(es_l, argv[parsed_args], err);
    if (arguments->input_es == NULL)
      had_err = -1;
    gt_encseq_loader_delete(es_l);
  }

/* TODO DW: this should be adjusted to reflect the parameter tests done. it
   could get fairly complicated heuristic, or we leave it as is.
   setting hard defaults for dna or protein would work, too.
  carefull: adjusting these might break test cases. */
  if (!had_err) {
    if (arguments->minalignlength == GT_UNDEF_UWORD)
      arguments->minalignlength = arguments->initsize != GT_UNDEF_UWORD ?
                                  arguments->initsize / (GtUword) 3UL :
                                  GT_UNDEF_UWORD;
    if (arguments->windowsize == GT_UNDEF_UINT)
      arguments->windowsize = arguments->minalignlength != GT_UNDEF_UWORD ?
                              (unsigned int) (arguments->minalignlength / 5U) :
                              GT_UNDEF_UINT;
    if (arguments->windowsize < 4U)
      arguments->windowsize = 4U;
    if (arguments->kmersize == GT_UNDEF_UINT) {
      unsigned int size =
        gt_alphabet_num_of_chars(gt_encseq_alphabet(arguments->input_es));
      /* size^k ~= 100000 */
      gt_safe_assign(arguments->kmersize,
                     gt_round_to_long(gt_log_base(100000.0, (double) size)));
      gt_logger_log(logger, "|A|: %u, k: %u",
                    size, arguments->kmersize);
    }

    if (arguments->windowsize == GT_UNDEF_UINT) {
      arguments->windowsize = 5U * arguments->kmersize;
    }
    if (arguments->minalignlength == GT_UNDEF_UWORD) {
      arguments->minalignlength = (GtUword) (3UL * arguments->windowsize);
    }
    if (arguments->initsize == GT_UNDEF_UWORD) {
      arguments->initsize = (GtUword) (3UL * arguments->minalignlength);
    }
  }
  if (!had_err &&
      arguments->windowsize <= arguments->kmersize) {
    gt_error_set(err, "-windowsize (%u) must be larger -kmersize (%u)!",
                 arguments->windowsize, arguments->kmersize);
    had_err = -1;
  }
  if (!had_err &&
      arguments->minalignlength < (GtUword) arguments->windowsize) {
    gt_error_set(err, "-alignlength (" GT_WU ") must be at least "
                 "-windowsize (%u)!", arguments->minalignlength,
                 arguments->windowsize);
    had_err = -1;
  }
  if (!had_err && (arguments->initsize < arguments->minalignlength)) {
    gt_error_set(err, "-initsize (" GT_WU ") must be at least "
                 "-alignlength (" GT_WU ")!", arguments->initsize,
                 arguments->minalignlength);
    had_err = -1;
  }

  if (!had_err) {
    GtCondenseqCreator *ces_c;

    if (!had_err) {
      ces_c = gt_condenseq_creator_new(arguments->initsize,
                                       arguments->minalignlength,
                                       arguments->xdrop,
                                       &(arguments->scores),
                                       arguments->kmersize,
                                       arguments->windowsize,
                                       logger,
                                       err);
      if (ces_c == NULL)
        had_err = -1;
    }
    if (!had_err) {
      if (arguments->cutoff_value == GT_UNDEF_UWORD)
        gt_condenseq_creator_use_mean_cutoff(ces_c);
      else if (arguments->cutoff_value == 0)
        gt_condenseq_creator_disable_cutoff(ces_c);
      else
        gt_condenseq_creator_set_cutoff(ces_c, arguments->cutoff_value);
      gt_condenseq_creator_set_mean_fraction(ces_c, arguments->fraction);
      if (arguments->prune)
        gt_condenseq_creator_disable_prune(ces_c);
      if (arguments->brute)
        gt_condenseq_creator_enable_brute_force(ces_c);
      if (!arguments->diags)
        gt_condenseq_creator_disable_diagonals(ces_c);
      if (arguments->full_diags)
        gt_condenseq_creator_enable_full_diagonals(ces_c);
      if (arguments->clean_percent != GT_UNDEF_UINT)
        gt_condenseq_creator_set_diags_clean_limit(ces_c,
                                                   arguments->clean_percent);

      had_err = gt_condenseq_creator_create(ces_c,
                                            arguments->indexname,
                                            arguments->input_es,
                                            logger, kdb_logger, err);

      gt_condenseq_creator_delete(ces_c);
    }
  }

  gt_logger_delete(logger);
  gt_logger_delete(kdb_logger);
  if (arguments->kdb)
    gt_fa_fclose(kmer_fp);
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbp
movq %rcx, %rbx
movl %edx, %r13d
movq %rsi, %r14
testq %r8, %r8
je 0x1feed
movq %rbp, %rdi
callq 0x89eb7
testb %al, %al
jne 0x20283
movq %r14, 0x10(%rsp)
testq %rbx, %rbx
je 0x20255
movzbl 0x57(%rbx), %edi
movq 0x418062(%rip), %r12    # 0x437f68
movq (%r12), %rdx
leaq 0x2c69c3(%rip), %r15    # 0x2e68d4
movq %r15, %rsi
callq 0x92b50
movq %rax, %r14
movzbl 0x58(%rbx), %edi
movq (%r12), %rdx
movq %r15, %rsi
callq 0x92b50
cmpb $0x1, 0x58(%rbx)
movq %rax, 0x8(%rsp)
jne 0x1ff70
movq %rax, %r12
movq %r14, %r15
leaq 0x2c8e67(%rip), %rdi    # 0x2e8dab
leaq 0x3139c3(%rip), %rsi    # 0x33390e
leaq 0x2c8616(%rip), %rdx    # 0x2e8568
movl $0x122, %ecx            # imm = 0x122
movq %rbp, %r8
callq 0x8a156
movq %r12, %rdi
movq %rax, (%rsp)
movq %rax, %rsi
callq 0x92cd9
jmp 0x1ff7b
movq %r14, %r15
movq $0x0, (%rsp)
movq 0x8(%rbx), %rdi
callq 0xad289
movslq %r13d, %r14
testq %rax, %rax
movq 0x10(%rsp), %r12
jne 0x1ffbd
movq (%r12,%r14,8), %rdi
callq 0x5a384
movq %rax, %r13
movq 0x8(%rbx), %rdi
movq %rax, %rsi
callq 0xacc8b
leaq 0x2c85b8(%rip), %rsi    # 0x2e8568
movq %r13, %rdi
movl $0x12a, %edx            # imm = 0x12A
callq 0x936f9
callq 0x791cd
movq %rax, %r13
movq (%r12,%r14,8), %rsi
movq %rax, %rdi
movq %rbp, %r12
movq %rbp, %rdx
callq 0x7921d
movq %rax, %r14
movq %rax, (%rbx)
movq %r13, %rdi
callq 0x79f01
pushq $-0x1
popq %rbp
testq %r14, %r14
je 0x20123
movq 0x20(%rbx), %rcx
cmpq $-0x1, %rcx
movq %r15, %r14
jne 0x2001c
movq 0x38(%rbx), %rsi
pushq $0x3
popq %rcx
movq %rsi, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
cmpq $-0x1, %rsi
cmoveq %rsi, %rcx
movq %rcx, 0x20(%rbx)
movl 0x4c(%rbx), %r9d
cmpl $-0x1, %r9d
movq 0x8(%rsp), %r15
jne 0x20046
pushq $0x5
popq %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
cmpq $-0x1, %rcx
pushq $-0x1
popq %r9
cmovnel %eax, %r9d
movl %r9d, 0x4c(%rbx)
cmpl $0x3, %r9d
ja 0x20057
movl $0x4, 0x4c(%rbx)
pushq $0x4
popq %r9
cmpl $-0x1, 0x48(%rbx)
jne 0x200c6
movq (%rbx), %rdi
callq 0x754dd
movq %rax, %rdi
callq 0x56c8e
movl %eax, %r13d
movl %eax, %eax
cvtsi2sd %rax, %xmm1
movsd 0x2c84e1(%rip), %xmm0   # 0x2e8560
callq 0x95a1d
callq 0x95920
movq %rax, %rcx
shrq $0x20, %rcx
jne 0x202bb
testq %rax, %rax
setne %cl
testl %eax, %eax
sete %dl
testb %dl, %cl
jne 0x202bb
movl %eax, 0x48(%rbx)
leaq 0x2c8d26(%rip), %rsi    # 0x2e8dd9
movq %r14, %rdi
movl %r13d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x92e71
movl 0x4c(%rbx), %r9d
cmpl $-0x1, %r9d
jne 0x200d5
imull $0x5, 0x48(%rbx), %r9d
movl %r9d, 0x4c(%rbx)
movq 0x20(%rbx), %r10
movl %r9d, %ecx
cmpq $-0x1, %r10
jne 0x200ea
leaq (%rcx,%rcx,2), %r10
movq %r10, 0x20(%rbx)
movq 0x38(%rbx), %rax
cmpq $-0x1, %rax
jne 0x200fc
leaq (%r10,%r10,2), %rax
movq %rax, 0x38(%rbx)
movl 0x48(%rbx), %r8d
cmpl %r8d, %r9d
jbe 0x2012d
cmpq %rcx, %r10
jae 0x20174
leaq 0x2c8d07(%rip), %rsi    # 0x2e8e18
movq %r12, %rdi
movq %r10, %rdx
movl %r9d, %ecx
xorl %eax, %eax
callq 0x89dbb
jmp 0x20144
movq %r15, %r14
movq 0x8(%rsp), %r15
jmp 0x20144
leaq 0x2c8cb4(%rip), %rsi    # 0x2e8de8
movq %r12, %rdi
movl %r9d, %edx
movl %r8d, %ecx
xorl %eax, %eax
callq 0x89dbb
movq %r14, %rdi
callq 0x92fd0
movq %r15, %rdi
callq 0x92fd0
cmpb $0x1, 0x58(%rbx)
jne 0x20163
movq (%rsp), %rdi
callq 0x8a4fd
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %r10, %rax
jae 0x20192
leaq 0x2c8cce(%rip), %rsi    # 0x2e8e4e
movq %r12, %rdi
movq %rax, %rdx
movq %r10, %rcx
xorl %eax, %eax
callq 0x89dbb
jmp 0x20144
movq 0x40(%rbx), %rdx
leaq 0x10(%rbx), %rcx
movq %rax, %rdi
movq %r10, %rsi
pushq %r12
pushq %r14
callq 0xc3c8c
addq $0x10, %rsp
testq %rax, %rax
je 0x20144
movq %rax, %r13
movq 0x28(%rbx), %rsi
movq %rax, %rdi
testq %rsi, %rsi
je 0x201ce
cmpq $-0x1, %rsi
jne 0x201d5
callq 0xc532c
jmp 0x201da
callq 0xc52de
jmp 0x201da
callq 0xc5291
movq 0x30(%rbx), %rsi
movq %r13, %rdi
callq 0xc53c2
cmpb $0x1, 0x59(%rbx)
jne 0x201f4
movq %r13, %rdi
callq 0xc537c
cmpb $0x1, 0x56(%rbx)
jne 0x20202
movq %r13, %rdi
callq 0xc4a61
cmpb $0x0, 0x54(%rbx)
jne 0x20210
movq %r13, %rdi
callq 0xc5232
cmpb $0x1, 0x55(%rbx)
jne 0x2021e
movq %r13, %rdi
callq 0xc5257
movl 0x50(%rbx), %esi
cmpl $-0x1, %esi
je 0x2022e
movq %r13, %rdi
callq 0xc4a1c
movq (%rbx), %rdx
movq 0x8(%rbx), %rsi
movq %r13, %rdi
movq %r14, %rcx
movq %r15, %r8
movq %r12, %r9
callq 0xc5515
movl %eax, %ebp
movq %r13, %rdi
callq 0xc543c
jmp 0x20144
movq 0x417d0c(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2c4dad(%rip), %rsi    # 0x2e5013
leaq 0x3283e6(%rip), %rdx    # 0x348653
leaq 0x2c8b1a(%rip), %rcx    # 0x2e8d8e
leaq 0x2c82ed(%rip), %r8     # 0x2e8568
movl $0x11d, %r9d            # imm = 0x11D
jmp 0x202af
movq 0x417cde(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2c4d7f(%rip), %rsi    # 0x2e5013
leaq 0x2c4f24(%rip), %rdx    # 0x2e51bf
leaq 0x2c8aec(%rip), %rcx    # 0x2e8d8e
leaq 0x2c82bf(%rip), %r8     # 0x2e8568
movl $0x11c, %r9d            # imm = 0x11C
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x417ca6(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2c8aeb(%rip), %rsi    # 0x2e8db7
leaq 0x2c8295(%rip), %rdx    # 0x2e8568
movl $0x149, %ecx            # imm = 0x149
xorl %eax, %eax
callq 0x17a50
pushq $0x1
popq %rdi
callq 0x178f0
nop