// File: sighingnow[P]compile-pascal/pl0_opt.cpp
// Function: BasicBlock::solveDAG()
void BasicBlock::solveDAG() {
    std::vector<TAC> irs;
    for (int i = 0; i < this->s; ++i) {
        irs.emplace_back(this->code[i]);
    }
    std::vector<int> stack;
    std::vector<DAGNode> t_nodes = G;

    while (!t_nodes.empty()) {
        auto iter = t_nodes.rbegin();
        bool flag = true;
        while (iter != t_nodes.rend()) {
            DAGNode & node = *iter;
            if (node.ready()) {
                stack.push_back(node.no);
                if (node.lhs != -1) {
                    t_nodes[node.lhs].lessFa();
                }
                if (node.op != "write_e" && node.op != "read" && node.rhs != -1) {
                    t_nodes[node.rhs].lessFa();
                }
                t_nodes.erase((++iter).base());
                flag = false;
                break;
            }
            else {
                iter++;
            }
        }
        if (flag) {
            std::cout << ";; DAG graph export warning: Circle found." << std::endl;
            break;
        }
    }
    auto r_iter = stack.rbegin();
    while (r_iter != stack.rend()) {
        int node = *r_iter;
        releaseLeaf(irs, G[node].item);
        r_iter++;
    }

    r_iter = stack.rbegin();
    while (r_iter != stack.rend()) {
        int node = *r_iter;
        if (!G[node].leaf) {
            this->trans(irs, node);
        }
        auto iter = G[node].items.begin();
        while (iter != G[node].items.end()) {
            if (*iter != G[node].item && (*iter)->t != Value::TYPE::IMM) {
                irs.push_back(TAC("=", *iter, G[node].item));
            }
            iter++;
        }
        r_iter++;
    }
    while (!this->IOBuf.empty()) {
        irs.emplace_back(this->IOBuf[0].second);
        this->IOBuf.erase(IOBuf.begin());
    }
    for (size_t i = t; i < this->code.size(); ++i) {
        irs.emplace_back(this->code[i]);
    }
    this->code.swap(irs);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xa4790
movl $0x0, -0x24(%rbp)
movq -0x1a0(%rbp), %rcx
movl -0x24(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0xcab19
movq -0x1a0(%rbp), %rdi
addq $0x18, %rdi
movslq -0x24(%rbp), %rsi
callq 0xcceb0
movq %rax, %rsi
leaq -0x20(%rbp), %rdi
callq 0xccb20
jmp 0xcaafb
jmp 0xcaafd
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xcaaca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xcb27d
leaq -0x50(%rbp), %rdi
callq 0xbfa60
movq -0x1a0(%rbp), %rsi
addq $0x60, %rsi
leaq -0x68(%rbp), %rdi
callq 0xcd790
jmp 0xcab38
jmp 0xcab3a
leaq -0x68(%rbp), %rdi
callq 0xcd880
xorb $-0x1, %al
testb $0x1, %al
jne 0xcab4e
jmp 0xcad8f
leaq -0x70(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xcd8c0
movb $0x1, -0x71(%rbp)
leaq -0x80(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
leaq -0x68(%rbp), %rsi
callq 0xcd940
movq -0x1b0(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0xcd910
movb %al, -0x1a1(%rbp)
jmp 0xcab8b
movb -0x1a1(%rbp), %al
testb $0x1, %al
jne 0xcab9a
jmp 0xcad51
leaq -0x70(%rbp), %rdi
callq 0xcd990
movq %rax, -0x1b8(%rbp)
jmp 0xcabac
movq -0x1b8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
callq 0xcd9c0
movb %al, -0x1b9(%rbp)
jmp 0xcabce
movb -0x1b9(%rbp), %al
testb $0x1, %al
jne 0xcabdd
jmp 0xcad36
movq -0x88(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xcd9e0
jmp 0xcabef
movq -0x88(%rbp), %rax
cmpl $-0x1, 0x50(%rax)
je 0xcac3e
movq -0x88(%rbp), %rax
movslq 0x50(%rax), %rsi
leaq -0x68(%rbp), %rdi
callq 0xcd130
movq %rax, %rdi
callq 0xcda50
jmp 0xcac1a
jmp 0xcac3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xcb274
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xcb26b
movq -0x88(%rbp), %rdi
addq $0x30, %rdi
leaq 0x267c3(%rip), %rsi     # 0xf1413
callq 0xc02b0
movb %al, -0x1ba(%rbp)
jmp 0xcac5d
movb -0x1ba(%rbp), %al
testb $0x1, %al
jne 0xcac69
jmp 0xcacc1
movq -0x88(%rbp), %rdi
addq $0x30, %rdi
leaq 0x2493c(%rip), %rsi     # 0xef5b7
callq 0xc02b0
movb %al, -0x1bb(%rbp)
jmp 0xcac88
movb -0x1bb(%rbp), %al
testb $0x1, %al
jne 0xcac94
jmp 0xcacc1
movq -0x88(%rbp), %rax
cmpl $-0x1, 0x54(%rax)
je 0xcacc1
movq -0x88(%rbp), %rax
movslq 0x54(%rax), %rsi
leaq -0x68(%rbp), %rdi
callq 0xcd130
movq %rax, %rdi
callq 0xcda50
jmp 0xcacbf
jmp 0xcacc1
leaq -0x70(%rbp), %rdi
callq 0xcdae0
movq %rax, -0x1c8(%rbp)
jmp 0xcacd3
movq -0x1c8(%rbp), %rdi
callq 0xcdb10
movq %rax, -0x1d0(%rbp)
jmp 0xcace8
movq -0x1d0(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xcdb30
movq -0x90(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0xcda70
movq %rax, -0x1d8(%rbp)
jmp 0xcad22
movq -0x1d8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movb $0x0, -0x71(%rbp)
jmp 0xcad51
leaq -0xa8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
xorl %edx, %edx
callq 0xcdb70
jmp 0xcad4a
jmp 0xcad4c
jmp 0xcab5f
testb $0x1, -0x71(%rbp)
je 0xcad8a
movq 0x9427a(%rip), %rdi     # 0x15efd8
leaq 0x266ba(%rip), %rsi     # 0xf141f
callq 0x5330
movq %rax, -0x1e0(%rbp)
jmp 0xcad73
movq -0x1e0(%rbp), %rdi
movq 0x9423f(%rip), %rsi     # 0x15efc0
callq 0x53a0
jmp 0xcad88
jmp 0xcad8f
jmp 0xcab3a
leaq -0xb0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xcdbb0
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
leaq -0x50(%rbp), %rsi
callq 0xcdc30
movq -0x1f0(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0xcdc00
movb %al, -0x1e1(%rbp)
jmp 0xcadd1
movb -0x1e1(%rbp), %al
testb $0x1, %al
jne 0xcaddd
jmp 0xcae4a
leaq -0xb0(%rbp), %rdi
callq 0xcdc80
movq %rax, -0x1f8(%rbp)
jmp 0xcadf2
movq -0x1a0(%rbp), %rdi
movq -0x1f8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xbc(%rbp)
addq $0x60, %rdi
movslq -0xbc(%rbp), %rsi
callq 0xcd130
movq -0x1a0(%rbp), %rdi
movq 0x10(%rax), %rdx
leaq -0x20(%rbp), %rsi
callq 0xcb290
jmp 0xcae2e
leaq -0xc8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
xorl %edx, %edx
callq 0xcdcb0
jmp 0xcae45
jmp 0xcad9f
leaq -0xd0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xcdbb0
movq -0xd0(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x208(%rbp)
leaq -0x50(%rbp), %rsi
callq 0xcdc30
movq -0x208(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0xcdc00
movb %al, -0x1f9(%rbp)
jmp 0xcae9a
movb -0x1f9(%rbp), %al
testb $0x1, %al
jne 0xcaea9
jmp 0xcb10d
leaq -0xb0(%rbp), %rdi
callq 0xcdc80
movq %rax, -0x210(%rbp)
jmp 0xcaebe
movq -0x1a0(%rbp), %rdi
movq -0x210(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xdc(%rbp)
addq $0x60, %rdi
movslq -0xdc(%rbp), %rsi
callq 0xcd130
testb $0x1, 0x9(%rax)
jne 0xcaf04
movq -0x1a0(%rbp), %rdi
movl -0xdc(%rbp), %edx
leaq -0x20(%rbp), %rsi
callq 0xcb570
jmp 0xcaf02
jmp 0xcaf04
movq -0x1a0(%rbp), %rdi
addq $0x60, %rdi
movslq -0xdc(%rbp), %rsi
callq 0xcd130
movq %rax, %rdi
addq $0x18, %rdi
callq 0xcd540
movq %rax, -0xe8(%rbp)
movq -0x1a0(%rbp), %rdi
addq $0x60, %rdi
movslq -0xdc(%rbp), %rsi
callq 0xcd130
movq %rax, %rdi
addq $0x18, %rdi
callq 0xcd5b0
movq %rax, -0xf0(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xcd570
testb $0x1, %al
jne 0xcaf74
jmp 0xcb0f1
leaq -0xe8(%rbp), %rdi
callq 0xcd5e0
movq -0x1a0(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x218(%rbp)
addq $0x60, %rdi
movslq -0xdc(%rbp), %rsi
callq 0xcd130
movq %rax, %rcx
movq -0x218(%rbp), %rax
cmpq 0x10(%rcx), %rax
je 0xcb0d7
leaq -0xe8(%rbp), %rdi
callq 0xcd5e0
movq (%rax), %rax
cmpl $0x0, (%rax)
je 0xcb0d7
leaq -0x161(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x55d0
movq -0x220(%rbp), %rdx
leaq 0x2442e(%rip), %rsi     # 0xef41c
leaq -0x160(%rbp), %rdi
callq 0x19840
jmp 0xcaffc
leaq -0xe8(%rbp), %rdi
callq 0xcd5e0
movq -0x1a0(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x228(%rbp)
addq $0x60, %rdi
movslq -0xdc(%rbp), %rsi
callq 0xcd130
movq -0x228(%rbp), %rdx
movq 0x10(%rax), %rcx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x140(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0xc15f0
jmp 0xcb04e
leaq -0x20(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0xcdcf0
jmp 0xcb060
leaq -0x140(%rbp), %rdi
callq 0xa3cd0
leaq -0x160(%rbp), %rdi
callq 0x5200
leaq -0x161(%rbp), %rdi
callq 0x53c0
jmp 0xcb0d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xcb0c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xcb0ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x140(%rbp), %rdi
callq 0xa3cd0
leaq -0x160(%rbp), %rdi
callq 0x5200
leaq -0x161(%rbp), %rdi
callq 0x53c0
jmp 0xcb26b
leaq -0xe8(%rbp), %rdi
xorl %esi, %esi
callq 0xcd750
movq %rax, -0x170(%rbp)
jmp 0xcaf2e
leaq -0x178(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
xorl %edx, %edx
callq 0xcdcb0
jmp 0xcb108
jmp 0xcae68
jmp 0xcb10f
movq -0x1a0(%rbp), %rdi
addq $0xa8, %rdi
callq 0xcdd20
xorb $-0x1, %al
testb $0x1, %al
jne 0xcb12d
jmp 0xcb1b9
movq -0x1a0(%rbp), %rdi
addq $0xa8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xcdd60
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x20(%rbp), %rdi
callq 0xccb20
jmp 0xcb156
movq -0x1a0(%rbp), %rdi
addq $0xa8, %rdi
movq %rdi, -0x238(%rbp)
callq 0xcddf0
movq %rax, -0x188(%rbp)
leaq -0x180(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0xcde20
movq -0x238(%rbp), %rdi
movq -0x180(%rbp), %rsi
callq 0xcdd80
movq %rax, -0x230(%rbp)
jmp 0xcb1a6
movq -0x230(%rbp), %rax
movq %rax, -0x190(%rbp)
jmp 0xcb10f
movq -0x1a0(%rbp), %rax
movslq 0x14(%rax), %rax
movq %rax, -0x198(%rbp)
movq -0x1a0(%rbp), %rdi
movq -0x198(%rbp), %rax
movq %rax, -0x240(%rbp)
addq $0x18, %rdi
callq 0xc1c30
movq %rax, %rcx
movq -0x240(%rbp), %rax
cmpq %rcx, %rax
jae 0xcb233
movq -0x1a0(%rbp), %rdi
addq $0x18, %rdi
movq -0x198(%rbp), %rsi
callq 0xcceb0
movq %rax, %rsi
leaq -0x20(%rbp), %rdi
callq 0xccb20
jmp 0xcb21d
jmp 0xcb21f
movq -0x198(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x198(%rbp)
jmp 0xcb1cb
movq -0x1a0(%rbp), %rdi
addq $0x18, %rdi
leaq -0x20(%rbp), %rsi
callq 0xcde60
leaq -0x68(%rbp), %rdi
callq 0xcdec0
leaq -0x50(%rbp), %rdi
callq 0xbfc40
leaq -0x20(%rbp), %rdi
callq 0xa4860
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0xcdec0
leaq -0x50(%rbp), %rdi
callq 0xbfc40
leaq -0x20(%rbp), %rdi
callq 0xa4860
movq -0x30(%rbp), %rdi
callq 0x55b0
nop