// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/kmer_database.c
// Function: gt_kmer_database_merge
static void gt_kmer_database_merge(GtKmerDatabase *kdb)
{
  GtUword left = 0,
          right,
          new_pos,
          code,
          kmercode,
          size_sb,
          preprocessed_size,
          startpos,
          current_min_occ = GT_UNDEF_UWORD,
          current_min_code = 0,
          occ;
  bool deleted;

  gt_assert(kdb != NULL);

  size_sb = kdb->sb.kmer_count;
  gt_kmer_database_preprocess_buffer(kdb);
  preprocessed_size = kdb->sb.preprocessed_kmer_count;

  if (preprocessed_size > 0) {
    if (preprocessed_size + kdb->offset[kdb->nu_kmer_codes] > kdb->current_size)
      gt_kmer_database_increase_size(kdb);

    for (code = kdb->nu_kmer_codes;
         code > 0 && preprocessed_size != 0;
         code--) {
      left = kdb->offset[code - 1];
      right = kdb->offset[code];
      occ = right - left;

      deleted = gt_bittab_bit_is_set(kdb->deleted_positions, code - 1);

      kdb->offset[code] += preprocessed_size;

      gt_kmer_database_decode_kmer(kdb->sb.kmers[size_sb - 1].a,
                                   kmercode, startpos);
      /* add new kmer positions from buffer (last to first) where <kmercode> =
         <code> - 1 */
      while (preprocessed_size > 0 && code - 1 == kmercode && size_sb > 0) {
        if (!kdb->cutoff_is_set || !deleted) {
          new_pos = right + preprocessed_size - 1;
          kdb->positions[new_pos] = kdb->sb.offset + startpos;
          kdb->unique_ids[new_pos] = kdb->sb.kmers[size_sb - 1].b;
          preprocessed_size--;
          occ++;
          if (code - 1 == kdb->min_code)
            kdb->min_nu_occ++;
        }
        size_sb--;
        if (size_sb > 0) {
          gt_kmer_database_decode_kmer(kdb->sb.kmers[size_sb - 1].a,
                                       kmercode, startpos);
        }
      }
      if (occ != 0 && occ < current_min_occ) {
        current_min_occ = occ;
        current_min_code = code - 1;
      }
      /* move previously included kmers with <code> to the right */
      if (left < right && preprocessed_size > 0) {
        memmove(kdb->positions + (left + preprocessed_size),
                kdb->positions + left,
                (size_t) (right - left) * sizeof (*kdb->positions));
        memmove(kdb->unique_ids + (left + preprocessed_size),
                kdb->unique_ids + left,
                (size_t) (right - left) * sizeof (*kdb->unique_ids));
      }
    }
    gt_assert(preprocessed_size == 0);
    if ((current_min_occ < kdb->min_nu_occ) ||
        (kdb->min_nu_occ == 0)) {
      kdb->min_nu_occ = current_min_occ;
      kdb->min_code = current_min_code;
    }
  }
  if (kdb->prune_is_set &&
      (kdb->last_size * GT_KMER_DATABASE_CALL_PRUNE_FACTOR <=
       kdb->offset[kdb->nu_kmer_codes])) {
      gt_kmer_database_prune(kdb);
      kdb->last_size = kdb->offset[kdb->nu_kmer_codes];
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
testq %rdi, %rdi
je 0x157769
movq %rdi, %rbx
movq 0xb0(%rdi), %r12
movq %r12, 0xb8(%rdi)
testq %r12, %r12
je 0x1572f2
xorl %r15d, %r15d
movq 0xa0(%rbx), %rcx
movq %r15, %rdx
shlq $0x4, %rdx
leaq 0x1(%r15), %rax
cmpq %rax, %r12
cmovaq %r12, %rax
addq %rdx, %rcx
addq $0x10, %rcx
movl -0xc(%rcx), %r14d
leaq -0x1(%rax), %rdx
movq $-0x1, %rsi
movq %r15, %r13
movq %rsi, %rbp
cmpq %r15, %rdx
je 0x15727d
leaq -0x1(%rbp), %rsi
leaq 0x10(%rcx), %rdi
leaq 0x1(%r13), %r15
cmpl 0x4(%rcx), %r14d
movq %rdi, %rcx
je 0x15725b
jmp 0x157280
movq %rax, %r15
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rcx
testq %rcx, %rcx
jne 0x157295
incq 0x40(%rbx)
movq (%rax,%r14,8), %rcx
subq %rbp, %rcx
movq %rcx, (%rax,%r14,8)
movq 0x28(%rbx), %rcx
subq %rbp, (%rax,%rcx,8)
cmpb $0x1, 0x78(%rbx)
jne 0x1572e6
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0xd6e4a
testb %al, %al
je 0x1572e6
cmpb $0x1, 0x79(%rbx)
jne 0x1572df
movq 0x8(%rbx), %rax
movq 0x48(%rbx), %rcx
shrq %rcx
cmpq %rcx, (%rax,%r14,8)
jae 0x1572df
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0xd6ae3
jmp 0x1572e6
addq %rbp, 0xb8(%rbx)
incq %r13
cmpq %r12, %r13
jb 0x15722c
cmpb $0x1, 0x79(%rbx)
jne 0x15732f
movq %rbx, %rdi
callq 0x157c90
xorl %edx, %edx
divq 0x58(%rbx)
movq %rax, %r14
movq %rax, 0x48(%rbx)
movq 0x50(%rbx), %rax
cmpq %rax, %r14
jb 0x15732b
movq %rbx, %rdi
callq 0x157cc5
cmpq %rax, %r14
jae 0x15732f
movq %rbx, %rdi
callq 0x157cc5
movq %rax, 0x48(%rbx)
movq 0xb8(%rbx), %r13
testq %r13, %r13
je 0x157593
movq (%rbx), %rax
movq 0x28(%rbx), %r14
movq (%rax,%r14,8), %rcx
addq %r13, %rcx
movq 0x38(%rbx), %rax
cmpq %rax, %rcx
jbe 0x1573eb
movq %rax, %xmm0
punpckldq 0x1f0579(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1f0581(%rip), %xmm0   # 0x3478f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x1f0995(%rip), %xmm1   # 0x347d18
cvttsd2si %xmm1, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x1f0989(%rip), %xmm1   # 0x347d20
cvttsd2si %xmm1, %rsi
andq %rcx, %rsi
orq %rax, %rsi
addq 0x30(%rbx), %rsi
movq %rsi, 0x38(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
leaq 0x22dc27(%rip), %r14    # 0x384fe0
movq %r14, %rdx
movl $0xa3, %ecx
callq 0x104461
movq %rax, 0x10(%rbx)
movq 0x18(%rbx), %rdi
movq 0x38(%rbx), %rsi
shlq $0x3, %rsi
movq %r14, %rdx
movl $0xa5, %ecx
callq 0x104461
movq %rax, 0x18(%rbx)
movq 0x28(%rbx), %r14
testq %r14, %r14
je 0x157764
movq $-0x1, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movq %r14, %rbp
decq %r14
movq (%rbx), %rax
movq 0x20(%rbx), %rdi
movq -0x8(%rax,%rbp,8), %rcx
movq (%rax,%rbp,8), %r15
movq %r15, (%rsp)
movq %rcx, 0x20(%rsp)
subq %rcx, %r15
movq %r14, %rsi
callq 0xd6e4a
movq (%rbx), %rcx
addq %r13, (%rcx,%rbp,8)
movq 0xa0(%rbx), %rcx
movq %r12, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rsi
addq $-0x8, %rsi
movq -0x8(%rsi), %r10
movl %r10d, %r8d
shrq $0x20, %r10
movq (%rsp), %rcx
leaq -0x1(%rcx), %rdi
movq %r15, 0x10(%rsp)
movq %r15, %rcx
movq %r12, %r9
cmpq %r10, %r14
setne %r10b
subq $0x1, %r12
setb %dl
orb %r10b, %dl
testb $0x1, %dl
jne 0x1574de
testb %al, 0x78(%rbx)
jne 0x1574b9
leaq (%rdi,%r13), %r10
movq 0xc0(%rbx), %r11
addq %r8, %r11
movq 0x10(%rbx), %rbp
movq %r11, (%rbp,%r10,8)
movq (%rsi), %r11
movq 0x18(%rbx), %rbp
movq %r11, (%rbp,%r10,8)
decq %r13
incq %rcx
cmpq 0x68(%rbx), %r14
jne 0x1574b9
incq 0x60(%rbx)
movq %r14, %r10
cmpq $0x1, %r9
je 0x1574cd
movq -0x18(%rsi), %r10
movl %r10d, %r8d
shrq $0x20, %r10
addq $-0x10, %rsi
movq %r12, %r9
testq %r13, %r13
jne 0x15746b
xorl %r13d, %r13d
jmp 0x1574e1
movq %r9, %r12
movq 0x20(%rsp), %r15
movq (%rsp), %r9
testq %rcx, %rcx
setne %al
movq 0x8(%rsp), %rdi
cmpq %rdi, %rcx
setb %sil
testb %sil, %al
cmovneq %rcx, %rdi
movq %rdi, 0x8(%rsp)
movq 0x18(%rsp), %rax
cmovneq %r14, %rax
movq %rax, 0x18(%rsp)
cmpq %r15, %r9
setbe %al
notb %dl
orb %al, %dl
testb $0x1, %dl
jne 0x15755e
movq 0x10(%rbx), %rax
leaq (%r15,%r13), %rbp
leaq (%rax,%rbp,8), %rdi
leaq (%rax,%r15,8), %rsi
movq 0x10(%rsp), %rdx
shlq $0x3, %rdx
movq %rdx, 0x10(%rsp)
callq 0x17cd0
movq 0x18(%rbx), %rax
leaq (%rax,%rbp,8), %rdi
leaq (%rax,%r15,8), %rsi
movq 0x10(%rsp), %rdx
callq 0x17cd0
testq %r14, %r14
je 0x15756c
testq %r13, %r13
jne 0x157406
testq %r13, %r13
jne 0x157764
movq 0x60(%rbx), %rax
decq %rax
movq 0x8(%rsp), %rcx
cmpq %rcx, %rax
jb 0x157593
movq %rcx, 0x60(%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x68(%rbx)
cmpb $0x1, 0x7a(%rbx)
jne 0x157755
movsd 0x70(%rbx), %xmm0
movsd 0x1f0336(%rip), %xmm1   # 0x3478e0
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1f033b(%rip), %xmm2   # 0x3478f0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
mulsd 0x22da0b(%rip), %xmm3   # 0x384fd8
movq (%rbx), %rcx
movq 0x28(%rbx), %rax
movsd (%rcx,%rax,8), %xmm0
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
ucomisd %xmm3, %xmm1
jb 0x157755
testq %rax, %rax
je 0x15773d
xorl %r15d, %r15d
movq $0x0, (%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
movq (%rbx), %rax
movq (%rax,%r14,8), %r13
movq 0x8(%rax,%r14,8), %r12
movq %r13, %rcx
subq %rbp, %rcx
movq %rcx, (%rax,%r14,8)
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rax
cmpq 0x48(%rbx), %rax
jbe 0x157643
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0xd6e4a
testb %al, %al
je 0x157662
testb $0x1, %r15b
movq (%rsp), %rax
cmovneq %r13, %rax
movq %rax, (%rsp)
movzbl %r15b, %r15d
movl $0x0, %eax
cmovnel %eax, %r15d
jmp 0x1576db
testb $0x1, %r15b
jne 0x1576c6
testq %rbp, %rbp
je 0x1576c6
movq %r12, 0x10(%rsp)
movq (%rsp), %rax
leaq (,%rax,8), %r12
movq 0x10(%rbx), %rsi
addq %r12, %rsi
leaq (,%rbp,8), %rcx
movq %rcx, 0x8(%rsp)
movq %rsi, %rdi
subq %rcx, %rdi
movq %r13, %r15
subq %rax, %r15
shlq $0x3, %r15
movq %r15, %rdx
callq 0x17cd0
addq 0x18(%rbx), %r12
movq %r12, %rdi
subq 0x8(%rsp), %rdi
movq %r12, %rsi
movq 0x10(%rsp), %r12
movq %r15, %rdx
callq 0x17cd0
subq %r13, %rbp
addq %r12, %rbp
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0xd6abc
movb $0x1, %r15b
incq %r14
cmpq 0x28(%rbx), %r14
jb 0x15760f
testb $0x1, %r15b
jne 0x157742
testq %rbp, %rbp
je 0x157742
movq %r12, %r13
movq (%rsp), %rax
leaq (,%rax,8), %r12
movq 0x10(%rbx), %rsi
addq %r12, %rsi
leaq (,%rbp,8), %r15
movq %rsi, %rdi
subq %r15, %rdi
subq %rax, %r13
shlq $0x3, %r13
movq %r13, %rdx
callq 0x17cd0
addq 0x18(%rbx), %r12
movq %r12, %rdi
subq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x17cd0
jmp 0x157742
xorl %r14d, %r14d
xorl %ebp, %ebp
movq (%rbx), %rax
subq %rbp, (%rax,%r14,8)
movq 0x28(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x70(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x49ef8
callq 0x49f31