// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/kmer_database.c
// Function: gt_kmer_database_unit_test
int gt_kmer_database_unit_test(GtError *err)
{
  int            had_err = 0;
  GtUword        i,
                 j,
                 k = (GtUword) 0,
                 kmercode,
                 startpos,
                 seq_length = (GtUword) 10,
                 nu_kmer_codes = (GtUword) 4,
                 max_nu_kmers = (GtUword) 6,
                 nu_kmers_sort_test = (GtUword) 8,
                 /*Seq: A C C T A G G T C T = 0 1 1 3 0 2 2 3 1 3
                   SB-Seq: T C G G A A = 3 1 2 2 0 0*/
                 offset[] = {(GtUword) 0,(GtUword) 2,(GtUword) 5,(GtUword) 7,
                             (GtUword) 10},
                 positions[] = {(GtUword) 0,(GtUword) 4,(GtUword) 1,(GtUword) 2,
                                (GtUword) 8,(GtUword) 5,(GtUword) 6,(GtUword) 3,
                                (GtUword) 7,(GtUword) 9},
                 seq[] = {(GtUword) 0,(GtUword) 1,(GtUword) 1,(GtUword) 3,
                          (GtUword) 0,(GtUword) 2,(GtUword) 2,(GtUword) 3,
                          (GtUword) 1,(GtUword) 3},
                 sb_codes[] = {(GtUword) 0,(GtUword) 0,(GtUword) 1,(GtUword) 2,
                               (GtUword) 2,(GtUword) 3},
                 sb_starts[] = {(GtUword) 14,(GtUword) 15,(GtUword) 11,
                                (GtUword) 12,(GtUword) 13,(GtUword) 10},
                 offset_empty[] = {(GtUword) 0,(GtUword) 2,(GtUword) 3,
                                   (GtUword) 5,(GtUword) 6},
                 starts[] = {(GtUword) 5,(GtUword) 7,(GtUword) 0,(GtUword) 2,
                             (GtUword) 3,(GtUword) 6,(GtUword) 9,(GtUword) 15},
                 unsorted_starts[] = {(GtUword) 2,(GtUword) 5,(GtUword) 9,
                                      (GtUword) 0,(GtUword) 3,(GtUword) 6,
                                      (GtUword) 15,(GtUword) 7};
  GtCodetype     codes[] = {(GtUword) 0,(GtUword) 0,(GtUword) 1,(GtUword) 2,
                            (GtUword) 2,(GtUword) 2,(GtUword) 3,(GtUword) 3},
                 unsorted_codes[] = {(GtUword) 2,(GtUword) 0,(GtUword) 3,
                                     (GtUword) 1,(GtUword) 2,(GtUword) 2,
                                     (GtUword) 3,(GtUword) 0};
  GtAlphabet *al = gt_alphabet_new_dna();
  GtEncseqBuilder *eb = gt_encseq_builder_new(al);
  GtEncseq *es;
  GtKmerDatabase *sb_test,
                 *kdb,
                 *compare_kdb,
                 *empty_kdb,
                 *intervals_too_big;
  GtKmerStartpos kmer_interval;
  gt_alphabet_delete(al);

  gt_encseq_builder_add_cstr(eb, "ACCTAGGTCT", (GtUword) 10, NULL);
  es = gt_encseq_builder_build(eb, err);
  gt_encseq_builder_delete(eb);

  sb_test = gt_kmer_database_new(GT_KMERDB_AS, GT_KMERDB_K,
                                 nu_kmers_sort_test, es),
  kdb = gt_kmer_database_new(GT_KMERDB_AS, GT_KMERDB_K,
                             max_nu_kmers, es),
  compare_kdb = gt_kmer_database_new(GT_KMERDB_AS,
                                     GT_KMERDB_K,
                                     max_nu_kmers, es),
  empty_kdb = gt_kmer_database_new(GT_KMERDB_AS, GT_KMERDB_K,
                                   max_nu_kmers, es);
  intervals_too_big = gt_kmer_database_new(GT_KMERDB_AS, GT_KMERDB_K,
                                           max_nu_kmers, es);
  gt_encseq_delete(es);

  gt_error_check(err);

  /*test if sorting in sb works*/
  for (i = 0; i < nu_kmers_sort_test; i++) {
    gt_kmer_database_add_kmer_to_sb(sb_test, unsorted_codes[i],
                                    unsorted_starts[i], 0);
  }

  gt_kmer_database_sort_sb(sb_test);

  for (i = 0; !had_err && i < nu_kmers_sort_test; i++) {
    gt_kmer_database_decode_kmer(sb_test->sb.kmers[i].a, kmercode, startpos);
    gt_ensure(kmercode == codes[i]);
    gt_ensure(startpos == starts[i]);
  }

  /*test if add_kmer works*/
  for (i = 0; i < seq_length; i++) {
    gt_kmer_database_add_kmer(kdb, seq[i], i, 0);
    gt_kmer_database_add_kmer(compare_kdb, seq[i], i, 0);
  }

  had_err = gt_kmer_database_check_consistency(kdb, err);
  if (!had_err)
    had_err = gt_kmer_database_check_consistency(compare_kdb, err);

  for (i = 0; !had_err && i <= nu_kmer_codes; i++) {
    gt_ensure(kdb->offset[i] == offset[i]);
  }
  for (i = 0; !had_err && i < seq_length; i++) {
    gt_ensure(kdb->positions[i] == positions[i]);
  }

  /*test if intervals bigger than the buffer size are handled correctly*/
  if (!had_err) {
    gt_kmer_database_add_interval(intervals_too_big, 0, max_nu_kmers + 1, 0);
    gt_kmer_database_add_interval(intervals_too_big, max_nu_kmers + 2,
                                  seq_length, 0);
    gt_kmer_database_flush(intervals_too_big);
    had_err = gt_kmer_database_check_consistency(intervals_too_big, err);
  }
  if (!had_err)
    had_err = gt_kmer_database_compare(intervals_too_big, compare_kdb, err);

  /*test if merge works with empty kmer_database*/
  for (i = 0; i < max_nu_kmers; i++) {
    gt_kmer_database_add_kmer_to_sb(empty_kdb, sb_codes[i], sb_starts[i], 0);
  }

  gt_kmer_database_merge(empty_kdb);

  if (!had_err)
    had_err = gt_kmer_database_check_consistency(empty_kdb, err);

  for (i = 0; !had_err && i <= nu_kmer_codes; i++) {
    gt_ensure(empty_kdb->offset[i] == offset_empty[i]);
  }
  for (i = 0; !had_err && i < max_nu_kmers; i++) {
    gt_ensure(empty_kdb->positions[i] == sb_starts[i]);
  }

  /*test if merge works with filled kmer_database*/
  for (i = 0; i < max_nu_kmers; i++) {
    gt_kmer_database_add_kmer(compare_kdb, sb_codes[i], sb_starts[i], 0);
    gt_kmer_database_add_kmer_to_sb(kdb, sb_codes[i], sb_starts[i], 0);
  }

  gt_kmer_database_merge(kdb);

  if (!had_err)
    had_err = gt_kmer_database_check_consistency(kdb, err);
  if (!had_err)
    had_err = gt_kmer_database_check_consistency(compare_kdb, err);
  if (!had_err)
    had_err = gt_kmer_database_compare(kdb, compare_kdb, err);

  for (i = 0; !had_err && i <= nu_kmer_codes; i++) {
    gt_ensure(kdb->offset[i] == compare_kdb->offset[i]);
  }
  for (i = 0; !had_err && i < seq_length + max_nu_kmers; i++) {
    gt_ensure(kdb->positions[i] == compare_kdb->positions[i]);
  }

  /*test if min_no_occ works*/
  if (!had_err) {
    if (gt_kmer_database_get_min_nu_of_occ(kdb) != (GtUword) 4) {
      had_err = -1;
    }
  }

  /*test if this returns the right positions*/
  for (i = 0; !had_err && i < nu_kmer_codes; i++) {
    kmer_interval = gt_kmer_database_get_startpos(kdb, i);
    for (j = 0; !had_err && j < kmer_interval.no_positions; j++) {
      gt_ensure(kmer_interval.startpos[j] == kdb->positions[k + j]);
    }
    k += j;
  }

  gt_kmer_database_delete(sb_test);
  gt_kmer_database_delete(kdb);
  gt_kmer_database_delete(compare_kdb);
  gt_kmer_database_delete(empty_kdb);
  gt_kmer_database_delete(intervals_too_big);

  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdi, %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0xc0(%rsp)
movl $0x2, %eax
movq %rax, 0xc8(%rsp)
movl $0x5, %ecx
movq %rcx, 0xd0(%rsp)
movq $0x7, 0xd8(%rsp)
movl $0xa, %edx
movq %rdx, 0xe0(%rsp)
movaps %xmm0, 0xf0(%rsp)
movl $0x1, %esi
movq %rsi, 0x100(%rsp)
movq %rax, 0x108(%rsp)
movq %rax, 0x110(%rsp)
movl $0x3, %edi
movq %rdi, 0x118(%rsp)
movq $0xe, 0x20(%rsp)
movq $0xf, 0x28(%rsp)
movq $0xb, 0x30(%rsp)
movq $0xc, 0x38(%rsp)
movq $0xd, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
movaps %xmm0, 0x90(%rsp)
movq %rax, 0x98(%rsp)
movq %rdi, 0xa0(%rsp)
movq %rcx, 0xa8(%rsp)
movq $0x6, 0xb0(%rsp)
movaps %xmm0, 0x120(%rsp)
movq %rsi, 0x130(%rsp)
movq %rax, 0x138(%rsp)
movq %rax, 0x140(%rsp)
movq %rax, 0x148(%rsp)
movq %rdi, 0x150(%rsp)
movq %rdi, 0x158(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movq %rax, 0x50(%rsp)
movq %rdi, 0x60(%rsp)
movq %rsi, 0x68(%rsp)
movq %rax, 0x70(%rsp)
movq %rax, 0x78(%rsp)
movq %rdi, 0x80(%rsp)
callq 0xd0ece
movq %rax, %r14
movq %rax, %rdi
callq 0xf259c
movq %rax, %r15
movq %r14, %rdi
callq 0xd0e1c
leaq 0x22d4b7(%rip), %rsi    # 0x38580f
movl $0xa, %edx
movq %r15, %rdi
xorl %ecx, %ecx
callq 0xf26be
movq %r15, %rdi
movq %r13, %rsi
callq 0xf2e3b
movq %rax, %rbp
movq %r15, %rdi
callq 0xf63c5
movl $0x8, %edx
movl $0x4, %edi
movl $0x1, %esi
movq %rbp, %rcx
callq 0x156d64
movq %rax, 0x18(%rsp)
movl $0x6, %edx
movl $0x4, %edi
movl $0x1, %esi
movq %rbp, %rcx
callq 0x156d64
movq %rax, %r15
movl $0x6, %edx
movl $0x4, %edi
movl $0x1, %esi
movq %rbp, %rcx
callq 0x156d64
movq %rax, %r12
movl $0x6, %edx
movl $0x4, %edi
movl $0x1, %esi
movq %rbp, %rcx
callq 0x156d64
movq %rax, 0x10(%rsp)
movl $0x6, %edx
movl $0x4, %edi
movl $0x1, %esi
movq %rbp, %rcx
callq 0x156d64
movq %rax, (%rsp)
movq %rbp, %rdi
callq 0xea375
testq %r13, %r13
je 0x158421
movq %r13, %rdi
callq 0xfcc32
testb %al, %al
jne 0x1589a1
xorl %ebx, %ebx
leaq 0x22d6c6(%rip), %r14    # 0x385af0
movq 0x18(%rsp), %rbp
movq 0x50(%rsp,%rbx), %rsi
movq (%rbx,%r14), %rdx
movq %rbp, %rdi
xorl %ecx, %ecx
callq 0x1571a7
addq $0x8, %rbx
cmpq $0x40, %rbx
jne 0x15842f
testq %rbp, %rbp
je 0x15899c
movq 0xa0(%rbp), %rdi
movq 0xb0(%rbp), %rsi
callq 0x10fd8b
movq 0xa0(%rbp), %rax
movq $-0x1, %rcx
leaq 0x22d633(%rip), %rdx    # 0x385ab0
movq (%rax), %rsi
movq %rsi, %rdi
shrq $0x20, %rdi
cmpq 0x128(%rsp,%rcx,8), %rdi
jne 0x1584ab
movl %esi, %esi
cmpq (%rdx), %rsi
jne 0x1584d2
incq %rcx
addq $0x10, %rax
addq $0x8, %rdx
cmpq $0x7, %rcx
jb 0x15847d
jmp 0x1584fe
leaq 0x205f8c(%rip), %rsi    # 0x35e43e
leaq 0x22d37c(%rip), %rdx    # 0x385835
leaq 0x22d35a(%rip), %rcx    # 0x38581a
leaq 0x22cb19(%rip), %r8     # 0x384fe0
movq %r13, %rdi
movl $0x35a, %r9d            # imm = 0x35A
jmp 0x1584f7
leaq 0x205f65(%rip), %rsi    # 0x35e43e
leaq 0x22d36a(%rip), %rdx    # 0x38584a
leaq 0x22d333(%rip), %rcx    # 0x38581a
leaq 0x22caf2(%rip), %r8     # 0x384fe0
movq %r13, %rdi
movl $0x35b, %r9d            # imm = 0x35B
xorl %eax, %eax
callq 0xfcb67
movq %r13, 0x8(%rsp)
leaq 0x22d556(%rip), %r13    # 0x385a60
xorl %ebp, %ebp
movq (%r13), %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x157a08
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x157a08
incq %rbp
addq $0x8, %r13
cmpq $0xa, %rbp
jne 0x15850c
movq %r15, %rdi
movq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0x157dfc
testl %eax, %eax
je 0x15855d
xorl %ebx, %ebx
movq 0x10(%rsp), %rbp
jmp 0x158680
movq %r12, %rdi
movq %r13, %rsi
callq 0x157dfc
testl %eax, %eax
movq 0x10(%rsp), %rbp
je 0x158578
xorl %ebx, %ebx
jmp 0x158680
movq (%r15), %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movq 0xc0(%rsp,%rcx,8), %rsi
cmpq %rsi, %rdx
jne 0x158629
jne 0x1585a1
leaq 0x1(%rcx), %rdx
cmpq $0x4, %rcx
movq %rdx, %rcx
jb 0x15857d
movq 0x10(%r15), %rax
leaq 0x22d464(%rip), %rcx    # 0x385a10
xorl %edx, %edx
movq (%rax,%rdx,8), %rsi
movq (%rcx), %rdi
cmpq %rdi, %rsi
jne 0x158652
jne 0x1585d1
leaq 0x1(%rdx), %rsi
addq $0x8, %rcx
cmpq $0x9, %rdx
movq %rsi, %rdx
jb 0x1585ae
xorl %ebx, %ebx
movl $0x7, %edx
movq (%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x15776e
movl $0x8, %esi
movl $0xa, %edx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x15776e
movq %r14, %rdi
callq 0x157066
movq %r14, %rdi
movq %r13, %rsi
callq 0x157dfc
testl %eax, %eax
jne 0x158680
movq (%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x157cf7
testl %eax, %eax
sete %bl
jmp 0x158680
leaq 0x205e0e(%rip), %rsi    # 0x35e43e
leaq 0x22d229(%rip), %rdx    # 0x385860
leaq 0x22d1dc(%rip), %rcx    # 0x38581a
leaq 0x22c99b(%rip), %r8     # 0x384fe0
xorl %ebx, %ebx
movq %r13, %rdi
movl $0x369, %r9d            # imm = 0x369
jmp 0x158679
leaq 0x205de5(%rip), %rsi    # 0x35e43e
leaq 0x22d21c(%rip), %rdx    # 0x38587c
leaq 0x22d1b3(%rip), %rcx    # 0x38581a
leaq 0x22c972(%rip), %r8     # 0x384fe0
xorl %ebx, %ebx
movq %r13, %rdi
movl $0x36c, %r9d            # imm = 0x36C
xorl %eax, %eax
callq 0xfcb67
xorl %r14d, %r14d
movq 0xf0(%rsp,%r14,8), %rsi
movq 0x20(%rsp,%r14,8), %rdx
movq %rbp, %rdi
xorl %ecx, %ecx
callq 0x1571a7
incq %r14
cmpq $0x6, %r14
jne 0x158683
movq %rbp, %rdi
callq 0x1571f8
testb %bl, %bl
je 0x1586c2
movq %rbp, %rdi
movq %r13, %rsi
callq 0x157dfc
testl %eax, %eax
je 0x158827
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0xf0(%rsp,%r14,8), %rbx
movq 0x20(%rsp,%r14,8), %rbp
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x157a08
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x1571a7
incq %r14
cmpq $0x6, %r14
jne 0x1586c8
movq %r15, %rdi
callq 0x1571f8
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %r13b, %r13b
je 0x15895b
movq %r15, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x157dfc
testl %eax, %eax
jne 0x15895b
movq %r12, %rdi
movq %r14, %rsi
callq 0x157dfc
testl %eax, %eax
jne 0x15895b
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x157cf7
testl %eax, %eax
jne 0x15895b
movq (%r15), %rax
movq (%r12), %rcx
xorl %edx, %edx
movq (%rax,%rdx,8), %rsi
movq (%rcx,%rdx,8), %rdi
cmpq %rdi, %rsi
jne 0x1588dc
jne 0x15877e
leaq 0x1(%rdx), %rsi
cmpq $0x4, %rdx
movq %rsi, %rdx
jb 0x15875e
movq 0x10(%r15), %rax
movq 0x10(%r12), %rcx
xorl %edx, %edx
movq (%rax,%rdx,8), %rsi
movq (%rcx,%rdx,8), %rdi
cmpq %rdi, %rsi
jne 0x158903
jne 0x1587a9
leaq 0x1(%rdx), %rsi
cmpq $0xf, %rdx
movq %rsi, %rdx
jb 0x158789
movq %r15, %rdi
callq 0x157cc5
cmpq $0x4, %rax
jne 0x15895b
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %ebp, %ebp
leaq 0x160(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x157b70
movq 0x170(%rsp), %rax
testq %rax, %rax
je 0x158810
movq 0x160(%rsp), %rcx
leaq (,%rbx,8), %rsi
addq 0x10(%r15), %rsi
xorl %edx, %edx
movq (%rcx,%rdx,8), %rdi
cmpq (%rsi,%rdx,8), %rdi
jne 0x15892a
incq %rdx
cmpq %rax, %rdx
jb 0x1587f8
jmp 0x158812
xorl %edx, %edx
addq %rdx, %rbx
leaq 0x1(%r13), %rax
cmpq $0x3, %r13
movq %rax, %r13
jb 0x1587c2
jmp 0x15895b
movq (%rbp), %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movq 0x90(%rsp,%rcx,8), %rsi
cmpq %rsi, %rdx
jne 0x15887c
jne 0x15884d
leaq 0x1(%rcx), %rdx
cmpq $0x4, %rcx
movq %rdx, %rcx
jb 0x15882d
movq 0x10(%rbp), %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movq 0x20(%rsp,%rcx,8), %rsi
cmpq %rsi, %rdx
jne 0x1588a6
movb $0x1, %r13b
jne 0x1586c5
leaq 0x1(%rcx), %rdx
cmpq $0x5, %rcx
movq %rdx, %rcx
jb 0x158853
jmp 0x1586c5
leaq 0x205bbb(%rip), %rsi    # 0x35e43e
leaq 0x22d014(%rip), %rdx    # 0x38589e
leaq 0x22cf89(%rip), %rcx    # 0x38581a
leaq 0x22c748(%rip), %r8     # 0x384fe0
movq %r13, %rdi
xorl %r13d, %r13d
movl $0x385, %r9d            # imm = 0x385
jmp 0x1588d0
leaq 0x205b91(%rip), %rsi    # 0x35e43e
leaq 0x22d012(%rip), %rdx    # 0x3858c6
leaq 0x22cf5f(%rip), %rcx    # 0x38581a
leaq 0x22c71e(%rip), %r8     # 0x384fe0
xorl %r13d, %r13d
movq 0x8(%rsp), %rdi
movl $0x388, %r9d            # imm = 0x388
xorl %eax, %eax
callq 0xfcb67
jmp 0x1586c5
leaq 0x205b5b(%rip), %rsi    # 0x35e43e
leaq 0x22d004(%rip), %rdx    # 0x3858ee
leaq 0x22cf29(%rip), %rcx    # 0x38581a
leaq 0x22c6e8(%rip), %r8     # 0x384fe0
movq %r14, %rdi
movl $0x39b, %r9d            # imm = 0x39B
jmp 0x15894f
leaq 0x205b34(%rip), %rsi    # 0x35e43e
leaq 0x22d006(%rip), %rdx    # 0x385917
leaq 0x22cf02(%rip), %rcx    # 0x38581a
leaq 0x22c6c1(%rip), %r8     # 0x384fe0
movq %r14, %rdi
movl $0x39e, %r9d            # imm = 0x39E
jmp 0x15894f
leaq 0x205b0d(%rip), %rsi    # 0x35e43e
leaq 0x22d00e(%rip), %rdx    # 0x385946
leaq 0x22cedb(%rip), %rcx    # 0x38581a
leaq 0x22c69a(%rip), %r8     # 0x384fe0
movq %r14, %rdi
movl $0x3ac, %r9d            # imm = 0x3AC
xorl %eax, %eax
callq 0xfcb67
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rdi
callq 0x156f2a
movq %r15, %rdi
callq 0x156f2a
movq %r12, %rdi
callq 0x156f2a
movq 0x10(%rsp), %rdi
callq 0x156f2a
movq (%rsp), %rdi
callq 0x156f2a
movl %ebp, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4a76e
callq 0x4a735
nop