// File: davidsun[P]TinyCompiler/LRAnalytics.cpp
// Function: LRAnalytics::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool) const
vector <int> LRAnalytics::parse(string str, bool quiet) const{
    str += INPUT_END_LETTER;
    string terminals = getTerminals();
    string nonTerminals = getNonTerminals();
    vector <int> ret;
    stack <int> sStates;
    map <char, int> translation;
    vector <vector <string> > table = genTable();
    for (int i = 0; i < table[0].size(); i ++) translation[table[0][i][0]] = i;
    int strPos = 0;
    sStates.push(0);
    while (1){
        int curState = sStates.top();
        const vector <string> &row = table[curState + 1];
        int curId = translation[str[strPos]];
        if (row[curId] == "acc"){
            if (!quiet) printf("Accept\n");
            break;
        }  else if (row[curId].size() > 0 && row[curId][0] == 'r'){
            int m = Utils::toInt(row[curId].substr(1));
            ret.push_back(m);
            for (int i = 0; i < _rules[m].right_side.size(); i ++) sStates.pop();
            char nt = _rules[m].left_side;
            curState = sStates.top();
            const vector <string> &newRow = table[curState + 1];
            curId = translation[nt];
            sStates.push(Utils::toInt(newRow[curId].substr(1)));
            if (!quiet) printf("Reduct %d\n", m);
        }  else if (row[curId].size() > 0 && row[curId][0] == 's'){
            int m = Utils::toInt(row[curId].substr(1));
            sStates.push(m);
            strPos ++;
            if (!quiet) printf("Shift %d\n", m);
        }  else {
            throw Exception("ERROR: unrecognizable input!\n");
        }
    }
    return ret; 
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movl %ecx, %eax
movq %rdx, -0x1f0(%rbp)
movq %rdi, %rcx
movq -0x1f0(%rbp), %rdi
movq %rcx, -0x1e8(%rbp)
movq %rcx, %rdx
movq %rdx, -0x1e0(%rbp)
movq %rcx, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movl $0x24, %esi
callq 0x31b0
movq -0x1d8(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x82b0
movq -0x1d8(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x8190
jmp 0x8e87
movq -0x1e8(%rbp), %rdi
movb $0x0, -0x6d(%rbp)
callq 0x9af0
leaq -0xc0(%rbp), %rdi
callq 0x9b10
jmp 0x8ea5
leaq -0xf0(%rbp), %rdi
callq 0x9b40
movq -0x1d8(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0x83c0
jmp 0x8ec6
movl $0x0, -0x10c(%rbp)
movslq -0x10c(%rbp), %rax
movq %rax, -0x1f8(%rbp)
leaq -0x108(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9940
movq %rax, %rdi
callq 0x9a50
movq %rax, %rcx
movq -0x1f8(%rbp), %rax
cmpq %rcx, %rax
jae 0x8fd6
movl -0x10c(%rbp), %eax
movl %eax, -0x20c(%rbp)
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x208(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x9940
movq %rax, %rdi
movslq -0x10c(%rbp), %rsi
callq 0x9a70
movq -0x208(%rbp), %rsi
movq %rax, %rdi
callq 0x34f0
movq %rax, -0x200(%rbp)
jmp 0x8f53
movq -0x200(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x9b60
movq %rax, -0x218(%rbp)
jmp 0x8f6f
movq -0x218(%rbp), %rax
movl -0x20c(%rbp), %ecx
movl %ecx, (%rax)
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0x8ed0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x95e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x95cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x9587
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x957b
movl $0x0, -0x110(%rbp)
movl $0x0, -0x114(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0x114(%rbp), %rsi
callq 0x9c40
jmp 0x8fff
jmp 0x9001
jmp 0x9003
leaq -0xc0(%rbp), %rdi
callq 0x9c70
movq %rax, -0x220(%rbp)
jmp 0x9018
movq -0x220(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x118(%rbp)
movl -0x118(%rbp), %eax
incl %eax
movslq %eax, %rsi
leaq -0x108(%rbp), %rdi
callq 0x9940
movq -0x1f0(%rbp), %rdi
movq %rax, -0x120(%rbp)
movslq -0x110(%rbp), %rsi
callq 0x34f0
movq %rax, -0x228(%rbp)
jmp 0x9061
movq -0x228(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x9b60
movq %rax, -0x230(%rbp)
jmp 0x907d
movq -0x230(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x124(%rbp)
movq -0x120(%rbp), %rdi
movslq -0x124(%rbp), %rsi
callq 0x9c90
movq %rax, %rdi
leaq 0x1c1ed(%rip), %rsi     # 0x25296
callq 0x6de0
movb %al, -0x231(%rbp)
jmp 0x90b6
movb -0x231(%rbp), %al
testb $0x1, %al
jne 0x90c2
jmp 0x90df
testb $0x1, -0x19(%rbp)
jne 0x90da
leaq 0x1c1e6(%rip), %rdi     # 0x252b5
xorl %eax, %eax
callq 0x3060
jmp 0x90d8
jmp 0x90da
jmp 0x954b
movq -0x120(%rbp), %rdi
movslq -0x124(%rbp), %rsi
callq 0x9c90
movq %rax, %rdi
callq 0x31e0
cmpq $0x0, %rax
jbe 0x9365
movq -0x120(%rbp), %rdi
movslq -0x124(%rbp), %rsi
callq 0x9c90
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3300
movsbl (%rax), %eax
cmpl $0x72, %eax
jne 0x9365
movq -0x120(%rbp), %rdi
movslq -0x124(%rbp), %rsi
callq 0x9c90
movq %rax, %rsi
leaq -0x148(%rbp), %rdi
movl $0x1, %edx
movq $-0x1, %rcx
callq 0x32a0
jmp 0x915f
leaq -0x148(%rbp), %rdi
callq 0x3710
movl %eax, -0x238(%rbp)
jmp 0x9173
leaq -0x148(%rbp), %rdi
callq 0x31a0
movl -0x238(%rbp), %eax
movq -0x1e8(%rbp), %rdi
movl %eax, -0x128(%rbp)
leaq -0x128(%rbp), %rsi
callq 0x9cb0
jmp 0x91a0
movl $0x0, -0x14c(%rbp)
movq -0x1d8(%rbp), %rdi
movslq -0x14c(%rbp), %rax
movq %rax, -0x240(%rbp)
addq $0x20, %rdi
movslq -0x128(%rbp), %rsi
callq 0x4920
movq %rax, %rdi
addq $0x8, %rdi
callq 0x31e0
movq %rax, %rcx
movq -0x240(%rbp), %rax
cmpq %rcx, %rax
jae 0x9228
leaq -0xc0(%rbp), %rdi
callq 0x9d20
jmp 0x91f8
jmp 0x91fa
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x91aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x31a0
jmp 0x957b
movq -0x1d8(%rbp), %rdi
addq $0x20, %rdi
movslq -0x128(%rbp), %rsi
callq 0x4920
movb (%rax), %al
movb %al, -0x14d(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x9c70
movq %rax, -0x248(%rbp)
jmp 0x925c
movq -0x248(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x118(%rbp)
movl -0x118(%rbp), %eax
incl %eax
movslq %eax, %rsi
leaq -0x108(%rbp), %rdi
callq 0x9940
movq %rax, -0x158(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0x14d(%rbp), %rsi
callq 0x9b60
movq %rax, -0x250(%rbp)
jmp 0x92a5
movq -0x250(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x124(%rbp)
movq -0x158(%rbp), %rdi
movslq -0x124(%rbp), %rsi
callq 0x9c90
movq %rax, %rsi
leaq -0x180(%rbp), %rdi
movl $0x1, %edx
movq $-0x1, %rcx
callq 0x32a0
jmp 0x92e4
leaq -0x180(%rbp), %rdi
callq 0x3710
movl %eax, -0x254(%rbp)
jmp 0x92f8
movl -0x254(%rbp), %eax
movl %eax, -0x15c(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0x15c(%rbp), %rsi
callq 0x9c40
jmp 0x9319
leaq -0x180(%rbp), %rdi
callq 0x31a0
testb $0x1, -0x19(%rbp)
jne 0x9360
movl -0x128(%rbp), %esi
leaq 0x1bf85(%rip), %rdi     # 0x252bd
xorl %eax, %eax
callq 0x3060
jmp 0x9341
jmp 0x9360
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x31a0
jmp 0x957b
jmp 0x9544
movq -0x120(%rbp), %rdi
movslq -0x124(%rbp), %rsi
callq 0x9c90
movq %rax, %rdi
callq 0x31e0
cmpq $0x0, %rax
jbe 0x9475
movq -0x120(%rbp), %rdi
movslq -0x124(%rbp), %rsi
callq 0x9c90
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3300
movsbl (%rax), %eax
cmpl $0x73, %eax
jne 0x9475
movq -0x120(%rbp), %rdi
movslq -0x124(%rbp), %rsi
callq 0x9c90
movq %rax, %rsi
leaq -0x1a8(%rbp), %rdi
movl $0x1, %edx
movq $-0x1, %rcx
callq 0x32a0
jmp 0x93e5
leaq -0x1a8(%rbp), %rdi
callq 0x3710
movl %eax, -0x258(%rbp)
jmp 0x93f9
leaq -0x1a8(%rbp), %rdi
callq 0x31a0
movl -0x258(%rbp), %eax
movl %eax, -0x184(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0x184(%rbp), %rsi
callq 0x9d40
jmp 0x9426
movl -0x110(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x110(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x9470
movl -0x184(%rbp), %esi
leaq 0x1be80(%rip), %rdi     # 0x252c8
xorl %eax, %eax
callq 0x3060
jmp 0x9451
jmp 0x9470
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x31a0
jmp 0x957b
jmp 0x9542
movb $0x1, -0x1ca(%rbp)
movl $0x28, %edi
callq 0x3150
movq %rax, -0x268(%rbp)
leaq -0x1c9(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x3490
movq -0x260(%rbp), %rdx
leaq 0x1be24(%rip), %rsi     # 0x252d2
leaq -0x1c8(%rbp), %rdi
callq 0x3870
jmp 0x94bc
movq -0x268(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x3600
jmp 0x94d1
movq -0x268(%rbp), %rdi
movb $0x0, -0x1ca(%rbp)
leaq 0x2c8ba(%rip), %rsi     # 0x35da0
leaq -0x5e8d(%rip), %rdx     # 0x3660
callq 0x3460
jmp 0x95f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x951d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x31a0
leaq -0x1c9(%rbp), %rdi
callq 0x32e0
testb $0x1, -0x1ca(%rbp)
jne 0x9534
jmp 0x9540
movq -0x268(%rbp), %rdi
callq 0x3210
jmp 0x957b
jmp 0x9544
jmp 0x9546
jmp 0x9001
movb $0x1, -0x6d(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x9a90
leaq -0xf0(%rbp), %rdi
callq 0x9d70
leaq -0xc0(%rbp), %rdi
callq 0x9d90
testb $0x1, -0x6d(%rbp)
jne 0x95ad
jmp 0x95a1
leaq -0x108(%rbp), %rdi
callq 0x9a90
leaq -0xf0(%rbp), %rdi
callq 0x9d70
leaq -0xc0(%rbp), %rdi
callq 0x9d90
jmp 0x95cf
movq -0x1e8(%rbp), %rdi
callq 0x9db0
leaq -0x60(%rbp), %rdi
callq 0x31a0
leaq -0x40(%rbp), %rdi
callq 0x31a0
movq -0x1e0(%rbp), %rax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq -0x1e8(%rbp), %rdi
callq 0x9db0
leaq -0x60(%rbp), %rdi
callq 0x31a0
leaq -0x40(%rbp), %rdi
callq 0x31a0
movq -0x68(%rbp), %rdi
callq 0x3480
nopw %cs:(%rax,%rax)