// File: /workspace/github_cpp_makefile_star2_O1/fpavetic[P]lcskpp/lcskpp.cpp
// Function: get_matches(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>*)
static void get_matches(
    const string& a, const string& b,
    const int k, vector<pair<int, int> >* matches) {
  assert(matches != NULL);
  matches->clear();

  vector<char> aid;
  int alphabet_size;
  prepare_alphabet(a, b, aid, alphabet_size);

  // We assume: alphabet_size ** k < 2 ** 64,
  // in the case this does not hold, the entire
  // get_matches function probably has to be
  // reimplemented using non-perfect hashing or
  // suffix arrays.
  if (k * log(alphabet_size) >= 64 * log(2)) {
    fprintf(stderr, "We assume that alphabet_size ** k <\
2 ** 64.\nPlease see lcskpp.cpp for more information.");
    exit(1);
  }

  typedef unordered_multimap<uint64_t, int> MatchIndexType;
  unique_ptr<MatchIndexType> match_index =
    unique_ptr<MatchIndexType>(new MatchIndexType());

  uint64_t hash_mod = 1;
  for (int i = 0; i < k; ++i) hash_mod *= alphabet_size;

  if (alphabet_size == 4) {
    assert(hash_mod == (1LL<<(2*k)));
  }

  uint64_t rolling_hash = 0;
  for (int i = 0; i < a.size(); ++i) {
    rolling_hash = rolling_hash * alphabet_size + aid[a[i]];
    rolling_hash %= hash_mod;

    if (i+1 >= k) {
      match_index->insert(
        MatchIndexType::value_type(rolling_hash, i-k+1));
    }
  }

  rolling_hash = 0;
  for (int i = 0; i < b.size(); ++i) {
    rolling_hash = rolling_hash * alphabet_size + aid[b[i]];
    rolling_hash %= hash_mod;

    if (i+1 >= k) {
      auto positions_in_a = match_index->equal_range(rolling_hash);
      for (auto it = positions_in_a.first; 
           it != positions_in_a.second; ++it) {
        matches->push_back(make_pair(it->second, i-k+1));
      }
    }
  }

  sort(matches->begin(), matches->end());
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
testq %rcx, %rcx
je 0x31b9
movq %rcx, %r14
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r13
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x2ed1
movq %rax, 0x8(%r14)
movl $0x100, %edi            # imm = 0x100
callq 0x2150
movq %rax, %r12
movq %rbx, 0x20(%rsp)
movl $0x100, %edx            # imm = 0x100
movq %rax, %rdi
movl $0xff, %esi
callq 0x20a0
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x2f28
movq (%r13), %rcx
xorl %r15d, %r15d
xorl %edx, %edx
movsbq (%rcx,%rdx), %rsi
cmpb $-0x1, (%r12,%rsi)
jne 0x2f1e
movb %r15b, (%r12,%rsi)
leal 0x1(%r15), %esi
movl %esi, %r15d
incq %rdx
cmpq %rdx, %rax
jne 0x2f07
jmp 0x2f2b
xorl %r15d, %r15d
movq 0x20(%rsp), %rcx
movq 0x8(%rcx), %rax
testq %rax, %rax
je 0x2f5d
movq (%rcx), %rcx
xorl %edx, %edx
movsbq (%rcx,%rdx), %rsi
cmpb $-0x1, (%r12,%rsi)
jne 0x2f55
movb %r15b, (%r12,%rsi)
leal 0x1(%r15), %esi
movl %esi, %r15d
incq %rdx
cmpq %rdx, %rax
jne 0x2f3e
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
callq 0x20f0
mulsd 0x10(%rsp), %xmm0
ucomisd 0x32fe(%rip), %xmm0     # 0x6280
jae 0x31d8
movl $0x38, %edi
movq %r12, 0x8(%rsp)
callq 0x2150
xorpd %xmm0, %xmm0
movapd %xmm0, (%rax)
movapd %xmm0, 0x20(%rax)
movapd %xmm0, 0x10(%rax)
movq $0x0, 0x30(%rax)
movq %rax, %rcx
addq $0x30, %rcx
movq %rcx, (%rax)
movq $0x1, 0x8(%rax)
movl $0x3f800000, 0x20(%rax) # imm = 0x3F800000
movupd %xmm0, 0x28(%rax)
movq %rax, 0x18(%rsp)
movslq %r15d, %rcx
movl $0x1, %ebx
testl %ebp, %ebp
jle 0x2fea
movl %ebp, %eax
imulq %rcx, %rbx
decl %eax
jne 0x2fe2
movq %rcx, 0x10(%rsp)
cmpl $0x4, %r15d
jne 0x300d
leal (,%rbp,2), %ecx
movl $0x1, %eax
shlq %cl, %rax
cmpq %rax, %rbx
jne 0x31dd
movq $0x0, (%rsp)
cmpq $0x0, 0x8(%r13)
movq %rbp, 0x28(%rsp)
movslq %ebp, %rax
movq %rax, 0x30(%rsp)
je 0x3093
movl $0x1, %r12d
subl 0x28(%rsp), %r12d
xorl %ecx, %ecx
leaq 0x38(%rsp), %r15
movq (%rsp), %rdx
imulq 0x10(%rsp), %rdx
movq (%r13), %rax
movsbq (%rax,%rcx), %rax
movq 0x8(%rsp), %rsi
movsbq (%rsi,%rax), %rax
addq %rdx, %rax
xorl %edx, %edx
divq %rbx
movq %rdx, (%rsp)
leaq 0x1(%rcx), %rbp
cmpq 0x30(%rsp), %rbp
jl 0x308a
movq 0x18(%rsp), %rdi
addl %r12d, %ecx
movq %rdx, 0x38(%rsp)
movl %ecx, 0x40(%rsp)
xorl %esi, %esi
movq %r15, %rdx
callq 0x411e
movq %rbp, %rcx
cmpq %rbp, 0x8(%r13)
ja 0x303b
movq $0x0, (%rsp)
movq 0x20(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x314a
xorl %ebp, %ebp
movq %rbp, %r12
movq (%rsp), %rcx
imulq 0x10(%rsp), %rcx
movq (%rax), %rax
movsbq (%rax,%rbp), %rax
movq 0x8(%rsp), %rdx
movsbq (%rdx,%rax), %rax
addq %rcx, %rax
xorl %edx, %edx
divq %rbx
movq %rdx, (%rsp)
incq %rbp
cmpq 0x30(%rsp), %rbp
jl 0x313b
movq 0x18(%rsp), %rdi
movq %rsp, %rsi
callq 0x44a2
movq %rax, %r15
movq %rdx, %r13
cmpq %rdx, %rax
je 0x313b
subl 0x28(%rsp), %r12d
incl %r12d
shlq $0x20, %r12
movl 0x10(%r15), %eax
orq %r12, %rax
movq %rax, 0x38(%rsp)
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x3126
movq %rax, (%rsi)
addq $0x8, 0x8(%r14)
jmp 0x3133
movq %r14, %rdi
leaq 0x38(%rsp), %rdx
callq 0x44ec
movq (%r15), %r15
cmpq %r13, %r15
jne 0x3106
movq 0x20(%rsp), %rax
cmpq %rbp, 0x8(%rax)
ja 0x30ad
movq (%r14), %r15
movq 0x8(%r14), %r14
cmpq %r14, %r15
je 0x3183
movq %r14, %rax
subq %r15, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x4629
movq %r15, %rdi
movq %r14, %rsi
callq 0x46dc
movq 0x18(%rsp), %r14
testq %r14, %r14
movq 0x8(%rsp), %rbx
je 0x31a2
movq %r14, %rdi
callq 0x4aa2
movq %r14, %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x2130
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3100(%rip), %rdi      # 0x62c0
leaq 0x2ee4(%rip), %rsi      # 0x60ab
leaq 0x3102(%rip), %rcx      # 0x62d0
movl $0x36, %edx
callq 0x20b0
callq 0x2230
leaq 0x319a(%rip), %rdi      # 0x637e
leaq 0x2ec0(%rip), %rsi      # 0x60ab
leaq 0x30de(%rip), %rcx      # 0x62d0
movl $0x50, %edx
callq 0x20b0
movq %rax, %r14
jmp 0x3222
movq %rax, %r14
movq $0x0, 0x8(%rsp)
jmp 0x3222
jmp 0x3215
jmp 0x3215
jmp 0x3215
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x40f0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x3231
callq 0x2130
movq %r14, %rdi
callq 0x21f0