// File: /workspace/github_c_makefile_star2_O1/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, %r12
movq %rcx, %rbx
movl %edx, %r13d
movq %rsi, %rbp
testq %r8, %r8
je 0xa0e5e
movq %r12, %rdi
callq 0x101a9a
testb %al, %al
jne 0xa11c0
testq %rbx, %rbx
je 0xa11bb
movzbl 0x57(%rbx), %edi
movq 0x42310e(%rip), %r14    # 0x4c3f80
movq (%r14), %rdx
leaq 0x2aea58(%rip), %r15    # 0x34f8d4
movq %r15, %rsi
callq 0x108ed0
movq %rax, 0x10(%rsp)
movzbl 0x58(%rbx), %edi
movq (%r14), %rdx
movq %r15, %rsi
callq 0x108ed0
movq %rax, %r15
cmpb $0x1, 0x58(%rbx)
jne 0xa0ed5
leaq 0x2b0f13(%rip), %rdi    # 0x351dbb
leaq 0x2fbb82(%rip), %rsi    # 0x39ca31
leaq 0x2b06c2(%rip), %rdx    # 0x351578
movl $0x122, %ecx            # imm = 0x122
movq %r12, %r8
callq 0x101c23
movq %r15, %rdi
movq %rax, 0x8(%rsp)
movq %rax, %rsi
callq 0x108f6a
jmp 0xa0ede
movq $0x0, 0x8(%rsp)
movq 0x8(%rbx), %rdi
callq 0x120d4c
movslq %r13d, %r14
testq %rax, %rax
jne 0xa0f1c
movq (%rbp,%r14,8), %rdi
callq 0xd6450
movq %rax, %r13
movq 0x8(%rbx), %rdi
movq %rax, %rsi
callq 0x1209e4
leaq 0x2b0669(%rip), %rsi    # 0x351578
movq %r13, %rdi
movl $0x12a, %edx            # imm = 0x12A
callq 0x109670
callq 0xf36ef
movq %rax, %r13
movq (%rbp,%r14,8), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0xf374b
movq %rax, %r14
movq %rax, (%rbx)
movq %r13, %rdi
callq 0xf424d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0xa1087
cmpq $-0x1, 0x20(%rbx)
movq 0x10(%rsp), %r14
jne 0xa0f7f
movq 0x38(%rbx), %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
movq %rcx, %rax
mulq %rdx
shrq %rdx
cmpq $-0x1, %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x20(%rbx)
cmpl $-0x1, 0x4c(%rbx)
jne 0xa0fac
movq 0x20(%rbx), %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
movq %rcx, %rax
mulq %rdx
shrq $0x2, %rdx
cmpq $-0x1, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %edx, %eax
movl %eax, 0x4c(%rbx)
cmpl $0x3, 0x4c(%rbx)
ja 0xa0fb9
movl $0x4, 0x4c(%rbx)
cmpl $-0x1, 0x48(%rbx)
jne 0xa1024
movq (%rbx), %rdi
callq 0xf02da
movq %rax, %rdi
callq 0xd3713
movl %eax, %r13d
movl %eax, %eax
cvtsi2sd %rax, %xmm1
movsd 0x2b058f(%rip), %xmm0   # 0x351570
callq 0x10b124
callq 0x10b057
movq %rax, %rcx
shrq $0x20, %rcx
jne 0xa11c5
testq %rax, %rax
setne %cl
testl %eax, %eax
sete %dl
testb %dl, %cl
jne 0xa11c5
movl %eax, 0x48(%rbx)
leaq 0x2b0dd4(%rip), %rsi    # 0x351de9
movq %r14, %rdi
movl %r13d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x10906e
cmpl $-0x1, 0x4c(%rbx)
jne 0xa1033
movl 0x48(%rbx), %eax
leal (%rax,%rax,4), %eax
movl %eax, 0x4c(%rbx)
cmpq $-0x1, 0x20(%rbx)
jne 0xa1045
movl 0x4c(%rbx), %eax
leaq (%rax,%rax,2), %rax
movq %rax, 0x20(%rbx)
cmpq $-0x1, 0x38(%rbx)
jne 0xa1058
movq 0x20(%rbx), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x38(%rbx)
movl 0x48(%rbx), %r8d
movl 0x4c(%rbx), %r9d
cmpl %r8d, %r9d
jbe 0xa108e
movq 0x20(%rbx), %r10
cmpq %r9, %r10
jae 0xa10d6
leaq 0x2b0db3(%rip), %rsi    # 0x351e28
movq %r12, %rdi
movq %r10, %rdx
movl %r9d, %ecx
xorl %eax, %eax
callq 0x1019cf
jmp 0xa10a5
movq 0x10(%rsp), %r14
jmp 0xa10a5
leaq 0x2b0d63(%rip), %rsi    # 0x351df8
movq %r12, %rdi
movl %r9d, %edx
movl %r8d, %ecx
xorl %eax, %eax
callq 0x1019cf
movq %r14, %rdi
callq 0x10916a
movq %r15, %rdi
callq 0x10916a
cmpb $0x1, 0x58(%rbx)
jne 0xa10c5
movq 0x8(%rsp), %rdi
callq 0x101e80
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x38(%rbx), %rax
cmpq %r10, %rax
jae 0xa10f8
leaq 0x2b0d78(%rip), %rsi    # 0x351e5e
movq %r12, %rdi
movq %rax, %rdx
movq %r10, %rcx
xorl %eax, %eax
callq 0x1019cf
jmp 0xa10a5
movq 0x40(%rbx), %rdx
leaq 0x10(%rbx), %rcx
movq %rax, %rdi
movq %r10, %rsi
pushq %r12
pushq %r14
callq 0x13441c
addq $0x10, %rsp
testq %rax, %rax
je 0xa10a5
movq %rax, %r13
movq 0x28(%rbx), %rsi
movq %rax, %rdi
testq %rsi, %rsi
je 0xa1134
cmpq $-0x1, %rsi
jne 0xa113b
callq 0x1355d0
jmp 0xa1140
callq 0x1355b2
jmp 0xa1140
callq 0x135598
movq 0x30(%rbx), %rsi
movq %r13, %rdi
callq 0x135603
cmpb $0x1, 0x59(%rbx)
jne 0xa115a
movq %r13, %rdi
callq 0x1355f0
cmpb $0x1, 0x56(%rbx)
jne 0xa1168
movq %r13, %rdi
callq 0x134ecb
cmpb $0x0, 0x54(%rbx)
jne 0xa1176
movq %r13, %rdi
callq 0x135539
cmpb $0x1, 0x55(%rbx)
jne 0xa1184
movq %r13, %rdi
callq 0x13555e
movl 0x50(%rbx), %esi
cmpl $-0x1, %esi
je 0xa1194
movq %r13, %rdi
callq 0x134eb9
movq (%rbx), %rdx
movq 0x8(%rbx), %rsi
movq %r13, %rdi
movq %r14, %rcx
movq %r15, %r8
movq %r12, %r9
callq 0x1356fa
movl %eax, %ebp
movq %r13, %rdi
callq 0x135621
jmp 0xa10a5
callq 0x1930c
callq 0x192a6
callq 0x192df
nop