// File: /workspace/github_cpp_makefile_star2_O2/sighingnow[P]compile-pascal/pl0_opt.cpp
// Function: pl0_block_helper(std::vector<TAC, std::allocator<TAC>>&, std::vector<BasicBlock, std::allocator<BasicBlock>>&, int, std::map<int, std::vector<int, std::allocator<int>>, std::less<int>, std::allocator<std::pair<int const, std::vector<int, std::allocator<int>>>>>&, std::map<int, std::vector<int, std::allocator<int>>, std::less<int>, std::allocator<std::pair<int const, std::vector<int, std::allocator<int>>>>>&)
static int pl0_block_helper(std::vector<TAC> & code, std::vector<BasicBlock> & bbs, int p,
        std::map<int, std::vector<int>> & pres, std::map<int, std::vector<int>> & sufs)
{
    BasicBlock header(0, false);
    while (code[p].op == "param" || code[p].op == "paramref") {
        header.push(code[p++]);
    }
    header.push(code[p++]); // function or procedure.
    while (code[p].op == "def" || code[p].op == "allocret") {
        header.push(code[p++]);
    }
    int hidx = bbs.size();
    bbs.emplace_back(header);
    while (code[p].op == "param" || code[p].op == "paramref"
            || code[p].op == "function" || code[p].op == "procedure") {
        p = pl0_block_helper(code, bbs, p, pres, sufs);
    }
    bbs[hidx].setBegin(code[p].rd->iv);

    while (code[p].op != "endproc" && code[p].op != "endfunc") {
        BasicBlock body(code[p].rd->iv, true);
        body.push(code[p++]);
        while (code[p].op != "goto" && code[p].op != "call"
                && code[p].op != "endproc" && code[p].op != "endfunc") {
            if (code[p].op == "cmp") {
                sufs[body.no].emplace_back(code[p].rd->iv);
                pres[code[p].rd->iv].emplace_back(body.no);
            }
            if (code[p].op == "def") {
                // add temporary variable to symbol table.
                bbs[hidx].push(code[p++]);
            }
            else {
                body.push(code[p++]);
            }
        }
        if (code[p].op == "goto") {
            // goto label
            sufs[body.no].emplace_back(code[p].rs->iv);
            pres[code[p].rs->iv].emplace_back(body.no);
            body.push(code[p++]);
        }
        else if (code[p].op == "call") {
            // call ... -> ...
            // label: 
            body.push(code[p++]);
            sufs[body.no].emplace_back(code[p].rd->iv);
            pres[code[p].rd->iv].emplace_back(body.no);
        }
        else {
            body.push(code[p]);
        }

        bbs.emplace_back(body);
    }
    bbs[hidx].setEnd(bbs.back().no);
    bbs.back().is_end = true;
    return (++p);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %r8, 0x8(%rsp)
leaq 0xf0(%rsp), %r14
andl $0x0, -0x18(%r14)
movq %rcx, (%rsp)
andw $0x0, -0x14(%r14)
movq %rsi, %r15
movaps 0xfafb(%rip), %xmm0     # 0x5ac90
movups %xmm0, -0x10(%r14)
leaq 0x158(%rsp), %rax
andl $0x0, (%rax)
movq %rdi, %r12
andq $0x0, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x68(%rax)
movups %xmm0, -0x58(%rax)
movups %xmm0, -0x48(%rax)
movups %xmm0, -0x38(%rax)
movups %xmm0, -0x28(%rax)
movups %xmm0, -0x18(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movslq %edx, %rax
leal 0x1(%rax), %ebp
imulq $0x50, %rax, %r13
leaq 0xf812(%rip), %rbx      # 0x5a9fb
movq (%r12), %rdi
addq %r13, %rdi
movq %rbx, %rsi
callq 0x15c52
testb %al, %al
jne 0x4b213
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xf7e8(%rip), %rsi      # 0x5a9f2
callq 0x15c52
testb %al, %al
je 0x4b22a
incl %ebp
movq (%r12), %rsi
addq %r13, %rsi
addq $0x50, %r13
movq %r14, %rdi
callq 0x4b6f0
jmp 0x4b1e9
movq (%r12), %rsi
addq %r13, %rsi
movq %r14, %rdi
callq 0x4b6f0
addq $0x50, %r13
leaq 0xf757(%rip), %rbx      # 0x5a99b
movq (%r12), %rdi
addq %r13, %rdi
movq %rbx, %rsi
callq 0x15c52
testb %al, %al
jne 0x4b26e
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xfaed(%rip), %rsi      # 0x5ad52
callq 0x15c52
testb %al, %al
je 0x4b28d
incl %ebp
leaq 0x50(%r13), %r14
addq (%r12), %r13
leaq 0xf0(%rsp), %rdi
movq %r13, %rsi
callq 0x4b6f0
movq %r14, %r13
jmp 0x4b244
movq 0x8(%r15), %rax
subq (%r15), %rax
movl $0xc0, %ecx
cqto
idivq %rcx
movq %rax, 0x10(%rsp)
leaq 0xd8(%rsp), %rsi
movq %r15, %rdi
callq 0x4bcdc
leaq 0xf741(%rip), %r13      # 0x5a9fb
leaq 0xf731(%rip), %rbx      # 0x5a9f2
movslq %ebp, %rax
imulq $0x50, %rax, %r14
movq (%r12), %rdi
addq %r14, %rdi
movq %r13, %rsi
callq 0x15c52
testb %al, %al
jne 0x4b31c
movq (%r12), %rdi
addq %r14, %rdi
movq %rbx, %rsi
callq 0x15c52
testb %al, %al
jne 0x4b31c
movq (%r12), %rdi
addq %r14, %rdi
leaq 0xf6c3(%rip), %rsi      # 0x5a9bf
callq 0x15c52
testb %al, %al
jne 0x4b31c
movq (%r12), %rdi
addq %r14, %rdi
leaq 0xe5d5(%rip), %rsi      # 0x598e8
callq 0x15c52
testb %al, %al
je 0x4b336
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq (%rsp), %rcx
movq 0x8(%rsp), %r8
callq 0x4b15e
movl %eax, %ebp
jmp 0x4b2c1
movslq 0x10(%rsp), %rax
movq (%r15), %rcx
movq (%r12), %rdi
movq 0x20(%rdi,%r14), %rdx
movl 0x4(%rdx), %edx
imulq $0xc0, %rax, %rbx
movl %edx, 0x8(%rcx,%rbx)
movslq %ebp, %rax
imulq $0x50, %rax, %r13
addq %r13, %rdi
leaq 0xf5f5(%rip), %rsi      # 0x5a95b
callq 0x47a19
testb %al, %al
je 0x4b642
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xf64f(%rip), %rsi      # 0x5a9d0
callq 0x47a19
testb %al, %al
je 0x4b642
movq (%r12), %rsi
movq 0x20(%rsi,%r13), %rax
movl 0x4(%rax), %eax
movl %eax, 0x18(%rsp)
movw $0x1, 0x1c(%rsp)
movaps 0xf8e4(%rip), %xmm0     # 0x5ac90
movups %xmm0, 0x20(%rsp)
andl $0x0, 0x98(%rsp)
andq $0x0, 0xa0(%rsp)
addq %r13, %rsi
leaq 0x30(%rsp), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rdi)
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
leaq 0x98(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq %rax, 0xb0(%rsp)
movups %xmm0, 0x98(%rdi)
movups %xmm0, 0x88(%rdi)
callq 0x4b6f0
addl $0x2, %ebp
addq $0x50, %r13
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xf69e(%rip), %rsi      # 0x5aac2
callq 0x47a19
testb %al, %al
je 0x4b523
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xe654(%rip), %rsi      # 0x59a93
callq 0x47a19
testb %al, %al
je 0x4b523
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xf501(%rip), %rsi      # 0x5a95b
callq 0x47a19
testb %al, %al
je 0x4b523
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xf55b(%rip), %rsi      # 0x5a9d0
callq 0x47a19
testb %al, %al
je 0x4b523
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xf62e(%rip), %rsi      # 0x5aabe
callq 0x15c52
testb %al, %al
je 0x4b4e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x4bade
movq (%r12), %rcx
movq 0x20(%rcx,%r13), %rsi
addq $0x4, %rsi
movq %rax, %rdi
callq 0x477c4
movq (%r12), %rax
movq 0x20(%rax,%r13), %rsi
addq $0x4, %rsi
movq (%rsp), %rdi
callq 0x4bade
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4bd1c
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xf4ad(%rip), %rsi      # 0x5a99b
callq 0x15c52
movq (%r15), %rcx
leaq (%rcx,%rbx), %rdi
addq $0x18, %rdi
testb %al, %al
leaq 0x30(%rsp), %rax
cmoveq %rax, %rdi
incl %ebp
leaq 0x50(%r13), %r14
addq (%r12), %r13
movq %r13, %rsi
callq 0x4b6f0
movq %r14, %r13
jmp 0x4b416
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xf591(%rip), %rsi      # 0x5aac2
callq 0x15c52
testb %al, %al
je 0x4b597
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x4bade
movq (%r12), %rcx
movq 0x28(%rcx,%r13), %rsi
addq $0x4, %rsi
movq %rax, %rdi
callq 0x477c4
movq (%r12), %rax
movq 0x28(%rax,%r13), %rsi
addq $0x4, %rsi
movq (%rsp), %rdi
callq 0x4bade
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4bd1c
addq (%r12), %r13
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x4b6f0
jmp 0x4b622
movq (%r12), %rdi
addq %r13, %rdi
leaq 0xe4ee(%rip), %rsi      # 0x59a93
callq 0x15c52
testb %al, %al
je 0x4b60f
addq (%r12), %r13
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x4b6f0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x4bade
movslq %ebp, %rcx
movq (%r12), %rdx
imulq $0x50, %rcx, %r14
movq 0x20(%rdx,%r14), %rsi
addq $0x4, %rsi
movq %rax, %rdi
callq 0x477c4
movq (%r12), %rax
movq 0x20(%rax,%r14), %rsi
addq $0x4, %rsi
movq (%rsp), %rdi
callq 0x4bade
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4bd1c
jmp 0x4b622
addq (%r12), %r13
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x4b6f0
decl %ebp
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4bcdc
leaq 0x18(%rsp), %rdi
callq 0x4bd50
movq (%r12), %rdi
jmp 0x4b355
movq (%r15), %rax
movq 0x8(%r15), %rcx
movl -0xc0(%rcx), %edx
movl %edx, 0xc(%rax,%rbx)
movb $0x1, -0xbb(%rcx)
incl %ebp
leaq 0xd8(%rsp), %rdi
callq 0x4bd50
movl %ebp, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4b689
jmp 0x4b689
jmp 0x4b689
jmp 0x4b689
jmp 0x4b689
jmp 0x4b68e
movq %rax, %rbx
jmp 0x4b69b
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x4bd50
leaq 0xd8(%rsp), %rdi
callq 0x4bd50
movq %rbx, %rdi
callq 0x53f0