// File: /workspace/github_cpp_makefile_star2_O1/JameyWoo[P]re2graph/algorithms.cpp
// Function: dfaPattern(DFA, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool dfaPattern(DFA dfa, string pattern) {
    /**
     * 模式匹配函数, 以bool形式返回匹配的结果
     * 直接遍历pattern然后跳转状态, 同时保存所有到达接受状态的模式串就好了
     */
    int state = 0;
    for (auto c : pattern) {  // 遍历待匹配的字符
        char real = c;
        if (count(dfa.chars.begin(), dfa.chars.end(), c) == 0) {  // ! 如果字符在chars没找到, 那么当作OTHER来处理
            c = OTHER;
            if (count(dfa.chars.begin(), dfa.chars.end(), c) == 0) {  // ! 如果dfa本身没有处理OTHER的功能, 那么退出并返回之前的匹配
                cout << "error char: " << real << " !" << endl;
                return false;
            }
        }

        if (dfa.jump_map[state].count(c)) {  // 查看输入字符是否支持当前状态
            state = dfa.jump_map[state][c];
        } else {
            return false;
        }
        if (state == ERROR) return false;  // 超过的最长长度, 可以舍去了
    }
    if (count(dfa.end_states.begin(), dfa.end_states.end(), state)) {  // 查询是否到达接受状态
        return true;
    }
    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq 0x8(%rsi), %r15
testq %r15, %r15
je 0x7fff
movq (%rsi), %r12
addq %r12, %r15
xorl %eax, %eax
leaq 0xe(%rsp), %r14
movb (%r12), %bpl
movb %bpl, 0xe(%rsp)
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %rdx
cmpq %rdx, %rcx
je 0x8030
xorl %esi, %esi
movq %rcx, %rdi
xorl %r8d, %r8d
cmpb %bpl, (%rdi)
sete %r8b
addq %r8, %rsi
incq %rdi
cmpq %rdx, %rdi
jne 0x7f30
testq %rsi, %rsi
jne 0x7f77
movb $0x5e, 0xe(%rsp)
cmpq %rdx, %rcx
je 0x8035
xorl %esi, %esi
xorl %edi, %edi
cmpb $0x5e, (%rcx)
sete %dil
addq %rdi, %rsi
incq %rcx
cmpq %rdx, %rcx
jne 0x7f5a
testq %rsi, %rsi
je 0x8035
cltq
movq 0x58(%rbx), %rdi
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq (%rdi,%rax), %rcx
addq $0x8, %rcx
movq 0x8(%rcx), %rsi
movq %rcx, %rdx
testq %rsi, %rsi
je 0x7fba
movb 0xe(%rsp), %r8b
movq %rcx, %rdx
xorl %r9d, %r9d
cmpb %r8b, 0x20(%rsi)
setl %r9b
cmovgeq %rsi, %rdx
movq 0x10(%rsi,%r9,8), %rsi
testq %rsi, %rsi
jne 0x7fa1
movq %rcx, %rsi
cmpq %rcx, %rdx
je 0x7fd2
movb 0xe(%rsp), %sil
cmpb 0x20(%rdx), %sil
cmovlq %rcx, %rdx
movq %rdx, %rsi
cmpq %rcx, %rsi
je 0x80a3
addq %rax, %rdi
movq %r14, %rsi
callq 0xd87a
movl (%rax), %eax
cmpl $-0x1, %eax
je 0x80a3
incq %r12
cmpq %r15, %r12
jne 0x7f11
jmp 0x8001
xorl %eax, %eax
movq 0x40(%rbx), %rcx
movq 0x48(%rbx), %rdx
cmpq %rdx, %rcx
je 0x80a3
xorl %esi, %esi
xorl %edi, %edi
cmpl %eax, (%rcx)
sete %dil
addq %rdi, %rsi
addq $0x4, %rcx
cmpq %rdx, %rcx
jne 0x8014
testq %rsi, %rsi
setne %al
jmp 0x80a5
movb $0x5e, 0xe(%rsp)
movq 0x10f94(%rip), %rbx     # 0x18fd0
leaq 0xb168(%rip), %rsi      # 0x131ab
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2240
leaq 0xf(%rsp), %rsi
movb %bpl, (%rsi)
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2240
movq %rax, %rbx
leaq 0xb149(%rip), %rsi      # 0x131b8
movl $0x2, %edx
movq %rax, %rdi
callq 0x2240
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq