// File: /workspace/github_cpp_makefile_star2_O3/shangjingbo1226[P]MACFP/src/methods/MACFP.cpp
// Function: enumerateEdit(int, int, int, int, int, int, int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>&)
bool enumerateEdit(int ptr, int length, int l, int r, int left, int right, int remainDist, vector<PII> &ret)
{
    if (remainDist == 0 && left == right) {
        return false;
    }
    if (ptr == r + 1) {
        ULL key = (left * MAGIC + right) * MAGIC + length;
        if (checked.count(key)) {
            return false;
        }
        checked.insert(key);
        for (int i = left; i <= right; ++ i) {
            int start = s->sa->sa[i];
            int end = s->sa->sa[i] + length - 1;
            if (max(start, l) > min(end, r)) {
                ret.push_back(make_pair(start, end));
            }
        }
        if (makeMaximal(ret).size() >= MIN_SUP) {
            return true;
        }
    }
    int last[alphabet.size()];
    for (int i = 0; i < alphabet.size(); ++ i) {
        int l = (i == 0) ? left - 1 : last[i - 1];
        int r = right + 1;
        while (l + 1 < r) {
            int mid = l + r >> 1;
            int index = s->sa->sa[mid] + length;
            if (index < s->size() && alphabet[i] < s->s[index]) {
                r = mid;
            } else {
                l = mid;
            }
        }
        last[i] = l;
    }
    for (int i = 0; i < alphabet.size(); ++ i) {
        int new_left = (i == 0) ? left : last[i - 1] + 1;
        while (s->sa->sa[new_left] + length == s->size()) {
            ++ new_left;
        }
        int new_right = last[i];

        if (new_left > new_right) {
            continue;
        }
        myAssert(s->s[s->sa->sa[new_left] + length] == alphabet[i], "index error");
        myAssert(s->s[s->sa->sa[new_right] + length] == alphabet[i], "index error");

        // replace
        if (ptr <= r && remainDist >= (s->s[ptr] != alphabet[i])) {
            if (enumerateEdit(ptr + 1, length + 1, l, r, new_left, new_right, remainDist - (s->s[ptr] != alphabet[i]), ret)) {
                return true;
            }
        }
        //insert
        if (remainDist > 0) {
            if (enumerateEdit(ptr, length + 1, l, r, new_left, new_right, remainDist - 1, ret)) {
                return true;
            }
        }
    }
    // delete
    if (remainDist > 0 && ptr <= r) {
        if (enumerateEdit(ptr + 1, length, l, r, left, right, remainDist - 1, ret)) {
            return true;
        }
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %edx, -0x2c(%rbp)
movl 0x10(%rbp), %edx
movl %r8d, %eax
xorl %r9d, %eax
orl %edx, %eax
jne 0x45d3
xorl %r12d, %r12d
jmp 0x4a7c
movl %r9d, %r14d
leal 0x1(%rcx), %eax
movq %rdi, -0x68(%rbp)
cmpl %edi, %eax
movq %r8, -0x40(%rbp)
movq %rcx, -0x38(%rbp)
movq %rsi, -0x60(%rbp)
jne 0x4724
movslq %r8d, %rbx
imulq $0xabcdef, %rbx, %rax   # imm = 0xABCDEF
movslq %r14d, %rcx
addq %rax, %rcx
imulq $0xabcdef, %rcx, %rax   # imm = 0xABCDEF
movslq %esi, %rcx
addq %rax, %rcx
leaq -0xc0(%rbp), %rsi
movq %rcx, (%rsi)
leaq 0x5f67e21(%rip), %r13   # 0x5f6c440
movq %r8, %r15
movq %r13, %rdi
callq 0x92a0
testq %rax, %rax
sete %r12b
jne 0x4a7c
leaq -0xf8(%rbp), %rdx
movq %r13, (%rdx)
leaq -0xc0(%rbp), %rsi
movq %r13, %rdi
callq 0x92fc
movq %r14, -0x48(%rbp)
cmpl %r14d, %r15d
movq -0x38(%rbp), %r8
jg 0x46d2
movq -0x60(%rbp), %rax
leal -0x1(%rax), %r14d
movq 0x5f67cfc(%rip), %rax   # 0x5f6c368
movq -0x48(%rbp), %rcx
movl %ecx, %r15d
subl -0x40(%rbp), %r15d
incl %r15d
leaq -0xf8(%rbp), %r13
movq 0x20(%rax), %rcx
movq 0x28(%rcx), %rcx
movl (%rcx,%rbx,4), %ecx
leal (%r14,%rcx), %edx
movl -0x2c(%rbp), %esi
cmpl %esi, %ecx
cmovgl %ecx, %esi
cmpl %r8d, %edx
movl %r8d, %edi
cmovll %edx, %edi
cmpl %edi, %esi
jle 0x46ca
shlq $0x20, %rdx
orq %rcx, %rdx
movq %rdx, -0xf8(%rbp)
movq 0x18(%rbp), %rdi
movq %r13, %rsi
callq 0x958a
movq -0x38(%rbp), %r8
movq 0x5f67c9e(%rip), %rax   # 0x5f6c368
incq %rbx
decl %r15d
jne 0x4681
leaq -0xf8(%rbp), %r13
movq %r13, %rdi
movq 0x18(%rbp), %rsi
callq 0x2815
movq (%r13), %rdi
movq 0x8(%r13), %rbx
subq %rdi, %rbx
sarq $0x3, %rbx
movslq 0x9ad1(%rip), %r14      # 0xe1cc
testq %rdi, %rdi
je 0x470f
movq -0xe8(%rbp), %rsi
subq %rdi, %rsi
callq 0x21f0
cmpq %r14, %rbx
movq -0x48(%rbp), %r14
movq -0x40(%rbp), %r8
jae 0x4a7c
movq -0x38(%rbp), %rcx
movq %r14, -0x48(%rbp)
movq %rsp, -0xa8(%rbp)
movq 0x5f67c1a(%rip), %rax   # 0x5f6c350
movq %rsp, %r14
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq 0x5f67bfe(%rip), %rax   # 0x5f6c350
testq %rax, %rax
je 0x4a31
leal -0x1(%r8), %ecx
movq -0x48(%rbp), %rdx
incl %edx
movl %edx, -0x50(%rbp)
movq 0x5f67bf9(%rip), %rsi   # 0x5f6c368
movq 0x5f67bd2(%rip), %rdi   # 0x5f6c348
xorl %r8d, %r8d
movslq -0x60(%rbp), %r15
movq %r14, -0x80(%rbp)
movl %ecx, %r9d
testq %r8, %r8
je 0x478e
movl -0x4(%r14,%r8,4), %r9d
cmpl -0x48(%rbp), %r9d
jge 0x47d8
movq 0x8(%rsi), %r10
movq 0x20(%rsi), %r11
movq 0x28(%r11), %r11
movl -0x50(%rbp), %edx
movl %edx, %ebx
leal (%rbx,%r9), %r14d
sarl %r14d
movslq %r14d, %r12
movslq (%r11,%r12,4), %r12
addq %r15, %r12
cmpq %r12, %r10
jbe 0x47cd
movb (%rdi,%r8), %r13b
movq (%rsi), %rdx
cmpb (%rdx,%r12), %r13b
jge 0x47cd
movl %r14d, %ebx
jmp 0x47d0
movl %r14d, %r9d
leal 0x1(%r9), %edx
cmpl %ebx, %edx
jl 0x47a5
movq -0x80(%rbp), %r14
movl %r9d, (%r14,%r8,4)
incq %r8
cmpq %rax, %r8
jne 0x4781
leaq -0x90(%rbp), %r9
movq -0x68(%rbp), %rax
movslq %eax, %rcx
movq %rcx, -0xb8(%rbp)
incl %eax
movl %eax, -0x6c(%rbp)
movq -0x60(%rbp), %rax
incl %eax
movl %eax, -0x54(%rbp)
movl 0x10(%rbp), %eax
decl %eax
movq %rax, -0xb0(%rbp)
xorl %ebx, %ebx
movq -0x40(%rbp), %r8
movq -0x38(%rbp), %rcx
movq %r9, -0x78(%rbp)
movl %r8d, %edx
testq %rbx, %rbx
je 0x4834
movl -0x4(%r14,%rbx,4), %edx
incl %edx
movq 0x5f67b2d(%rip), %rax   # 0x5f6c368
movq 0x8(%rax), %rdi
movq 0x20(%rax), %rsi
movslq %edx, %rdx
leal -0x1(%rdx), %r12d
shlq $0x2, %rdx
addq 0x28(%rsi), %rdx
movslq (%rdx), %rsi
addq %r15, %rsi
incl %r12d
addq $0x4, %rdx
cmpq %rsi, %rdi
je 0x4852
movslq (%r14,%rbx,4), %rdi
movq %rdi, -0x50(%rbp)
cmpl %r12d, %edi
jl 0x4a21
movq (%rax), %rax
movb (%rax,%rsi), %al
movq 0x5f67ac6(%rip), %rcx   # 0x5f6c348
xorl %r14d, %r14d
cmpb (%rcx,%rbx), %al
movq %r9, -0xa0(%rbp)
sete %r14b
leaq -0xa0(%rbp), %rdi
leaq 0x58ac(%rip), %rsi      # 0xa14d
leaq 0x58b0(%rip), %rdx      # 0xa158
movq %r9, %r13
callq 0x87ec
movl %r14d, %edi
leaq -0xa0(%rbp), %rsi
callq 0x2920
movq -0xa0(%rbp), %rdi
cmpq %r13, %rdi
je 0x48da
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x21f0
movq 0x5f67a87(%rip), %rax   # 0x5f6c368
movq (%rax), %rcx
movq 0x20(%rax), %rax
movq 0x28(%rax), %rax
movq -0x50(%rbp), %rdx
movslq (%rax,%rdx,4), %rax
addq %r15, %rax
movb (%rcx,%rax), %al
movq 0x5f67a47(%rip), %rcx   # 0x5f6c348
xorl %r14d, %r14d
cmpb (%rcx,%rbx), %al
leaq -0xd0(%rbp), %r13
movq %r13, -0xe0(%rbp)
sete %r14b
leaq -0xe0(%rbp), %rdi
leaq 0x5826(%rip), %rsi      # 0xa14d
leaq 0x582a(%rip), %rdx      # 0xa158
callq 0x87ec
movl %r14d, %edi
leaq -0xe0(%rbp), %rsi
callq 0x2920
movq -0xe0(%rbp), %rdi
cmpq %r13, %rdi
movq -0x80(%rbp), %r14
je 0x4961
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x21f0
movq -0x38(%rbp), %rcx
cmpl -0x68(%rbp), %ecx
jl 0x49d9
movq 0x5f679f7(%rip), %rax   # 0x5f6c368
movq (%rax), %rax
movq -0xb8(%rbp), %rdx
movb (%rax,%rdx), %al
movq 0x5f679c3(%rip), %rdx   # 0x5f6c348
movb (%rdx,%rbx), %dil
xorl %edx, %edx
cmpb %dil, %al
setne %dl
movl 0x10(%rbp), %esi
cmpl %esi, %edx
movq -0x40(%rbp), %r8
leaq -0x90(%rbp), %r9
jg 0x4a21
xorl %edx, %edx
cmpb %dil, %al
setne %dl
movl 0x10(%rbp), %eax
subl %edx, %eax
movl -0x6c(%rbp), %edi
movl -0x54(%rbp), %esi
movl -0x2c(%rbp), %edx
movl %r12d, %r8d
movq -0x50(%rbp), %r9
pushq 0x18(%rbp)
pushq %rax
callq 0x45a7
movq -0x38(%rbp), %rcx
addq $0x10, %rsp
testb %al, %al
jne 0x4a72
movl 0x10(%rbp), %eax
testl %eax, %eax
movq -0x40(%rbp), %r8
leaq -0x90(%rbp), %r9
jle 0x4a21
movq -0x68(%rbp), %rdi
movl -0x54(%rbp), %esi
movl -0x2c(%rbp), %edx
movl %r12d, %r8d
movq -0x50(%rbp), %r9
pushq 0x18(%rbp)
pushq -0xb0(%rbp)
callq 0x45a7
leaq -0x90(%rbp), %r9
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
addq $0x10, %rsp
testb %al, %al
jne 0x4a72
incq %rbx
cmpq %rbx, 0x5f67925(%rip)   # 0x5f6c350
ja 0x4825
movl 0x10(%rbp), %r10d
testl %r10d, %r10d
setle %al
movq -0x68(%rbp), %rdi
cmpl %edi, %ecx
setl %dl
orb %al, %dl
jne 0x4a6d
incl %edi
decl %r10d
movq -0x60(%rbp), %rsi
movl -0x2c(%rbp), %edx
movq -0x48(%rbp), %r9
pushq 0x18(%rbp)
pushq %r10
callq 0x45a7
addq $0x10, %rsp
movb $0x1, %r12b
testb %al, %al
jne 0x4a75
xorl %r12d, %r12d
jmp 0x4a75
movb $0x1, %r12b
movq -0xa8(%rbp), %rsp
movl %r12d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
movq %r13, -0x78(%rbp)
jmp 0x4aa8
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
cmpq %r13, %rdi
je 0x4abc
movq -0x78(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2330