// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x78(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq %rsi, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3290
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3180
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8b00
testb $0x1, %al
jne 0xd772
jmp 0xd8b1
leaq -0x30(%rbp), %rdi
callq 0x8bb0
movq -0x78(%rbp), %rdi
movb (%rax), %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
movb %al, -0x3a(%rbp)
addq $0x10, %rdi
callq 0x131a0
movq -0x78(%rbp), %rdi
movq %rax, -0x48(%rbp)
addq $0x10, %rdi
callq 0x131d0
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x39(%rbp), %rdx
callq 0x14050
cmpq $0x0, %rax
jne 0xd848
movq -0x78(%rbp), %rdi
movb $0x5e, -0x39(%rbp)
addq $0x10, %rdi
callq 0x131a0
movq -0x78(%rbp), %rdi
movq %rax, -0x58(%rbp)
addq $0x10, %rdi
callq 0x131d0
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
leaq -0x39(%rbp), %rdx
callq 0x14050
cmpq $0x0, %rax
jne 0xd846
movq 0x357c9(%rip), %rdi     # 0x42fd0
leaq 0x1fa25(%rip), %rsi     # 0x2d233
callq 0x32c0
movq %rax, %rdi
movsbl -0x3a(%rbp), %esi
callq 0x3390
movq %rax, %rdi
leaq 0x1fa17(%rip), %rsi     # 0x2d240
callq 0x32c0
movq %rax, %rdi
movq 0x35778(%rip), %rsi     # 0x42fb0
callq 0x3300
movb $0x0, -0x1(%rbp)
jmp 0xd8f4
jmp 0xd848
movq -0x78(%rbp), %rdi
addq $0x58, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x13320
movq %rax, %rdi
leaq -0x39(%rbp), %rsi
callq 0x13ba0
cmpq $0x0, %rax
je 0xd88f
movq -0x78(%rbp), %rdi
addq $0x58, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x13320
movq %rax, %rdi
leaq -0x39(%rbp), %rsi
callq 0x13340
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
jmp 0xd895
movb $0x0, -0x1(%rbp)
jmp 0xd8f4
cmpl $-0x1, -0x1c(%rbp)
jne 0xd8a1
movb $0x0, -0x1(%rbp)
jmp 0xd8f4
jmp 0xd8a3
leaq -0x30(%rbp), %rdi
callq 0x8b80
jmp 0xd75c
movq -0x78(%rbp), %rdi
addq $0x40, %rdi
callq 0x12900
movq -0x78(%rbp), %rdi
movq %rax, -0x68(%rbp)
addq $0x40, %rdi
callq 0x12930
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
leaq -0x1c(%rbp), %rdx
callq 0x13980
cmpq $0x0, %rax
je 0xd8f0
movb $0x1, -0x1(%rbp)
jmp 0xd8f4
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)