// File: /workspace/github_cpp_makefile_star2_O1/adamnovak[P]rlcsa/suffixarray.cpp
// Function: CSA::SuffixArray::count(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
pair_type
SuffixArray::count(const std::string& pattern) const
{
  pair_type range;
  for(uint i = 0; i < pattern.length(); i++)
  {
    if(pattern[i] == '\0')
    {
      std::cerr << "Error: Pattern must not contain \\0!" << std::endl;
      return EMPTY_PAIR;
    }
  }

  // Lower bound for the range.
  sint low = 0, high = this->getSize() - 1;
  uint last_high = high;
  while(low < high)
  {
    uint mid = low + (high - low) / 2;
    uint matched = this->match(pattern, mid);
    if(matched >= pattern.length()) { high = mid; }
    else if((uchar)(pattern[matched]) < this->data[this->sa[mid] + matched])
    {
      high = ((sint)mid) - 1; last_high = high;
    }
    else { low = mid + 1; }
  }
  if(this->match(pattern, low) == pattern.length()) { range.first = low; }
  else { return EMPTY_PAIR; }

  // Upper bound for the range.
  high = last_high;
  while(low < high)
  {
    uint mid = low + (high - low + 1) / 2;
    uint matched = this->match(pattern, mid);
    if(matched >= pattern.length()) { low = mid; }
    else                            { high = mid - 1; }
  }
  range.second = high;

  return range;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0xf556
movq (%rsi), %rcx
movl $0x1, %edx
xorl %r8d, %r8d
cmpb $0x0, (%rcx,%r8)
je 0xf5e7
movl %edx, %r8d
incl %edx
cmpq %r8, %rax
ja 0xf541
movl 0x2c(%rdi), %ecx
notl %ecx
addl 0x28(%rdi), %ecx
testl %ecx, %ecx
jle 0xf633
movq (%rsi), %rax
movq 0x8(%rsi), %r8
movq 0x8(%rdi), %r9
movq 0x10(%rdi), %r10
xorl %edx, %edx
movl %ecx, %r11d
movl %r11d, %ebp
subl %edx, %ebp
movl %ebp, %ebx
shrl $0x1f, %ebx
addl %ebp, %ebx
sarl %ebx
addl %edx, %ebx
movl %ebx, %r14d
movl $0x0, %r15d
testq %r8, %r8
je 0xf5b5
movl (%r10,%r14,4), %r12d
xorl %r15d, %r15d
leal (%r12,%r15), %r13d
movb (%rax,%r15), %bpl
cmpb (%r9,%r13), %bpl
jne 0xf5b5
incl %r15d
cmpq %r15, %r8
ja 0xf59f
movl %r15d, %r15d
cmpq %r15, %r8
jbe 0xf5d7
movb (%rax,%r15), %bpl
movl (%r10,%r14,4), %r14d
addl %r15d, %r14d
cmpb (%r9,%r14), %bpl
jae 0xf5dc
decl %ebx
movl %ebx, %r11d
movl %ebx, %ecx
jmp 0xf5e0
movl %ebx, %r11d
jmp 0xf5e0
incl %ebx
movl %ebx, %edx
cmpl %r11d, %edx
jl 0xf57a
jmp 0xf635
movq 0xfa02(%rip), %rbx      # 0x1eff0
leaq 0x8232(%rip), %rsi      # 0x17827
movl $0x23, %edx
movq %rbx, %rdi
callq 0x32b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3190
movl $0x1, %eax
jmp 0xf6ea
xorl %edx, %edx
movq 0x8(%rsi), %r9
xorl %r10d, %r10d
movl %edx, %r8d
testq %r9, %r9
je 0xf66c
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %r11
movl (%r11,%r8,4), %r11d
movq (%rsi), %rbx
leal (%r11,%r10), %r14d
movb (%rbx,%r10), %bpl
cmpb (%rax,%r14), %bpl
jne 0xf669
incl %r10d
cmpq %r10, %r9
ja 0xf653
movl %r10d, %r10d
movl $0x1, %eax
cmpq %r10, %r9
jne 0xf6ea
cmpl %ecx, %edx
jge 0xf6e0
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %rdi
movq (%rsi), %rsi
movl %ecx, %r10d
subl %edx, %r10d
movl %r10d, %r11d
incl %r11d
shrl $0x1f, %r11d
addl %r11d, %r10d
incl %r10d
sarl %r10d
addl %edx, %r10d
testq %r9, %r9
je 0xf6cb
movl %r10d, %r11d
movl (%rdi,%r11,4), %ebx
xorl %r11d, %r11d
leal (%rbx,%r11), %r14d
movb (%rsi,%r11), %bpl
cmpb (%rax,%r14), %bpl
jne 0xf6c6
incl %r11d
cmpq %r11, %r9
ja 0xf6b0
movl %r11d, %r11d
jmp 0xf6ce
xorl %r11d, %r11d
leal -0x1(%r10), %ebx
cmpq %r11, %r9
cmoval %ebx, %ecx
cmovbel %r10d, %edx
cmpl %ecx, %edx
jl 0xf685
shlq $0x20, %rcx
orq %rcx, %r8
movq %r8, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop