// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]ramulator/src/DDR4.cpp
// Function: ramulator::DDR4::init_prereq()
void DDR4::init_prereq()
{
    // RD
    prereq[int(Level::Rank)][int(Command::RD)] = [] (DRAM<DDR4>* 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<DDR4>* 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<DDR4>* 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;};

    // PD
    prereq[int(Level::Rank)][int(Command::PDE)] = [] (DRAM<DDR4>* 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<DDR4>* 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 0x285e(%rip), %rcx      # 0x112a1e
movq %rcx, 0x18(%rsp)
leaq 0x2890(%rip), %rdx      # 0x112a5c
movq %rdx, 0x10(%rsp)
movups 0x3c0(%rdi), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x3c0(%rdi)
movq 0x3d0(%rdi), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x3d0(%rdi)
movq 0x3d8(%rdi), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x3d8(%rdi)
testq %rax, %rax
je 0x11021b
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x284b(%rip), %rcx      # 0x112a74
movq %rcx, 0x18(%rsp)
leaq 0x28c7(%rip), %rdx      # 0x112afc
movq %rdx, 0x10(%rsp)
movups 0x6c0(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x6c0(%rbx)
movq 0x6d0(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x6d0(%rbx)
movq 0x6d8(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x6d8(%rbx)
testq %rax, %rax
je 0x110284
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x3c0(%rbx), %rsi
leaq 0x6c0(%rbx), %r14
leaq 0x3e0(%rbx), %rdi
callq 0x1131e8
leaq 0x6e0(%rbx), %rdi
movq %r14, %rsi
callq 0x1131e8
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x2859(%rip), %rcx      # 0x112b14
movq %rcx, 0x18(%rsp)
leaq 0x28b3(%rip), %rdx      # 0x112b7a
movq %rdx, 0x10(%rsp)
movups 0x440(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x440(%rbx)
movq 0x450(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x450(%rbx)
movq 0x458(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x458(%rbx)
testq %rax, %rax
je 0x110316
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x286e(%rip), %rcx      # 0x112b92
movq %rcx, 0x18(%rsp)
leaq 0x28a0(%rip), %rdx      # 0x112bd0
movq %rdx, 0x10(%rsp)
movups 0x460(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x460(%rbx)
movq 0x470(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x470(%rbx)
movq 0x478(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x478(%rbx)
testq %rax, %rax
je 0x11037f
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
leaq 0x285b(%rip), %rcx      # 0x112be8
movq %rcx, 0x18(%rsp)
leaq 0x288d(%rip), %rdx      # 0x112c26
movq %rdx, 0x10(%rsp)
movups 0x4a0(%rbx), %xmm1
movaps %xmm1, (%rsp)
movups %xmm0, 0x4a0(%rbx)
movq 0x4b0(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x4b0(%rbx)
movq 0x4b8(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x4b8(%rbx)
testq %rax, %rax
je 0x1103e8
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
jmp 0x1103f8
jmp 0x1103f8
jmp 0x1103f8
jmp 0x1103f8
movq %rax, %rdi
callq 0x1718f