// File: /workspace/github_cpp_makefile_star2_O1/davidsun[P]TinyCompiler/main.cpp
// Function: main
int main(void){
    LexicalAnalytics la;
    FILE *fprog = fopen("program.txt", "r");
    string program;
    int ch;
    while ((ch = fgetc(fprog)) != EOF){
        program += (char)ch;
    }
    vector <pair <char, string> > la_result = la.parse(program);
    string la_result_str;
    for (int i = 0; i < la_result.size(); i ++) la_result_str += la_result[i].first;

    LRAnalytics lra;
    FILE *f = fopen("input.txt", "r");
    vector <ItemSet> sets = lra.genStates();
    vector <ListCodeItems> code_items;
    ListCodeItems code_items_tmp;
    char s[100];
    while (fgets(s, 100, f)){
        if (s[0] == '#'){
            char s1[100], s2[100];
            sscanf(s + 1, "%s%s", s1, s2);
            string ss2 = s2;
            if (ss2 == "<EMPTY>") ss2 = "";
            lra.addRule(s1[0], ss2);
            code_items.push_back(code_items_tmp);
            code_items_tmp.clear();
        }  else {
            char s1[100], s2[100], s3[100];
            if (sscanf(s, "%s%s%s", s1, s2, s3) == 3) code_items_tmp.push_back(CodeItem(s1, s2[0], s3[0]));
        }
    }
    code_items.push_back(code_items_tmp);
    fclose(f);

    vector <int> lra_result = lra.parse(la_result_str, true);
    CodeGenerator g;
    vector <string> ret = g.parse(lra, la_result, lra_result, code_items);
    for (int i = 0; i < ret.size(); i ++){
        printf("%d: %s\n", i + 1, ret[i].c_str());
    }

    CodeRunner r;
    r.execute(ret);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
leaq 0xf(%rsp), %rdi
callq 0x3738
leaq 0x1843(%rip), %rdi      # 0x102c5
leaq 0x164e(%rip), %rsi      # 0x100d7
callq 0x2200
movq %rax, %rbx
leaq 0x70(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
leaq 0x60(%rsp), %r14
movq %rbx, %rdi
callq 0x2290
cmpl $-0x1, %eax
je 0xeac5
movsbl %al, %esi
movq %r14, %rdi
callq 0x2170
jmp 0xeaab
leaq 0x120(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
leaq 0x110(%rsp), %rdi
callq 0x2854
leaq 0x28(%rsp), %rdi
leaq 0xf(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0x373a
movq 0x110(%rsp), %rdi
cmpq %r14, %rdi
je 0xeb1f
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x28(%rsp), %rax
cmpq %rax, 0x30(%rsp)
je 0xeb82
xorl %r14d, %r14d
leaq 0x40(%rsp), %rbx
movabsq $-0x3333333333333333, %r15 # imm = 0xCCCCCCCCCCCCCCCD
xorl %r12d, %r12d
movsbl (%rax,%r14), %esi
movq %rbx, %rdi
callq 0x2170
incq %r12
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r15, %rcx
addq $0x28, %r14
cmpq %r12, %rcx
ja 0xeb54
leaq 0x1a0(%rsp), %rdi
callq 0x423c
leaq 0x173b(%rip), %rdi      # 0x102d1
leaq 0x153a(%rip), %rsi      # 0x100d7
callq 0x2200
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x44be
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
xorl %eax, %eax
movq %rax, 0x90(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0x2f0(%rsp), %rdi
movl $0x64, %esi
movq %rbx, %rdx
callq 0x22b0
testq %rax, %rax
je 0xee53
leaq 0x260(%rsp), %r15
leaq 0x1f0(%rsp), %r12
leaq 0x2f0(%rsp), %r14
leaq 0xa0(%rsp), %rbp
leaq 0xc8(%rsp), %r13
movq %rbx, 0xc0(%rsp)
cmpb $0x23, 0x2f0(%rsp)
jne 0xed72
movq %rbp, %r13
movq %r14, %rbp
leaq 0x2f1(%rsp), %rdi
leaq 0x169b(%rip), %rsi      # 0x102e5
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x2180
leaq 0x140(%rsp), %rax
movq %rax, 0x130(%rsp)
movq %r12, %rdi
callq 0x20d0
leaq (%rsp,%rax), %rdx
addq $0x1f0, %rdx            # imm = 0x1F0
leaq 0x130(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x299a
movq %r14, %rdi
leaq 0x1644(%rip), %rsi      # 0x102db
callq 0x2090
testl %eax, %eax
jne 0xecbc
movq 0x138(%rsp), %rdx
movq %r14, %rdi
xorl %esi, %esi
leaq 0x15a2(%rip), %rcx      # 0x10256
xorl %r8d, %r8d
callq 0x2270
movsbl 0x260(%rsp), %esi
leaq 0x1a0(%rsp), %rdi
movq %r14, %rdx
callq 0x438e
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xf288
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
cmpq %r15, %r12
je 0xed22
leaq 0x10(%r15), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0xed0d
movq (%r14), %rsi
incq %rsi
callq 0x21b0
leaq 0x28(%r14), %rax
addq $0x18, %r14
cmpq %r12, %r14
movq %rax, %r14
jne 0xecf9
movq %r15, 0x18(%rsp)
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0xed47
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0xc0(%rsp), %rbx
leaq 0x260(%rsp), %r15
leaq 0x1f0(%rsp), %r12
movq %rbp, %r14
movq %r13, %rbp
leaq 0xc8(%rsp), %r13
jmp 0xee3a
movq %r14, %rdi
leaq 0x1567(%rip), %rsi      # 0x102e3
movq %r15, %rdx
movq %r12, %rcx
leaq 0x130(%rsp), %r8
xorl %eax, %eax
callq 0x2180
cmpl $0x3, %eax
jne 0xee3a
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq %r15, %rdi
callq 0x20d0
leaq (%rsp,%rax), %rdx
addq $0x260, %rdx            # imm = 0x260
movq %rbp, %rdi
movq %r15, %rsi
callq 0x299a
movsbl 0x1f0(%rsp), %edx
movsbl 0x130(%rsp), %ecx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2b2c
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xf558
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0xee15
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xee3a
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %r14, %rdi
movl $0x64, %esi
movq %rbx, %rdx
callq 0x22b0
testq %rax, %rax
jne 0xec27
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xf288
movq %rbx, %rdi
callq 0x2190
leaq 0x100(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
addq %rsi, %rdx
leaq 0xf0(%rsp), %rdi
callq 0x2854
leaq 0x1f0(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
movl $0x1, %ecx
callq 0x519e
movq 0xf0(%rsp), %rdi
cmpq %r14, %rdi
je 0xeed2
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x270(%rsp), %rdi
callq 0x423c
xorps %xmm0, %xmm0
leaq 0x260(%rsp), %rsi
movups %xmm0, 0x78(%rsi)
movups %xmm0, 0x68(%rsi)
movups %xmm0, 0x58(%rsi)
movups %xmm0, 0x48(%rsi)
movq $0x0, 0x88(%rsi)
leaq 0x130(%rsp), %rdi
leaq 0x1a0(%rsp), %rdx
leaq 0x28(%rsp), %rcx
leaq 0x1f0(%rsp), %r8
leaq 0x80(%rsp), %r9
callq 0x6f40
movq 0x130(%rsp), %rax
cmpq %rax, 0x138(%rsp)
je 0xef82
leaq 0x13a2(%rip), %rbx      # 0x102ea
xorl %r15d, %r15d
xorl %r14d, %r14d
incq %r14
movq (%rax,%r15), %rdx
movq %rbx, %rdi
movl %r14d, %esi
xorl %eax, %eax
callq 0x2040
movq 0x130(%rsp), %rax
movq 0x138(%rsp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
addq $0x20, %r15
cmpq %r14, %rcx
ja 0xef4e
leaq 0xc8(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x9d40
leaq 0x2a8(%rsp), %rbx
leaq 0x130(%rsp), %rdi
callq 0x5840
leaq 0x2d8(%rsp), %r14
movq %r14, %rdi
callq 0xf304
movq -0x18(%r14), %rdi
testq %rdi, %rdi
leaq 0x70(%rsp), %r14
je 0xefda
movq 0x2d0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x3f1a
leaq 0x290(%rsp), %rbx
movq %rbx, %rdi
callq 0x32c8
movq -0x20(%rbx), %rdi
leaq 0x280(%rsp), %rax
cmpq %rax, %rdi
je 0xf013
movq 0x280(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x1f0(%rsp), %rdi
testq %rdi, %rdi
je 0xf030
movq 0x200(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
leaq 0x10(%rsp), %rdi
callq 0x9240
leaq 0x80(%rsp), %rdi
callq 0xf304
leaq 0x1d8(%rsp), %rdi
callq 0x57fe
leaq 0x1c0(%rsp), %rbx
movq %rbx, %rdi
callq 0x32c8
movq -0x20(%rbx), %rdi
leaq 0x1b0(%rsp), %rax
cmpq %rax, %rdi
je 0xf085
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xf0a1
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x28(%rsp), %rdi
callq 0x3f1a
movq 0x60(%rsp), %rdi
cmpq %r14, %rdi
je 0xf0c2
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21b0
xorl %eax, %eax
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
leaq 0x130(%rsp), %rdi
callq 0x5840
jmp 0xf0eb
movq %rax, %r12
leaq 0x260(%rsp), %rdi
callq 0xf2b4
jmp 0xf0fd
movq %rax, %r12
movq 0x1f0(%rsp), %rdi
testq %rdi, %rdi
je 0xf207
movq 0x200(%rsp), %rsi
subq %rdi, %rsi
jmp 0xf202
movq %rax, %r12
movq 0xf0(%rsp), %rdi
cmpq %r14, %rdi
je 0xf207
movq 0x100(%rsp), %rsi
jmp 0xf1ff
jmp 0xf1d5
jmp 0xf1d5
movq %rax, %r12
jmp 0xf22b
jmp 0xf1da
movq %rax, %r12
movq 0x110(%rsp), %rdi
cmpq %r14, %rdi
je 0xf25e
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0xf25e
movq %rax, %r12
jmp 0xf25e
movq %rax, %r12
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0xf1b4
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0xf1b4
movq %rax, %r12
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xf207
movq 0xb0(%rsp), %rsi
jmp 0xf1ff
jmp 0xf1d5
movq %rax, %r12
jmp 0xf207
movq %rax, %r12
jmp 0xf238
movq %rax, %r12
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0xf207
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x10(%rsp), %rdi
callq 0x9240
leaq 0x80(%rsp), %rdi
callq 0xf304
leaq 0x1d8(%rsp), %rdi
callq 0x57fe
leaq 0x1a0(%rsp), %rdi
callq 0xf346
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xf254
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x28(%rsp), %rdi
callq 0x3f1a
leaq 0x70(%rsp), %r15
jmp 0xf268
movq %rax, %r12
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0xf27f
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %r12, %rdi
callq 0x22f0
nop