// File: readmapping[P]alfalfa/src/sparseSA.cpp
// Function: sparseSA::collectAllMEMs(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, interval_t, interval_t, std::vector<match_t, std::allocator<match_t>>&, int, int) const
void sparseSA::collectAllMEMs(const string &P, int prefix, const interval_t mli,
        interval_t xmi, vector<match_t> &matches, int min_len, int maxLeft) const {
  // All of the suffixes in xmi's interval are right maximal.
  long xmiEnd = xmi.end;
  for(long i = xmi.start; i <= xmiEnd; i++) find_LmaximalStrict(P, prefix, SA[i], xmi.depth, matches, min_len, maxLeft);

  if(mli.start == xmi.start && mli.end == xmi.end){ return;}
  while(xmi.depth >= mli.depth) {
    // Attempt to "unmatch" xmi using LCP information.
    if(xmi.end+1 < N/K) xmi.depth = max(LCP[xmi.start], LCP[xmi.end+1]);
    else xmi.depth = LCP[xmi.start];

    // If unmatched XMI is > matched depth from mli, then examine rmems.
    if(xmi.depth >= mli.depth) {
      // Scan RMEMs to the left, check their left maximality..
      while(LCP[xmi.start] >= xmi.depth) {
	xmi.start--;
	find_LmaximalStrict(P, prefix, SA[xmi.start], xmi.depth, matches, min_len, maxLeft);
      }
      // Find RMEMs to the right, check their left maximality.
      while(xmi.end+1 < N/K && LCP[xmi.end+1] >= xmi.depth) {
	xmi.end++;
	find_LmaximalStrict(P, prefix, SA[xmi.end], xmi.depth, matches, min_len, maxLeft);
      }
    }
  }
}

// Assembly:
subq $0xa8, %rsp
movq %r8, 0x48(%rsp)
movq %rcx, 0x50(%rsp)
movl 0xb8(%rsp), %eax
movl 0xb0(%rsp), %eax
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movl %edx, 0x94(%rsp)
movq %rcx, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x78(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x8(%r8), %rax
movq %rax, 0x70(%rsp)
movq (%r8), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
cmpq 0x70(%rsp), %rax
jg 0x1ae90
movq 0x58(%rsp), %rdi
movq 0x98(%rsp), %rax
movq %rax, 0x38(%rsp)
movl 0x94(%rsp), %eax
movl %eax, 0x44(%rsp)
addq $0x70, %rdi
movq 0x68(%rsp), %rsi
callq 0x1fb90
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x44(%rsp), %edx
movq %rax, %rcx
movq 0x48(%rsp), %rax
movl (%rcx), %ecx
movl 0x10(%rax), %r8d
movq 0x78(%rsp), %r9
movl 0xb0(%rsp), %r10d
movl 0xb8(%rsp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1fa80
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x1ae09
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rax
movq (%rax), %rax
cmpq (%rcx), %rax
jne 0x1aebb
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
cmpq 0x8(%rcx), %rax
jne 0x1aebb
jmp 0x1b125
jmp 0x1aebd
movq 0x50(%rsp), %rcx
movq 0x48(%rsp), %rax
movl 0x10(%rax), %eax
cmpl 0x10(%rcx), %eax
jl 0x1b125
movq 0x58(%rsp), %rcx
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rcx), %rax
cqto
idivq 0xe8(%rcx)
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jge 0x1af63
movq 0x48(%rsp), %rax
movq 0x58(%rsp), %rdi
addq $0xa0, %rdi
movq (%rax), %rsi
callq 0x1ed20
movq 0x58(%rsp), %rdi
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x64(%rsp)
addq $0xa0, %rdi
movq 0x8(%rax), %rsi
addq $0x1, %rsi
callq 0x1ed20
movl %eax, 0x60(%rsp)
leaq 0x64(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x14d40
movq %rax, %rcx
movq 0x48(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x10(%rax)
jmp 0x1af86
movq 0x48(%rsp), %rax
movq 0x58(%rsp), %rdi
addq $0xa0, %rdi
movq (%rax), %rsi
callq 0x1ed20
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x50(%rsp), %rcx
movq 0x48(%rsp), %rax
movl 0x10(%rax), %eax
cmpl 0x10(%rcx), %eax
jl 0x1b120
jmp 0x1af9e
movq 0x48(%rsp), %rax
movq 0x58(%rsp), %rdi
addq $0xa0, %rdi
movq (%rax), %rsi
callq 0x1ed20
movq 0x48(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jl 0x1b03b
movq 0x58(%rsp), %rdi
movq 0x48(%rsp), %rax
movq (%rax), %rcx
addq $-0x1, %rcx
movq %rcx, (%rax)
movq 0x98(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movl 0x94(%rsp), %ecx
movl %ecx, 0x2c(%rsp)
addq $0x70, %rdi
movq (%rax), %rsi
callq 0x1fb90
movq 0x58(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x2c(%rsp), %edx
movq %rax, %rcx
movq 0x48(%rsp), %rax
movl (%rcx), %ecx
movl 0x10(%rax), %r8d
movq 0x78(%rsp), %r9
movl 0xb0(%rsp), %r10d
movl 0xb8(%rsp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1fa80
jmp 0x1af9e
jmp 0x1b03d
movq 0x58(%rsp), %rsi
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq 0x38(%rsi), %rax
cqto
idivq 0xe8(%rsi)
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x1f(%rsp)
jge 0x1b097
movq 0x48(%rsp), %rax
movq 0x58(%rsp), %rdi
addq $0xa0, %rdi
movq 0x8(%rax), %rsi
addq $0x1, %rsi
callq 0x1ed20
movq 0x48(%rsp), %rcx
cmpl 0x10(%rcx), %eax
setge %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x1b0a1
jmp 0x1b11e
movq 0x58(%rsp), %rdi
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq 0x98(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movl 0x94(%rsp), %ecx
movl %ecx, 0x18(%rsp)
addq $0x70, %rdi
movq 0x8(%rax), %rsi
callq 0x1fb90
movq 0x58(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x18(%rsp), %edx
movq %rax, %rcx
movq 0x48(%rsp), %rax
movl (%rcx), %ecx
movl 0x10(%rax), %r8d
movq 0x78(%rsp), %r9
movl 0xb0(%rsp), %r10d
movl 0xb8(%rsp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1fa80
jmp 0x1b03d
jmp 0x1b120
jmp 0x1aebd
addq $0xa8, %rsp
retq
nopl (%rax)