// File: /workspace/github_cpp_makefile_star2_O3/daniel5151[P]mips241/src/debug.cc
// Function: MIPS::Debugger::debugREPL()
void Debugger::debugREPL() {
  // If we are not stepping each cycle, then we might be able
  //  to skip some instructions
  if (!cycleStep) {
    // If we are not in Stage 0, don't debug
    if (cpu.getStage() != 0) return;

    // If we are stepping, or there is a breakpoint, debug
    if (step || breakpoints.count(cpu.getPC()) != 0) {
      // do the debug
    } else return;
  }

  debugPrint();

  // the worst REPL you've ever seen
  for (;;) {
    cerr << prevInput << "> "; // prompt

    string input;
    getline(cin, input);

    if (input == "") {
      input = prevInput; // Redo prev input
    }

    prevInput = input; // Save new input in history

    stringstream in_ss (input);

    bool valid = true;

    string tok;
    while (in_ss >> tok) {
      if (tok == "step") {
        step = true;  return;
      }
      else if (tok == "run")  {
        step = false;

        // "clear" screen
        cerr << string(100, '\n');
        return;
      }
      else if (tok == "+bp") {
        uint32_t bp_addr;
        in_ss >> hex >> bp_addr;
        breakpoints.insert(bp_addr);
        higlight[bp_addr] = '!';
      }
      else if (tok == "-bp") {
        uint32_t bp_addr;
        in_ss >> hex >> bp_addr;
        breakpoints.erase(bp_addr);
           higlight.erase(bp_addr);
      }
      else if (tok == "peek") {
        uint32_t memaddr;
        in_ss >> hex >> memaddr;
        cerr << toHex(bus.load(memaddr)) << endl;
      }
      else if (tok == "poke") {
        uint32_t memaddr;
        uint32_t new_val;
        in_ss
          >> hex >> memaddr
          >> hex >> new_val;

        bus.store(memaddr, new_val);
      }
      else if (tok == "+watch") {
        uint32_t memaddr;
        in_ss >> hex >> memaddr;
        watch.insert(memaddr);
      }
      else if (tok == "-watch") {
        uint32_t memaddr;
        in_ss >> hex >> memaddr;
        watch.erase(memaddr);
      }
      else if (tok == "print") {
        debugPrint();
      }
      else if (tok == "help") {
        cerr
          << "  step              - exec one instruction"         << endl
          << "  run               - resume regular execution"     << endl
          << "  +bp <addr>        - add breakpoint at <addr>"     << endl
          << "  -bp <addr>        - remove breakpoint at <addr>"  << endl
          << "  peek <addr>       - print out contents of <addr>" << endl
          << "  poke <addr> <val> - edit contents of <addr>"      << endl
          << "  +watch <addr>     - keep an eye on <addr>"        << endl
          << "  -watch <addr>     - don't keep an eye on <addr>"  << endl
          << "  print             - display debug data"           << endl;
      }

      else {
        valid = false;
        break;

      }
    }
    if (!valid) cerr << "Unknown command." << endl;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdi, (%rsp)
cmpb $0x0, 0x48(%rdi)
je 0x62c6
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x57ba
leaq 0xb0(%rbx), %rax
movq %rax, 0x48(%rsp)
movl $0x80, %eax
leaq (%rbx,%rax), %rcx
movq %rcx, 0x30(%rsp)
leaq 0x50(%rbx), %r13
leaq 0x18(%rbx), %rbp
leaq 0x90(%rsp), %rbx
addq %rbx, %rax
movq %rax, 0x40(%rsp)
leaq 0x50(%rsp), %r12
leaq 0x10(%rsp), %r14
movq (%rsp), %rax
movq 0xb0(%rax), %rsi
movq 0xb8(%rax), %rdx
movq 0x7496(%rip), %rdi      # 0xcff0
callq 0x3250
movl $0x2, %edx
movq %rax, %rdi
leaq 0x372d(%rip), %rsi      # 0x929b
callq 0x3250
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq $0x0, 0x78(%rsp)
movb $0x0, 0x80(%rsp)
movq 0x7440(%rip), %rcx      # 0xcfd8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x31e0
leaq 0x70(%rsp), %r15
movsbl %al, %edx
movq 0x741d(%rip), %rdi      # 0xcfd8
movq %r15, %rsi
callq 0x33c0
movq %r15, %rdi
leaq 0x3438(%rip), %rsi      # 0x9005
callq 0x3090
testl %eax, %eax
jne 0x5be3
movq %r15, %rdi
movq 0x48(%rsp), %rsi
callq 0x3120
movq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0x3120
movq %rbx, %rdi
movq %r15, %rsi
movl $0x18, %edx
callq 0x3320
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq $0x0, 0x58(%rsp)
movb $0x0, 0x60(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x32a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movb $0x1, %r15b
testb $0x5, 0x20(%rax,%rcx)
jne 0x6215
movq %r12, %rdi
leaq 0x34c8(%rip), %rsi      # 0x910a
callq 0x3090
testl %eax, %eax
je 0x61b2
movq %r12, %rdi
leaq 0x3645(%rip), %rsi      # 0x929e
callq 0x3090
testl %eax, %eax
je 0x61bc
movq %r12, %rdi
leaq 0x3632(%rip), %rsi      # 0x92a2
callq 0x3090
testl %eax, %eax
je 0x5f5d
movq %r12, %rdi
leaq 0x361f(%rip), %rsi      # 0x92a6
callq 0x3090
testl %eax, %eax
je 0x5fa6
movq %r12, %rdi
leaq 0x360c(%rip), %rsi      # 0x92aa
callq 0x3090
testl %eax, %eax
je 0x6002
movq %r12, %rdi
leaq 0x35fa(%rip), %rsi      # 0x92af
callq 0x3090
testl %eax, %eax
je 0x60b6
movq %r12, %rdi
leaq 0x35e8(%rip), %rsi      # 0x92b4
callq 0x3090
testl %eax, %eax
je 0x611d
movq %r12, %rdi
leaq 0x35d8(%rip), %rsi      # 0x92bb
callq 0x3090
testl %eax, %eax
je 0x615a
movq %r12, %rdi
leaq 0x35c8(%rip), %rsi      # 0x92c2
callq 0x3090
testl %eax, %eax
je 0x61a4
movq %r12, %rdi
leaq 0x35b7(%rip), %rsi      # 0x92c8
callq 0x3090
testl %eax, %eax
jne 0x6277
movl $0x2a, %edx
movq 0x72c6(%rip), %rdi      # 0xcff0
leaq 0x359c(%rip), %rsi      # 0x92cd
callq 0x3250
movq 0x72b3(%rip), %rcx      # 0xcff0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq 0x7295(%rip), %rdi      # 0xcff0
callq 0x3040
movq %rax, %rdi
callq 0x3160
movq %rax, %r15
movl $0x2e, %edx
movq %rax, %rdi
leaq 0x357e(%rip), %rsi      # 0x92f8
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3160
movq %rax, %r15
movl $0x2e, %edx
movq %rax, %rdi
leaq 0x356f(%rip), %rsi      # 0x9327
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3160
movq %rax, %r15
movl $0x31, %edx
movq %rax, %rdi
leaq 0x3560(%rip), %rsi      # 0x9356
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3160
movq %rax, %r15
movl $0x32, %edx
movq %rax, %rdi
leaq 0x3554(%rip), %rsi      # 0x9388
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3160
movq %rax, %r15
movl $0x2d, %edx
movq %rax, %rdi
leaq 0x3549(%rip), %rsi      # 0x93bb
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3160
movq %rax, %r15
movl $0x2b, %edx
movq %rax, %rdi
leaq 0x3539(%rip), %rsi      # 0x93e9
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3160
movq %rax, %r15
movl $0x31, %edx
movq %rax, %rdi
leaq 0x3527(%rip), %rsi      # 0x9415
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3160
movq %rax, %r15
movl $0x28, %edx
movq %rax, %rdi
leaq 0x351b(%rip), %rsi      # 0x9447
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3160
jmp 0x5c18
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
movl 0xa8(%rsp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0xa8(%rsp,%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3390
movq %r13, %rdi
movq %r14, %rsi
callq 0x6a28
movq %rbp, %rdi
movq %r14, %rsi
callq 0x63e0
movb $0x21, (%rax)
jmp 0x5c18
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
movl 0xa8(%rsp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0xa8(%rsp,%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3390
movq %r13, %rdi
movq %r14, %rsi
callq 0x6ad2
movq %r13, %rdi
movq %rax, %rsi
callq 0x6b50
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6904
movq %rbp, %rdi
movq %rax, %rsi
callq 0x6982
jmp 0x5c18
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
movl 0xa8(%rsp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0xa8(%rsp,%rax)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0x3390
movq (%rsp), %rax
movq 0x10(%rax), %rdi
movl 0xc(%rsp), %esi
callq 0x361c
movl %eax, 0x3c(%rsp)
movq %r14, %rdi
leaq 0x3c(%rsp), %rsi
callq 0x6445
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x6f8e(%rip), %rdi      # 0xcff0
callq 0x3250
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3160
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x5c18
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3200
jmp 0x5c18
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
movl 0xa8(%rsp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0xa8(%rsp,%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3390
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
leaq 0xc(%rsp), %rsi
callq 0x3390
movq (%rsp), %rax
movq 0x10(%rax), %rdi
movl 0x10(%rsp), %esi
movl 0xc(%rsp), %edx
callq 0x3740
jmp 0x5c18
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
movl 0xa8(%rsp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0xa8(%rsp,%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3390
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x6a28
jmp 0x5c18
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
movl 0xa8(%rsp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0xa8(%rsp,%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3390
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x6ad2
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x6b50
jmp 0x5c18
movq (%rsp), %rdi
callq 0x57ba
jmp 0x5c18
movq (%rsp), %rax
movb $0x1, 0x49(%rax)
jmp 0x6212
movq (%rsp), %rax
movb $0x0, 0x49(%rax)
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movl $0x64, %esi
movq %r14, %rdi
movl $0xa, %edx
callq 0x3270
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x6dff(%rip), %rdi      # 0xcff0
callq 0x3250
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x6212
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3200
xorl %r15d, %r15d
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x6231
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3200
movq %rbx, %rdi
movq 0x6d5d(%rip), %rsi      # 0xcf98
callq 0x31a0
movq 0x40(%rsp), %rdi
callq 0x30a0
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x626c
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x3200
testb %r15b, %r15b
jne 0x5b41
jmp 0x62d6
movl $0x10, %edx
movq 0x6d6d(%rip), %rdi      # 0xcff0
leaq 0x31e6(%rip), %rsi      # 0x9470
callq 0x3250
movq 0x6d5a(%rip), %rcx      # 0xcff0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x31e0
movsbl %al, %esi
movq 0x6d3c(%rip), %rdi      # 0xcff0
callq 0x3040
movq %rax, %rdi
callq 0x3160
jmp 0x6215
movq (%rsp), %rax
movq (%rax), %rdi
callq 0x3eec
testl %eax, %eax
je 0x62e8
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
cmpb $0x0, 0x49(%rax)
jne 0x5af9
movq (%rsp), %rbx
movq (%rbx), %rdi
callq 0x3ef4
movq 0x60(%rbx), %rcx
testq %rcx, %rcx
je 0x62d6
movq (%rsp), %rdx
leaq 0x58(%rdx), %rsi
movq %rsi, %rdx
xorl %edi, %edi
cmpl %eax, 0x20(%rcx)
setb %dil
cmovaeq %rcx, %rdx
movq 0x10(%rcx,%rdi,8), %rcx
testq %rcx, %rcx
jne 0x6316
cmpq %rsi, %rdx
je 0x62d6
cmpl 0x20(%rdx), %eax
jae 0x5af9
jmp 0x62d6
jmp 0x6379
jmp 0x6354
jmp 0x6379
jmp 0x634f
jmp 0x6379
jmp 0x6379
jmp 0x6379
jmp 0x6379
jmp 0x6379
movq %rax, %rbx
jmp 0x63b6
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x637c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3200
jmp 0x637c
jmp 0x6379
jmp 0x6379
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x6398
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3200
movq 0x6bf9(%rip), %rsi      # 0xcf98
leaq 0x90(%rsp), %rdi
callq 0x31a0
movq 0x40(%rsp), %rdi
callq 0x30a0
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x63d8
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x3200
movq %rbx, %rdi
callq 0x33a0