// File: /workspace/github_cpp_makefile_star2_O2/shangjingbo1226[P]MACFP/src/methods/MACFP.cpp
// Function: expandRight(int, int, int, int)
vector<int> expandRight(int rightBound, int r, int y, int remainDistance)
{
    ULL key = rightBound;
    key = key * MAGIC + r;
    key = key * MAGIC + y;
    key = key * MAGIC + remainDistance;
    if (bufferRight.count(key)) {
        return bufferRight[key];
    }
    vector<int> best(remainDistance + 1, -1);

    deque< pair<int, PII> > q;
    q.push_front(make_pair(0, make_pair(r + 1, y + 1)));
    while (q.size()) {
        int dist = q.front().first;
        int u = q.front().second.first;
        int v = q.front().second.second;
        q.pop_front();

        if (best[dist] != -1 && best[dist] <= v - 1) {
            continue;
        }

        if (u > rightBound) {
            if (best[dist] == -1 || best[dist] > v - 1) {
                best[dist] = v - 1;
            }
            continue;
        }

        if (u <= rightBound && v < s->size() && s->s[u] == s->s[v]) {
            int lcp = s->sa->lcp(u, v);
            myAssert(u + lcp <= s->size(), "u+lcp error");
            myAssert(v + lcp <= s->size(), "v+lcp error");
            lcp = min(lcp, rightBound - u + 1);
            q.push_front(make_pair(dist, make_pair(u + lcp, v + lcp)));
        } else {
            for (int du = 0; du <= remainDistance - dist; ++ du) {
                if (u + du > rightBound + 1) {
                    break;
                }
                for (int dv = 0; dv <= remainDistance - dist; ++ dv) {
                    if (v + dv > s->size()) {
                        break;
                    }
                    if (du + dv > 0){
                        if (u + du == rightBound + 1 || v + dv == s->size() || s->s[u + du] == s->s[v + dv]) {
                            q.push_back(make_pair(dist + max(du, dv), make_pair(u + du, v + dv)));
                        }
                    }
                }
            }
        }
    }
    for (int i = 0; i < remainDistance; ++ i) {
        if (best[i] != -1) {
            if (best[i + 1] == -1 || best[i + 1] > best[i] - 1) {
                best[i + 1] = best[i] - 1;
            }
        }
    }
    return bufferRight[key] = best;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl %r8d, %r15d
movl %ecx, %ebx
movl %edx, %r12d
movl %esi, %r13d
movq %rdi, %r14
movslq %esi, %rax
imulq $0xabcdef, %rax, %rax   # imm = 0xABCDEF
movslq %edx, %rcx
addq %rax, %rcx
imulq $0xabcdef, %rcx, %rax   # imm = 0xABCDEF
movslq %ebx, %rcx
addq %rax, %rcx
imulq $0xabcdef, %rcx, %rax   # imm = 0xABCDEF
movslq %r8d, %rcx
addq %rax, %rcx
leaq 0x38(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0x5f69090(%rip), %rdi   # 0x5f6c3c8
callq 0x78da
testq %rax, %rax
je 0x3363
leaq 0x5f6907f(%rip), %rdi   # 0x5f6c3c8
leaq 0x38(%rsp), %rsi
callq 0x796a
movq %r14, %rdi
movq %rax, %rsi
callq 0x4a0c
jmp 0x36f0
leal 0x1(%r15), %eax
movslq %eax, %rsi
leaq 0x88(%rsp), %rdx
orl $-0x1, (%rdx)
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rcx
callq 0x4970
leaq 0x88(%rsp), %rdi
callq 0x4fec
movq %r15, 0x28(%rsp)
movq %r14, 0x40(%rsp)
incl %r12d
incl %ebx
movq %rbx, %rax
shlq $0x20, %rax
orq %rax, %r12
andl $0x0, 0x8(%rsp)
movq %r12, 0xc(%rsp)
movq 0x8(%rsp), %rax
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
movl %ebx, 0x8(%rsi)
leaq 0x88(%rsp), %rdi
callq 0x7f62
movq %r13, 0x30(%rsp)
leal 0x1(%r13), %eax
movl %eax, 0x14(%rsp)
cltq
movq %rax, 0x48(%rsp)
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0x4a5a
testq %rax, %rax
je 0x3675
movq 0x98(%rsp), %rax
movl (%rax), %ebp
movl 0x4(%rax), %r15d
movslq 0x8(%rax), %r13
movq %rbx, %rdi
callq 0x4a6a
movl %ebp, 0x4(%rsp)
movslq %ebp, %rax
movq 0x70(%rsp), %rcx
movl (%rcx,%rax,4), %edx
cmpl $-0x1, %edx
je 0x355c
cmpl %r13d, %edx
movabsq $0x100000000, %rdi      # imm = 0x100000000
jl 0x33e5
cmpl 0x30(%rsp), %r15d
jg 0x3571
movslq %r15d, %rsi
movq 0x5f68f14(%rip), %rax   # 0x5f6c368
cmpq %r13, 0x8(%rax)
jbe 0x357d
movq (%rax), %rcx
movb (%rcx,%rsi), %dl
cmpb (%rcx,%r13), %dl
jne 0x357d
movq %r15, %r12
movq 0x20(%rax), %rdi
movq %r13, %rdx
callq 0x4a88
movq %rax, %rbp
movq 0x5f68ee1(%rip), %rax   # 0x5f6c368
movq 0x8(%rax), %rbx
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
leaq 0x5c47(%rip), %rsi      # 0x90e4
leaq 0x8(%rsp), %r15
movq %r15, %rdx
callq 0x48da
leal (%r12,%rbp), %eax
cltq
xorl %edi, %edi
cmpq %rax, %rbx
setae %dil
movq %r14, %rsi
callq 0x272c
movq %r14, %rdi
callq 0x2378
movq 0x5f68e98(%rip), %rax   # 0x5f6c368
movq 0x8(%rax), %rbx
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
leaq 0x5c0a(%rip), %rsi      # 0x90f0
movq %r15, %rdx
callq 0x48da
leal (%r13,%rbp), %eax
cltq
xorl %edi, %edi
cmpq %rax, %rbx
setae %dil
movq %r14, %rsi
callq 0x272c
movq %r14, %rdi
callq 0x2378
movl 0x14(%rsp), %eax
subl %r12d, %eax
cmpl %ebp, %eax
cmovgel %ebp, %eax
addl %eax, %r12d
addl %r13d, %eax
movq %rax, %rcx
shlq $0x20, %rcx
orq %rcx, %r12
movl 0x4(%rsp), %ecx
movl %ecx, 0x8(%rsp)
movq %r12, 0xc(%rsp)
movq 0x8(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movl %eax, 0x20(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x7f62
jmp 0x33e5
cmpl 0x30(%rsp), %r15d
movabsq $0x100000000, %rdi      # imm = 0x100000000
jle 0x344a
decl %r13d
movl %r13d, (%rcx,%rax,4)
jmp 0x33e5
movq 0x28(%rsp), %rax
subl 0x4(%rsp), %eax
movslq %eax, %r12
movq %r13, %rax
shlq $0x20, %rax
movq %rax, 0x58(%rsp)
movl %r13d, %eax
movq %rax, 0x68(%rsp)
xorl %r14d, %r14d
movq %rsi, 0x50(%rsp)
movq %r15, 0x60(%rsp)
movl %r15d, %ebx
addq 0x58(%rsp), %rbx
cmpq %r12, %r14
jg 0x33e5
leaq (%r14,%rsi), %r15
cmpq 0x48(%rsp), %r15
jg 0x33e5
xorl %ebp, %ebp
cmpq %r12, %rbp
jg 0x3660
movq %r13, %rcx
addq %rbp, %rcx
movq 0x5f68d86(%rip), %rax   # 0x5f6c368
movq 0x8(%rax), %rdx
cmpq %rcx, %rdx
jb 0x3660
movl %ebp, %esi
orl %r14d, %esi
je 0x3655
cmpl %r15d, 0x14(%rsp)
je 0x360e
cmpq %rdx, %rcx
je 0x360e
movq (%rax), %rax
movb (%rax,%r15), %cl
addq %r13, %rax
cmpb (%rbp,%rax), %cl
jne 0x3655
cmpl %ebp, %r14d
movl %ebp, %eax
cmoval %r14d, %eax
addl 0x4(%rsp), %eax
movq 0x68(%rsp), %rcx
addl %ebp, %ecx
movl %eax, 0x8(%rsp)
movq %rbx, 0xc(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
movl %ecx, 0x20(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x7cc2
movabsq $0x100000000, %rdi      # imm = 0x100000000
incq %rbp
addq %rdi, %rbx
jmp 0x35cc
incq %r14
movq 0x60(%rsp), %r15
incl %r15d
movq 0x50(%rsp), %rsi
jmp 0x35a5
movq 0x70(%rsp), %rax
xorl %ecx, %ecx
movq 0x28(%rsp), %rdi
testl %edi, %edi
cmovlel %ecx, %edi
movq 0x40(%rsp), %r14
cmpq %rcx, %rdi
je 0x36b0
movl (%rax,%rcx,4), %edx
cmpl $-0x1, %edx
je 0x36ab
movl 0x4(%rax,%rcx,4), %esi
cmpl $-0x1, %esi
je 0x36a5
cmpl %edx, %esi
jl 0x36ab
decl %edx
movl %edx, 0x4(%rax,%rcx,4)
incq %rcx
jmp 0x368b
leaq 0x5f68d11(%rip), %rdi   # 0x5f6c3c8
leaq 0x38(%rsp), %rsi
callq 0x796a
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x4ac4
movq %r14, %rdi
movq %rax, %rsi
callq 0x4a0c
leaq 0x88(%rsp), %rdi
callq 0x7c94
leaq 0x70(%rsp), %rdi
callq 0x66a2
movq %r14, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3735
movq %rax, %rbx
jmp 0x3745
jmp 0x3735
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
jmp 0x3728
jmp 0x3735
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x2378
jmp 0x3738
jmp 0x3735
jmp 0x3735
jmp 0x3735
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x7c94
leaq 0x70(%rsp), %rdi
callq 0x66a2
movq %rbx, %rdi
callq 0x2310