// File: /workspace/github_cpp_makefile_star2_O1/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
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
cmpl $0x0, 0x10(%rdi)
jle 0x8063c
xorl %r14d, %r14d
movq %rsp, %rbx
xorl %r15d, %r15d
movq 0x18(%r12), %rsi
addq %r14, %rsi
movq %rbx, %rdi
callq 0x81b58
incq %r15
movslq 0x10(%r12), %rax
addq $0x50, %r14
cmpq %rax, %r15
jl 0x8061b
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
leaq 0x60(%r12), %rsi
leaq 0x48(%rsp), %rdi
movq %rsi, 0x38(%rsp)
callq 0x81efc
movq 0x50(%rsp), %rbx
cmpq %rbx, 0x48(%rsp)
movq %r12, 0x40(%rsp)
je 0x8079b
movb $0x1, %bpl
movq 0x3f958(%rip), %r15     # 0xbffd8
leaq 0x20(%rsp), %r14
cmpq 0x48(%rsp), %rbx
je 0x80741
leaq -0x58(%rbx), %r13
movl -0x54(%rbx), %r12d
testl %r12d, %r12d
jne 0x80730
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x806be
movl (%r13), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x806c9
movq %r14, %rdi
movq %r13, %rdx
callq 0x82e48
movslq -0x8(%rbx), %rax
cmpq $-0x1, %rax
je 0x806e0
movq 0x48(%rsp), %rcx
imulq $0x58, %rax, %rax
decl 0x4(%rcx,%rax)
leaq -0x28(%rbx), %rbp
movq %rbp, %rdi
leaq 0x185fd(%rip), %rsi     # 0x98ceb
callq 0x50c0
testl %eax, %eax
je 0x80721
movq %rbp, %rdi
leaq 0x16a2b(%rip), %rsi     # 0x9712c
callq 0x50c0
testl %eax, %eax
je 0x80721
movslq -0x4(%rbx), %rax
cmpq $-0x1, %rax
je 0x80721
movq 0x48(%rsp), %rcx
imulq $0x58, %rax, %rax
decl 0x4(%rcx,%rax)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x83d1a
xorl %ebp, %ebp
movq %r13, %rbx
testl %r12d, %r12d
movq 0x40(%rsp), %r12
jne 0x80685
testb $0x1, %bpl
je 0x80788
movl $0x2a, %edx
movq %r15, %rdi
leaq 0x185a1(%rip), %rsi     # 0x98cf7
callq 0x52e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x5240
movsbl %al, %esi
movq %r15, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5190
testb $0x1, %bpl
jne 0x8079b
movq 0x50(%rsp), %rbx
movb $0x1, %bpl
cmpq %rbx, 0x48(%rsp)
jne 0x80685
movq 0x28(%rsp), %r15
movq %rsp, %rbx
cmpq 0x20(%rsp), %r15
je 0x807cd
movslq -0x4(%r15), %rax
addq $-0x4, %r15
movq 0x60(%r12), %rcx
imulq $0x58, %rax, %rax
movq 0x10(%rcx,%rax), %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x80ac6
jmp 0x807a3
movq 0x28(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x80941
leaq 0x70(%rsp), %r12
leaq 0x98(%rsp), %rbp
leaq 0x88(%rsp), %r13
movq %rax, 0x80(%rsp)
movslq -0x4(%rax), %rdx
movq 0x38(%rsp), %rax
movq (%rax), %rax
imulq $0x58, %rdx, %rbx
cmpb $0x0, 0x9(%rax,%rbx)
jne 0x8081e
movq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x80d38
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%rbx), %r15
cmpq 0x20(%rax,%rbx), %r15
je 0x8092a
movq (%r15), %rcx
cmpq 0x10(%rax,%rbx), %rcx
je 0x80919
cmpl $0x0, (%rcx)
je 0x80919
movq %r12, 0x60(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x168ba(%rip), %rsi     # 0x97118
leaq 0x168b4(%rip), %rdx     # 0x97119
callq 0x2670a
movq (%r15), %r12
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rbx, %r14
movq 0x10(%rax,%rbx), %rbx
movq %rbp, 0x88(%rsp)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x36590
movq %r12, 0xa8(%rsp)
movq %rbx, 0xb0(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbp)
movups %xmm0, 0x20(%rbp)
movq %rsp, %rdi
movq %r13, %rsi
callq 0x7d292
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
leaq 0x70(%rsp), %r12
je 0x808e2
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x5260
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
movq %r14, %rbx
je 0x80902
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0x80919
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x5260
addq $0x8, %r15
movq 0x38(%rsp), %rax
movq (%rax), %rax
jmp 0x8082b
movq 0x80(%rsp), %rax
addq $-0x4, %rax
cmpq 0x20(%rsp), %rax
jne 0x807f2
movq 0x40(%rsp), %r13
leaq 0xa8(%r13), %rbx
movq %rsp, %r14
movq 0xa8(%r13), %rsi
cmpq 0xb0(%r13), %rsi
je 0x80979
addq $0x8, %rsi
movq %r14, %rdi
callq 0x81b58
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x83e10
jmp 0x80950
movslq 0x14(%r13), %r14
movq 0x18(%r13), %rsi
movq 0x20(%r13), %rax
movq %rax, %rcx
subq %rsi, %rcx
sarq $0x4, %rcx
movabsq $-0x3333333333333333, %r15 # imm = 0xCCCCCCCCCCCCCCCD
imulq %r15, %rcx
cmpq %r14, %rcx
jbe 0x809dd
movq %r14, %rax
shlq $0x4, %rax
leaq (%rax,%rax,4), %r12
movq %rsp, %rbx
addq %r12, %rsi
movq %rbx, %rdi
callq 0x81b58
incq %r14
movq 0x18(%r13), %rsi
movq 0x20(%r13), %rax
movq %rax, %rcx
subq %rsi, %rcx
sarq $0x4, %rcx
imulq %r15, %rcx
addq $0x50, %r12
cmpq %rcx, %r14
jb 0x809b0
movq 0x28(%r13), %rcx
movq (%rsp), %rdx
movq %rdx, 0x18(%r13)
movq 0x8(%rsp), %rdx
movq %rdx, 0x20(%r13)
movq 0x10(%rsp), %rdx
movq %rdx, 0x28(%r13)
movq %rsi, (%rsp)
movq %rax, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x81f94
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x80a2a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x5260
movq %rsp, %rdi
callq 0x6b198
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x80a9e
jmp 0x80a91
jmp 0x80a91
jmp 0x80a91
jmp 0x80a91
movq %rax, %rbx
jmp 0x80ab5
jmp 0x80a91
jmp 0x80a91
jmp 0x80a91
jmp 0x80a91
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x6afce
jmp 0x80a73
movq %rax, %rbx
leaq 0x70(%rsp), %r14
movq 0x60(%rsp), %rdi
cmpq %r14, %rdi
je 0x80a94
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x80a94
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x81f94
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x80ab5
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x5260
movq %rsp, %rdi
callq 0x6b198
movq %rbx, %rdi
callq 0x53d0
nop