// File: /workspace/github_cpp_makefile_star2_O3/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 -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x3a23(%rip), %r13      # 0x6040
leaq 0x39fc(%rip), %r12      # 0x6020
movq %rsi, -0x50(%rbp)
movl %r14d, %edi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2040
cmpl $0x6f, %eax
jg 0x26c9
leal -0x63(%rax), %ecx
cmpl $0x6, %ecx
ja 0x2757
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq 0x6965(%rip), %rax      # 0x8fc0
movq (%rax), %rdi
callq 0x21d0
leaq -0x70(%rbp), %rdi
movl %eax, %esi
callq 0x2a90
movl -0x70(%rbp), %eax
leaq 0x6b98(%rip), %rdx      # 0x9210
movl %eax, (%rdx)
movups 0x8(%rdx), %xmm0
movq 0x18(%rdx), %rax
movups -0x68(%rbp), %xmm1
movups %xmm1, 0x8(%rdx)
movq -0x58(%rbp), %rcx
movq %rcx, 0x18(%rdx)
movups %xmm0, -0x88(%rbp)
movq %rax, -0x78(%rbp)
leaq -0x68(%rbp), %r15
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq $0x0, 0x10(%r15)
leaq -0x88(%rbp), %rdi
callq 0x2b64
movq %r15, %rdi
callq 0x2b64
jmp 0x2628
cmpl $0x77, %eax
je 0x273f
cmpl $0x73, %eax
je 0x274b
cmpl $0x70, %eax
jne 0x2628
movb $0x1, 0x6af1(%rip)      # 0x91d4
jmp 0x2628
movq %r12, %rbx
movq %r13, %r12
movq 0x68cb(%rip), %rax      # 0x8fc0
movq (%rax), %r13
movq -0x40(%rbp), %r15
movq %r13, %rdi
callq 0x2080
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r13, %rcx
movq %r12, %r13
movq %rbx, %r12
movq -0x50(%rbp), %rbx
movq %rax, %r8
callq 0x21c0
jmp 0x2628
movb $0x1, 0x6aa8(%rip)      # 0x91d6
jmp 0x2628
movb $0x1, 0x6a9b(%rip)      # 0x91d5
jmp 0x2628
movb $0x1, 0x6a91(%rip)      # 0x91d7
jmp 0x2628
movb $0x1, 0x6a86(%rip)      # 0x91d8
jmp 0x2628
cmpl $-0x1, %eax
jne 0x2628
leaq 0x3bac(%rip), %rsi      # 0x6313
leaq -0x48(%rbp), %rdi
callq 0x2060
testl %eax, %eax
je 0x29c1
movq -0x48(%rbp), %rdi
callq 0x548a
cmpb $0x1, 0x6a4c(%rip)      # 0x91d4
jne 0x27de
movq 0x683f(%rip), %rbx      # 0x8fd0
leaq 0x38f6(%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 0x680d(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x6981(%rip), %rdi      # 0x9158
xorl %esi, %esi
callq 0x4842
movq 0x67eb(%rip), %rbx      # 0x8fd0
leaq 0x38b0(%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 0x69bc(%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 0x6984(%rip), %edx      # 0x91d0
leaq 0x6955(%rip), %rdi      # 0x91a8
movl $0xf, %esi
callq 0x46b2
leaq 0x6944(%rip), %rbx      # 0x91a8
movq %rbx, %rdi
movl $0xf, %esi
callq 0x470a
movl 0x68f9(%rip), %ecx      # 0x9170
cmpl %eax, %ecx
ja 0x2899
movq 0x68de(%rip), %rdx      # 0x9160
subq 0x68cf(%rip), %rdx      # 0x9158
shrq %rdx
addl %edx, %ecx
cmpl %eax, %ecx
jbe 0x2899
callq 0x57c9
jmp 0x2864
cmpb $0x1, 0x6935(%rip)      # 0x91d5
jne 0x2954
movq 0x6723(%rip), %rbx      # 0x8fd0
leaq 0x37f8(%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 0x66f1(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x688d(%rip), %rdi      # 0x9180
movl $0x1, %esi
callq 0x471a
movq 0x66cc(%rip), %rbx      # 0x8fd0
leaq 0x37a7(%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 0x669a(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x685e(%rip), %rdi      # 0x91a8
movl $0x1, %esi
callq 0x486e
cmpb $0x1, 0x687d(%rip)      # 0x91d8
jne 0x2997
leaq 0x6880(%rip), %rdi      # 0x91e4
callq 0x48a0
leaq 0x68a0(%rip), %rax      # 0x9210
cmpl $0x0, (%rax)
je 0x2997
leaq 0x6894(%rip), %rax      # 0x9210
movq 0x8(%rax), %rbx
movq 0x10(%rax), %r14
cmpq %r14, %rbx
je 0x2997
movq %rbx, %rdi
callq 0x2ef2
addq $0x28, %rbx
jmp 0x2984
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x29b0
movq -0x38(%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 0x6628(%rip), %rdi      # 0x8ff0
leaq 0x367b(%rip), %rsi      # 0x604a
movl $0x21, %edx
callq 0x2170
movq 0x6610(%rip), %rdi      # 0x8ff0
leaq 0x3685(%rip), %rsi      # 0x606c
movl $0x21, %edx
callq 0x2170
movq 0x65f8(%rip), %rdi      # 0x8ff0
callq 0x2090
movl $0x1, %edi
callq 0x2180
jmp 0x2a11
jmp 0x2a11
jmp 0x2a11
jmp 0x2a11
jmp 0x2a11
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x2a2d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2230
nop