// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]ramulator/src/LPDDR3.cpp
// Function: ramulator::LPDDR3::init_prereq()
void LPDDR3::init_prereq()
{
    // RD
    prereq[int(Level::Rank)][int(Command::RD)] = [] (DRAM<LPDDR3>* 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::SREFX;
            default: assert(false);
        }};
    prereq[int(Level::Bank)][int(Command::RD)] = [] (DRAM<LPDDR3>* 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;
                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<LPDDR3>* node, Command cmd, int id) {
        for (auto bank : node->children) {
            if (bank->state == State::Closed)
                continue;
            return Command::PRA;
        }
        return Command::REF;};

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

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

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

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x25a8(%rip), %rcx      # 0x124236
movq %rcx, 0x18(%rsp)
leaq 0x25da(%rip), %rdx      # 0x124274
movq %rdx, 0x10(%rsp)
movups 0x400(%rdi), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x400(%rdi)
movq 0x410(%rdi), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x410(%rdi)
movq 0x418(%rdi), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x418(%rdi)
testq %rax, %rax
je 0x121ce9
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x2595(%rip), %rcx      # 0x12428c
movq %rcx, 0x18(%rsp)
leaq 0x2611(%rip), %rdx      # 0x124314
movq %rdx, 0x10(%rsp)
movups 0x5a0(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x5a0(%rbx)
movq 0x5b0(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x5b0(%rbx)
movq 0x5b8(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x5b8(%rbx)
testq %rax, %rax
je 0x121d52
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x400(%rbx), %rsi
leaq 0x5a0(%rbx), %r14
leaq 0x420(%rbx), %rdi
callq 0x1249a4
leaq 0x5c0(%rbx), %rdi
movq %r14, %rsi
callq 0x1249a4
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x25a3(%rip), %rcx      # 0x12432c
movq %rcx, 0x18(%rsp)
leaq 0x25cb(%rip), %rdx      # 0x124360
movq %rdx, 0x10(%rsp)
movups 0x480(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x480(%rbx)
movq 0x490(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x490(%rbx)
movq 0x498(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x498(%rbx)
testq %rax, %rax
je 0x121de4
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x2586(%rip), %rcx      # 0x124378
movq %rcx, 0x18(%rsp)
leaq 0x2592(%rip), %rdx      # 0x124390
movq %rdx, 0x10(%rsp)
movups 0x640(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x640(%rbx)
movq 0x650(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x650(%rbx)
movq 0x658(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x658(%rbx)
testq %rax, %rax
je 0x121e4d
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x254d(%rip), %rcx      # 0x1243a8
movq %rcx, 0x18(%rsp)
leaq 0x257f(%rip), %rdx      # 0x1243e6
movq %rdx, 0x10(%rsp)
movups 0x4c0(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x4c0(%rbx)
movq 0x4d0(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x4d0(%rbx)
movq 0x4d8(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x4d8(%rbx)
testq %rax, %rax
je 0x121eb6
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x253a(%rip), %rcx      # 0x1243fe
movq %rcx, 0x18(%rsp)
leaq 0x256c(%rip), %rdx      # 0x12443c
movq %rdx, 0x10(%rsp)
movups 0x500(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x500(%rbx)
movq 0x510(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x510(%rbx)
movq 0x518(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x518(%rbx)
testq %rax, %rax
je 0x121f1f
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
jmp 0x121f31
jmp 0x121f31
jmp 0x121f31
jmp 0x121f31
jmp 0x121f31
movq %rax, %rdi
callq 0x1718f
nop