// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/match/eis-seqranges.c
// Function: gt_SRLSymbolCountInSeqRegion
GtUword
gt_SRLSymbolCountInSeqRegion(struct seqRangeList *rangeList,
                          GtUword start,
                          GtUword end,
                          Symbol esym,
                          seqRangeListSearchHint *hint)
{
  const struct seqRange *p;
  if (rangeList->numRanges == 0)
    return 0;
  p = gt_SRLFindPositionNext(rangeList, start, NULL);
  if (p)
  {
    if (rangeList->partialSymSums)
    {
      const struct seqRange *q = gt_SRLFindPositionLast(rangeList, end, hint);
      if (!q)
      {
        /* in case
         * - end precedes first region
         * or
         * - start is after last region
         * no symbols can be encoded in range
         */
        return 0;
      }
      {
        size_t pOff = p - rangeList->ranges, qOff = q - rangeList->ranges;
        size_t numSyms = gt_MRAEncGetSize(rangeList->alphabet);
        GtUword symCount;
        Symbol sym = MRAEncMapSymbol(rangeList->alphabet, esym);
        unsigned symBits = rangeList->symBits;
        symCount = rangeList->partialSymSums[qOff * numSyms + sym]
          - rangeList->partialSymSums[pOff * numSyms + sym];
        /* two special cases: start might be inside p and end inside q */
        if (sym == seqRangeSym(p, symBits) && start >= p->startPos)
          symCount -= start - p->startPos;
        if (sym == seqRangeSym(q, symBits))
        {
          regionLength lastOverlap = GT_MIN(end - q->startPos,
                                         seqRangeLen(q, symBits));
          symCount += lastOverlap;
        }
        return symCount;
      }
    }
    else
    {
      GtUword symCount = 0;
      GtUword s = GT_MAX(start, p->startPos);
      Symbol sym = MRAEncMapSymbol(rangeList->alphabet, esym);
      unsigned symBits = rangeList->symBits;
      struct seqRange *maxRange = rangeList->ranges + rangeList->numRanges - 1;
      while (s < end)
      {
        if (seqRangeSym(p, symBits) == sym)
          symCount += GT_MIN(p->startPos + seqRangeLen(p, symBits), end) - s;
        if (p == maxRange)
          break;
        s = (++p)->startPos;
      }
      return symCount;
    }
  }
  else
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpq $0x0, 0x8(%rdi)
je 0x2ae712
movq %r8, %r13
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %rbp
movl %ecx, (%rsp)
xorl %r14d, %r14d
xorl %edx, %edx
callq 0x2ade6a
testq %rax, %rax
je 0x2ae7dc
movq %rax, %r12
cmpq $0x0, 0x18(%rbp)
je 0x2ae71a
movq %rbp, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2ae11f
testq %rax, %rax
je 0x2ae712
movq 0x10(%rbp), %rcx
movq 0x20(%rbp), %rdi
movq %rax, %r14
movq %r12, %r13
subq %rcx, %r13
sarq $0x4, %r13
movq %rax, 0x8(%rsp)
subq %rcx, %r14
sarq $0x4, %r14
callq 0x14906a
movzwl %ax, %eax
movq %rax, 0x10(%rsp)
movq 0x20(%rbp), %rdi
movzbl (%rsp), %esi
callq 0x2adaf8
movl 0x28(%rbp), %esi
movq 0x18(%rbp), %rdi
movq 0x10(%rsp), %r8
imulq %r8, %r14
leaq (%rdi,%r14,8), %rcx
movb %al, (%rsp)
movzbl %al, %ebp
leal (,%rbp,8), %edx
movq (%rdx,%rcx), %r14
imulq %r8, %r13
leaq (%rdi,%r13,8), %rax
movl %esi, %r13d
subq (%rdx,%rax), %r14
movq %r12, %rdi
callq 0x2adb53
cmpb %al, %bpl
jne 0x2ae6d5
movq (%r12), %rax
cmpq %r15, %rax
ja 0x2ae6d5
subq %r15, %r14
addq %rax, %r14
movq 0x8(%rsp), %r12
movq %r12, %rdi
movl %r13d, %esi
callq 0x2adb53
cmpb %al, (%rsp)
jne 0x2ae7dc
movq %rbx, %r15
subq (%r12), %r15
movq %r12, %rdi
movl %r13d, %esi
callq 0x2adb40
cmpq %rax, %r15
jae 0x2ae7c8
subq (%r12), %rbx
jmp 0x2ae7d6
xorl %r14d, %r14d
jmp 0x2ae7dc
movq (%r12), %rax
cmpq %r15, %rax
cmovaq %rax, %r15
movq 0x20(%rbp), %rdi
movzbl (%rsp), %esi
callq 0x2adaf8
movb %al, 0x8(%rsp)
movl 0x28(%rbp), %r13d
movq 0x8(%rbp), %rax
movq 0x10(%rbp), %rcx
shlq $0x4, %rax
leaq (%rcx,%rax), %r14
addq $-0x10, %r14
movq $0x0, (%rsp)
cmpq %rbx, %r15
jae 0x2ae7c2
movq %r12, %rdi
movl %r13d, %esi
callq 0x2adb53
cmpb 0x8(%rsp), %al
jne 0x2ae7b2
movq %rbx, %rbp
movq (%r12), %rbx
movq %r12, %rdi
movl %r13d, %esi
callq 0x2adb40
movq %rax, %rcx
addq %rbx, %rcx
movq %rbp, %rbx
movq %rbp, %rax
cmpq %rbp, %rcx
jae 0x2ae7a4
movq (%r12), %rbx
movq %r12, %rdi
movl %r13d, %esi
callq 0x2adb40
addq %rbx, %rax
movq %rbp, %rbx
movq (%rsp), %rcx
subq %r15, %rcx
addq %rax, %rcx
movq %rcx, (%rsp)
cmpq %r14, %r12
je 0x2ae7c2
movq 0x10(%r12), %r15
addq $0x10, %r12
jmp 0x2ae756
movq (%rsp), %r14
jmp 0x2ae7dc
movq %r12, %rdi
movl %r13d, %esi
callq 0x2adb40
movq %rax, %rbx
movzwl %bx, %eax
addq %rax, %r14
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq