// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]ramulator/src/DSARP.cpp
// Function: ramulator::DSARP::init_prereq()
void DSARP::init_prereq()
{
  // RD
  prereq[int(Level::Rank)][int(Command::RD)] = [] (DRAM<DSARP>* 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);
    }};
  // Rank transitions to Bank
  prereq[int(Level::Bank)][int(Command::RD)] = [] (DRAM<DSARP>* node, Command cmd, int id) {
    switch (int(node->state)) {
      case int(State::Closed): return Command::ACT;
      case int(State::Opened):
        // Really is the subarray state. If the subarray matches, check the row ID
        if (node->row_state.find(id) != node->row_state.end())
          return Command::MAX;
        return Command::PRE;
      default: assert(false);
    }};
  // Bank transitions to Subarray
  prereq[int(Level::SubArray)][int(Command::RD)] = [] (DRAM<DSARP>* node, Command cmd, int id) {
    switch (int(node->state)) {
      case int(State::Closed): return Command::ACT;
      case int(State::Opened):
        // Actual row state
        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)];
  prereq[int(Level::SubArray)][int(Command::WR)] = prereq[int(Level::SubArray)][int(Command::RD)];

  // REF -- on all banks
  prereq[int(Level::Rank)][int(Command::REF)] = [] (DRAM<DSARP>* node, Command cmd, int id) {
    for (auto bank : node->children) {
      if (bank->state == State::Closed)
        continue;
      return Command::PREA;
    }
    return Command::REF;};

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

  // PD
  prereq[int(Level::Rank)][int(Command::PDE)] = [] (DRAM<DSARP>* 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<DSARP>* 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 0x410(%rdi), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x410(%rdi)
movq 0x420(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x3448(%rip), %rcx      # 0x114d18
movq %rcx, 0x420(%rdi)
movq 0x428(%rdi), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x33f0(%rip), %rcx      # 0x114cda
movq %rcx, 0x428(%rdi)
testq %rax, %rax
je 0x111903
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x5b0(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x5b0(%rbx)
movq 0x5c0(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x348f(%rip), %rcx      # 0x114dba
movq %rcx, 0x5c0(%rbx)
movq 0x5c8(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x33eb(%rip), %rcx      # 0x114d30
movq %rcx, 0x5c8(%rbx)
testq %rax, %rax
je 0x11195e
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x750(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x750(%rbx)
movq 0x760(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x34d4(%rip), %rcx      # 0x114e5a
movq %rcx, 0x760(%rbx)
movq 0x768(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3432(%rip), %rcx      # 0x114dd2
movq %rcx, 0x768(%rbx)
testq %rax, %rax
je 0x1119b9
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x410(%rbx), %rsi
leaq 0x5b0(%rbx), %r14
leaq 0x750(%rbx), %r15
leaq 0x430(%rbx), %rdi
callq 0x1156c8
leaq 0x5d0(%rbx), %rdi
movq %r14, %rsi
callq 0x1156c8
leaq 0x770(%rbx), %rdi
movq %r15, %rsi
callq 0x1156c8
movups 0x490(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x490(%rbx)
movq 0x4a0(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3486(%rip), %rcx      # 0x114ea6
movq %rcx, 0x4a0(%rbx)
movq 0x4a8(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3438(%rip), %rcx      # 0x114e72
movq %rcx, 0x4a8(%rbx)
testq %rax, %rax
je 0x111a53
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x650(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x650(%rbx)
movq 0x660(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x345b(%rip), %rcx      # 0x114ed6
movq %rcx, 0x660(%rbx)
movq 0x668(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x3429(%rip), %rcx      # 0x114ebe
movq %rcx, 0x668(%rbx)
testq %rax, %rax
je 0x111aae
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x4d0(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x4d0(%rbx)
movq 0x4e0(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3456(%rip), %rcx      # 0x114f2c
movq %rcx, 0x4e0(%rbx)
movq 0x4e8(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x33fe(%rip), %rcx      # 0x114eee
movq %rcx, 0x4e8(%rbx)
testq %rax, %rax
je 0x111b09
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movups 0x510(%rbx), %xmm0
movaps %xmm0, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x510(%rbx)
movq 0x520(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x3451(%rip), %rcx      # 0x114f82
movq %rcx, 0x520(%rbx)
movq 0x528(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x33f9(%rip), %rcx      # 0x114f44
movq %rcx, 0x528(%rbx)
testq %rax, %rax
je 0x111b64
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
jmp 0x111b7a
jmp 0x111b7a
jmp 0x111b7a
jmp 0x111b7a
jmp 0x111b7a
jmp 0x111b7a
movq %rax, %rdi
callq 0x171a3