// File: /workspace/github_cpp_makefile_star2_O3/Lupo-CalPoly[P]cpe315-thumbsim/parse.cpp
// Function: parseMem(std::basic_ifstream<char, std::char_traits<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void parseMem(ifstream & in, string type) {
  string s;
  unsigned int data, addr;
  in >> s;
  transform(s.begin(), s.end(), s.begin(), (int(*)(int))tolower);
  transform(type.begin(), type.end(), type.begin(), 
            (int(*)(int))std::tolower);
  if (s == "ta") {
    s = "data";                 // hack
  }
  if (s != type) {
    cerr << "Bad type in parseMem: " << s << endl;
    exit(1);
  }
  if (type == "instruction") {
    addr = imem.getBase();
  } else if (type == "data") {
    addr = dmem.getBase();
  }
  in >> s;
  transform(s.begin(), s.end(), s.begin(), (int(*)(int))tolower);
  if (s != "memory") {
    cerr << "Bad type (memory) in parseMem: " << s << endl;
    exit(1);
  }
  while (in >> addr >> data) {
    //cout << "Addr: " << hex << addr << " Data: " << data << endl;
    // data is in native format
    if (type == "instruction") {
      imem.write(addr, data);
      addr += 2;
    } else if (type == "data") {
      dmem.write(addr, data);
      addr += 4;
    } else {
      cerr << "Bad type in while loop in parseMem: " << s << endl;
      exit(1);
    }
  }
  in.clear();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x50(%rbp), %rsi
callq 0x2190
movq -0x48(%rbp), %r15
testq %r15, %r15
je 0x51f1
movq -0x50(%rbp), %r12
xorl %r13d, %r13d
movsbl (%r12,%r13), %edi
callq 0x21a0
movb %al, (%r12,%r13)
incq %r13
cmpq %r13, %r15
jne 0x51db
movq 0x8(%r14), %r15
testq %r15, %r15
je 0x5216
movq (%r14), %r12
xorl %r13d, %r13d
movsbl (%r12,%r13), %edi
callq 0x21a0
movb %al, (%r12,%r13)
incq %r13
cmpq %r13, %r15
jne 0x5200
leaq 0x11df(%rip), %rsi      # 0x63fc
leaq -0x50(%rbp), %rdi
callq 0x2060
testl %eax, %eax
jne 0x5246
leaq -0x50(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x11c1(%rip), %rcx      # 0x63fa
movl $0x4, %r8d
xorl %esi, %esi
callq 0x21c0
movq -0x48(%rbp), %rdx
cmpq 0x8(%r14), %rdx
jne 0x53f6
testq %rdx, %rdx
je 0x526d
movq (%r14), %rsi
movq -0x50(%rbp), %rdi
callq 0x2160
testl %eax, %eax
jne 0x53f6
leaq 0x11a2(%rip), %rsi      # 0x6416
movq %r14, %rdi
callq 0x2060
testl %eax, %eax
je 0x529c
leaq 0x1173(%rip), %rsi      # 0x63fa
movq %r14, %rdi
callq 0x2060
testl %eax, %eax
jne 0x52a9
leaq 0x3ee6(%rip), %rax      # 0x9180
jmp 0x52a3
leaq 0x3eb5(%rip), %rax      # 0x9158
movl 0x18(%rax), %eax
movl %eax, -0x2c(%rbp)
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
callq 0x2190
movq -0x48(%rbp), %r15
testq %r15, %r15
je 0x52db
movq -0x50(%rbp), %r12
xorl %r13d, %r13d
movsbl (%r12,%r13), %edi
callq 0x21a0
movb %al, (%r12,%r13)
incq %r13
cmpq %r13, %r15
jne 0x52c5
leaq 0x1140(%rip), %rsi      # 0x6422
leaq -0x50(%rbp), %rdi
callq 0x2060
testl %eax, %eax
jne 0x542c
leaq -0x2c(%rbp), %r15
leaq -0x54(%rbp), %r12
leaq 0x1114(%rip), %r13      # 0x6416
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2220
movq %rax, %rdi
movq %r12, %rsi
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x537f
movq %r14, %rdi
movq %r13, %rsi
callq 0x2060
testl %eax, %eax
je 0x5362
movq %r14, %rdi
leaq 0x10bb(%rip), %rsi      # 0x63fa
callq 0x2060
testl %eax, %eax
jne 0x53b8
movl -0x2c(%rbp), %esi
movl -0x54(%rbp), %edx
leaq 0x3e2b(%rip), %rdi      # 0x9180
callq 0x43dc
movl -0x2c(%rbp), %eax
addl $0x4, %eax
jmp 0x537a
movl -0x2c(%rbp), %esi
movl -0x54(%rbp), %edx
leaq 0x3de9(%rip), %rdi      # 0x9158
callq 0x4534
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
jmp 0x5302
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2200
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x53a9
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3c31(%rip), %rdi      # 0x8ff0
leaq 0x1083(%rip), %rsi      # 0x6449
movl $0x24, %edx
callq 0x2170
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x3c11(%rip), %rdi      # 0x8ff0
callq 0x2170
movq %rax, %rdi
callq 0x2090
movl $0x1, %edi
callq 0x2180
movq 0x3bf3(%rip), %rdi      # 0x8ff0
leaq 0xffb(%rip), %rsi       # 0x63ff
movl $0x16, %edx
callq 0x2170
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x3bd3(%rip), %rdi      # 0x8ff0
callq 0x2170
movq %rax, %rdi
callq 0x2090
jmp 0x53ec
movq 0x3bbd(%rip), %rdi      # 0x8ff0
leaq 0xfef(%rip), %rsi       # 0x6429
movl $0x1f, %edx
callq 0x2170
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x3b9d(%rip), %rdi      # 0x8ff0
callq 0x2170
movq %rax, %rdi
callq 0x2090
jmp 0x53ec
jmp 0x5466
jmp 0x5466
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5482
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2230