// File: /workspace/github_cpp_makefile_star2_O2/Lupo-CalPoly[P]cpe315-thumbsim/main.cpp
// Function: main
int main(int argc, char ** argv) {
  int c;
  string filename;
  while ((c = getopt(argc, argv, "pdiwsc:f:")) != -1) {
    switch(c) {
    case 'p':
      opts.program = true;
      break;
    case 'd':
      opts.dump = true;
      break;
    case 'i':
      opts.instrs = true;
      break;
    case 'w':
      opts.writes = true;
      break;
    case 's':
      opts.stats = true;
      break;
    case 'c':
      caches = Caches(atoi(optarg));
      break;
    case 'f':
      filename = optarg;
      break;
    }
  }

  if (filename == "") {
    cerr << "ERROR: no source file specified; "
         << "run this program with -f filename" << endl;
    exit(1);
  }

  parse(filename.c_str());

  if (opts.program) {
    cout << "Instructions:" << endl;
    imem.dump(INSTRUCTIONS);
  }

  cout << "Starting at PC " << hex << pc << endl;
  rf.write(15, pc);
  while(imem.inRange(rf[15])) {
    execute();
  }

  if (opts.dump) {
    cout << "DATA:" << endl;
    dmem.dump(DATA);
    cout << "RF:" << endl;
    rf.dump(DATA);
  }

  if (opts.stats) {
    stats.print();
    caches.printStats();
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movl %edi, %r14d
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x3aba(%rip), %r12      # 0x6024
leaq 0x3a93(%rip), %r15      # 0x6004
leaq -0x68(%rbp), %r13
movl %r14d, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2030
leal -0x63(%rax), %ecx
cmpl $0x6, %ecx
ja 0x25c7
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
movq 0x6a25(%rip), %rax      # 0x8fc0
movq (%rax), %rdi
callq 0x21e0
movq %r13, %rdi
movl %eax, %esi
callq 0x28a4
leaq 0x6c74(%rip), %rdi      # 0x9228
movq %r13, %rsi
callq 0x2930
leaq -0x60(%rbp), %rdi
callq 0x2aa2
jmp 0x2575
cmpl $0x70, %eax
je 0x2616
cmpl $0x73, %eax
je 0x260a
cmpl $0x77, %eax
je 0x2622
cmpl $-0x1, %eax
jne 0x2575
jmp 0x262e
movq 0x69dc(%rip), %rax      # 0x8fc0
movq (%rax), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2280
jmp 0x2575
movb $0x1, 0x6bf5(%rip)      # 0x91ee
jmp 0x2575
movb $0x1, 0x6be8(%rip)      # 0x91ed
jmp 0x2575
movb $0x1, 0x6bdf(%rip)      # 0x91f0
jmp 0x2575
movb $0x1, 0x6bcf(%rip)      # 0x91ec
jmp 0x2575
movb $0x1, 0x6bc6(%rip)      # 0x91ef
jmp 0x2575
leaq 0x3cc2(%rip), %rsi      # 0x62f7
leaq -0x48(%rbp), %rdi
callq 0x2954
testb %al, %al
jne 0x279e
movq -0x48(%rbp), %rdi
callq 0x4f6a
cmpb $0x1, 0x6b96(%rip)      # 0x91ec
jne 0x2681
movq 0x6971(%rip), %rdi      # 0x8fd0
leaq 0x3a0c(%rip), %rsi      # 0x6072
callq 0x2150
movq %rax, %rdi
callq 0x20c0
leaq 0x6af6(%rip), %rdi      # 0x9170
xorl %esi, %esi
callq 0x4590
movq 0x6948(%rip), %rdi      # 0x8fd0
leaq 0x39f1(%rip), %rsi      # 0x6080
callq 0x2150
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movl 0x6b39(%rip), %esi      # 0x91e8
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20c0
movl 0x6b23(%rip), %edx      # 0x91e8
leaq 0x6af4(%rip), %rdi      # 0x91c0
pushq $0xf
popq %rsi
callq 0x443a
leaq 0x6ae5(%rip), %rbx      # 0x91c0
pushq $0xf
popq %r14
leaq 0x6a8a(%rip), %r15      # 0x9170
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4492
movq %r15, %rdi
movl %eax, %esi
callq 0x2964
testb %al, %al
je 0x2706
callq 0x52d1
jmp 0x26e6
cmpb $0x1, 0x6ae0(%rip)      # 0x91ed
jne 0x2763
movq 0x68ba(%rip), %rdi      # 0x8fd0
leaq 0x3973(%rip), %rsi      # 0x6090
callq 0x2150
movq %rax, %rdi
callq 0x20c0
leaq 0x6a67(%rip), %rdi      # 0x9198
pushq $0x1
popq %rsi
callq 0x44a2
movq 0x6890(%rip), %rdi      # 0x8fd0
leaq 0x394f(%rip), %rsi      # 0x6096
callq 0x2150
movq %rax, %rdi
callq 0x20c0
leaq 0x6a65(%rip), %rdi      # 0x91c0
pushq $0x1
popq %rsi
callq 0x45b2
cmpb $0x1, 0x6a86(%rip)      # 0x91f0
jne 0x2784
leaq 0x6a89(%rip), %rdi      # 0x91fc
callq 0x45dc
leaq 0x6aa9(%rip), %rdi      # 0x9228
callq 0x2986
leaq -0x48(%rbp), %rdi
callq 0x20b0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x684b(%rip), %rdi      # 0x8ff0
leaq 0x3882(%rip), %rsi      # 0x602e
callq 0x2150
leaq 0x3898(%rip), %rsi      # 0x6050
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
pushq $0x1
popq %rdi
callq 0x2190
jmp 0x27d8
jmp 0x27d8
jmp 0x27d8
jmp 0x27d8
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2250