// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rsi, %rbx
movl %edi, %r14d
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x3a23(%rip), %r15      # 0x6040
leaq 0x39fc(%rip), %r12      # 0x6020
movq 0x6995(%rip), %r13      # 0x8fc0
movl %edi, -0x2c(%rbp)
movq %rsi, -0x58(%rbp)
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2040
cmpl $0x6f, %eax
jg 0x26d8
leal -0x63(%rax), %ecx
cmpl $0x6, %ecx
ja 0x276a
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%r13), %rdi
callq 0x21d0
leaq -0x78(%rbp), %rdi
movl %eax, %esi
callq 0x2aa2
movl -0x78(%rbp), %eax
leaq 0x6b94(%rip), %rdx      # 0x9210
movl %eax, (%rdx)
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movups 0x8(%rdx), %xmm0
movq 0x18(%rdx), %rax
movups -0x70(%rbp), %xmm1
movups %xmm1, 0x8(%rdx)
movq -0x60(%rbp), %rcx
movq %rcx, 0x18(%rdx)
movaps -0x90(%rbp), %xmm1
movaps %xmm0, -0x90(%rbp)
movq %rax, -0x80(%rbp)
movups %xmm1, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x2b76
leaq -0x70(%rbp), %rdi
callq 0x2b76
jmp 0x2632
cmpl $0x77, %eax
je 0x2752
cmpl $0x73, %eax
je 0x275e
cmpl $0x70, %eax
jne 0x2632
movb $0x1, 0x6ae2(%rip)      # 0x91d4
jmp 0x2632
movq %r12, %rbx
movq %r15, %r12
movq (%r13), %r15
movq %r13, %r14
movq -0x48(%rbp), %r13
movq %r15, %rdi
callq 0x2080
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r14, %r13
movq %r15, %rcx
movq %r12, %r15
movq %rbx, %r12
movq -0x58(%rbp), %rbx
movl -0x2c(%rbp), %r14d
movq %rax, %r8
callq 0x21c0
jmp 0x2632
movb $0x1, 0x6a95(%rip)      # 0x91d6
jmp 0x2632
movb $0x1, 0x6a88(%rip)      # 0x91d5
jmp 0x2632
movb $0x1, 0x6a7e(%rip)      # 0x91d7
jmp 0x2632
movb $0x1, 0x6a73(%rip)      # 0x91d8
jmp 0x2632
cmpl $-0x1, %eax
jne 0x2632
leaq 0x3b99(%rip), %rsi      # 0x6313
leaq -0x50(%rbp), %rdi
callq 0x2060
testl %eax, %eax
je 0x29d4
movq -0x50(%rbp), %rdi
callq 0x5466
cmpb $0x1, 0x6a39(%rip)      # 0x91d4
jne 0x27f1
movq 0x682c(%rip), %rbx      # 0x8fd0
leaq 0x38e3(%rip), %rsi      # 0x608e
movl $0xd, %edx
movq %rbx, %rdi
callq 0x2170
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq 0x67fa(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x696e(%rip), %rdi      # 0x9158
xorl %esi, %esi
callq 0x4824
movq 0x67d8(%rip), %rbx      # 0x8fd0
leaq 0x389d(%rip), %rsi      # 0x609c
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2170
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rbx,%rax)
movl 0x69a9(%rip), %esi      # 0x91d0
movq %rbx, %rdi
callq 0x20c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movl 0x6971(%rip), %edx      # 0x91d0
leaq 0x6942(%rip), %rdi      # 0x91a8
movl $0xf, %esi
callq 0x4694
leaq 0x6931(%rip), %rbx      # 0x91a8
movq %rbx, %rdi
movl $0xf, %esi
callq 0x46ec
movl 0x68e6(%rip), %ecx      # 0x9170
cmpl %eax, %ecx
ja 0x28ac
movq 0x68cb(%rip), %rdx      # 0x9160
subq 0x68bc(%rip), %rdx      # 0x9158
shrq %rdx
addl %edx, %ecx
cmpl %eax, %ecx
jbe 0x28ac
callq 0x57a1
jmp 0x2877
cmpb $0x1, 0x6922(%rip)      # 0x91d5
jne 0x2967
movq 0x6710(%rip), %rbx      # 0x8fd0
leaq 0x37e5(%rip), %rsi      # 0x60ac
movl $0x5, %edx
movq %rbx, %rdi
callq 0x2170
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq 0x66de(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x687a(%rip), %rdi      # 0x9180
movl $0x1, %esi
callq 0x46fc
movq 0x66b9(%rip), %rbx      # 0x8fd0
leaq 0x3794(%rip), %rsi      # 0x60b2
movl $0x3, %edx
movq %rbx, %rdi
callq 0x2170
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq 0x6687(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x684b(%rip), %rdi      # 0x91a8
movl $0x1, %esi
callq 0x4850
cmpb $0x1, 0x686a(%rip)      # 0x91d8
jne 0x29aa
leaq 0x686d(%rip), %rdi      # 0x91e4
callq 0x4882
leaq 0x688d(%rip), %rax      # 0x9210
cmpl $0x0, (%rax)
je 0x29aa
leaq 0x6881(%rip), %rax      # 0x9210
movq 0x8(%rax), %rbx
movq 0x10(%rax), %r14
cmpq %r14, %rbx
je 0x29aa
movq %rbx, %rdi
callq 0x2ef8
addq $0x28, %rbx
jmp 0x2997
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x29c3
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6615(%rip), %rdi      # 0x8ff0
leaq 0x3668(%rip), %rsi      # 0x604a
movl $0x21, %edx
callq 0x2170
movq 0x65fd(%rip), %rdi      # 0x8ff0
leaq 0x3672(%rip), %rsi      # 0x606c
movl $0x21, %edx
callq 0x2170
movq 0x65e5(%rip), %rdi      # 0x8ff0
callq 0x2090
movl $0x1, %edi
callq 0x2180
jmp 0x2a24
jmp 0x2a24
jmp 0x2a24
jmp 0x2a24
jmp 0x2a24
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2a40
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2230