// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]ramulator/src/HBM.cpp
// Function: ramulator::HBM::init_prereq()
void HBM::init_prereq()
{
    // RD
    prereq[int(Level::Rank)][int(Command::RD)] = [] (DRAM<HBM>* node, Command cmd, int id) {
        switch (int(node->state)) {
            case int(State::PowerUp): return Command::MAX;
            case int(State::ActPowerDown): return Command::PDX;
            case int(State::PrePowerDown): return Command::PDX;
            case int(State::SelfRefresh): return Command::SRX;
            default: assert(false);
        }};
    prereq[int(Level::Bank)][int(Command::RD)] = [] (DRAM<HBM>* node, Command cmd, int id) {
        switch (int(node->state)) {
            case int(State::Closed): return Command::ACT;
            case int(State::Opened):
                if (node->row_state.find(id) != node->row_state.end())
                    return cmd;
                else return Command::PRE;
            default: assert(false);
        }};

    // WR
    prereq[int(Level::Rank)][int(Command::WR)] = prereq[int(Level::Rank)][int(Command::RD)];
    prereq[int(Level::Bank)][int(Command::WR)] = prereq[int(Level::Bank)][int(Command::RD)];

    // REF
    prereq[int(Level::Rank)][int(Command::REF)] = [] (DRAM<HBM>* node, Command cmd, int id) {
        for (auto bg : node->children)
            for (auto bank: bg->children) {
                if (bank->state == State::Closed)
                    continue;
                return Command::PREA;
            }
        return Command::REF;};

    // REFSB
    prereq[int(Level::Bank)][int(Command::REFSB)] = [] (DRAM<HBM>* node, Command cmd, int id) {
        if (node->state == State::Closed) return Command::REFSB;
        return Command::PRE;};

    // PD
    prereq[int(Level::Rank)][int(Command::PDE)] = [] (DRAM<HBM>* node, Command cmd, int id) {
        switch (int(node->state)) {
            case int(State::PowerUp): return Command::PDE;
            case int(State::ActPowerDown): return Command::PDE;
            case int(State::PrePowerDown): return Command::PDE;
            case int(State::SelfRefresh): return Command::SRX;
            default: assert(false);
        }};

    // SR
    prereq[int(Level::Rank)][int(Command::SRE)] = [] (DRAM<HBM>* node, Command cmd, int id) {
        switch (int(node->state)) {
            case int(State::PowerUp): return Command::SRE;
            case int(State::ActPowerDown): return Command::PDX;
            case int(State::PrePowerDown): return Command::PDX;
            case int(State::SelfRefresh): return Command::SRE;
            default: assert(false);
        }};
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x2456(%rip), %rcx      # 0x11feee
movq %rcx, 0x18(%rsp)
leaq 0x2488(%rip), %rdx      # 0x11ff2c
movq %rdx, 0x10(%rsp)
movups 0x408(%rdi), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x408(%rdi)
movq 0x418(%rdi), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x418(%rdi)
movq 0x420(%rdi), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x420(%rdi)
testq %rax, %rax
je 0x11daf3
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x2443(%rip), %rcx      # 0x11ff44
movq %rcx, 0x18(%rsp)
leaq 0x24bf(%rip), %rdx      # 0x11ffcc
movq %rdx, 0x10(%rsp)
movups 0x748(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x748(%rbx)
movq 0x758(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x758(%rbx)
movq 0x760(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x760(%rbx)
testq %rax, %rax
je 0x11db5c
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x408(%rbx), %rsi
leaq 0x748(%rbx), %r14
leaq 0x428(%rbx), %rdi
callq 0x1206e8
leaq 0x768(%rbx), %rdi
movq %r14, %rsi
callq 0x1206e8
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x2451(%rip), %rcx      # 0x11ffe4
movq %rcx, 0x18(%rsp)
leaq 0x24ab(%rip), %rdx      # 0x12004a
movq %rdx, 0x10(%rsp)
movups 0x488(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x488(%rbx)
movq 0x498(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x498(%rbx)
movq 0x4a0(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x4a0(%rbx)
testq %rax, %rax
je 0x11dbee
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x2466(%rip), %rcx      # 0x120062
movq %rcx, 0x18(%rsp)
leaq 0x2472(%rip), %rdx      # 0x12007a
movq %rdx, 0x10(%rsp)
movups 0x7e8(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x7e8(%rbx)
movq 0x7f8(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x7f8(%rbx)
movq 0x800(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x800(%rbx)
testq %rax, %rax
je 0x11dc57
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x242d(%rip), %rcx      # 0x120092
movq %rcx, 0x18(%rsp)
leaq 0x245f(%rip), %rdx      # 0x1200d0
movq %rdx, 0x10(%rsp)
movups 0x4c8(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x4c8(%rbx)
movq 0x4d8(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x4d8(%rbx)
movq 0x4e0(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x4e0(%rbx)
testq %rax, %rax
je 0x11dcc0
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x241a(%rip), %rcx      # 0x1200e8
movq %rcx, 0x18(%rsp)
leaq 0x244c(%rip), %rdx      # 0x120126
movq %rdx, 0x10(%rsp)
movups 0x508(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x508(%rbx)
movq 0x518(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x518(%rbx)
movq 0x520(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x520(%rbx)
testq %rax, %rax
je 0x11dd29
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
jmp 0x11dd3b
jmp 0x11dd3b
jmp 0x11dd3b
jmp 0x11dd3b
jmp 0x11dd3b
movq %rax, %rdi
callq 0x1718f
nop