// File: /workspace/github_cpp_makefile_star2_O2/acliusBackHome[P]kamaya/dist/BaseBlock.cpp
// Function: BaseBlock::get_base_blocks(std::vector<std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>> const&)
BaseBlockListAndMap BaseBlock::get_base_blocks(const vector<Qua> &qua_list) {
    if (qua_list.empty()) {
        return BaseBlockListAndMap(vector<BaseBlock>(), map<size_t, size_t>());
    }
    set<size_t> tags; //标记基本块的标记
    tags.insert(0);
    for (size_t i = 0; i < qua_list.size(); ++i) {
        const string &op = get<0>(qua_list[i]);
        if (op == "jmp" || op == "j>" || op == "j<" || op == "j<=" ||
            op == "j>=" || op == "j==" || op == "j!=") {
            size_t jump_adr = strtoull(get<3>(qua_list[i]).c_str(), nullptr, 10),
                    next_instr = i + 1;
            if (tags.find(jump_adr) == tags.end()) {
                tags.insert(jump_adr);
            }
            if (next_instr < qua_list.size()) {
                if (tags.find(next_instr) == tags.end()) {
                    tags.insert(next_instr);
                }
            }
        }
    }
    size_t last_qua = qua_list.size();
    if (tags.find(last_qua) == tags.end()) {
        tags.insert(last_qua);
    }
    vector<BaseBlock> res;
    BaseBlock block_now;
    block_now.block_id = block_now.begin_index = 0;
    auto iter = tags.begin();
    block_now.qua_list.emplace_back(qua_list[*iter]);
    iter++;
    // 建立行号到基本块id的映射
    map<size_t, size_t> line2block_id;
    line2block_id[0] = block_now.block_id;
    for (size_t i = 1; i < qua_list.size(); ++i) {
        if (iter == tags.end()) {
            break;
        }
        if (i == *iter) {
            block_now.end_index = i - 1;
            res.emplace_back(block_now);
            block_now.block_id++;
            block_now.begin_index = i;
            block_now.qua_list.clear();
            line2block_id[i] = block_now.block_id;
            block_now.qua_list.emplace_back(qua_list[i]);
            iter++;
        } else {
            block_now.qua_list.emplace_back(qua_list[i]);
            line2block_id[i] = block_now.block_id;
        }
    }
    block_now.end_index = *iter - 1;
    res.emplace_back(block_now);
    // 结束
    line2block_id[qua_list.size()] = res.size();
    for (auto &each : res) {
        if (each.qua_list.empty()) {
            cout << "bug: 有空的基本块" << endl;
            continue;
        }
        const auto &block_last_qua = each.qua_list[each.qua_list.size() - 1];
        const string &op = get<0>(block_last_qua);
        if (op == "jmp") {
            size_t jump_adr = strtoull(get<3>(block_last_qua).c_str(), nullptr, 10);
            each.jump_to.emplace_back(line2block_id[jump_adr]);
        } else if (op == "j>" || op == "j<" || op == "j<=" ||
                   op == "j>=" || op == "j==" || op == "j!=") {
            size_t jump_adr = strtoull(get<3>(block_last_qua).c_str(), nullptr, 10),
                    next_instr = each.end_index + 1;
            each.jump_to.emplace_back(line2block_id[jump_adr]);
            each.jump_to.emplace_back(line2block_id[next_instr]);
        } else {
            size_t next_instr = each.end_index + 1;
            each.jump_to.emplace_back(line2block_id[next_instr]);
        }
    }
    return BaseBlockListAndMap(res, line2block_id);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq (%rsi), %rax
cmpq 0x8(%rsi), %rax
je 0x2d4aa
movq %rsi, %r14
movq %rdi, -0x58(%rbp)
leaq -0x88(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0x120(%rbp), %rsi
andq $0x0, (%rsi)
leaq -0x90(%rbp), %rdi
callq 0x2defe
xorl %r13d, %r13d
leaq -0x90(%rbp), %r12
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x7, %rcx
cmpq %rcx, %r13
jae 0x2d0f3
movq %r13, %rbx
shlq $0x7, %rbx
leaq (%rax,%rbx), %r15
addq $0x60, %r15
movq %r15, %rdi
leaq 0xb080(%rip), %rsi      # 0x38055
callq 0x1ddf5
testb %al, %al
jne 0x2d054
movq %r15, %rdi
leaq 0xb05e(%rip), %rsi      # 0x38046
callq 0x1ddf5
testb %al, %al
jne 0x2d054
movq %r15, %rdi
leaq 0xb044(%rip), %rsi      # 0x3803f
callq 0x1ddf5
testb %al, %al
jne 0x2d054
movq %r15, %rdi
leaq 0xb034(%rip), %rsi      # 0x38042
callq 0x1ddf5
testb %al, %al
jne 0x2d054
movq %r15, %rdi
leaq 0xb028(%rip), %rsi      # 0x38049
callq 0x1ddf5
testb %al, %al
jne 0x2d054
movq %r15, %rdi
leaq 0xb019(%rip), %rsi      # 0x3804d
callq 0x1ddf5
testb %al, %al
jne 0x2d054
movq %r15, %rdi
leaq 0xb00a(%rip), %rsi      # 0x38051
callq 0x1ddf5
testb %al, %al
je 0x2d0eb
movq (%r14), %rax
movq (%rax,%rbx), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x4380
movq %rax, -0x120(%rbp)
incq %r13
movq %r13, -0xc0(%rbp)
movq %r12, %rdi
leaq -0x120(%rbp), %rsi
callq 0x172a2
leaq -0x88(%rbp), %rcx
cmpq %rcx, %rax
jne 0x2d0a0
movq %r12, %rdi
leaq -0x120(%rbp), %rsi
callq 0x1704e
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x7, %rax
cmpq %rax, -0xc0(%rbp)
jae 0x2cfa5
movq %r12, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x172a2
leaq -0x88(%rbp), %rcx
cmpq %rcx, %rax
jne 0x2cfa5
movq %r12, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x1704e
jmp 0x2cfa5
incq %r13
jmp 0x2cfa5
leaq -0xd0(%rbp), %rsi
movq %rcx, (%rsi)
leaq -0x90(%rbp), %rdi
callq 0x172a2
leaq -0x88(%rbp), %rcx
cmpq %rcx, %rax
jne 0x2d128
leaq -0x90(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1704e
andq $0x0, -0x40(%rbp)
xorps %xmm0, %xmm0
leaq -0x118(%rbp), %rbx
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
orq $-0x1, 0x38(%rbx)
movaps %xmm0, -0x50(%rbp)
andq $0x0, 0x30(%rbx)
andq $0x0, -0x8(%rbx)
movq -0x78(%rbp), %r15
movq 0x20(%r15), %rsi
shlq $0x7, %rsi
addq (%r14), %rsi
movq %rbx, %rdi
callq 0x2d886
movq %r15, %rdi
callq 0x42f0
leaq -0xb8(%rbp), %rcx
andl $0x0, (%rcx)
andq $0x0, 0x8(%rcx)
movq %rax, %r15
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
andq $0x0, 0x20(%rcx)
movq -0x120(%rbp), %r12
leaq -0x30(%rbp), %rsi
andq $0x0, (%rsi)
leaq -0xc0(%rbp), %rdi
callq 0x2d8c2
movq %r12, (%rax)
pushq $0x1
popq %rax
leaq -0x30(%rbp), %r13
movq %rax, -0x30(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rcx
subq %rsi, %rcx
sarq $0x7, %rcx
cmpq %rcx, %rax
jae 0x2d28a
leaq -0x88(%rbp), %rcx
cmpq %rcx, %r15
je 0x2d28a
cmpq 0x20(%r15), %rax
jne 0x2d256
decq %rax
movq %rax, -0xe0(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x2d914
incq -0x120(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq %rbx, %rdi
callq 0x2d950
movq -0x120(%rbp), %r12
leaq -0xc0(%rbp), %rdi
movq %r13, %rsi
callq 0x2d95e
movq %r12, (%rax)
movq -0x30(%rbp), %rsi
shlq $0x7, %rsi
addq (%r14), %rsi
movq %rbx, %rdi
callq 0x2d886
movq %r15, %rdi
callq 0x42f0
movq %rax, %r15
jmp 0x2d27e
shlq $0x7, %rax
addq %rax, %rsi
movq %rbx, %rdi
callq 0x2d886
movq -0x120(%rbp), %r12
leaq -0xc0(%rbp), %rdi
movq %r13, %rsi
callq 0x2d95e
movq %r12, (%rax)
movq -0x30(%rbp), %rax
incq %rax
jmp 0x2d1b8
movq 0x20(%r15), %rax
decq %rax
leaq -0x120(%rbp), %rsi
movq %rax, 0x40(%rsi)
leaq -0x50(%rbp), %rdi
callq 0x2d914
movq -0x50(%rbp), %r15
movq 0x8(%r14), %rax
subq (%r14), %rax
movq -0x48(%rbp), %rbx
sarq $0x7, %rax
leaq -0x30(%rbp), %rsi
movq %rax, (%rsi)
leaq -0xc0(%rbp), %rdi
callq 0x2d8c2
movq %rax, %rcx
subq %r15, %rbx
pushq $0x48
popq %rsi
movq %rbx, %rax
cqto
idivq %rsi
movq %rax, (%rcx)
movq -0x50(%rbp), %r14
movq -0x48(%rbp), %rbx
addq $0x20, %r14
leaq -0xc0(%rbp), %r15
leaq -0x20(%r14), %rax
cmpq %rbx, %rax
je 0x2d463
movq 0x10(%rax), %r12
cmpq %r12, 0x8(%rax)
je 0x2d352
movq %r12, %r13
addq $-0x20, %r13
movq %r13, %rdi
leaq 0xad3b(%rip), %rsi      # 0x38055
callq 0x1ddf5
testb %al, %al
je 0x2d372
movq -0x80(%r12), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x4380
movq %rax, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2d95e
movq %r14, %rdi
movq %rax, %rsi
callq 0x1b546
jmp 0x2d436
movq 0x25c6f(%rip), %rdi     # 0x52fc8
leaq 0xf374(%rip), %rsi      # 0x3c6d4
callq 0x4280
movq %rax, %rdi
callq 0x4170
jmp 0x2d436
movq %r13, %rdi
leaq 0xacca(%rip), %rsi      # 0x38046
callq 0x1ddf5
testb %al, %al
jne 0x2d3e4
movq %r13, %rdi
leaq 0xacb0(%rip), %rsi      # 0x3803f
callq 0x1ddf5
testb %al, %al
jne 0x2d3e4
movq %r13, %rdi
leaq 0xaca0(%rip), %rsi      # 0x38042
callq 0x1ddf5
testb %al, %al
jne 0x2d3e4
movq %r13, %rdi
leaq 0xac94(%rip), %rsi      # 0x38049
callq 0x1ddf5
testb %al, %al
jne 0x2d3e4
movq %r13, %rdi
leaq 0xac85(%rip), %rsi      # 0x3804d
callq 0x1ddf5
testb %al, %al
jne 0x2d3e4
movq %r13, %rdi
leaq 0xac76(%rip), %rsi      # 0x38051
callq 0x1ddf5
testb %al, %al
je 0x2d43f
movq -0x80(%r12), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x4380
movq %rax, -0x30(%rbp)
movq 0x20(%r14), %rax
incq %rax
movq %rax, -0xc8(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2d95e
movq %r14, %rdi
movq %rax, %rsi
callq 0x1b546
movq %r15, %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2d95e
movq %r14, %rdi
movq %rax, %rsi
callq 0x1b546
addq $0x48, %r14
jmp 0x2d2f2
movq 0x20(%r14), %rax
incq %rax
movq %rax, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2d95e
movq %r14, %rdi
movq %rax, %rsi
callq 0x1b546
jmp 0x2d436
leaq -0x50(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
movq -0x58(%rbp), %rdi
callq 0x2da1a
leaq -0xc0(%rbp), %rdi
callq 0x10e62
leaq -0x120(%rbp), %rdi
callq 0x128a2
leaq -0x50(%rbp), %rdi
callq 0x1283c
leaq -0x90(%rbp), %rdi
callq 0x11412
movq -0x58(%rbp), %r15
jmp 0x2d4fe
leaq -0x118(%rbp), %rax
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movaps %xmm0, -0x8(%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0x120(%rbp), %r14
movq %rbx, %rsi
movq %rdi, %r15
movq %r14, %rdx
callq 0x2d872
movq %r14, %rdi
callq 0x10e62
movq %rbx, %rdi
callq 0x1283c
movq %r15, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2d535
jmp 0x2d52e
jmp 0x2d535
jmp 0x2d535
movq %rax, %rbx
jmp 0x2d544
jmp 0x2d52e
jmp 0x2d52e
jmp 0x2d535
jmp 0x2d52e
jmp 0x2d52e
jmp 0x2d535
jmp 0x2d535
movq %rax, %rbx
jmp 0x2d559
jmp 0x2d535
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x10e62
leaq -0x120(%rbp), %rdi
callq 0x128a2
leaq -0x50(%rbp), %rdi
callq 0x1283c
leaq -0x90(%rbp), %rdi
callq 0x11412
movq %rbx, %rdi
callq 0x4500
nop