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

    switch(int(type)){
        case int(Type::SALP_1):
            prereq[int(Level::Bank)][int(Command::RD)] = [] (DRAM<SALP>* node, Command cmd, int id) {
                switch (int(node->state)){
                    case int(State::Closed): return Command::ACT;
                    case int(State::Opened):
                        return Command::MAX;
                    default: assert(false);}};
            prereq[int(Level::Bank)][int(Command::WR)] = prereq[int(Level::Bank)][int(Command::RD)];
            prereq[int(Level::SubArray)][int(Command::RD)] = [] (DRAM<SALP>* node, Command cmd, int id) {
              if (node->row_state.find(id) != node->row_state.end()) {
                return cmd;
              } else if (node->row_state.size()) {
                return Command::PRE;
              } else {
                return Command::PRE_OTHER;
              }
            };
            prereq[int(Level::SubArray)][int(Command::WR)] = prereq[int(Level::SubArray)][int(Command::RD)];
            prereq[int(Level::Rank)][int(Command::REF)] = [] (DRAM<SALP>* node, Command cmd, int id) {
                for (auto bank : node->children) {
                    if (bank->state == State::Closed)
                        continue;
                    return Command::PRER;
                }
                return Command::REF;};
            break;
        case int(Type::SALP_2):
            prereq[int(Level::SubArray)][int(Command::RD)] = [] (DRAM<SALP>* 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()) {
                          for (auto sa : node->parent->children) {
                              if (sa != node && sa->state == State::Opened) {
                                  return Command::PRE_OTHER;
                              }
                          }
                          return cmd;
                        } else {
                          // if this subarray has another row open, close it
                          // first
                          return Command::PRE;
                        }
                    default: assert(false);}};
            prereq[int(Level::SubArray)][int(Command::WR)] = prereq[int(Level::SubArray)][int(Command::RD)];
            prereq[int(Level::Rank)][int(Command::REF)] = [] (DRAM<SALP>* node, Command cmd, int id) {
                for (auto bank : node->children)
                    for (auto sa : bank->children) {
                        if (sa->state == State::Closed)
                            continue;
                        return Command::PRER;
                    }
                return Command::REF;};
            break;
        case int(Type::MASA):
            prereq[int(Level::SubArray)][int(Command::RD)] = [] (DRAM<SALP>* 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 Command::SASEL;
                        else return Command::PRE;
                    case int(State::Selected):
                        if (node->row_state.find(id) != node->row_state.end()) return cmd;
                        else return Command::PRE;
                    default: assert(false);
                }};
            prereq[int(Level::SubArray)][int(Command::WR)] = prereq[int(Level::SubArray)][int(Command::RD)];
            prereq[int(Level::Rank)][int(Command::REF)] = [] (DRAM<SALP>* node, Command cmd, int id) {
                for (auto bank : node->children)
                    for (auto sa : bank->children){
                        if (sa->state == State::Closed)
                            continue;
                        return Command::PRER;
                    }
                return Command::REF;};
            break;
        default: assert(false);
    }
    // PD
    prereq[int(Level::Rank)][int(Command::PDE)] = [] (DRAM<SALP>* 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<SALP>* 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 %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movups 0x490(%rdi), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x490(%rdi)
movq 0x4a0(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x3588(%rip), %rcx      # 0x134e32
movq %rcx, 0x4a0(%rdi)
movq 0x4a8(%rdi), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3530(%rip), %rcx      # 0x134df4
movq %rcx, 0x4a8(%rdi)
testq %rax, %rax
je 0x1318dd
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x490(%rbx), %rsi
leaq 0x4b0(%rbx), %rdi
callq 0x135f14
movl 0x20(%rbx), %eax
cmpl $0x2, %eax
je 0x131b1f
cmpl $0x1, %eax
je 0x131a4d
testl %eax, %eax
jne 0x131ca4
movups 0x650(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x650(%rbx)
movq 0x660(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x354f(%rip), %rcx      # 0x134e84
movq %rcx, 0x660(%rbx)
movq 0x668(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x34fb(%rip), %rcx      # 0x134e4a
movq %rcx, 0x668(%rbx)
testq %rax, %rax
je 0x131968
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x650(%rbx), %rsi
leaq 0x670(%rbx), %rdi
callq 0x135f14
movups 0x810(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x810(%rbx)
movq 0x820(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x354f(%rip), %rcx      # 0x134ef2
movq %rcx, 0x820(%rbx)
movq 0x828(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x34df(%rip), %rcx      # 0x134e9c
movq %rcx, 0x828(%rbx)
testq %rax, %rax
je 0x1319d6
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x810(%rbx), %rsi
leaq 0x830(%rbx), %rdi
callq 0x135f14
movups 0x510(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x510(%rbx)
movq 0x520(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x352d(%rip), %rcx      # 0x134f3e
movq %rcx, 0x520(%rbx)
movq 0x528(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x34df(%rip), %rcx      # 0x134f0a
movq %rcx, 0x528(%rbx)
testq %rax, %rax
je 0x131be8
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x131be8
movups 0x810(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x810(%rbx)
movq 0x820(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3597(%rip), %rcx      # 0x13500c
movq %rcx, 0x820(%rbx)
movq 0x828(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x34c7(%rip), %rcx      # 0x134f56
movq %rcx, 0x828(%rbx)
testq %rax, %rax
je 0x131aa8
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x810(%rbx), %rsi
leaq 0x830(%rbx), %rdi
callq 0x135f14
movups 0x510(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x510(%rbx)
movq 0x520(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3591(%rip), %rcx      # 0x135074
movq %rcx, 0x520(%rbx)
movq 0x528(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3527(%rip), %rcx      # 0x135024
movq %rcx, 0x528(%rbx)
testq %rax, %rax
je 0x131be8
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x131be8
movups 0x810(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x810(%rbx)
movq 0x820(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3629(%rip), %rcx      # 0x135170
movq %rcx, 0x820(%rbx)
movq 0x828(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x352b(%rip), %rcx      # 0x13508c
movq %rcx, 0x828(%rbx)
testq %rax, %rax
je 0x131b7a
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x810(%rbx), %rsi
leaq 0x830(%rbx), %rdi
callq 0x135f14
movups 0x510(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x510(%rbx)
movq 0x520(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3623(%rip), %rcx      # 0x1351d8
movq %rcx, 0x520(%rbx)
movq 0x528(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x35b9(%rip), %rcx      # 0x135188
movq %rcx, 0x528(%rbx)
testq %rax, %rax
je 0x131be8
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x530(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x530(%rbx)
movq 0x540(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x361e(%rip), %rcx      # 0x13522e
movq %rcx, 0x540(%rbx)
movq 0x548(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x35c6(%rip), %rcx      # 0x1351f0
movq %rcx, 0x548(%rbx)
testq %rax, %rax
je 0x131c43
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x570(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x570(%rbx)
movq 0x580(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3619(%rip), %rcx      # 0x135284
movq %rcx, 0x580(%rbx)
movq 0x588(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x35c1(%rip), %rcx      # 0x135246
movq %rcx, 0x588(%rbx)
testq %rax, %rax
je 0x131c9e
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x20, %rsp
popq %rbx
retq
leaq 0x186ee(%rip), %rdi     # 0x14a399
leaq 0x298d8(%rip), %rsi     # 0x15b58a
leaq 0x2992e(%rip), %rcx     # 0x15b5e7
movl $0xc8, %edx
callq 0xb200
jmp 0x131cd5
jmp 0x131cd5
jmp 0x131cd5
jmp 0x131cd5
jmp 0x131cd5
jmp 0x131cd5
jmp 0x131cd5
jmp 0x131cd5
jmp 0x131cd5
movq %rax, %rdi
callq 0x171a3
nop