// File: /workspace/github_cpp_makefile_star2_O3/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), %rcx
testq %rcx, %rcx
je 0xf724
movq (%rsi), %rax
movl $0x1, %edx
xorl %r8d, %r8d
cmpb $0x0, (%rax,%r8)
je 0xf7b5
movl %edx, %r8d
incl %edx
cmpq %r8, %rcx
ja 0xf70f
movl 0x2c(%rdi), %edx
notl %edx
addl 0x28(%rdi), %edx
testl %edx, %edx
jle 0xf801
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %r9
movq (%rsi), %r10
xorl %r8d, %r8d
movl %edx, %r11d
movl %r11d, %ebp
subl %r8d, %ebp
movl %ebp, %ebx
shrl $0x1f, %ebx
addl %ebp, %ebx
sarl %ebx
addl %r8d, %ebx
movl %ebx, %r14d
movl $0x0, %r15d
testq %rcx, %rcx
je 0xf782
movl (%r9,%r14,4), %r12d
xorl %r15d, %r15d
leal (%r12,%r15), %r13d
movb (%r10,%r15), %bpl
cmpb (%rax,%r13), %bpl
jne 0xf782
incl %r15d
cmpq %r15, %rcx
ja 0xf76c
movl %r15d, %r15d
cmpq %r15, %rcx
jbe 0xf7a4
movb (%r10,%r15), %bpl
movl (%r9,%r14,4), %r14d
addl %r15d, %r14d
cmpb (%rax,%r14), %bpl
jae 0xf7a9
decl %ebx
movl %ebx, %r11d
movl %ebx, %edx
jmp 0xf7ae
movl %ebx, %r11d
jmp 0xf7ae
incl %ebx
movl %ebx, %r8d
cmpl %r11d, %r8d
jl 0xf745
jmp 0xf804
movq 0x10834(%rip), %rbx     # 0x1fff0
leaq 0x90b1(%rip), %rsi      # 0x18874
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 0xf8b5
xorl %r8d, %r8d
movl %r8d, %r9d
testq %rcx, %rcx
je 0xf83f
movq 0x8(%rdi), %r10
movq 0x10(%rdi), %rax
movl (%rax,%r9,4), %r11d
movq (%rsi), %rbx
xorl %eax, %eax
leal (%r11,%rax), %r14d
movb (%rbx,%rax), %bpl
cmpb (%r10,%r14), %bpl
jne 0xf832
incl %eax
cmpq %rax, %rcx
ja 0xf81d
movl %eax, %r10d
movl $0x1, %eax
cmpq %r10, %rcx
jne 0xf8b5
cmpl %edx, %r8d
jge 0xf8ab
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %rdi
movq (%rsi), %rsi
movl %edx, %r10d
subl %r8d, %r10d
movl %r10d, %r11d
incl %r11d
shrl $0x1f, %r11d
addl %r11d, %r10d
incl %r10d
sarl %r10d
addl %r8d, %r10d
testq %rcx, %rcx
je 0xf895
movl %r10d, %r11d
movl (%rdi,%r11,4), %ebx
xorl %r11d, %r11d
leal (%rbx,%r11), %r14d
movb (%rsi,%r11), %bpl
cmpb (%rax,%r14), %bpl
jne 0xf890
incl %r11d
cmpq %r11, %rcx
ja 0xf87a
movl %r11d, %r11d
jmp 0xf898
xorl %r11d, %r11d
leal -0x1(%r10), %ebx
cmpq %r11, %rcx
cmoval %ebx, %edx
cmovbel %r10d, %r8d
cmpl %edx, %r8d
jl 0xf84f
shlq $0x20, %rdx
orq %rdx, %r9
movq %r9, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq