// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl %ecx, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %r12
pushq $0x24
popq %rsi
movq %rdx, 0x18(%rsp)
movq %rdx, %rdi
callq 0x2190
leaq 0xf8(%rsp), %rdi
movq %r15, %rsi
callq 0x3d90
leaq 0xd8(%rsp), %rdi
movq %r15, %rsi
callq 0x3cfc
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
andq $0x0, 0x10(%r12)
leaq 0x58(%rsp), %rdi
callq 0x49ca
movq %r12, (%rsp)
leaq 0xb0(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x3e2a
xorl %r14d, %r14d
leaq 0xa8(%rsp), %rbx
xorl %r12d, %r12d
movq 0x40(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %r12, %rcx
jbe 0x44ff
movq (%rax,%r14), %rsi
movq %rbx, %rdi
callq 0x49e6
movl %r12d, (%rax)
incq %r12
addq $0x20, %r14
jmp 0x44cf
leaq 0x20(%rsp), %rsi
andl $0x0, (%rsi)
leaq 0x58(%rsp), %rdi
callq 0x5b70
leaq 0x20(%rsp), %rbx
leaq 0x58(%rsp), %r14
xorl %ebp, %ebp
movl %ebp, %ebp
movq 0x88(%rsp), %rax
cmpq 0x90(%rsp), %rax
jne 0x4545
movq 0xa0(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movslq -0x4(%rax), %rax
imulq $0x18, %rax, %r13
addq 0x40(%rsp), %r13
movq 0x18(%rsp), %rax
movq (%rax), %rsi
addq %rbp, %rsi
leaq 0xa8(%rsp), %rdi
callq 0x49e6
movslq (%rax), %r12
shlq $0x5, %r12
movq 0x18(%r13), %rdi
addq %r12, %rdi
leaq 0x8b54(%rip), %rsi      # 0xd0d3
callq 0x36c4
testb %al, %al
jne 0x4710
movq 0x18(%r13), %rsi
cmpq $0x0, 0x8(%rsi,%r12)
je 0x4774
addq %r12, %rsi
movq (%rsi), %rax
movzbl (%rax), %eax
cmpl $0x72, %eax
jne 0x46b4
movq %rbx, %rdi
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
callq 0x21e0
movq %rbx, %rdi
movq (%rsp), %r12
callq 0x2510
movl %eax, %r13d
movq %rbx, %rdi
callq 0x20f0
movl %r13d, 0x8(%rsp)
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x4a34
xorl %r12d, %r12d
movslq 0x8(%rsp), %rcx
movq 0x20(%r15), %rax
imulq $0x30, %rcx, %rcx
cmpq %r12, 0x10(%rax,%rcx)
jbe 0x4609
movq %r14, %rdi
callq 0x5edc
incq %r12
jmp 0x45e8
addq %rcx, %rax
movb (%rax), %al
movb %al, 0xf(%rsp)
movq 0x88(%rsp), %rax
cmpq 0x90(%rsp), %rax
jne 0x4638
movq 0xa0(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movslq -0x4(%rax), %r13
movq 0x40(%rsp), %r12
leaq 0xa8(%rsp), %rdi
leaq 0xf(%rsp), %rsi
callq 0x49e6
imulq $0x18, %r13, %rcx
movslq (%rax), %rsi
shlq $0x5, %rsi
addq 0x18(%r12,%rcx), %rsi
movq %rbx, %rdi
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
callq 0x21e0
movq %rbx, %rdi
callq 0x2510
movl %eax, 0x14(%rsp)
movq %r14, %rdi
leaq 0x14(%rsp), %rsi
callq 0x5b70
movq %rbx, %rdi
callq 0x20f0
cmpb $0x0, 0x10(%rsp)
jne 0x451f
movl 0x8(%rsp), %esi
leaq 0x8a4a(%rip), %rdi      # 0xd0f2
xorl %eax, %eax
callq 0x2040
jmp 0x451f
cmpl $0x73, %eax
jne 0x4774
movq %rbx, %rdi
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
callq 0x21e0
movq %rbx, %rdi
callq 0x2510
movl %eax, %r13d
movq %rbx, %rdi
callq 0x20f0
movl %r13d, 0x8(%rsp)
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x5f32
cmpb $0x0, 0x10(%rsp)
jne 0x4709
movl 0x8(%rsp), %esi
leaq 0x89fb(%rip), %rdi      # 0xd0fd
xorl %eax, %eax
callq 0x2040
incl %ebp
jmp 0x451d
cmpb $0x0, 0x10(%rsp)
jne 0x4723
leaq 0x8a37(%rip), %rdi      # 0xd155
callq 0x2290
leaq 0x40(%rsp), %rdi
callq 0x49a8
leaq 0xa8(%rsp), %rdi
callq 0x4a52
leaq 0x58(%rsp), %rdi
callq 0x4aaa
leaq 0xd8(%rsp), %rdi
callq 0x20f0
leaq 0xf8(%rsp), %rdi
callq 0x20f0
movq (%rsp), %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x28
popq %rdi
callq 0x2100
movq %rax, %r14
leaq 0x8981(%rip), %rsi      # 0xd107
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x25ae
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x249c
xorl %ebp, %ebp
leaq 0xf5fa(%rip), %rsi      # 0x13da8
leaq -0x22e3(%rip), %rdx     # 0x24d2
movq %r14, %rdi
callq 0x2320
jmp 0x4820
jmp 0x4825
jmp 0x4820
jmp 0x4820
movq %rax, %rbx
movq (%rsp), %r12
jmp 0x4840
movq %rax, %rbx
jmp 0x4857
movq %rax, %rbx
jmp 0x486c
jmp 0x4820
jmp 0x4820
jmp 0x4820
jmp 0x4820
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20f0
jmp 0x4836
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20f0
testb %bpl, %bpl
movq (%rsp), %r12
jne 0x4814
jmp 0x4836
movq %rax, %rbx
movq (%rsp), %r12
movq %r14, %rdi
callq 0x2160
jmp 0x4836
jmp 0x4820
movq %rax, %rbx
jmp 0x4832
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20f0
movq (%rsp), %r12
leaq 0x40(%rsp), %rdi
callq 0x49a8
leaq 0xa8(%rsp), %rdi
callq 0x4a52
leaq 0x58(%rsp), %rdi
callq 0x4aaa
movq %r12, %rdi
callq 0x56e6
leaq 0xd8(%rsp), %rdi
callq 0x20f0
leaq 0xf8(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2330
nop