// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/match/eis-seqranges.c
// Function: gt_SRLAllSymbolsCountInSeqRegion
GtUword
gt_SRLAllSymbolsCountInSeqRegion(struct seqRangeList *rangeList,
                              GtUword start,
                              GtUword end,
                              seqRangeListSearchHint *hint)
{
  const struct seqRange *p;
  if (rangeList->numRanges == 0)
    return 0;
  p = gt_SRLFindPositionNext(rangeList, start, hint);
  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 = 0;
        Symbol sym;
        unsigned symBits = rangeList->symBits;
        for (sym = 0; sym < numSyms; ++sym)
        {
          symCount += rangeList->partialSymSums[qOff * numSyms + sym]
            - rangeList->partialSymSums[pOff * numSyms + sym];
          /* two special cases: start might be inside p and end inside q */
        }
        if (start >= p->startPos)
          symCount -= start - p->startPos;

        {
          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);
      struct seqRange *maxRange = rangeList->ranges + rangeList->numRanges - 1;
      unsigned symBits = rangeList->symBits;
      while (s < end)
      {
        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
movq %rdx, 0x8(%rsp)
cmpq $0x0, 0x8(%rdi)
je 0x2ae8a8
movq %rcx, %r15
movq %rsi, %r14
movq %rdi, %r13
movq %rcx, %rdx
callq 0x2ade6a
testq %rax, %rax
je 0x2ae8a8
movq %rax, %r12
cmpq $0x0, 0x18(%r13)
je 0x2ae8f7
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2ae11f
testq %rax, %rax
je 0x2ae8a8
movq 0x10(%r13), %rcx
movq 0x20(%r13), %rdi
movq %r12, %rbp
subq %rcx, %rbp
sarq $0x4, %rbp
movq %rax, 0x10(%rsp)
movq %rax, %rbx
subq %rcx, %rbx
sarq $0x4, %rbx
callq 0x14906a
movzwl %ax, %eax
movl 0x28(%r13), %esi
imulq %rax, %rbx
imulq %rax, %rbp
xorl %ecx, %ecx
xorl %r15d, %r15d
movzbl %cl, %ecx
cmpq %rax, %rcx
jae 0x2ae8bd
movq 0x18(%r13), %rdx
leaq (%rdx,%rbx,8), %r8
movl %ecx, %edi
shll $0x3, %edi
addq (%rdi,%r8), %r15
leaq (%rdx,%rbp,8), %rdx
subq (%rdi,%rdx), %r15
incl %ecx
jmp 0x2ae883
xorl %r15d, %r15d
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
subq (%r12), %r14
cmovaeq %r14, %rax
subq %rax, %r15
movq 0x8(%rsp), %r14
movq %r14, %rbx
movq 0x10(%rsp), %r12
subq (%r12), %rbx
movq %r12, %rdi
movl %esi, %ebp
callq 0x2adb40
cmpq %rax, %rbx
jae 0x2ae973
subq (%r12), %r14
jmp 0x2ae980
movq (%r12), %rbx
cmpq %r14, %rbx
cmovaq %rbx, %r14
movq 0x8(%r13), %rax
movq 0x10(%r13), %rcx
shlq $0x4, %rax
addq %rcx, %rax
addq $-0x10, %rax
movq %rax, 0x10(%rsp)
movl 0x28(%r13), %ebp
xorl %r15d, %r15d
movq 0x8(%rsp), %r13
cmpq %r13, %r14
jae 0x2ae8ab
movq %r12, %rdi
movl %ebp, %esi
callq 0x2adb40
movq %rax, %rcx
addq %rbx, %rcx
movq %r13, %rax
cmpq %r13, %rcx
jae 0x2ae954
movq (%r12), %rbx
movq %r12, %rdi
movl %ebp, %esi
callq 0x2adb40
addq %rbx, %rax
subq %r14, %rax
addq %rax, %r15
cmpq 0x10(%rsp), %r12
je 0x2ae8ab
movq 0x10(%r12), %rbx
addq $0x10, %r12
movq %rbx, %r14
jmp 0x2ae926
movq %r12, %rdi
movl %ebp, %esi
callq 0x2adb40
movq %rax, %r14
movzwl %r14w, %eax
addq %rax, %r15
jmp 0x2ae8ab