// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
testq %rcx, %rcx
je 0x31bb
movq %rcx, %r14
movl %edx, %r12d
movq %rdi, %rbp
movq %rsi, 0x20(%rsp)
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x2ee0
movq %rax, 0x8(%r14)
movl $0x100, %edi            # imm = 0x100
callq 0x2150
movq %rax, %rbx
movl $0x100, %edx            # imm = 0x100
movq %rax, %rdi
movl $0xff, %esi
callq 0x20a0
movq 0x8(%rbp), %rax
testq %rax, %rax
je 0x2f31
movq (%rbp), %rcx
xorl %r15d, %r15d
xorl %edx, %edx
movsbq (%rcx,%rdx), %rsi
cmpb $-0x1, (%rbx,%rsi)
jne 0x2f27
movb %r15b, (%rbx,%rsi)
leal 0x1(%r15), %esi
movl %esi, %r15d
incq %rdx
cmpq %rdx, %rax
jne 0x2f11
jmp 0x2f34
xorl %r15d, %r15d
movq 0x20(%rsp), %rcx
movq 0x8(%rcx), %rax
testq %rax, %rax
je 0x2f65
movq (%rcx), %rcx
xorl %edx, %edx
movsbq (%rcx,%rdx), %rsi
cmpb $-0x1, (%rbx,%rsi)
jne 0x2f5d
movb %r15b, (%rbx,%rsi)
leal 0x1(%r15), %esi
movl %esi, %r15d
incq %rdx
cmpq %rdx, %rax
jne 0x2f47
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
callq 0x20f0
mulsd 0x8(%rsp), %xmm0
ucomisd 0x32f5(%rip), %xmm0     # 0x6280
jae 0x31da
movl $0x38, %edi
movq %rbx, 0x10(%rsp)
callq 0x2150
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rax)
movq %rax, %rcx
addq $0x30, %rcx
movq %rcx, (%rax)
movq $0x1, 0x8(%rax)
movupd %xmm0, 0x10(%rax)
movl $0x3f800000, 0x20(%rax) # imm = 0x3F800000
movupd %xmm0, 0x28(%rax)
movq %rax, 0x50(%rsp)
movslq %r15d, %rdx
movl $0x1, %ebx
testl %r12d, %r12d
jle 0x2fe9
movl %r12d, %ecx
imulq %rdx, %rbx
decl %ecx
jne 0x2fe1
cmpl $0x4, %r15d
movq %rdx, 0x8(%rsp)
jne 0x300e
leal (%r12,%r12), %ecx
movl $0x1, %edx
shlq %cl, %rdx
cmpq %rdx, %rbx
movq 0x8(%rsp), %rdx
jne 0x31df
movq %rax, 0x18(%rsp)
movq 0x8(%rbp), %rcx
movq %r12, 0x30(%rsp)
movslq %r12d, %rax
movq %rax, 0x38(%rsp)
testq %rcx, %rcx
je 0x3094
movl $0x1, %r12d
subl 0x30(%rsp), %r12d
xorl %r13d, %r13d
xorl %esi, %esi
imulq %rdx, %r13
movq (%rbp), %rax
movsbq (%rax,%rsi), %rax
movq 0x10(%rsp), %rdx
movsbq (%rdx,%rax), %rax
addq %r13, %rax
xorl %edx, %edx
divq %rbx
leaq 0x1(%rsi), %r15
movq %rdx, %r13
cmpq 0x38(%rsp), %r15
jl 0x3087
addl %r12d, %esi
movq %r13, 0x40(%rsp)
movl %esi, 0x48(%rsp)
movq 0x18(%rsp), %rdi
xorl %esi, %esi
leaq 0x40(%rsp), %rdx
callq 0x4120
movq 0x8(%rbp), %rcx
movq %r15, %rsi
cmpq %r15, %rcx
movq 0x8(%rsp), %rdx
ja 0x3039
movq $0x0, 0x28(%rsp)
movq 0x20(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3154
xorl %r15d, %r15d
movq %r15, %r12
movq 0x28(%rsp), %rcx
imulq %rdx, %rcx
movq (%rax), %rax
movsbq (%rax,%r15), %rax
movq 0x10(%rsp), %rdx
movsbq (%rdx,%rax), %rax
addq %rcx, %rax
xorl %edx, %edx
divq %rbx
movq %rdx, 0x28(%rsp)
incq %r15
cmpq 0x38(%rsp), %r15
jl 0x3140
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4472
movq %rax, %rbp
movq %rdx, %r13
cmpq %rdx, %rax
je 0x3140
subl 0x30(%rsp), %r12d
incl %r12d
shlq $0x20, %r12
movl 0x10(%rbp), %eax
orq %r12, %rax
movq %rax, 0x40(%rsp)
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x312a
movq %rax, (%rsi)
addq $0x8, 0x8(%r14)
jmp 0x3137
movq %r14, %rdi
leaq 0x40(%rsp), %rdx
callq 0x44f4
movq (%rbp), %rbp
cmpq %r13, %rbp
jne 0x310b
movq 0x20(%rsp), %rax
cmpq %r15, 0x8(%rax)
movq 0x8(%rsp), %rdx
ja 0x30b0
movq (%r14), %r15
movq 0x8(%r14), %r14
cmpq %r14, %r15
je 0x318d
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 0x4631
movq %r15, %rdi
movq %r14, %rsi
callq 0x46e4
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x4aa8
movq %rbx, %rdi
callq 0x2130
movq 0x10(%rsp), %rdi
callq 0x2130
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30fe(%rip), %rdi      # 0x62c0
leaq 0x2ee2(%rip), %rsi      # 0x60ab
leaq 0x3100(%rip), %rcx      # 0x62d0
movl $0x36, %edx
callq 0x20b0
callq 0x2230
leaq 0x3198(%rip), %rdi      # 0x637e
leaq 0x2ebe(%rip), %rsi      # 0x60ab
leaq 0x30dc(%rip), %rcx      # 0x62d0
movl $0x50, %edx
callq 0x20b0
movq %rax, %r14
jmp 0x3216
jmp 0x3209
jmp 0x3209
jmp 0x3209
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x40f2
movq 0x10(%rsp), %rdi
callq 0x2130
movq %r14, %rdi
callq 0x21f0