// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %r12
leaq 0x50(%rsp), %rbx
andq $0x0, 0x10(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
xorl %r14d, %r14d
xorl %r15d, %r15d
movslq 0x10(%r12), %rax
cmpq %rax, %r15
jge 0x4a8ad
movq 0x18(%r12), %rsi
addq %r14, %rsi
movq %rbx, %rdi
callq 0x4b6f0
incq %r15
addq $0x50, %r14
jmp 0x4a88a
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq %r12, 0x28(%rsp)
leaq 0x60(%r12), %r14
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x4ba38
leaq 0x10(%rsp), %rbx
leaq 0x1043d(%rip), %r15     # 0x5ad1b
leaq 0x38(%rsp), %r13
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
cmpq %rcx, %rax
je 0x4a9a4
addq $0x30, %rcx
leaq -0x30(%rcx), %rdx
cmpq %rax, %rdx
je 0x4a989
leaq -0x58(%rcx), %r12
cmpl $0x0, -0x84(%rcx)
movq %r12, %rcx
jne 0x4a8fa
leaq -0x30(%r12), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4ba92
movslq 0x20(%r12), %rax
cmpq $-0x1, %rax
je 0x4a93f
movq 0x38(%rsp), %rcx
imulq $0x58, %rax, %rax
decl 0x4(%rcx,%rax)
movq %r12, %rdi
movq %r15, %rsi
callq 0x47a19
testb %al, %al
je 0x4a979
movq %r12, %rdi
leaq 0xe7d4(%rip), %rsi      # 0x5912c
callq 0x47a19
testb %al, %al
je 0x4a979
movslq 0x24(%r12), %rax
cmpq $-0x1, %rax
je 0x4a979
movq 0x38(%rsp), %rcx
imulq $0x58, %rax, %rax
decl 0x4(%rcx,%rax)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4bab0
jmp 0x4a8e3
movq 0x40648(%rip), %rdi     # 0x8afd8
leaq 0x10390(%rip), %rsi     # 0x5ad27
callq 0x5250
movq %rax, %rdi
callq 0x5130
movq 0x18(%rsp), %r15
leaq 0x50(%rsp), %rbx
movq 0x28(%rsp), %r13
cmpq 0x10(%rsp), %r15
je 0x4a9dc
movslq -0x4(%r15), %rax
addq $-0x4, %r15
movq 0x60(%r13), %rcx
imulq $0x58, %rax, %rax
movq 0x10(%rcx,%rax), %rdx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4abd6
jmp 0x4a9b3
movq 0x18(%rsp), %rax
leaq 0x68(%rsp), %r12
leaq 0x88(%rsp), %rbp
leaq 0x50(%rsp), %rbx
cmpq %r15, %rax
je 0x4aaad
movq %rax, 0x30(%rsp)
movslq -0x4(%rax), %rdx
movq (%r14), %rax
imulq $0x58, %rdx, %r15
cmpb $0x0, 0x9(%rax,%r15)
jne 0x4aa22
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4ad3a
movq (%r14), %rax
addq $-0x4, 0x30(%rsp)
movq 0x18(%rax,%r15), %r13
cmpq 0x20(%rax,%r15), %r13
je 0x4aa99
leaq (%rax,%r15), %rdx
movq (%r13), %rcx
cmpq 0x10(%rdx), %rcx
je 0x4aa93
cmpl $0x0, (%rcx)
je 0x4aa93
movq %r12, %rdi
leaq 0xe6c7(%rip), %rsi      # 0x59118
leaq 0xf(%rsp), %rdx
callq 0xfa26
movq (%r13), %rdx
movq (%r14), %rax
movq 0x10(%rax,%r15), %rcx
movq %rbp, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x47f44
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x47f08
movq %rbp, %rdi
callq 0x3ccde
movq %r12, %rdi
callq 0x5120
movq (%r14), %rax
addq $0x8, %r13
jmp 0x4aa2d
movq 0x10(%rsp), %r15
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %rax
jmp 0x4a9f3
leaq 0xa8(%r13), %rbx
leaq 0x50(%rsp), %r14
movq 0xa8(%r13), %rsi
cmpq 0xb0(%r13), %rsi
je 0x4aae2
addq $0x8, %rsi
movq %r14, %rdi
callq 0x4b6f0
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x4bab6
jmp 0x4aab9
movslq 0x14(%r13), %r14
imulq $0x50, %r14, %r15
pushq $0x50
popq %r12
leaq 0x50(%rsp), %rbx
movq 0x18(%r13), %rsi
movq 0x20(%r13), %rcx
movq %rcx, %rax
subq %rsi, %rax
cqto
idivq %r12
cmpq %rax, %r14
jae 0x4ab1f
addq %r15, %rsi
movq %rbx, %rdi
callq 0x4b6f0
incq %r14
addq $0x50, %r15
jmp 0x4aaf3
movq 0x28(%r13), %rax
leaq 0x50(%rsp), %rbx
movaps (%rbx), %xmm0
movups %xmm0, 0x18(%r13)
movq 0x10(%rbx), %rdx
movq %rdx, 0x28(%r13)
movq %rsi, (%rbx)
movq %rcx, 0x8(%rbx)
movq %rax, 0x10(%rbx)
leaq 0x38(%rsp), %rdi
callq 0x4babc
leaq 0x10(%rsp), %rdi
callq 0x481ca
movq %rbx, %rdi
callq 0x3ced4
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4ab90
movq %rax, %rbx
jmp 0x4abb9
jmp 0x4ab90
jmp 0x4ab90
jmp 0x4ab90
jmp 0x4ab90
jmp 0x4ab90
jmp 0x4ab90
jmp 0x4ab90
movq %rax, %rbx
jmp 0x4abc3
movq %rax, %rbx
jmp 0x4aba5
movq %rax, %rbx
jmp 0x4abaf
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3ccde
leaq 0x68(%rsp), %rdi
callq 0x5120
leaq 0x38(%rsp), %rdi
callq 0x4babc
leaq 0x10(%rsp), %rdi
callq 0x481ca
leaq 0x50(%rsp), %rdi
callq 0x3ced4
movq %rbx, %rdi
callq 0x53f0
nop