// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
cmpq $0x0, 0x8(%rdi)
je 0x319832
movq %r8, %r13
movl %ecx, %r14d
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %rbp
movq $0x0, 0x8(%rsp)
xorl %edx, %edx
callq 0x318eb5
testq %rax, %rax
je 0x31985a
movq %rax, %r12
cmpq $0x0, 0x18(%rbp)
je 0x31973f
movq %rbp, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x31916d
testq %rax, %rax
je 0x319832
movq %rax, %r13
movl %r14d, 0x8(%rsp)
movq 0x10(%rbp), %r14
movq 0x20(%rbp), %rdi
callq 0x1a67a7
movq 0x20(%rbp), %rcx
cmpl $0x1, (%rcx)
jne 0x31986e
movzwl %ax, %eax
movq %r13, 0x18(%rsp)
movq %r13, %rdx
subq %r14, %rdx
sarq $0x4, %rdx
movq %r12, %rsi
subq %r14, %rsi
sarq $0x4, %rsi
movzbl 0x8(%rsp), %edi
movzbl 0x18(%rcx,%rdi), %r13d
movl 0x28(%rbp), %edi
movq 0x18(%rbp), %rcx
movq %rdi, %rbp
imulq %rax, %rdx
leaq (%rcx,%rdx,8), %rdx
movl %r13d, %edi
shll $0x3, %edi
movq (%rdi,%rdx), %r14
imulq %rax, %rsi
leaq (%rcx,%rsi,8), %rax
subq (%rdi,%rax), %r14
movq %r12, %rdi
addq $0x8, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x2fddcc
movl %r13d, 0x8(%rsp)
cmpb %al, %r13b
jne 0x3196ee
movq (%r12), %rax
cmpq %r15, %rax
ja 0x3196ee
subq %r15, %r14
addq %rax, %r14
movq 0x18(%rsp), %r13
leaq 0x8(%r13), %r15
movq %r15, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x2fddcc
cmpb %al, 0x8(%rsp)
jne 0x319855
movq %rbx, %r12
subq (%r13), %r12
movq %rbp, %rsi
movl $0x40, %ebp
subl %esi, %ebp
movq %r15, %rdi
movq %rsi, 0x8(%rsp)
movl %ebp, %edx
callq 0x2fcc2c
cmpq %rax, %r12
jae 0x31983d
subq (%r13), %rbx
jmp 0x31984f
movq 0x20(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x31986e
movq (%r12), %rcx
cmpq %r15, %rcx
cmovaq %rcx, %r15
cmpq %rbx, %r15
jae 0x319832
movzbl %r14b, %ecx
movb 0x18(%rax,%rcx), %r13b
movl 0x28(%rbp), %r14d
movq 0x8(%rbp), %rax
movq 0x10(%rbp), %rcx
shlq $0x4, %rax
addq %rcx, %rax
addq $-0x10, %rax
movq %rax, 0x18(%rsp)
movl $0x40, %eax
subl %r14d, %eax
movl %eax, 0x14(%rsp)
movq $0x0, 0x8(%rsp)
movb %r13b, 0x13(%rsp)
movq %r14, 0x20(%rsp)
leaq 0x8(%r12), %rbp
movq %rbp, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x2fddcc
cmpb %r13b, %al
jne 0x319817
movq %rbx, %r13
movq (%r12), %rbx
movq %rbp, %rdi
movq %r14, %rsi
movl 0x14(%rsp), %edx
callq 0x2fcc2c
movq %rax, %rcx
addq %rbx, %rcx
movq %r13, %rbx
movq %r13, %rax
cmpq %r13, %rcx
jae 0x3197fd
movq (%r12), %rbx
movq %rbp, %rdi
movq 0x20(%rsp), %rsi
movl 0x14(%rsp), %edx
callq 0x2fcc2c
addq %rbx, %rax
movq %r13, %rbx
movq 0x8(%rsp), %rcx
subq %r15, %rcx
addq %rax, %rcx
movq %rcx, 0x8(%rsp)
movb 0x13(%rsp), %r13b
movq 0x20(%rsp), %r14
cmpq 0x18(%rsp), %r12
je 0x31985a
movq 0x10(%r12), %r15
addq $0x10, %r12
cmpq %rbx, %r15
jb 0x3197a4
jmp 0x31985a
movq $0x0, 0x8(%rsp)
jmp 0x31985a
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
callq 0x2fcc2c
movq %rax, %rbx
movzwl %bx, %eax
addq %rax, %r14
movq %r14, 0x8(%rsp)
movq 0x8(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x173b0