// File: /workspace/github_cpp_makefile_star2_O3/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
movups 0x408(%rdi), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x408(%rdi)
movq 0x418(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x24e4(%rip), %rcx      # 0x11cea4
movq %rcx, 0x418(%rdi)
movq 0x420(%rdi), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x248c(%rip), %rcx      # 0x11ce66
movq %rcx, 0x420(%rdi)
testq %rax, %rax
je 0x11a9f3
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x748(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x748(%rbx)
movq 0x758(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x2529(%rip), %rcx      # 0x11cf44
movq %rcx, 0x758(%rbx)
movq 0x760(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x2487(%rip), %rcx      # 0x11cebc
movq %rcx, 0x760(%rbx)
testq %rax, %rax
je 0x11aa4e
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x408(%rbx), %rsi
leaq 0x748(%rbx), %r14
leaq 0x428(%rbx), %rdi
callq 0x11d61e
leaq 0x768(%rbx), %rdi
movq %r14, %rsi
callq 0x11d61e
movups 0x488(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x488(%rbx)
movq 0x498(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x250d(%rip), %rcx      # 0x11cfac
movq %rcx, 0x498(%rbx)
movq 0x4a0(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x24a3(%rip), %rcx      # 0x11cf5c
movq %rcx, 0x4a0(%rbx)
testq %rax, %rax
je 0x11aad2
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x7e8(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x7e8(%rbx)
movq 0x7f8(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x24e2(%rip), %rcx      # 0x11cfdc
movq %rcx, 0x7f8(%rbx)
movq 0x800(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x24b0(%rip), %rcx      # 0x11cfc4
movq %rcx, 0x800(%rbx)
testq %rax, %rax
je 0x11ab2d
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x4c8(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x4c8(%rbx)
movq 0x4d8(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x24dd(%rip), %rcx      # 0x11d032
movq %rcx, 0x4d8(%rbx)
movq 0x4e0(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x2485(%rip), %rcx      # 0x11cff4
movq %rcx, 0x4e0(%rbx)
testq %rax, %rax
je 0x11ab88
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x508(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x508(%rbx)
movq 0x518(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x24d8(%rip), %rcx      # 0x11d088
movq %rcx, 0x518(%rbx)
movq 0x520(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x2480(%rip), %rcx      # 0x11d04a
movq %rcx, 0x520(%rbx)
testq %rax, %rax
je 0x11abe3
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
jmp 0x11abf5
jmp 0x11abf5
jmp 0x11abf5
jmp 0x11abf5
jmp 0x11abf5
movq %rax, %rdi
callq 0x171a3
nop