// File: /workspace/github_cpp_makefile_star2_O2/maxgodfrey2004[P]gss/src/rabin_karp.cc
// Function: gss::rabin_karp::FindMatches(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::vector<int> FindMatches(std::string search, std::string pattern) {
  int search_length = static_cast<int>(search.length());
  int pattern_length = static_cast<int>(pattern.length());
  std::vector<int> occurrences;

  // Precompute (MAX_CHAR ^ (M - 1) mod HASH_KEY) where ^ is an exponent.
  int mc_precomp = 1;
  for (int i = 0; i + 1 < pattern_length; ++i) {
    mc_precomp = (MAX_CHAR * mc_precomp) % HASH_KEY;
  }

  // Hash the search string and the pattern according to a modular hash
  // function. The hash value is computed for the first "window", or text
  // segment whose length is that of pattern.
  int search_hash = 0;
  int pattern_hash = 0;
  for (int i = 0; i < pattern_length; ++i) {
    search_hash = (MAX_CHAR * search_hash + search[i]) % HASH_KEY;
    pattern_hash = (MAX_CHAR * pattern_hash + pattern[i]) % HASH_KEY;
  }

  // Start searching...
  for (int i = 0; i <= search_length - pattern_length; ++i) {
    if (search_hash == pattern_hash) {
      int current_idx = 0;
      for (; current_idx < pattern_length; ++current_idx) {
        if (search[i + current_idx] != pattern[current_idx]) {
          break;
        }
      }

      if (current_idx == pattern_length) {
        // We have found an occurrence of pattern in our search string!
        occurrences.push_back(i);
      }
    }

    // Hash the next "window".
    if (i < search_length - pattern_length) {
      search_hash = (MAX_CHAR * (search_hash - search[i] * mc_precomp) +
                      search[i + pattern_length]) % HASH_KEY;
      if (search_hash < 0) {
        search_hash += HASH_KEY;
      }
    }
  }

  return occurrences;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq 0x8(%rsi), %rax
movq %rax, 0x10(%rsp)
movl 0x8(%rdx), %esi
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rdi)
movq %rdi, 0x18(%rsp)
movups %xmm0, (%rdi)
pushq $0x1
popq %rcx
movl %ecx, %ebp
pushq $0x65
popq %rdi
cmpl %esi, %ecx
jge 0x2f9b
shll $0x8, %ebp
movl %ebp, %eax
xorl %edx, %edx
divl %edi
incl %ecx
movl %edx, %ebp
jmp 0x2f88
xorl %ecx, %ecx
testl %esi, %esi
movl $0x0, %ebx
movq %rsi, 0x20(%rsp)
cmovgl %esi, %ebx
xorl %r13d, %r13d
xorl %r12d, %r12d
pushq $0x65
popq %rdi
cmpq %rcx, %rbx
je 0x2fea
movq (%r15), %rax
movsbl (%rax,%rcx), %eax
movq (%r14), %rsi
shll $0x8, %r12d
shll $0x8, %r13d
addl %eax, %r13d
movl %r13d, %eax
cltd
idivl %edi
movsbl (%rsi,%rcx), %eax
addl %r12d, %eax
movl %edx, %r13d
cltd
idivl %edi
incq %rcx
movl %edx, %r12d
jmp 0x2fb5
movq 0x10(%rsp), %rax
subl 0x20(%rsp), %eax
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
movl %ecx, 0xc(%rsp)
cmpl 0x10(%rsp), %ecx
jg 0x308c
cmpl %r12d, %r13d
jne 0x304a
movslq %ecx, %rdx
xorl %eax, %eax
cmpq %rax, %rbx
je 0x302f
movq (%r15), %rsi
addq %rdx, %rsi
movb (%rax,%rsi), %sil
movq (%r14), %rdi
cmpb (%rdi,%rax), %sil
jne 0x3031
incq %rax
jmp 0x3012
movl %ebx, %eax
cmpl 0x20(%rsp), %eax
jne 0x304a
movq 0x18(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x30b6
movl 0xc(%rsp), %ecx
cmpl 0x10(%rsp), %ecx
jge 0x3085
movslq %ecx, %rax
movq (%r15), %rdx
movsbl (%rdx,%rax), %eax
movq 0x20(%rsp), %rsi
addl %ecx, %esi
movslq %esi, %rsi
imull %ebp, %eax
subl %eax, %r13d
shll $0x8, %r13d
movsbl (%rdx,%rsi), %eax
addl %r13d, %eax
cltd
pushq $0x65
popq %rsi
idivl %esi
leal 0x65(%rdx), %r13d
testl %edx, %edx
cmovnsl %edx, %r13d
incl %ecx
jmp 0x2ffa
movq 0x18(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x18(%rsp), %rdi
callq 0x2ac6
movq %r14, %rdi
callq 0x21c0
nop