// File: /workspace/github_cpp_makefile_star2_O1/sighingnow[P]compile-pascal/pl0c.cpp
// Function: main
int main(int argc, char **argv) {
    bool opt;
    if (argc == 3 && string(argv[2]) == "-O") {
        opt = true;
    }
    else {
        opt = false;
    }
    auto parse_tool = ParsecT<decltype(pl0_program)>(pl0_program);
    input_t *in = load_case(argv[1]);
    auto res = parse_tool(in);
    if (!res.status) {
        cout << "Errors occurred during parsing." << endl;
        return 0;
    }
    if (!res.strict) {
        cout << "Extra characters in source text." << endl;
    }

    if (!pl0_tac_program(res.actual)) {
        cout << "Errors occurred during semantic analysing." << endl;
    }

    cout << "\n;; <<<<<<<<<<<<<  All Basic Blocks <<<<<<<<<<<<<<<<<<<<<<<<<<<\n" << endl;

    std::vector<BasicBlock> bbs;
    pl0_block(irb.irs, bbs);
    for (auto && bb: bbs) {
        bb.dump();
        if (opt) {
            cout << ";;;;;;;;;;;;;;;;;;;;;DO DAG Pass" << endl;
            bb.DAGPass();
            bb.dump();
        }
    }

    cout << "\n;; <<<<<<<<<<<<<  Assembly (Intel syntax, nasm)   <<<<<<<<<<<<\n" << endl;

    try { // try exception throwed during assembly code generating.
        pl0_x86_gen(string(argv[1]), bbs);
    } catch (std::exception & e) {
        cout << string(";; !!!Exception: ") + string(e.what()) << endl;
    } catch (...) {
        cout << string(";; !!!Exception: ") + "unknown exception." << endl;
    }
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rsi, %rbx
movl %edi, %ebp
cmpl $0x3, %edi
jne 0x959b9
movq 0x10(%rbx), %rsi
leaq 0xf0(%rsp), %r14
leaq 0xf(%rsp), %rdx
movq %r14, %rdi
callq 0x16132
leaq 0x3a55(%rip), %rsi      # 0x993fe
movq %r14, %rdi
callq 0x50c0
testl %eax, %eax
sete %r13b
jmp 0x959bc
xorl %r13d, %r13d
cmpl $0x3, %ebp
jne 0x959e2
leaq 0x100(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x959e2
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x2af5f(%rip), %rsi     # 0xc0948
leaq 0x110(%rsp), %rdi
callq 0x95fba
movq 0x8(%rbx), %rdi
callq 0x957b8
leaq 0xb0(%rsp), %rdi
leaq 0x110(%rsp), %rsi
movq %rax, %rdx
callq 0x963a4
cmpb $0x0, 0xb0(%rsp)
je 0x95c4e
cmpb $0x0, 0xe8(%rsp)
jne 0x95a75
movq 0x2a5a2(%rip), %r14     # 0xbffd8
leaq 0x39e4(%rip), %rsi      # 0x99421
movl $0x20, %edx
movq %r14, %rdi
callq 0x52e0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x5240
movsbl %al, %esi
movq 0x2a570(%rip), %rdi     # 0xbffd8
callq 0x5030
movq %rax, %rdi
callq 0x5190
movq 0xc0(%rsp), %rdi
callq 0x6bf28
testb %al, %al
jne 0x95acc
movq 0x2a54b(%rip), %r14     # 0xbffd8
leaq 0x39ae(%rip), %rsi      # 0x99442
movl $0x2a, %edx
movq %r14, %rdi
callq 0x52e0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x5240
movsbl %al, %esi
movq 0x2a519(%rip), %rdi     # 0xbffd8
callq 0x5030
movq %rax, %rdi
callq 0x5190
movq 0x2a505(%rip), %r14     # 0xbffd8
leaq 0x3993(%rip), %rsi      # 0x9946d
movl $0x40, %edx
movq %r14, %rdi
callq 0x52e0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x5240
movsbl %al, %esi
movq 0x2a4d3(%rip), %r14     # 0xbffd8
movq %r14, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5190
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x2ba79(%rip), %rdi     # 0xc15a8
addq $0x10, %rdi
movl $0x1, %edx
callq 0x81274
movq 0x50(%rsp), %r15
movq 0x58(%rsp), %rbp
cmpq %rbp, %r15
je 0x95bb3
leaq 0x395b(%rip), %r12      # 0x994ae
movq %r15, %rdi
callq 0x7f45e
testb %r13b, %r13b
je 0x95ba7
movl $0x20, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x52e0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5240
movsbl %al, %esi
movq %r14, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5190
movq %r15, %rdi
callq 0x8125c
movq %r15, %rdi
callq 0x7f45e
addq $0xc0, %r15
cmpq %rbp, %r15
jne 0x95b53
movq 0x2a41e(%rip), %r14     # 0xbffd8
leaq 0x390e(%rip), %rsi      # 0x994cf
movl $0x40, %edx
movq %r14, %rdi
callq 0x52e0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x5240
movsbl %al, %esi
movq 0x2a3ec(%rip), %rdi     # 0xbffd8
callq 0x5030
movq %rax, %rdi
callq 0x5190
movq 0x8(%rbx), %rsi
leaq 0x90(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x16132
leaq 0x90(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x88504
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x95c42
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x50(%rsp), %rdi
callq 0x9602c
jmp 0x95c94
movq 0x2a383(%rip), %rbx     # 0xbffd8
leaq 0x37a5(%rip), %rsi      # 0x99401
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x52e0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x5240
movsbl %al, %esi
movq 0x2a351(%rip), %rdi     # 0xbffd8
callq 0x5030
movq %rax, %rdi
callq 0x5190
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x95cb5
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x110(%rsp), %rdi
callq 0x69b0c
xorl %eax, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %rbx
movq %rax, %r14
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x95d05
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x95d05
movq %rdx, %rbx
movq %rax, %r14
movq %r14, %rdi
callq 0x5100
leaq 0x40(%rsp), %r15
cmpl $0x2, %ebx
jne 0x95de3
movq %rax, %r14
leaq 0x30(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x37e3(%rip), %rsi      # 0x99510
leaq 0x37ed(%rip), %rdx      # 0x99521
callq 0x2670a
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
leaq 0x70(%rsp), %rdi
leaq 0xe(%rsp), %rdx
movq %rax, %rsi
callq 0x16132
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x94832
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x2a25f(%rip), %rdi     # 0xbffd8
callq 0x52e0
movq %rax, %rdi
callq 0x5130
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x95da1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x95dc2
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x95dd9
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5260
callq 0x53b0
jmp 0x95c42
leaq 0x30(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x371e(%rip), %rsi      # 0x99510
leaq 0x3728(%rip), %rdx      # 0x99521
callq 0x2670a
leaq 0x371d(%rip), %rsi      # 0x99522
leaq 0x30(%rsp), %rdi
callq 0x5420
leaq 0x20(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x95e36
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x95e3d
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x2a172(%rip), %rdi     # 0xbffd8
callq 0x52e0
movq %rax, %rdi
callq 0x5130
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x95e8a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x95ea1
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5260
callq 0x53b0
jmp 0x95c42
movq %rax, %rbx
jmp 0x95ee6
movq %rax, %rbx
jmp 0x95efd
jmp 0x95f77
movq %rax, %rbx
jmp 0x95f22
movq %rax, %rbx
jmp 0x95f43
movq %rax, %rbx
jmp 0x95f5a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x95ee6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x95efd
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5260
callq 0x53b0
jmp 0x95f7a
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x95f22
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x95f43
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x95f5a
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5260
callq 0x53b0
jmp 0x95f7a
movq %rax, %rdi
callq 0x266fe
jmp 0x95f6b
movq %rax, %rbx
jmp 0x95fa5
jmp 0x95f77
movq %rax, %rbx
jmp 0x95f84
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x9602c
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x95fa5
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x110(%rsp), %rdi
callq 0x69b0c
movq %rbx, %rdi
callq 0x53d0