// File: /workspace/github_cpp_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movq %rsi, %rbx
cmpl $0x3, %edi
jne 0x8fd62
movq 0x10(%rbx), %rsi
leaq 0xf0(%rsp), %r14
leaq 0xb0(%rsp), %rdx
movq %r14, %rdi
callq 0x16148
leaq 0x36cc(%rip), %rsi      # 0x933fe
movq %r14, %rdi
callq 0x50c0
testl %eax, %eax
sete %bpl
movq (%r14), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x8fd64
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x8fd64
xorl %ebp, %ebp
leaq 0x2abdd(%rip), %rsi     # 0xba948
leaq 0xf0(%rsp), %rdi
callq 0x90336
movq 0x8(%rbx), %rdi
callq 0x8fb40
leaq 0xb0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
movq %rax, %rdx
callq 0x90760
cmpb $0x0, 0xb0(%rsp)
je 0x8ffd0
cmpb $0x0, 0xe8(%rsp)
jne 0x8fdf7
movq 0x2a220(%rip), %r14     # 0xb9fd8
leaq 0x3662(%rip), %rsi      # 0x93421
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 0x2a1ee(%rip), %rdi     # 0xb9fd8
callq 0x5030
movq %rax, %rdi
callq 0x5190
movq 0xc0(%rsp), %rdi
callq 0x65ff0
testb %al, %al
jne 0x8fe4e
movq 0x2a1c9(%rip), %r14     # 0xb9fd8
leaq 0x362c(%rip), %rsi      # 0x93442
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 0x2a197(%rip), %rdi     # 0xb9fd8
callq 0x5030
movq %rax, %rdi
callq 0x5190
movq 0x2a183(%rip), %r14     # 0xb9fd8
leaq 0x3611(%rip), %rsi      # 0x9346d
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 0x2a151(%rip), %r14     # 0xb9fd8
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 0x2b6f7(%rip), %rdi     # 0xbb5a8
addq $0x10, %rdi
movl $0x1, %edx
callq 0x7b9dc
movq 0x50(%rsp), %r15
movq 0x58(%rsp), %r13
cmpq %r13, %r15
je 0x8ff35
leaq 0x35d9(%rip), %r12      # 0x934ae
movq %r15, %rdi
callq 0x79b72
testb %bpl, %bpl
je 0x8ff29
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 0x7b9c4
movq %r15, %rdi
callq 0x79b72
addq $0xc0, %r15
cmpq %r13, %r15
jne 0x8fed5
movq 0x2a09c(%rip), %r14     # 0xb9fd8
leaq 0x358c(%rip), %rsi      # 0x934cf
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 0x2a06a(%rip), %rdi     # 0xb9fd8
callq 0x5030
movq %rax, %rdi
callq 0x5190
movq 0x8(%rbx), %rsi
leaq 0x90(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x16148
leaq 0x90(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x82ae4
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8ffc4
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x50(%rsp), %rdi
callq 0x903a8
jmp 0x90016
movq 0x2a001(%rip), %rbx     # 0xb9fd8
leaq 0x3423(%rip), %rsi      # 0x93401
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 0x29fcf(%rip), %rdi     # 0xb9fd8
callq 0x5030
movq %rax, %rdi
callq 0x5190
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x90037
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0xf0(%rsp), %rdi
callq 0x63c34
xorl %eax, %eax
addq $0x138, %rsp            # imm = 0x138
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 0x90087
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x90087
movq %rdx, %rbx
movq %rax, %r14
movq %r14, %rdi
callq 0x5100
leaq 0x40(%rsp), %r15
cmpl $0x2, %ebx
jne 0x90165
movq %rax, %r14
leaq 0x30(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x3461(%rip), %rsi      # 0x93510
leaq 0x346b(%rip), %rdx      # 0x93521
callq 0x253d0
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
leaq 0x70(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %rax, %rsi
callq 0x16148
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x8ebf1
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x29edd(%rip), %rdi     # 0xb9fd8
callq 0x52e0
movq %rax, %rdi
callq 0x5130
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x90123
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x90144
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x9015b
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5260
callq 0x53b0
jmp 0x8ffc4
leaq 0x30(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x339c(%rip), %rsi      # 0x93510
leaq 0x33a6(%rip), %rdx      # 0x93521
callq 0x253d0
leaq 0x339b(%rip), %rsi      # 0x93522
leaq 0x30(%rsp), %rdi
callq 0x5420
leaq 0x20(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0x901b8
movq %rsi, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x901c2
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %r14, %rsi
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x29df7(%rip), %rdi     # 0xb9fd8
callq 0x52e0
movq %rax, %rdi
callq 0x5130
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x90205
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x9021c
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5260
callq 0x53b0
jmp 0x8ffc4
movq %rax, %rbx
jmp 0x90261
movq %rax, %rbx
jmp 0x90278
jmp 0x902f2
movq %rax, %rbx
jmp 0x9029d
movq %rax, %rbx
jmp 0x902be
movq %rax, %rbx
jmp 0x902d5
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x90261
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x90278
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5260
callq 0x53b0
jmp 0x902f5
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9029d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x902be
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x902d5
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5260
callq 0x53b0
jmp 0x902f5
movq %rax, %rdi
callq 0x253c4
jmp 0x902e6
movq %rax, %rbx
jmp 0x90320
jmp 0x902f2
movq %rax, %rbx
jmp 0x902ff
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x903a8
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x90320
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0xf0(%rsp), %rdi
callq 0x63c34
movq %rbx, %rdi
callq 0x53d0
nop