// File: 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
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rdi, -0x1c8(%rbp)
movq %rdi, %rax
movq %rax, -0x1c0(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movslq -0xc(%rbp), %rax
movq %rax, -0x20(%rbp)
imulq $0xabcdef, -0x20(%rbp), %rax # imm = 0xABCDEF
movslq -0x10(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
imulq $0xabcdef, -0x20(%rbp), %rax # imm = 0xABCDEF
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
imulq $0xabcdef, -0x20(%rbp), %rax # imm = 0xABCDEF
movslq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
leaq 0x5f82bdb(%rip), %rdi   # 0x5f87430
leaq -0x20(%rbp), %rsi
callq 0x8780
cmpq $0x0, %rax
je 0x4888
leaq 0x5f82bc5(%rip), %rdi   # 0x5f87430
leaq -0x20(%rbp), %rsi
callq 0x87b0
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
callq 0x87e0
jmp 0x51ef
movl -0x18(%rbp), %eax
incl %eax
cltq
movq %rax, -0x1d8(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
leaq -0x3d(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x84b0
movq -0x1d8(%rbp), %rsi
movq -0x1d0(%rbp), %rcx
leaq -0x38(%rbp), %rdi
leaq -0x3c(%rbp), %rdx
callq 0x84d0
jmp 0x48ca
leaq -0x3d(%rbp), %rdi
callq 0x8550
leaq -0xa0(%rbp), %rdi
callq 0x88d0
jmp 0x48e1
movl $0x0, -0xb4(%rbp)
movl -0x10(%rbp), %eax
decl %eax
movl %eax, -0xc0(%rbp)
movl -0x14(%rbp), %eax
decl %eax
movl %eax, -0xc4(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc4(%rbp), %rsi
callq 0x8960
movq %rax, -0x1e0(%rbp)
jmp 0x491d
movq -0x1e0(%rbp), %rax
movq %rax, -0xbc(%rbp)
leaq -0xb4(%rbp), %rdi
leaq -0xbc(%rbp), %rsi
callq 0x8920
movl %edx, -0x1ec(%rbp)
movq %rax, -0x1e8(%rbp)
jmp 0x494d
movl -0x1ec(%rbp), %eax
movq -0x1e8(%rbp), %rcx
movq %rcx, -0xd8(%rbp)
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x88f0
jmp 0x4996
jmp 0x4998
leaq -0xa0(%rbp), %rdi
callq 0x8990
cmpq $0x0, %rax
je 0x509f
leaq -0xa0(%rbp), %rdi
callq 0x89c0
movl (%rax), %eax
movl %eax, -0xdc(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x89c0
movl 0x4(%rax), %eax
movl %eax, -0xe0(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x89c0
movl 0x8(%rax), %eax
movl %eax, -0xe4(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x89f0
movslq -0xdc(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
cmpl $-0x1, (%rax)
je 0x4a6d
movslq -0xdc(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl (%rax), %eax
movl -0xe4(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jl 0x4a6d
jmp 0x4998
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x3d(%rbp), %rdi
callq 0x8550
jmp 0x51ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x51e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x51d8
movl -0xe0(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4ad8
movslq -0xdc(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
cmpl $-0x1, (%rax)
je 0x4aac
movslq -0xdc(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl (%rax), %eax
movl -0xe4(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4ad3
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1f0(%rbp)
movslq -0xdc(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl -0x1f0(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x4998
movq 0x5f82931(%rip), %rdi   # 0x5f87410
callq 0x8620
movq %rax, -0x1f8(%rbp)
jmp 0x4aed
movq -0x1f8(%rbp), %rax
movl %eax, %ecx
movl -0xe0(%rbp), %eax
notl %eax
addl %ecx, %eax
movl %eax, -0xe8(%rbp)
movq 0x5f82903(%rip), %rdi   # 0x5f87410
callq 0x8620
movq %rax, -0x200(%rbp)
jmp 0x4b1b
movq -0x200(%rbp), %rax
subl $0x1, %eax
subl -0xe4(%rbp), %eax
movl %eax, -0xec(%rbp)
movl -0xe0(%rbp), %eax
cmpl -0xc(%rbp), %eax
jl 0x4e45
cmpl $0x0, -0xe4(%rbp)
jl 0x4e45
movq 0x5f828bc(%rip), %rdi   # 0x5f87410
movslq -0xe8(%rbp), %rsi
callq 0x3490
movq %rax, -0x208(%rbp)
jmp 0x4b69
movq -0x208(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x214(%rbp)
movq 0x5f82890(%rip), %rdi   # 0x5f87410
movslq -0xec(%rbp), %rsi
callq 0x3490
movq %rax, -0x210(%rbp)
jmp 0x4b95
movl -0x214(%rbp), %eax
movq -0x210(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x4e45
movq 0x5f8285c(%rip), %rax   # 0x5f87410
movq 0x20(%rax), %rdi
movslq -0xe8(%rbp), %rsi
movslq -0xec(%rbp), %rdx
callq 0x8a60
movq %rax, -0x220(%rbp)
jmp 0x4bd4
movq -0x220(%rbp), %rax
movl %eax, -0xf0(%rbp)
movl -0xe0(%rbp), %eax
movl -0xf0(%rbp), %ecx
subl %ecx, %eax
subl $-0x1, %eax
setge %al
movb %al, -0x229(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x3430
movq -0x228(%rbp), %rdx
leaq 0x174b4(%rip), %rsi     # 0x1c0d0
leaq -0x110(%rbp), %rdi
callq 0x8300
jmp 0x4c2a
movb -0x229(%rbp), %al
movzbl %al, %edi
andl $0x1, %edi
leaq -0x110(%rbp), %rsi
callq 0x3a80
jmp 0x4c44
leaq -0x110(%rbp), %rdi
callq 0x34a8
leaq -0x111(%rbp), %rdi
callq 0x32c0
movl -0xe4(%rbp), %eax
movl -0xf0(%rbp), %ecx
subl %ecx, %eax
subl $-0x1, %eax
setge %al
movb %al, -0x239(%rbp)
leaq -0x139(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x3430
movq -0x238(%rbp), %rdx
leaq 0x17445(%rip), %rsi     # 0x1c0dc
leaq -0x138(%rbp), %rdi
callq 0x8300
jmp 0x4ca5
movb -0x239(%rbp), %al
movzbl %al, %edi
andl $0x1, %edi
leaq -0x138(%rbp), %rsi
callq 0x3a80
jmp 0x4cbf
leaq -0x138(%rbp), %rdi
callq 0x34a8
leaq -0x139(%rbp), %rdi
callq 0x32c0
movl -0xe0(%rbp), %eax
movl -0xc(%rbp), %ecx
subl %ecx, %eax
incl %eax
movl %eax, -0x140(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x8b30
movq %rax, -0x248(%rbp)
jmp 0x4d06
movq -0x248(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xf0(%rbp)
movl -0xe0(%rbp), %eax
movl -0xf0(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x15c(%rbp)
movl -0xe4(%rbp), %eax
movl -0xf0(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x160(%rbp)
leaq -0x15c(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x8960
movq %rax, -0x250(%rbp)
jmp 0x4d59
movq -0x250(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0xdc(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x8ba0
movl %edx, -0x25c(%rbp)
movq %rax, -0x258(%rbp)
jmp 0x4d89
movl -0x25c(%rbp), %eax
movq -0x258(%rbp), %rcx
movq %rcx, -0x170(%rbp)
movl %eax, -0x168(%rbp)
movl -0x168(%rbp), %eax
movl %eax, -0x148(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x8b70
jmp 0x4dd2
jmp 0x509a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x4dfd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x34a8
leaq -0x111(%rbp), %rdi
callq 0x32c0
jmp 0x51d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x4e34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x34a8
leaq -0x139(%rbp), %rdi
callq 0x32c0
jmp 0x51d8
movl $0x0, -0x174(%rbp)
movl -0x174(%rbp), %eax
movl -0x18(%rbp), %ecx
subl -0xdc(%rbp), %ecx
cmpl %ecx, %eax
jg 0x5098
movl -0xe0(%rbp), %eax
subl -0x174(%rbp), %eax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4e81
jmp 0x5098
movl $0x0, -0x178(%rbp)
movl -0x178(%rbp), %eax
movl -0x18(%rbp), %ecx
subl -0xdc(%rbp), %ecx
cmpl %ecx, %eax
jg 0x5082
movl -0xe4(%rbp), %eax
subl -0x178(%rbp), %eax
cmpl $-0x1, %eax
jge 0x4eb8
jmp 0x5082
movl -0x174(%rbp), %eax
addl -0x178(%rbp), %eax
cmpl $0x0, %eax
jle 0x506c
movl -0xe0(%rbp), %eax
subl -0x174(%rbp), %eax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x4f6c
movl -0xe4(%rbp), %eax
subl -0x178(%rbp), %eax
cmpl $-0x1, %eax
je 0x4f6c
movq 0x5f82511(%rip), %rdi   # 0x5f87410
movl -0xe8(%rbp), %eax
movl -0x174(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x3490
movq %rax, -0x268(%rbp)
jmp 0x4f1e
movq -0x268(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x274(%rbp)
movq 0x5f824db(%rip), %rdi   # 0x5f87410
movl -0xec(%rbp), %eax
movl -0x178(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x3490
movq %rax, -0x270(%rbp)
jmp 0x4f54
movl -0x274(%rbp), %eax
movq -0x270(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x506a
movl -0xdc(%rbp), %eax
movl %eax, -0x284(%rbp)
leaq -0x174(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x8be0
movq %rax, -0x280(%rbp)
jmp 0x4f94
movl -0x284(%rbp), %eax
movq -0x280(%rbp), %rcx
movl (%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x18c(%rbp)
movl -0xe0(%rbp), %eax
movl -0x174(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x198(%rbp)
movl -0xe4(%rbp), %eax
movl -0x178(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x19c(%rbp)
leaq -0x198(%rbp), %rdi
leaq -0x19c(%rbp), %rsi
callq 0x8960
movq %rax, -0x290(%rbp)
jmp 0x4fef
movq -0x290(%rbp), %rax
movq %rax, -0x194(%rbp)
leaq -0x18c(%rbp), %rdi
leaq -0x194(%rbp), %rsi
callq 0x8920
movl %edx, -0x29c(%rbp)
movq %rax, -0x298(%rbp)
jmp 0x501f
movl -0x29c(%rbp), %eax
movq -0x298(%rbp), %rcx
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1a8(%rbp)
movl -0x1a8(%rbp), %eax
movl %eax, -0x180(%rbp)
movq -0x1b0(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x88f0
jmp 0x5068
jmp 0x506a
jmp 0x506c
jmp 0x506e
movl -0x178(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x178(%rbp)
jmp 0x4e8b
jmp 0x5084
movl -0x174(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x174(%rbp)
jmp 0x4e4f
jmp 0x509a
jmp 0x4998
movl $0x0, -0x1b4(%rbp)
movl -0x1b4(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x517a
movslq -0x1b4(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
cmpl $-0x1, (%rax)
je 0x5164
movl -0x1b4(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
cmpl $-0x1, (%rax)
je 0x512a
movl -0x1b4(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl (%rax), %eax
movl %eax, -0x2a0(%rbp)
movslq -0x1b4(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movq %rax, %rcx
movl -0x2a0(%rbp), %eax
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x5162
movslq -0x1b4(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x2a4(%rbp)
movl -0x1b4(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl -0x2a4(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x5164
jmp 0x5166
movl -0x1b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b4(%rbp)
jmp 0x50a9
leaq 0x5f822af(%rip), %rdi   # 0x5f87430
leaq -0x20(%rbp), %rsi
callq 0x87b0
movq %rax, -0x2b0(%rbp)
jmp 0x5193
movq -0x2b0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8c20
movq %rax, -0x2b8(%rbp)
jmp 0x51ac
movq -0x2b8(%rbp), %rsi
movq -0x1c8(%rbp), %rdi
callq 0x87e0
jmp 0x51c1
leaq -0xa0(%rbp), %rdi
callq 0x8e70
leaq -0x38(%rbp), %rdi
callq 0x8640
jmp 0x51ef
leaq -0xa0(%rbp), %rdi
callq 0x8e70
leaq -0x38(%rbp), %rdi
callq 0x8640
jmp 0x51ff
movq -0x1c0(%rbp), %rax
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3420
nopl (%rax,%rax)