// File: /workspace/github_c_makefile_star2_O3/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
cmpq $0x0, 0x8(%rdi)
je 0x30f84d
movq %rcx, %r13
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r12
movq %rcx, %rdx
callq 0x30ed36
testq %rax, %rax
je 0x30f84d
movq %rax, %r15
cmpq $0x0, 0x18(%r12)
je 0x30f7b2
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x30eff0
testq %rax, %rax
je 0x30f84d
movq %rax, %r13
movq %rax, 0x8(%rsp)
movq 0x10(%r12), %r14
movq 0x20(%r12), %rdi
callq 0x19e077
movl 0x28(%r12), %esi
testw %ax, %ax
je 0x30f862
movzwl %ax, %eax
movq %r13, %rcx
subq %r14, %rcx
sarq $0x4, %rcx
movq %r15, %rdx
subq %r14, %rdx
sarq $0x4, %rdx
movq 0x18(%r12), %rdi
imulq %rax, %rcx
leaq (%rdi,%rcx,8), %rcx
imulq %rax, %rdx
leaq (%rdi,%rdx,8), %rdx
xorl %r8d, %r8d
xorl %r12d, %r12d
addq (%rcx,%r8,8), %r12
subq (%rdx,%r8,8), %r12
incq %r8
movzbl %r8b, %edi
cmpl %eax, %edi
jb 0x30f79a
jmp 0x30f865
movq (%r15), %r14
cmpq %rbp, %r14
cmovaq %r14, %rbp
cmpq %rbx, %rbp
jae 0x30f84d
movq 0x8(%r12), %rax
movq 0x10(%r12), %rcx
shlq $0x4, %rax
addq %rcx, %rax
addq $-0x10, %rax
movq %rax, 0x10(%rsp)
movl 0x28(%r12), %eax
movl $0x40, %ecx
movq %rax, 0x8(%rsp)
subl %eax, %ecx
movl %ecx, (%rsp)
xorl %r12d, %r12d
leaq 0x8(%r15), %r13
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movl (%rsp), %edx
callq 0x2f37dc
movq %rax, %rcx
addq %r14, %rcx
movq %rbx, %rax
cmpq %rbx, %rcx
jae 0x30f82e
movq (%r15), %r14
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movl (%rsp), %edx
callq 0x2f37dc
addq %r14, %rax
subq %rbp, %rax
addq %rax, %r12
cmpq 0x10(%rsp), %r15
je 0x30f850
movq 0x10(%r15), %r14
addq $0x10, %r15
movq %r14, %rbp
cmpq %rbx, %r14
jb 0x30f7f6
jmp 0x30f850
xorl %r12d, %r12d
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
xorl %eax, %eax
subq (%r15), %rbp
cmovaeq %rbp, %rax
movq %rbx, %r15
movq 0x8(%rsp), %rbp
subq (%rbp), %r15
subq %rax, %r12
addq $0x8, %r13
movl $0x40, %r14d
subl %esi, %r14d
movq %r13, %rdi
movl %r14d, %edx
movq %rsi, (%rsp)
callq 0x2f37dc
cmpq %rax, %r15
jae 0x30f8a4
subq (%rbp), %rbx
jmp 0x30f8b6
movq %r13, %rdi
movq (%rsp), %rsi
movl %r14d, %edx
callq 0x2f37dc
movq %rax, %rbx
movzwl %bx, %eax
addq %rax, %r12
jmp 0x30f850