// File: /workspace/github_cpp_makefile_star2_O1/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 %rsi, 0x18(%rsp)
movl 0x8(%rsi), %ebp
movq %rdx, 0x20(%rsp)
movq 0x8(%rdx), %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl $0x1, %r12d
cmpl $0x2, %r15d
jl 0x32b4
leal -0x1(%r15), %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 0x329b
movq %rdi, 0x10(%rsp)
testl %r15d, %r15d
jle 0x3337
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movl %r15d, %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 0x32de
jmp 0x333c
xorl %ebx, %ebx
xorl %r14d, %r14d
subl %r15d, %ebp
movl $0x0, 0xc(%rsp)
js 0x3418
movl %r15d, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %eax, %eax
cmpl %r14d, %ebx
jne 0x33bb
testl %r15d, %r15d
jle 0x338f
movq 0x20(%rsp), %rcx
movq (%rcx), %rdx
movslq %eax, %rsi
movq 0x18(%rsp), %rcx
addq (%rcx), %rsi
xorl %ecx, %ecx
movb (%rsi,%rcx), %dil
cmpb (%rdx,%rcx), %dil
jne 0x3391
incq %rcx
cmpq %rcx, %r13
jne 0x3378
movl %r15d, %ecx
jmp 0x3391
xorl %ecx, %ecx
cmpl %r15d, %ecx
jne 0x33bb
movq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x33b1
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x33bb
leaq 0xc(%rsp), %rdx
callq 0x3456
movslq 0xc(%rsp), %rcx
cmpl %ebp, %ecx
jge 0x3409
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsbl (%rax,%rcx), %edx
imull %r12d, %edx
leal (%rcx,%r15), %esi
movslq %esi, %rsi
subl %edx, %ebx
shll $0x8, %ebx
movsbl (%rax,%rsi), %eax
addl %ebx, %eax
cltq
imulq $0x288df0cb, %rax, %rdx # imm = 0x288DF0CB
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x24, %rdx
addl %esi, %edx
imull $0x65, %edx, %edx
subl %edx, %eax
leal 0x65(%rax), %ebx
testl %eax, %eax
cmovnsl %eax, %ebx
leal 0x1(%rcx), %eax
movl %eax, 0xc(%rsp)
cmpl %ebp, %ecx
jl 0x3359
movq 0x10(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x344d
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2150
movq %r14, %rdi
callq 0x21b0
nop