// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, %r15
movl 0x8(%rsi), %eax
movl %eax, 0x4(%rsp)
movq %rdx, 0x10(%rsp)
movq 0x8(%rdx), %rbp
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl $0x1, %r12d
cmpl $0x2, %ebp
jl 0x32f0
leal -0x1(%rbp), %eax
movl $0x1, %r12d
shll $0x8, %r12d
imulq $0x288df0cb, %r12, %rcx # imm = 0x288DF0CB
shrq $0x24, %rcx
imull $0x65, %ecx, %ecx
subl %ecx, %r12d
decl %eax
jne 0x32d7
movq %rdi, 0x8(%rsp)
testl %ebp, %ebp
jle 0x336c
movq (%r15), %rax
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movl %ebp, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorl %r14d, %r14d
xorl %ebx, %ebx
movsbl (%rax,%rsi), %edi
shll $0x8, %r14d
shll $0x8, %ebx
addl %edi, %ebx
movslq %ebx, %rbx
imulq $0x288df0cb, %rbx, %rdi # imm = 0x288DF0CB
movq %rdi, %r8
shrq $0x3f, %r8
sarq $0x24, %rdi
addl %r8d, %edi
imull $0x65, %edi, %edi
subl %edi, %ebx
movsbl (%rcx,%rsi), %edi
addl %r14d, %edi
movslq %edi, %r14
imulq $0x288df0cb, %r14, %rdi # imm = 0x288DF0CB
movq %rdi, %r8
shrq $0x3f, %r8
sarq $0x24, %rdi
addl %r8d, %edi
imull $0x65, %edi, %edi
subl %edi, %r14d
incq %rsi
cmpq %rsi, %rdx
jne 0x3313
jmp 0x3371
xorl %ebx, %ebx
xorl %r14d, %r14d
subl %ebp, 0x4(%rsp)
movl $0x0, (%rsp)
js 0x3438
movl %ebp, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %eax, %eax
cmpl %r14d, %ebx
jne 0x33e4
testl %ebp, %ebp
jle 0x33bb
movq 0x10(%rsp), %rcx
movq (%rcx), %rdx
movslq %eax, %rsi
addq (%r15), %rsi
xorl %ecx, %ecx
movb (%rsi,%rcx), %dil
cmpb (%rdx,%rcx), %dil
jne 0x33bd
incq %rcx
cmpq %rcx, %r13
jne 0x33a7
jmp 0x33c1
xorl %ecx, %ecx
cmpl %ebp, %ecx
jne 0x33e4
movq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x33dc
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x33e4
movq %rsp, %rdx
callq 0x3476
movslq (%rsp), %rax
cmpl 0x4(%rsp), %eax
jge 0x3438
movq (%r15), %rcx
movsbl (%rcx,%rax), %edx
imull %r12d, %edx
leal (%rax,%rbp), %esi
movslq %esi, %rsi
subl %edx, %ebx
shll $0x8, %ebx
movsbl (%rcx,%rsi), %ecx
addl %ebx, %ecx
movslq %ecx, %rcx
imulq $0x288df0cb, %rcx, %rdx # imm = 0x288DF0CB
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x24, %rdx
addl %esi, %edx
imull $0x65, %edx, %edx
subl %edx, %ecx
leal 0x65(%rcx), %ebx
testl %ecx, %ecx
cmovnsl %ecx, %ebx
incl %eax
movl %eax, (%rsp)
jmp 0x338e
movq 0x8(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x346d
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2150
movq %r14, %rdi
callq 0x21b0
nop