// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/condenseq.c
// Function: gt_condenseq_extract_encoded_range
const GtUchar *gt_condenseq_extract_encoded_range(GtCondenseq *condenseq,
                                                  GtRange range)
{
  GtUchar *buf;
  GtUword nextsep,
          linkid = 0,
          uniqueid,
          buffoffset = 0,
          length;
  GtCondenseqLink *link = NULL;
  GtCondenseqUnique *unique = NULL;

  gt_assert(condenseq && condenseq->uds_nelems != 0);
  gt_assert(condenseq->uniques[0].orig_startpos == 0);
  gt_assert(range.start <= range.end);
  gt_assert(range.end < condenseq->orig_len);

  nextsep = condenseq_next_sep(condenseq, range.start);
  uniqueid = gt_condenseq_uniques_position_binsearch(condenseq,
                                                     range.start);

  length = range.end - range.start + 1;

  /* TODO DW check if there is another way than using this buffer, so we could
     use const for condenseq here. */
  if (condenseq->ubuffer == NULL || condenseq->ubuffsize < length) {
    condenseq->ubuffer = gt_realloc(condenseq->ubuffer,
                                    sizeof (*condenseq->ubuffer) * length);
    condenseq->ubuffsize = length;
  }

  buf = condenseq->ubuffer;

  unique = &condenseq->uniques[uniqueid];

  if (unique->orig_startpos + unique->len <= range.start) {
    uniqueid++;
    if (uniqueid == condenseq->uds_nelems)
      unique = NULL;
    else {
      unique = &condenseq->uniques[uniqueid];
      gt_assert(unique->orig_startpos + unique->len > range.start);
    }
  }

  if (condenseq->lds_nelems != 0) {
      linkid = condenseq_links_position_binsearch(condenseq, range.start);
    if (linkid == condenseq->lds_nelems)
      linkid = 0;
    link = &condenseq->links[linkid];
  }
  if (link != NULL &&
      link->orig_startpos + link->len <= range.start) {
    linkid++;
    if (linkid == condenseq->lds_nelems)
      link = NULL;
    else {
      link = &condenseq->links[linkid];
      gt_assert(link->orig_startpos + link->len > range.start);
    }
  }

  while (buffoffset < length) {
    gt_assert(nextsep == range.start + buffoffset ||
              unique != NULL ||
              link != NULL);
    if (nextsep != 0 && nextsep == range.start + buffoffset) {
      buf[buffoffset++] = GT_SEPARATOR;
      nextsep = condenseq_next_sep(condenseq, range.start + buffoffset);
    }
    else if (unique != NULL &&
             (link == NULL || unique->orig_startpos < link->orig_startpos)) {
      buffoffset += condenseq_unique_extract_encoded(condenseq, uniqueid,
                                                     buf + buffoffset,
                                                     range.start + buffoffset,
                                                     range.end);
      if (++uniqueid == condenseq->uds_nelems)
        unique = NULL;
      else {
        unique = &condenseq->uniques[uniqueid];
        gt_assert(unique->orig_startpos + unique->len > range.start);
      }
    }
    else {
      gt_assert(link != NULL);
      buffoffset += condenseq_link_extract_encoded(condenseq, linkid,
                                                   buf + buffoffset,
                                                   range.start + buffoffset,
                                                   range.end);
      if (++linkid == condenseq->lds_nelems)
        link = NULL;
      else {
        link = &condenseq->links[linkid];
        gt_assert(link->orig_startpos + link->len > range.start);
      }
    }
  }
  gt_assert(buffoffset == length);
  return buf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
testq %rdi, %rdi
je 0x12d4cc
movq %rdi, %rbp
cmpq $0x0, 0x98(%rdi)
je 0x12d4cc
movq 0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x12d4d1
movq %rdx, %rbx
movq %rsi, %r12
movq %rdx, %r14
subq %rsi, %r14
jb 0x12d4d6
cmpq %rbx, 0x78(%rbp)
jbe 0x12d4db
movq %rbp, %rdi
movq %r12, %rsi
callq 0x12d4f4
movq %rax, %r13
movq %rbp, %rdi
movq %r12, %rsi
callq 0x12cfba
movq %rax, %r15
incq %r14
movq 0x30(%rbp), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x12d0b5
cmpq %r14, 0x88(%rbp)
jae 0x12d0de
leaq 0x24bb6a(%rip), %rdx    # 0x378c26
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movl $0x2f4, %ecx            # imm = 0x2F4
callq 0x104461
movq %rax, 0x10(%rsp)
movq %rax, 0x30(%rbp)
movq %r14, 0x88(%rbp)
movq 0x10(%rbp), %rsi
leaq (%r15,%r15,4), %rcx
movl 0x20(%rsi,%rcx,8), %edx
addq 0x18(%rsi,%rcx,8), %rdx
cmpq %r12, %rdx
movq %r13, %rax
ja 0x12d11e
incq %r15
cmpq 0x98(%rbp), %r15
jne 0x12d108
xorl %r9d, %r9d
jmp 0x12d122
leaq (%r15,%r15,4), %rcx
movl 0x20(%rsi,%rcx,8), %edx
addq 0x18(%rsi,%rcx,8), %rdx
cmpq %r12, %rdx
jbe 0x12d4ea
leaq (%rsi,%rcx,8), %r9
movq 0x70(%rbp), %r8
testq %r8, %r8
je 0x12d1a9
jle 0x12d4e5
leaq -0x1(%r8), %rcx
shrq %rcx
movq 0x8(%rbp), %r10
movq $-0x1, %rdx
movq %r8, %rsi
movq %rcx, %rdi
shlq $0x5, %rdi
cmpq %r12, 0x8(%r10,%rdi)
ja 0x12d159
movq %rcx, %rdx
jmp 0x12d15c
movq %rcx, %rsi
leaq (%rdx,%rsi), %rcx
sarq %rcx
movq %rsi, %rdi
subq %rdx, %rdi
cmpq $0x1, %rdi
jg 0x12d146
testq %rdx, %rdx
js 0x12d182
movq %rcx, %rdx
shlq $0x5, %rdx
cmpq %r12, 0x8(%r10,%rdx)
jbe 0x12d185
movq %r8, %rcx
xorl %esi, %esi
cmpq %r8, %rcx
cmovneq %rcx, %rsi
movq %rsi, %rcx
shlq $0x5, %rcx
movl 0x10(%r10,%rcx), %edx
addq 0x8(%r10,%rcx), %rdx
cmpq %r12, %rdx
jbe 0x12d1b0
addq %rcx, %r10
jmp 0x12d1dd
xorl %esi, %esi
xorl %r10d, %r10d
jmp 0x12d1dd
incq %rsi
cmpq %r8, %rsi
jne 0x12d1c0
xorl %r10d, %r10d
movq %r8, %rsi
jmp 0x12d1dd
movq %rsi, %rdx
shlq $0x5, %rdx
movl 0x10(%r10,%rdx), %ecx
addq 0x8(%r10,%rdx), %rcx
cmpq %r12, %rcx
jbe 0x12d4ef
addq %rdx, %r10
testq %r14, %r14
je 0x12d483
movq %rsi, 0x40(%rsp)
movq %r15, 0x18(%rsp)
movq %rbx, 0x50(%rsp)
xorl %r13d, %r13d
movq %r12, 0x30(%rsp)
movq %r14, 0x20(%rsp)
leaq (%r12,%r13), %rbx
cmpq %rbx, %rax
je 0x12d219
testq %r9, %r9
jne 0x12d219
testq %r10, %r10
je 0x12d49f
testq %rax, %rax
je 0x12d251
cmpq %rbx, %rax
jne 0x12d251
leaq 0x1(%r13), %r15
movq 0x10(%rsp), %rax
movb $-0x1, (%rax,%r13)
leaq (%r12,%r13), %rsi
incq %rsi
movq %rbp, %rdi
movq %r9, %rbx
movq %r10, %r13
callq 0x12d4f4
movq %r13, %r10
movq %rbx, %r9
jmp 0x12d475
testq %r9, %r9
movq %rax, 0x48(%rsp)
je 0x12d342
testq %r10, %r10
je 0x12d272
movq 0x18(%r9), %rcx
cmpq 0x8(%r10), %rcx
jae 0x12d34b
movq 0x10(%rbp), %rsi
movq 0x18(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
movq %rbx, %r12
subq 0x18(%rsi,%rcx,8), %r12
jb 0x12d4b8
movq %rbp, %r14
movq %r10, 0x28(%rsp)
leaq (%rsi,%rcx,8), %rax
movl 0x20(%rax), %r15d
movq %r15, %rbp
subq %r12, %rbp
jbe 0x12d4b3
movq 0x10(%rsp), %rax
addq %r13, %rax
movq %rax, 0x38(%rsp)
movq 0x18(%r14), %rdi
movq 0x18(%rsp), %rsi
movq %rsi, 0x18(%rsp)
callq 0xeb6ee
addq %rax, %r12
movq 0x50(%rsp), %rcx
subq %rbx, %rcx
leaq (%r12,%rcx), %rdx
incq %rcx
cmpq %rcx, %rbp
leaq -0x1(%r15,%rax), %rbp
cmovaeq %rdx, %rbp
movq 0x18(%r14), %rdi
movq 0x38(%rsp), %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0xe9127
subq %r12, %r13
leaq 0x1(,%rbp), %r15
addq %r13, %r15
movq 0x18(%rsp), %rcx
movq %r14, %rbp
incq %rcx
cmpq 0x98(%r14), %rcx
movq %rcx, 0x18(%rsp)
jne 0x12d447
xorl %r9d, %r9d
movq 0x30(%rsp), %r12
movq 0x20(%rsp), %r14
movq 0x48(%rsp), %rax
movq 0x28(%rsp), %r10
jmp 0x12d475
testq %r10, %r10
je 0x12d4bd
movq %r9, 0x28(%rsp)
movq 0x8(%rbp), %rax
movq 0x40(%rsp), %rcx
shlq $0x5, %rcx
movq %rbp, %r14
movq %rbx, %rbp
subq 0x8(%rax,%rcx), %rbp
jb 0x12d4a4
leaq (%rax,%rcx), %rdx
movq (%rax,%rcx), %rsi
movq %rsi, 0x38(%rsp)
movl 0x10(%rax,%rcx), %r12d
movl 0x18(%rax,%rcx), %r15d
movl 0x14(%rdx), %esi
movq 0x18(%r14), %rdi
callq 0xeb6ee
movq %r12, %rcx
subq %rbp, %rcx
jbe 0x12d4a9
movq 0x10(%rsp), %rdx
addq %r13, %rdx
movq 0x50(%rsp), %rsi
subq %rbx, %rsi
decl %r12d
leaq (%rsi,%rbp), %rdi
incq %rsi
cmpq %rsi, %rcx
cmovaeq %rdi, %r12
movq 0x18(%r14), %rsi
addq %r15, %rax
movq %rdx, (%rsp)
movq 0x38(%rsp), %rdi
movq %rax, %rdx
xorl %ecx, %ecx
movq %rbp, %r8
movq %r12, %r9
callq 0x138a96
subq %rbp, %r12
incq %r12
cmpq %r12, %rax
jne 0x12d4ae
movq %rax, %r15
addq %r13, %r15
movq 0x40(%rsp), %rdx
incq %rdx
cmpq 0x70(%r14), %rdx
movq 0x30(%rsp), %r12
movq %r14, %rbp
movq 0x48(%rsp), %rax
movq 0x28(%rsp), %r9
movq %rdx, 0x40(%rsp)
jne 0x12d422
xorl %r10d, %r10d
movq 0x20(%rsp), %r14
jmp 0x12d475
movq 0x8(%rbp), %r10
shlq $0x5, %rdx
movl 0x10(%r10,%rdx), %ecx
addq 0x8(%r10,%rdx), %rcx
cmpq %r12, %rcx
movq 0x20(%rsp), %r14
jbe 0x12d4c2
addq %rdx, %r10
jmp 0x12d475
movq 0x10(%rbp), %rsi
leaq (%rcx,%rcx,4), %rcx
movl 0x20(%rsi,%rcx,8), %edx
addq 0x18(%rsi,%rcx,8), %rdx
movq 0x30(%rsp), %r12
cmpq %r12, %rdx
movq 0x20(%rsp), %r14
movq 0x48(%rsp), %rax
movq 0x28(%rsp), %r10
jbe 0x12d4c7
leaq (%rsi,%rcx,8), %r9
movq %r15, %r13
cmpq %r14, %r15
jb 0x12d202
jmp 0x12d486
xorl %r15d, %r15d
cmpq %r14, %r15
jne 0x12d4e0
movq 0x10(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3d522
callq 0x3d63f
callq 0x3d594
callq 0x3d5cd
callq 0x3d678
callq 0x3d6ea
callq 0x3d55b
callq 0x3d606
callq 0x3d6b1
callq 0x3d795
callq 0x3d411
callq 0x3d75c
callq 0x3d44a
callq 0x3d723
callq 0x3d4bc
callq 0x3d483
callq 0x3d4e9