// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/tools/gt_kmer_database.c
// Function: gt_kmer_database_runner
static int gt_kmer_database_runner(GT_UNUSED int argc, const char **argv,
                                   int parsed_args, void *tool_arguments,
                                   GtError *err)
{
  GtKmerDatabaseArguments *arguments = tool_arguments;
  int had_err = 0;
  GtEncseq       *es;
  GtUword        es_length,
                 nu_kmer_codes = 0;
  GtKmerDatabase *compare_db = NULL,
                 *db = NULL;
  GtLogger *logger;
  FILE *fp = NULL;
  GtHashmap *kmer_hash = NULL;
  GtTimer *timer = NULL;

  gt_error_check(err);
  gt_assert(arguments);

  if (arguments->use_hash)
    kmer_hash = gt_hashmap_new(GT_HASH_DIRECT, NULL,
                               (GtFree) gt_kmer_database_delete_hash_value);
  if (arguments->bench)
    timer = gt_timer_new_with_progress_description("loading encoded sequence");

  logger = gt_logger_new(arguments->verbose, GT_LOGGER_DEFLT_PREFIX, stderr);

  if (arguments->verbose && gt_str_length(arguments->print_filename) > 0UL) {
    fp = gt_fa_fopen(gt_str_get(arguments->print_filename), "w", err);
    gt_logger_set_target(logger, fp);
  }

  if (!had_err) {
    GtEncseqLoader *es_l;
    if (arguments->bench)
      gt_timer_start(timer);
    es_l = gt_encseq_loader_new();
    es = gt_encseq_loader_load(es_l, argv[parsed_args], err);
    if (arguments->bench)
      gt_timer_show_progress(timer, "saving kmers (+iterating over file)",
                             stdout);
    if (es == NULL) {
      had_err = -1;
    }
    gt_encseq_loader_delete(es_l);
  }
  if (!had_err) {
    es_length = gt_encseq_total_length(es);
    if (es_length < (GtUword) arguments->kmersize) {
      gt_error_set(err, "Input is too short for used kmersize. File length: "
                   GT_WU " kmersize: %u", es_length, arguments->kmersize);
      had_err = -1;
    }
  }
  if (!had_err) {
    GtAlphabet *alphabet;
    alphabet = gt_encseq_alphabet(es);
    if (arguments->bench)
    nu_kmer_codes = gt_power_for_small_exponents(
                                            gt_alphabet_num_of_chars(alphabet),
                                            arguments->kmersize);
    if (!arguments->merge_only && !arguments->use_hash && !arguments->bench) {
      compare_db = gt_kmer_database_new(gt_alphabet_num_of_chars(alphabet),
                                        arguments->kmersize,
                                        arguments->sb_size, es);
    }
    if (!arguments->use_hash) {
      db = gt_kmer_database_new(gt_alphabet_num_of_chars(alphabet),
                                arguments->kmersize,
                                arguments->sb_size, es);
      if (arguments->cutoff) {
        if (arguments->mean_cutoff)
          gt_kmer_database_use_mean_cutoff(db, (GtUword) 2,
                                           arguments->cutoff_value);
        else
          gt_kmer_database_set_cutoff(db, arguments->cutoff_value);
        if (!arguments->prune)
          gt_kmer_database_set_prune(db);
      }
    }
  }

  if (!had_err) {
    GtUword startpos = 0,
            endpos,
            interval_id = 0;
    GtKmercodeiterator *iter;
    const GtKmercode *kmercode = NULL;
    iter = gt_kmercodeiterator_encseq_new(es, GT_READMODE_FORWARD,
                                          arguments->kmersize, 0);
    while (!had_err && startpos < es_length - (arguments->kmersize - 1)) {
      GtUword startpos_add_kmer = startpos;
      if (arguments->merge_only) {
        endpos = startpos + (arguments->kmersize - 1) +
                 (gt_rand_max((arguments->sb_size - 1) * 2));
        if (endpos > es_length)
          endpos = es_length;
      }
      else {
        endpos = startpos + (arguments->kmersize - 1) +
                 (gt_rand_max(arguments->sb_size - 1));
      }
      gt_kmercodeiterator_reset(iter, GT_READMODE_FORWARD, startpos);
      while ((kmercode = gt_kmercodeiterator_encseq_next(iter)) != NULL &&
             startpos_add_kmer <= endpos - (arguments->kmersize - 1)) {
        if (!arguments->merge_only && !arguments->use_hash &&
            !kmercode->definedspecialposition && !arguments->bench) {
          gt_kmer_database_add_kmer(compare_db, kmercode->code,
                                    startpos_add_kmer, interval_id);
        }
        if (arguments->use_hash && !kmercode->definedspecialposition) {
          gt_kmer_database_add_to_hash(kmer_hash, kmercode->code,
                                       startpos_add_kmer);
        }
        startpos_add_kmer++;
      }
      if (!arguments->use_hash) {
        gt_kmer_database_add_interval(db, startpos, endpos, interval_id++);
        gt_kmer_database_print_buffer(db, logger);
        if (!arguments->bench)
          had_err = gt_kmer_database_check_consistency(db, err);
      }
      startpos = endpos + 1;
    }
    if (!arguments->use_hash) {
      gt_kmer_database_flush(db);
      gt_kmer_database_print_buffer(db, logger);
      if (!had_err && !arguments->bench)
        had_err = gt_kmer_database_check_consistency(db, err);
      if (!arguments->merge_only && !had_err && !arguments->bench)
        had_err = gt_kmer_database_check_consistency(compare_db, err);
      if (!arguments->merge_only && !arguments->bench)
        gt_kmer_database_print(compare_db, logger, true);
      if (!arguments->merge_only && !had_err && !arguments->bench)
        had_err = gt_kmer_database_compare(compare_db, db, err);
      gt_kmer_database_print(db, logger, true);
    }
    gt_kmercodeiterator_delete(iter);
  }

  if (arguments->bench) {
    GtKmerStartpos pos;
    GtArrayGtUword *pos_hash;
    GtUword rand_access = (GtUword) 50000000,
            rand_code,
            i,
            sum = 0;
    gt_timer_show_progress(timer, "random access", stdout);
    for (i = 0; i < rand_access; i++) {
      rand_code = gt_rand_max(nu_kmer_codes - 1);
      if (arguments->use_hash) {
        pos_hash = gt_hashmap_get(kmer_hash, (const void *) rand_code);
        if (pos_hash != NULL)
          sum += pos_hash->spaceGtUword[pos_hash->nextfreeGtUword - 1];
      }
      else {
        pos = gt_kmer_database_get_startpos(db, rand_code);
        if (pos.no_positions > 0)
          sum += pos.startpos[pos.no_positions - 1];
      }
    }
    printf("sum: " GT_WU "\n", sum);

    gt_timer_show_progress(timer, "", stdout);
    gt_timer_stop(timer);
    gt_timer_delete(timer);
  }
  if (arguments->use_hash)
    gt_hashmap_delete(kmer_hash);
  gt_encseq_delete(es);
  if (!arguments->use_hash)
    gt_kmer_database_delete(db);
  if (!arguments->merge_only && !arguments->bench)
    gt_kmer_database_delete(compare_db);
  gt_logger_delete(logger);
  gt_fa_fclose(fp);

  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, %r15
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r14
testq %r8, %r8
je 0x301c1
movq %r15, %rdi
callq 0x89eb7
testb %al, %al
jne 0x3094c
testq %rbx, %rbx
je 0x3091e
cmpb $0x1, 0x1d(%rbx)
jne 0x301e7
leaq 0x7a3(%rip), %rdx       # 0x3097a
xorl %edi, %edi
xorl %esi, %esi
callq 0x8f330
movq %rax, 0x28(%rsp)
jmp 0x301f0
movq $0x0, 0x28(%rsp)
cmpb $0x1, 0x1e(%rbx)
jne 0x30207
leaq 0x2bf783(%rip), %rdi    # 0x2ef980
callq 0xaf4a5
movq %rax, %r13
jmp 0x3020a
xorl %r13d, %r13d
movzbl 0x18(%rbx), %edi
movq 0x407d53(%rip), %rax    # 0x437f68
movq (%rax), %rdx
leaq 0x2b66b5(%rip), %rsi    # 0x2e68d4
callq 0x92b50
movq %rax, 0x18(%rsp)
cmpb $0x1, 0x18(%rbx)
jne 0x30278
movq 0x20(%rbx), %rdi
callq 0xad289
testq %rax, %rax
je 0x30278
movq 0x20(%rbx), %rdi
callq 0xad1fa
leaq 0x3036c1(%rip), %rsi    # 0x33390e
leaq 0x2bf31c(%rip), %rdx    # 0x2ef570
movq %rax, %rdi
movl $0xf5, %ecx
movq %r15, %r8
callq 0x8a156
movq 0x18(%rsp), %rdi
movq %rax, 0x38(%rsp)
movq %rax, %rsi
callq 0x92cd9
jmp 0x30281
movq $0x0, 0x38(%rsp)
movq %r15, 0x10(%rsp)
cmpb $0x1, 0x1e(%rbx)
jne 0x30294
movq %r13, %rdi
callq 0xaf4d6
callq 0x791cd
movq %rax, %r15
movslq %ebp, %rax
movq (%r14,%rax,8), %rsi
movq %r15, %rdi
movq 0x10(%rsp), %rdx
callq 0x7921d
movq %rax, 0x20(%rsp)
cmpb $0x1, 0x1e(%rbx)
jne 0x302d4
movq 0x407bee(%rip), %rax    # 0x437eb0
movq (%rax), %rdx
leaq 0x2bf6cd(%rip), %rsi    # 0x2ef999
movq %r13, %rdi
callq 0xaf86f
movq %r15, %rdi
callq 0x79f01
pushq $-0x1
popq %rbp
pushq $-0x1
popq %rax
movq %rax, 0x40(%rsp)
movq 0x20(%rsp), %r15
testq %r15, %r15
je 0x30324
movq %r15, %rdi
callq 0x7055e
movq %rax, %r12
movl (%rbx), %ecx
cmpq %rcx, %rax
jae 0x3033a
leaq 0x2bf6b3(%rip), %rsi    # 0x2ef9bd
movq $0x0, 0x8(%rsp)
movq 0x10(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x89dbb
jmp 0x3032d
movq $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
jmp 0x30735
movq %r15, %rdi
callq 0x754dd
movq %rax, %r14
cmpb $0x1, 0x1e(%rbx)
jne 0x30361
movq %r14, %rdi
callq 0x56c8e
movl (%rbx), %esi
movl %eax, %edi
callq 0x95871
decq %rax
jmp 0x30364
pushq $-0x1
popq %rax
movq %rax, 0x40(%rsp)
movb 0x1d(%rbx), %al
cmpb $0x0, 0x19(%rbx)
jne 0x3037c
testb $0x1, %al
jne 0x3037c
cmpb $0x0, 0x1e(%rbx)
je 0x303d4
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
testb $0x1, %al
movq %r13, 0x50(%rsp)
je 0x3039a
movq $0x0, (%rsp)
jmp 0x30411
movq %r14, %rdi
callq 0x56c8e
movl (%rbx), %esi
movq 0x8(%rbx), %rdx
movl %eax, %edi
movq %r15, %rcx
callq 0xf3f4c
movq %rax, (%rsp)
cmpb $0x1, 0x1a(%rbx)
jne 0x30411
movq 0x10(%rbx), %rdx
cmpb $0x1, 0x1c(%rbx)
jne 0x303f6
pushq $0x2
popq %rsi
movq (%rsp), %rdi
callq 0xf52e4
jmp 0x30402
movq %r14, %rdi
callq 0x56c8e
movl (%rbx), %esi
movq 0x8(%rbx), %rdx
movl %eax, %edi
movq %r15, %rcx
callq 0xf3f4c
movq %rax, 0x8(%rsp)
movb 0x1d(%rbx), %al
jmp 0x30385
movq (%rsp), %rdi
movq %rdx, %rsi
callq 0xf5226
cmpb $0x0, 0x1b(%rbx)
jne 0x30411
movq (%rsp), %rdi
callq 0xf5398
movl (%rbx), %edx
movq %r15, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x19f20f
movq %rax, %r13
xorl %ecx, %ecx
movq $0x0, 0x30(%rsp)
movq %r12, 0x58(%rsp)
testl %ebp, %ebp
jne 0x30693
movl (%rbx), %r15d
decl %r15d
movq %r12, %rax
subq %r15, %rax
cmpq %rax, %rcx
jae 0x30693
movq %rcx, 0x48(%rsp)
addq %rcx, %r15
movq 0x8(%rbx), %rdi
cmpb $0x1, 0x19(%rbx)
jne 0x3047a
leaq -0x2(,%rdi,2), %rdi
callq 0x955fa
addq %rax, %r15
cmpq %r12, %r15
cmovaeq %r12, %r15
jmp 0x30485
decq %rdi
callq 0x955fa
addq %rax, %r15
movq %r13, %rdi
xorl %esi, %esi
movq 0x48(%rsp), %rbp
movq %rbp, %rdx
callq 0x19eee0
movq %r13, %rdi
callq 0x19f495
testq %rax, %rax
je 0x30630
movq %rax, %r12
movl (%rbx), %eax
decl %eax
movq %r15, %rcx
subq %rax, %rcx
cmpq %rcx, %rbp
ja 0x30630
movb 0x1d(%rbx), %al
cmpb $0x0, 0x19(%rbx)
jne 0x304f2
testb $0x1, %al
jne 0x304f2
cmpb $0x0, (%r12)
jne 0x304f2
cmpb $0x0, 0x1e(%rbx)
jne 0x304f2
movq 0x8(%r12), %rsi
movq 0x8(%rsp), %rdi
movq %rbp, %rdx
movq 0x30(%rsp), %rcx
callq 0xf4ed5
movb 0x1d(%rbx), %al
testb $0x1, %al
je 0x30628
cmpb $0x0, (%r12)
jne 0x30628
movq 0x8(%r12), %r14
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x8f482
movq %rax, %r12
testq %rax, %rax
jne 0x30553
pushq $0x18
popq %rdi
leaq 0x2bf047(%rip), %rsi    # 0x2ef570
movl $0xcb, %edx
callq 0x93160
movq %rax, %r12
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq 0x28(%rsp), %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x8f4bd
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x3056d
cmpq %rax, 0x10(%r12)
jae 0x3059e
movq (%r12), %rax
jmp 0x3060b
movq $0x14, 0x8(%r12)
movq (%r12), %rdi
movl $0xa0, %esi
leaq 0x2befea(%rip), %rdx    # 0x2ef570
movl $0xd2, %ecx
callq 0x93472
movq %rax, (%r12)
testq %rax, %rax
jne 0x30614
jmp 0x308e6
movq %rax, %xmm0
punpckldq 0x2b7335(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2b733d(%rip), %xmm0   # 0x2e78f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x2bdc09(%rip), %xmm1   # 0x2ee1d0
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd 0x2b7745(%rip), %xmm1   # 0x2e7d20
cvttsd2si %xmm1, %rsi
andq %rdx, %rsi
orq %rcx, %rsi
addq %rax, %rsi
movq %rsi, 0x8(%r12)
movq (%r12), %rdi
shlq $0x3, %rsi
leaq 0x2bef73(%rip), %rdx    # 0x2ef570
movl $0xd6, %ecx
callq 0x93472
movq %rax, (%r12)
testq %rax, %rax
je 0x308b8
addq $0x10, %r12
movq (%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
movq %rbp, (%rax,%rcx,8)
incq %rbp
jmp 0x30497
xorl %ebp, %ebp
cmpb $0x0, 0x1d(%rbx)
je 0x3063f
movq 0x30(%rsp), %r14
jmp 0x3067e
movq 0x30(%rsp), %rcx
leaq 0x1(%rcx), %r14
movq (%rsp), %r12
movq %r12, %rdi
movq 0x48(%rsp), %rsi
movq %r15, %rdx
callq 0xf4b05
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq 0xf5ad9
cmpb $0x0, 0x1e(%rbx)
jne 0x3067e
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0xf5727
movl %eax, %ebp
incq %r15
movq %r15, %rcx
movq %r14, 0x30(%rsp)
movq 0x58(%rsp), %r12
jmp 0x30432
cmpb $0x0, 0x1d(%rbx)
je 0x306a3
movq 0x20(%rsp), %r15
jmp 0x30728
movq (%rsp), %r14
movq %r14, %rdi
callq 0xf4282
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0xf5ad9
testl %ebp, %ebp
je 0x3086d
movb 0x19(%rbx), %al
testb %al, %al
je 0x306d2
movq 0x20(%rsp), %r15
jmp 0x306f2
cmpb $0x0, 0x1e(%rbx)
movq 0x20(%rsp), %r15
jne 0x306f2
pushq $0x1
popq %rdx
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xf5900
movb 0x19(%rbx), %al
testb $0x1, %al
jne 0x30717
testl %ebp, %ebp
jne 0x30717
xorl %ebp, %ebp
cmpb $0x0, 0x1e(%rbx)
jne 0x30717
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0xf55bc
movl %eax, %ebp
pushq $0x1
popq %rdx
movq (%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xf5900
movq %r13, %rdi
callq 0x19f83e
movq 0x50(%rsp), %r13
cmpb $0x1, 0x1e(%rbx)
jne 0x3080b
movq %rbp, %r12
movq 0x407767(%rip), %rax    # 0x437eb0
movq (%rax), %rdx
leaq 0x2d776f(%rip), %rsi    # 0x307ec2
movq %r13, %rbp
movq %r13, %rdi
callq 0xaf86f
movl $0x2faf080, %r13d       # imm = 0x2FAF080
xorl %r14d, %r14d
leaq 0x60(%rsp), %r15
subq $0x1, %r13
jb 0x307c9
movq 0x40(%rsp), %rdi
callq 0x955fa
cmpb $0x1, 0x1d(%rbx)
jne 0x307a1
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x8f482
testq %rax, %rax
je 0x3076c
movq 0x10(%rax), %rcx
shlq $0x3, %rcx
addq (%rax), %rcx
jmp 0x307c3
movq %r15, %rdi
movq (%rsp), %rsi
movq %rax, %rdx
callq 0xf50ed
movq 0x70(%rsp), %rax
testq %rax, %rax
je 0x3076c
movq 0x60(%rsp), %rcx
leaq (%rcx,%rax,8), %rcx
addq -0x8(%rcx), %r14
jmp 0x3076c
leaq 0x2bf231(%rip), %rdi    # 0x2efa01
movq %r14, %rsi
xorl %eax, %eax
callq 0x17070
movq 0x4076cf(%rip), %rax    # 0x437eb0
movq (%rax), %rdx
leaq 0x339d85(%rip), %rsi    # 0x36a570
movq %rbp, %rdi
callq 0xaf86f
movq %rbp, %rdi
callq 0xaf549
movq %rbp, %rdi
callq 0xafc5b
movq 0x20(%rsp), %r15
movq %r12, %rbp
cmpb $0x1, 0x1d(%rbx)
jne 0x3081b
movq 0x28(%rsp), %rdi
callq 0x8f933
movq %r15, %rdi
callq 0x735fd
cmpb $0x0, 0x1d(%rbx)
jne 0x30832
movq (%rsp), %rdi
callq 0xf414c
cmpb $0x0, 0x19(%rbx)
jne 0x30848
cmpb $0x0, 0x1e(%rbx)
jne 0x30848
movq 0x8(%rsp), %rdi
callq 0xf414c
movq 0x18(%rsp), %rdi
callq 0x92fd0
movq 0x38(%rsp), %rdi
callq 0x8a4fd
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
cmpb $0x0, 0x1e(%rbx)
jne 0x30884
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0xf5727
movl %eax, %ebp
cmpb $0x0, 0x19(%rbx)
jne 0x306c4
testl %ebp, %ebp
jne 0x306c4
xorl %ebp, %ebp
cmpb $0x0, 0x1e(%rbx)
jne 0x306c4
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xf5727
movl %eax, %ebp
jmp 0x306c4
movq 0x4076a9(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2b474a(%rip), %rsi    # 0x2e5013
leaq 0x2bf158(%rip), %rdx    # 0x2efa28
leaq 0x2bf134(%rip), %rcx    # 0x2efa0b
leaq 0x2bec92(%rip), %r8     # 0x2ef570
movl $0xd6, %r9d
jmp 0x30912
movq 0x40767b(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2b471c(%rip), %rsi    # 0x2e5013
leaq 0x2bf12a(%rip), %rdx    # 0x2efa28
leaq 0x2bf106(%rip), %rcx    # 0x2efa0b
leaq 0x2bec64(%rip), %r8     # 0x2ef570
movl $0xd2, %r9d
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x407643(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2b46e4(%rip), %rsi    # 0x2e5013
leaq 0x317d1d(%rip), %rdx    # 0x348653
leaq 0x2bf02b(%rip), %rcx    # 0x2ef968
leaq 0x2bec2c(%rip), %r8     # 0x2ef570
movl $0xea, %r9d
jmp 0x30912
movq 0x407615(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2b46b6(%rip), %rsi    # 0x2e5013
leaq 0x2b485b(%rip), %rdx    # 0x2e51bf
leaq 0x2beffd(%rip), %rcx    # 0x2ef968
leaq 0x2bebfe(%rip), %r8     # 0x2ef570
movl $0xe9, %r9d
jmp 0x30912