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

    prereq[int(Level::Bank)][int(Command::RD)] = [] (DRAM<TLDRAM>* node, Command cmd, int id) {
        switch (int(node->state)) {
            case int(State::Closed):
                if (id % node->spec->segment_ratio)
                    return Command::ACT;
                else
                    return Command::ACTF;
            case int(State::Opened):
                if (node->row_state.find(id) != node->row_state.end())
                    return cmd;
                if (id % node->spec->segment_ratio)
                    return Command::PRE;
                else
                    return Command::PREF;
            default: assert(false);
        }
    };
    prereq[int(Level::Bank)][int(Command::MIG)] = [] (DRAM<TLDRAM>* node, Command cmd, int id) {
        switch (int(node->state)) {
            case int(State::Closed):
                return Command::ACTM;
            case int(State::Opened):
                if (node->row_state.find(id) != node->row_state.end())
                    return cmd;
                return Command::PREM;
            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<TLDRAM>* node, Command cmd, int id) {
        for (auto bank : node->children) {
            if (bank->state == State::Closed)
                continue;
            if (id % node->spec->segment_ratio)
                return Command::PREA;
            else
                return Command::PREAF;
        }
        return Command::REF;
    };

    // PD
    prereq[int(Level::Rank)][int(Command::PDE)] = [] (DRAM<TLDRAM>* 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<TLDRAM>* 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 %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movups 0x518(%rdi), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x518(%rdi)
movq 0x528(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x3d9c(%rip), %rcx      # 0x1403ae
movq %rcx, 0x528(%rdi)
movq 0x530(%rdi), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3d44(%rip), %rcx      # 0x140370
movq %rcx, 0x530(%rdi)
testq %rax, %rax
je 0x13c645
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x518(%rbx), %r14
leaq 0x658(%rbx), %rdi
movq %r14, %rsi
callq 0x140cec
movups 0x738(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x738(%rbx)
movq 0x748(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3de7(%rip), %rcx      # 0x14046a
movq %rcx, 0x748(%rbx)
movq 0x750(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3d29(%rip), %rcx      # 0x1403c6
movq %rcx, 0x750(%rbx)
testq %rax, %rax
je 0x13c6b6
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x878(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x878(%rbx)
movq 0x888(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3e30(%rip), %rcx      # 0x14050e
movq %rcx, 0x888(%rbx)
movq 0x890(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3d8a(%rip), %rcx      # 0x140482
movq %rcx, 0x890(%rbx)
testq %rax, %rax
je 0x13c711
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x738(%rbx), %r15
leaq 0x538(%rbx), %rdi
movq %r14, %rsi
callq 0x140cec
leaq 0x758(%rbx), %rdi
movq %r15, %rsi
callq 0x140cec
movups 0x558(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x558(%rbx)
movq 0x568(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3e18(%rip), %rcx      # 0x140576
movq %rcx, 0x568(%rbx)
movq 0x570(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3dae(%rip), %rcx      # 0x140526
movq %rcx, 0x570(%rbx)
testq %rax, %rax
je 0x13c791
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x578(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x578(%rbx)
movq 0x588(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3e13(%rip), %rcx      # 0x1405cc
movq %rcx, 0x588(%rbx)
movq 0x590(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3dbb(%rip), %rcx      # 0x14058e
movq %rcx, 0x590(%rbx)
testq %rax, %rax
je 0x13c7ec
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x5b8(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x5b8(%rbx)
movq 0x5c8(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3e0e(%rip), %rcx      # 0x140622
movq %rcx, 0x5c8(%rbx)
movq 0x5d0(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3db6(%rip), %rcx      # 0x1405e4
movq %rcx, 0x5d0(%rbx)
testq %rax, %rax
je 0x13c847
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
jmp 0x13c85b
jmp 0x13c85b
jmp 0x13c85b
jmp 0x13c85b
jmp 0x13c85b
movq %rax, %rdi
callq 0x171a3
nop