// File: /workspace/github_c_makefile_star2_O3/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 0x9ecce
movq %r12, %rdi
callq 0xfcc32
testb %al, %al
jne 0x9f03e
testq %rbx, %rbx
je 0x9f039
movzbl 0x57(%rbx), %edi
movq 0x41a29e(%rip), %r14    # 0x4b8f80
movq (%r14), %rdx
leaq 0x2a7be8(%rip), %r15    # 0x3468d4
movq %r15, %rsi
callq 0x103e40
movq %rax, 0x10(%rsp)
movzbl 0x58(%rbx), %edi
movq (%r14), %rdx
movq %r15, %rsi
callq 0x103e40
movq %rax, %r15
cmpb $0x1, 0x58(%rbx)
jne 0x9ed45
leaq 0x2aa093(%rip), %rdi    # 0x348dab
leaq 0x2f4896(%rip), %rsi    # 0x3935b5
leaq 0x2a9842(%rip), %rdx    # 0x348568
movl $0x122, %ecx            # imm = 0x122
movq %r12, %r8
callq 0xfcdbb
movq %r15, %rdi
movq %rax, 0x8(%rsp)
movq %rax, %rsi
callq 0x103eda
jmp 0x9ed4e
movq $0x0, 0x8(%rsp)
movq 0x8(%rbx), %rdi
callq 0x11b0ca
movslq %r13d, %r14
testq %rax, %rax
jne 0x9ed8c
movq (%rbp,%r14,8), %rdi
callq 0xd3e84
movq %rax, %r13
movq 0x8(%rbx), %rdi
movq %rax, %rsi
callq 0x11ad62
leaq 0x2a97e9(%rip), %rsi    # 0x348568
movq %r13, %rdi
movl $0x12a, %edx            # imm = 0x12A
callq 0x1045eb
callq 0xef0cd
movq %rax, %r13
movq (%rbp,%r14,8), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0xef129
movq %rax, %r14
movq %rax, (%rbx)
movq %r13, %rdi
callq 0xefbe3
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x9ef09
movq 0x20(%rbx), %rcx
cmpq $-0x1, %rcx
movq 0x10(%rsp), %r14
jne 0x9edf5
movq 0x38(%rbx), %rsi
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
movq %rsi, %rax
mulq %rcx
movq %rdx, %rcx
shrq %rcx
cmpq $-0x1, %rsi
cmoveq %rsi, %rcx
movq %rcx, 0x20(%rbx)
movl 0x4c(%rbx), %r9d
cmpl $-0x1, %r9d
jne 0x9ee25
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
movq %rcx, %rax
mulq %rdx
shrq $0x2, %rdx
cmpq $-0x1, %rcx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmovnel %edx, %r9d
movl %r9d, 0x4c(%rbx)
cmpl $0x3, %r9d
ja 0x9ee38
movl $0x4, 0x4c(%rbx)
movl $0x4, %r9d
cmpl $-0x1, 0x48(%rbx)
jne 0x9eea7
movq (%rbx), %rdi
callq 0xebcd9
movq %rax, %rdi
callq 0xd11be
movl %eax, %r13d
movl %eax, %eax
cvtsi2sd %rax, %xmm1
movsd 0x2a9700(%rip), %xmm0   # 0x348560
callq 0x10604f
callq 0x105f82
movq %rax, %rcx
shrq $0x20, %rcx
jne 0x9f043
testq %rax, %rax
setne %cl
testl %eax, %eax
sete %dl
testb %dl, %cl
jne 0x9f043
movl %eax, 0x48(%rbx)
leaq 0x2a9f45(%rip), %rsi    # 0x348dd9
movq %r14, %rdi
movl %r13d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x103fe1
movl 0x4c(%rbx), %r9d
cmpl $-0x1, %r9d
jne 0x9eeb8
movl 0x48(%rbx), %eax
leal (%rax,%rax,4), %r9d
movl %r9d, 0x4c(%rbx)
movq 0x20(%rbx), %r10
cmpq $-0x1, %r10
jne 0x9eecd
movl %r9d, %eax
leaq (%rax,%rax,2), %r10
movq %r10, 0x20(%rbx)
movq 0x38(%rbx), %rax
cmpq $-0x1, %rax
jne 0x9eedf
leaq (%r10,%r10,2), %rax
movq %rax, 0x38(%rbx)
movl 0x48(%rbx), %r8d
cmpl %r8d, %r9d
jbe 0x9ef10
movl %r9d, %ecx
cmpq %rcx, %r10
jae 0x9ef58
leaq 0x2a9f21(%rip), %rsi    # 0x348e18
movq %r12, %rdi
movq %r10, %rdx
movl %r9d, %ecx
xorl %eax, %eax
callq 0xfcb67
jmp 0x9ef27
movq 0x10(%rsp), %r14
jmp 0x9ef27
leaq 0x2a9ed1(%rip), %rsi    # 0x348de8
movq %r12, %rdi
movl %r9d, %edx
movl %r8d, %ecx
xorl %eax, %eax
callq 0xfcb67
movq %r14, %rdi
callq 0x1040e0
movq %r15, %rdi
callq 0x1040e0
cmpb $0x1, 0x58(%rbx)
jne 0x9ef47
movq 0x8(%rsp), %rdi
callq 0xfd018
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %r10, %rax
jae 0x9ef76
leaq 0x2a9eea(%rip), %rsi    # 0x348e4e
movq %r12, %rdi
movq %rax, %rdx
movq %r10, %rcx
xorl %eax, %eax
callq 0xfcb67
jmp 0x9ef27
movq 0x40(%rbx), %rdx
leaq 0x10(%rbx), %rcx
movq %rax, %rdi
movq %r10, %rsi
pushq %r12
pushq %r14
callq 0x12e3c0
addq $0x10, %rsp
testq %rax, %rax
je 0x9ef27
movq %rax, %r13
movq 0x28(%rbx), %rsi
movq %rax, %rdi
testq %rsi, %rsi
je 0x9efb2
cmpq $-0x1, %rsi
jne 0x9efb9
callq 0x12f48f
jmp 0x9efbe
callq 0x12f471
jmp 0x9efbe
callq 0x12f457
movq 0x30(%rbx), %rsi
movq %r13, %rdi
callq 0x12f4c2
cmpb $0x1, 0x59(%rbx)
jne 0x9efd8
movq %r13, %rdi
callq 0x12f4af
cmpb $0x1, 0x56(%rbx)
jne 0x9efe6
movq %r13, %rdi
callq 0x12ee22
cmpb $0x0, 0x54(%rbx)
jne 0x9eff4
movq %r13, %rdi
callq 0x12f3f8
cmpb $0x1, 0x55(%rbx)
jne 0x9f002
movq %r13, %rdi
callq 0x12f41d
movl 0x50(%rbx), %esi
cmpl $-0x1, %esi
je 0x9f012
movq %r13, %rdi
callq 0x12ee10
movq (%rbx), %rdx
movq 0x8(%rbx), %rsi
movq %r13, %rdi
movq %r14, %rcx
movq %r15, %r8
movq %r12, %r9
callq 0x12f5b9
movl %eax, %ebp
movq %r13, %rdi
callq 0x12f4e0
jmp 0x9ef27
callq 0x1929a
callq 0x19234
callq 0x1926d