// File: /workspace/github_cpp_makefile_star2_O1/shangjingbo1226[P]MACFP/src/methods/MACFP.cpp
// Function: expandLeft(int, int, int, int)
vector<int> expandLeft(int leftBound, int l, int x, int remainDistance)
{
    ULL key = leftBound;
    key = key * MAGIC + l;
    key = key * MAGIC + x;
    key = key * MAGIC + remainDistance;
    if (bufferLeft.count(key)) {
        return bufferLeft[key];
    }
    vector<int> best(remainDistance + 1, -1);

    deque< pair<int, PII> > q;
    q.push_back(make_pair(0, make_pair(l - 1, x - 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 < leftBound) {
            if (best[dist] == -1 || best[dist] < v + 1) {
                best[dist] = v + 1;
            }
            continue;
        }

        int rev_u = (int)rev_s->size() - 1 - u;
        int rev_v = (int)rev_s->size() - 1 - v;
        if (u >= leftBound && v >= 0 && rev_s->s[rev_u] == rev_s->s[rev_v]) {
            int lcp = rev_s->sa->lcp(rev_u, rev_v);
            myAssert(u - lcp >= -1, "u-lcp error");
            myAssert(v - lcp >= -1, "v-lcp error");
            lcp = min(lcp, u - leftBound + 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 < leftBound - 1) {
                    break;
                }
                for (int dv = 0; dv <= remainDistance - dist; ++ dv) {
                    if (v - dv < -1) {
                        break;
                    }
                    if (du + dv > 0){
                        if (u - du == leftBound - 1 || v - dv == -1 || rev_s->s[rev_u + du] == rev_s->s[rev_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 bufferLeft[key] = best;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %r8d, %r14d
movl %ecx, %r13d
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %rbx
movslq %esi, %rax
imulq $0xabcdef, %rax, %rax   # imm = 0xABCDEF
movslq %edx, %rcx
addq %rax, %rcx
imulq $0xabcdef, %rcx, %rax   # imm = 0xABCDEF
movslq %r13d, %rcx
addq %rax, %rcx
imulq $0xabcdef, %rcx, %rax   # imm = 0xABCDEF
movslq %r8d, %rcx
addq %rax, %rcx
leaq 0x40(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0x5f69156(%rip), %rdi   # 0x5f6c390
callq 0x8480
testq %rax, %rax
je 0x3265
leaq 0x5f69145(%rip), %rdi   # 0x5f6c390
leaq 0x40(%rsp), %rsi
callq 0x84fc
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5704
jmp 0x377c
leal 0x1(%r14), %eax
movl %eax, 0x2c(%rsp)
movslq %eax, %rsi
leaq 0x60(%rsp), %rbp
movl $0xffffffff, (%rbp)     # imm = 0xFFFFFFFF
leaq 0x48(%rsp), %rdi
leaq 0x10(%rsp), %rcx
movq %rbp, %rdx
callq 0x5632
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rbp)
movaps %xmm0, 0x30(%rbp)
movaps %xmm0, 0x20(%rbp)
movaps %xmm0, 0x10(%rbp)
movaps %xmm0, (%rbp)
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x5dae
movq %r14, 0x30(%rsp)
movq %rbx, 0xb8(%rsp)
decl %r12d
decl %r13d
shlq $0x20, %r13
orq %r13, %r12
movl $0x0, 0x10(%rsp)
movq %r12, 0x14(%rsp)
movq 0x10(%rsp), %rax
movl 0x18(%rsp), %ecx
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
movl %ecx, 0x8(%rsi)
leaq 0x60(%rsp), %rdi
callq 0x8822
movq %r15, 0xc0(%rsp)
leal -0x1(%r15), %eax
cltq
movq %rax, 0x38(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, %rcx
subq 0x88(%rsp), %rcx
sarq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
imulq $0x2a, %rcx, %rax
movq 0x90(%rsp), %rdx
subq 0x98(%rsp), %rdx
sarq $0x2, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
addq %rax, %rdx
movq 0x70(%rsp), %rax
movq 0x80(%rsp), %rcx
movq %rcx, %rsi
subq %rax, %rsi
sarq $0x2, %rsi
movabsq $0x5555555555555555, %rdi # imm = 0x5555555555555555
imulq %rdi, %rsi
cmpq %rsi, %rdx
je 0x36f5
movl (%rax), %edx
movl %edx, 0xc(%rsp)
movl 0x4(%rax), %ebx
movslq 0x8(%rax), %r15
addq $-0xc, %rcx
cmpq %rcx, %rax
je 0x339b
addq $0xc, %rax
jmp 0x33d6
movq 0x78(%rsp), %rdi
movl $0x1f8, %esi            # imm = 0x1F8
callq 0x21f0
movq 0x88(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x88(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x78(%rsp)
leaq 0x1f8(%rax), %rcx
movq %rcx, 0x80(%rsp)
movslq 0xc(%rsp), %rcx
movq %rax, 0x70(%rsp)
movq 0x48(%rsp), %rax
movl (%rax,%rcx,4), %edx
cmpl $-0x1, %edx
setne %sil
cmpl %r15d, %edx
setg %dil
testb %dil, %sil
jne 0x3309
movl %ebx, %ebp
subl 0xc0(%rsp), %ebp
jge 0x342c
cmpl $-0x1, %edx
setne %sil
cmpl %r15d, %edx
setg %dl
testb %dl, %sil
jne 0x3309
incl %r15d
movl %r15d, (%rax,%rcx,4)
jmp 0x3309
movq 0x5f68f3d(%rip), %rcx   # 0x5f6c370
movl 0x8(%rcx), %edx
movl %ebx, %eax
notl %eax
addl %edx, %eax
movq %r15, %rsi
movl %esi, %edi
notl %edi
addl %edx, %edi
testl %esi, %esi
js 0x3597
movslq %eax, %rsi
movq (%rcx), %r8
movb (%r8,%rsi), %r9b
movslq %edi, %rdx
cmpb (%r8,%rdx), %r9b
jne 0x3597
movq %rbx, %r12
movq 0x20(%rcx), %rdi
callq 0x5784
movq %rax, %r13
leaq 0x128(%rsp), %r14
movq %r14, 0x118(%rsp)
leaq 0x118(%rsp), %rbx
movq %rbx, %rdi
leaq 0x6c32(%rip), %rsi      # 0xa0c7
leaq 0x6c36(%rip), %rdx      # 0xa0d2
callq 0x809c
movl %r12d, %eax
subl %r13d, %eax
xorl %edi, %edi
cmpl $-0x1, %eax
setge %dil
movq %rbx, %rsi
callq 0x28d7
leaq 0xf8(%rsp), %rbx
movq 0x118(%rsp), %rdi
cmpq %r14, %rdi
je 0x34dd
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x108(%rsp), %r14
movq %r14, 0xf8(%rsp)
movq %rbx, %rdi
leaq 0x6bdc(%rip), %rsi      # 0xa0d3
leaq 0x6be0(%rip), %rdx      # 0xa0de
callq 0x809c
movl %r15d, %eax
subl %r13d, %eax
xorl %edi, %edi
cmpl $-0x1, %eax
setge %dil
movq %rbx, %rsi
callq 0x28d7
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3537
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x21f0
incl %ebp
cmpl %r13d, %ebp
cmovgel %r13d, %ebp
subl %ebp, %r12d
subl %ebp, %r15d
shlq $0x20, %r15
orq %r15, %r12
movl 0xc(%rsp), %eax
movl %eax, 0x10(%rsp)
movq %r12, 0x14(%rsp)
movq 0x10(%rsp), %rax
movl 0x18(%rsp), %ecx
movq %rax, 0x20(%rsp)
movl %ecx, 0x28(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x78(%rsp), %rax
je 0x36e1
movl 0x28(%rsp), %ecx
movl %ecx, -0x4(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, -0xc(%rax)
addq $-0xc, 0x70(%rsp)
jmp 0x3309
movl 0xc(%rsp), %ecx
cmpl 0x30(%rsp), %ecx
jg 0x3309
movslq %ebx, %rcx
movq %rcx, 0xd0(%rsp)
movslq %edi, %rcx
movq %rcx, 0xe8(%rsp)
movq %r15, %rdx
cmpl $-0x2, %edx
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
cmovll %edx, %ecx
subl %ecx, %r15d
cltq
movq %rax, 0xe0(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, %r13d
subl 0xc(%rsp), %r13d
movq %rdx, %rax
shlq $0x20, %rax
movq %rax, 0xc8(%rsp)
incq %rdx
movq %rdx, 0xf0(%rsp)
xorl %r12d, %r12d
movl %ebx, %ebp
addq 0xc8(%rsp), %rbp
movq 0xd0(%rsp), %r14
subq %r12, %r14
cmpq 0x38(%rsp), %r14
jl 0x3309
movq %rbx, 0xd8(%rsp)
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x36c6
movl %ebx, %eax
orl %r12d, %eax
je 0x36ad
cmpq 0x38(%rsp), %r14
sete %al
cmpq %rbx, 0xf0(%rsp)
sete %cl
orb %al, %cl
jne 0x3676
movq 0x5f68d19(%rip), %rax   # 0x5f6c370
movq (%rax), %rax
leaq (%rax,%r12), %rcx
movq 0xe0(%rsp), %rdx
movb (%rdx,%rcx), %cl
addq 0xe8(%rsp), %rax
cmpb (%rbx,%rax), %cl
jne 0x36ad
cmpl %ebx, %r12d
movl %ebx, %eax
cmoval %r12d, %eax
addl 0xc(%rsp), %eax
movl %eax, 0x10(%rsp)
movq %rbp, 0x14(%rsp)
movq 0x10(%rsp), %rax
movl 0x18(%rsp), %ecx
movq %rax, 0x20(%rsp)
movl %ecx, 0x28(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x8822
incq %rbx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rax, %rbp
cmpq %rbx, %r13
jne 0x3629
incq %r12
movq 0xd8(%rsp), %rbx
decl %ebx
cmpq %r13, %r12
jne 0x35ff
jmp 0x3309
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x8a9e
jmp 0x3309
movq 0x30(%rsp), %rcx
testl %ecx, %ecx
movq 0xb8(%rsp), %rbx
jle 0x3732
movq 0x48(%rsp), %rax
movl %ecx, %ecx
xorl %edx, %edx
movl (%rax,%rdx,4), %esi
cmpl $-0x1, %esi
je 0x372a
movl 0x4(%rax,%rdx,4), %edi
cmpl $-0x1, %edi
je 0x3724
cmpl %esi, %edi
jg 0x372a
incl %esi
movl %esi, 0x4(%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x370f
leaq 0x5f68c57(%rip), %rdi   # 0x5f6c390
leaq 0x40(%rsp), %rsi
callq 0x84fc
leaq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x57c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5704
leaq 0x60(%rsp), %rdi
callq 0x87d2
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x377c
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %rbx, %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x37de
jmp 0x37de
movq %rax, %rbx
jmp 0x37eb
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x37e1
movq 0x108(%rsp), %rsi
jmp 0x37ce
jmp 0x37de
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %r14, %rdi
je 0x37e1
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x37e1
jmp 0x37de
jmp 0x37de
jmp 0x37de
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x87d2
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3802
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2330