// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/extended/kmer_database.c
// Function: gt_kmer_database_add_interval
void gt_kmer_database_add_interval(GtKmerDatabase *kdb,
                                   GtUword start, GtUword end,
                                   GtUword id)
{
  GtRange new;
  GtUword interval_size;

  gt_assert(kdb != NULL);
  gt_assert(start < end + 1 - (kdb->sb.kmer_size - 1));

  if (kdb->sb.intervals_kmer_count > 0) {
    GT_UNUSED GtUword prev = kdb->sb.intervals->nextfreeGtRange - 1;
    gt_assert(start > kdb->sb.intervals->spaceGtRange[prev].end);
  }

  /*
     K=5
     S         E
     0 1 2 3 4 5 6
     _________     kmer1
       _________   kmer2
     E+1-(K-1)-S = 2
   */
  interval_size = end + 1 - (kdb->sb.kmer_size - 1) - start;

  /* flush if sum is to large */
  if (kdb->sb.intervals_kmer_count != 0 &&
      interval_size + kdb->sb.intervals_kmer_count >= kdb->sb.max_nu_kmers) {
    gt_kmer_database_flush(kdb);
    kdb->sb.printed = false;
  }

  /* split overall to large, sb is empty because of code above */
  while (interval_size > kdb->sb.max_nu_kmers) {
    kdb->sb.printed = false;

    new.start = start;
    new.end = start + kdb->sb.max_nu_kmers + (kdb->sb.kmer_size - 1) - 1;

    GT_STOREINARRAY(kdb->sb.intervals, GtRange, 10, new);
    GT_STOREINARRAY(kdb->sb.ids, GtUword, 10, id);

    kdb->sb.intervals_kmer_count += kdb->sb.max_nu_kmers;
    gt_kmer_database_flush(kdb);
    interval_size -= kdb->sb.max_nu_kmers;
    start = start + kdb->sb.max_nu_kmers;
  }

  /* definitely fits, add */
  new.start = start;
  new.end = end;
  GT_STOREINARRAY(kdb->sb.intervals, GtRange, 10, new);
  GT_STOREINARRAY(kdb->sb.ids, GtUword, 10, id);
  kdb->sb.intervals_kmer_count += interval_size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x15f5ef
movq %rcx, %rbx
movq %rsi, %r12
movq %rdi, %r14
leaq 0x1(%rdx), %rbp
movl 0xd0(%rdi), %eax
decl %eax
movq %rbp, %rcx
subq %rax, %rcx
cmpq %rsi, %rcx
jbe 0x15f5f4
movq 0xc8(%r14), %rcx
testq %rcx, %rcx
je 0x15f3be
movq 0x80(%r14), %rdi
movq (%rdi), %rsi
movq 0x10(%rdi), %rdi
shlq $0x4, %rdi
cmpq %r12, -0x8(%rsi,%rdi)
jae 0x15f603
movq %rdx, (%rsp)
addq %r12, %rax
subq %rax, %rbp
testq %rcx, %rcx
je 0x15f3e9
addq %rbp, %rcx
cmpq 0xa8(%r14), %rcx
jb 0x15f3e9
movq %r14, %rdi
callq 0x15ec22
movb $0x0, 0xd4(%r14)
movq 0xa8(%r14), %r15
cmpq %r15, %rbp
jbe 0x15f506
movb $0x0, 0xd4(%r14)
movl 0xd0(%r14), %r13d
movq 0x80(%r14), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, 0x10(%rax)
jb 0x15f443
addq $0xa, %rsi
movq %rsi, 0x8(%rax)
movq (%rax), %rdi
shlq $0x4, %rsi
leaq 0x22ef89(%rip), %rdx    # 0x38e3b8
movl $0x1c7, %ecx            # imm = 0x1C7
callq 0x1094e6
movq 0x80(%r14), %rcx
movq %rax, (%rcx)
movq 0x80(%r14), %rcx
movq (%rcx), %rax
testq %rax, %rax
je 0x15f5e5
decl %r13d
addq %r12, %r15
leaq (%r15,%r13), %rdx
decq %rdx
movq 0x10(%rcx), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, 0x10(%rcx)
shlq $0x4, %rsi
movq %r12, (%rax,%rsi)
movq %rdx, 0x8(%rax,%rsi)
movq 0x88(%r14), %rax
movq 0x8(%rax), %rcx
cmpq %rcx, 0x10(%rax)
jb 0x15f4bb
leaq 0xa(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq (%rax), %rdi
leaq 0x50(,%rcx,8), %rsi
leaq 0x22ef11(%rip), %rdx    # 0x38e3b8
movl $0x1c8, %ecx            # imm = 0x1C8
callq 0x1094e6
movq 0x88(%r14), %rcx
movq %rax, (%rcx)
movq 0x88(%r14), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x15f5ea
movq 0x10(%rax), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x10(%rax)
movq %rbx, (%rcx,%rdx,8)
movq 0xa8(%r14), %rax
addq %rax, 0xc8(%r14)
movq %r14, %rdi
callq 0x15ec22
movq 0xa8(%r14), %r15
subq %r15, %rbp
addq %r15, %r12
jmp 0x15f3f0
movq 0x80(%r14), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, 0x10(%rax)
jb 0x15f541
addq $0xa, %rsi
movq %rsi, 0x8(%rax)
movq (%rax), %rdi
shlq $0x4, %rsi
leaq 0x22ee8b(%rip), %rdx    # 0x38e3b8
movl $0x1d3, %ecx            # imm = 0x1D3
callq 0x1094e6
movq 0x80(%r14), %rcx
movq %rax, (%rcx)
movq 0x80(%r14), %rcx
movq (%rcx), %rax
testq %rax, %rax
movq (%rsp), %rdi
je 0x15f5f9
movq 0x10(%rcx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x10(%rcx)
shlq $0x4, %rdx
movq %r12, (%rax,%rdx)
movq %rdi, 0x8(%rax,%rdx)
movq 0x88(%r14), %rax
movq 0x8(%rax), %rcx
cmpq %rcx, 0x10(%rax)
jb 0x15f5b0
leaq 0xa(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq (%rax), %rdi
leaq 0x50(,%rcx,8), %rsi
leaq 0x22ee1c(%rip), %rdx    # 0x38e3b8
movl $0x1d4, %ecx            # imm = 0x1D4
callq 0x1094e6
movq 0x88(%r14), %rcx
movq %rax, (%rcx)
movq 0x88(%r14), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x15f5fe
movq 0x10(%rax), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x10(%rax)
movq %rbx, (%rcx,%rdx,8)
addq %rbp, 0xc8(%r14)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4ae9a
callq 0x4ae61
callq 0x4aed3
callq 0x4ad7d
callq 0x4ae28
callq 0x4adef
callq 0x4adb6