// File: /workspace/github_cpp_makefile_star2_O1/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
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x33a6(%rip), %rcx      # 0x117c96
movq %rcx, 0x18(%rsp)
leaq 0x33d8(%rip), %rdx      # 0x117cd4
movq %rdx, 0x10(%rsp)
movups 0x410(%rdi), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x410(%rdi)
movq 0x420(%rdi), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x420(%rdi)
movq 0x428(%rdi), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x428(%rdi)
testq %rax, %rax
je 0x11494b
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x3393(%rip), %rcx      # 0x117cec
movq %rcx, 0x18(%rsp)
leaq 0x3411(%rip), %rdx      # 0x117d76
movq %rdx, 0x10(%rsp)
movups 0x5b0(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x5b0(%rbx)
movq 0x5c0(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x5c0(%rbx)
movq 0x5c8(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x5c8(%rbx)
testq %rax, %rax
je 0x1149b4
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x33cc(%rip), %rcx      # 0x117d8e
movq %rcx, 0x18(%rsp)
leaq 0x3448(%rip), %rdx      # 0x117e16
movq %rdx, 0x10(%rsp)
movups 0x750(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x750(%rbx)
movq 0x760(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x760(%rbx)
movq 0x768(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x768(%rbx)
testq %rax, %rax
je 0x114a1d
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 0x1186c2
leaq 0x5d0(%rbx), %rdi
movq %r14, %rsi
callq 0x1186c2
leaq 0x770(%rbx), %rdi
movq %r15, %rsi
callq 0x1186c2
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x33c4(%rip), %rcx      # 0x117e2e
movq %rcx, 0x18(%rsp)
leaq 0x33ec(%rip), %rdx      # 0x117e62
movq %rdx, 0x10(%rsp)
movups 0x490(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x490(%rbx)
movq 0x4a0(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x4a0(%rbx)
movq 0x4a8(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x4a8(%rbx)
testq %rax, %rax
je 0x114ac5
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x33a7(%rip), %rcx      # 0x117e7a
movq %rcx, 0x18(%rsp)
leaq 0x33b3(%rip), %rdx      # 0x117e92
movq %rdx, 0x10(%rsp)
movups 0x650(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x650(%rbx)
movq 0x660(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x660(%rbx)
movq 0x668(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x668(%rbx)
testq %rax, %rax
je 0x114b2e
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm1, %xmm1
movaps %xmm1, (%rsp)
leaq 0x336e(%rip), %rcx      # 0x117eaa
movq %rcx, 0x18(%rsp)
leaq 0x33a0(%rip), %rdx      # 0x117ee8
movq %rdx, 0x10(%rsp)
movups 0x4d0(%rbx), %xmm0
movaps %xmm0, (%rsp)
movups %xmm1, 0x4d0(%rbx)
movq 0x4e0(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x4e0(%rbx)
movq 0x4e8(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x4e8(%rbx)
testq %rax, %rax
je 0x114b97
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
leaq 0x335b(%rip), %rcx      # 0x117f00
movq %rcx, 0x18(%rsp)
leaq 0x338d(%rip), %rdx      # 0x117f3e
movq %rdx, 0x10(%rsp)
movups 0x510(%rbx), %xmm1
movaps %xmm1, (%rsp)
movups %xmm0, 0x510(%rbx)
movq 0x520(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x520(%rbx)
movq 0x528(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, 0x528(%rbx)
testq %rax, %rax
je 0x114c00
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
jmp 0x114c16
jmp 0x114c16
jmp 0x114c16
jmp 0x114c16
jmp 0x114c16
jmp 0x114c16
movq %rax, %rdi
callq 0x1718f