// File: /workspace/github_cpp_makefile_star2_O1/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 0x51cd
movq -0x50(%rbp), %r12
xorl %r13d, %r13d
movsbl (%r12,%r13), %edi
callq 0x21a0
movb %al, (%r12,%r13)
incq %r13
cmpq %r13, %r15
jne 0x51b7
movq 0x8(%r14), %r15
testq %r15, %r15
je 0x51f2
movq (%r14), %r12
xorl %r13d, %r13d
movsbl (%r12,%r13), %edi
callq 0x21a0
movb %al, (%r12,%r13)
incq %r13
cmpq %r13, %r15
jne 0x51dc
leaq 0x1203(%rip), %rsi      # 0x63fc
leaq -0x50(%rbp), %rdi
callq 0x2060
testl %eax, %eax
jne 0x5222
leaq -0x50(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x11e5(%rip), %rcx      # 0x63fa
movl $0x4, %r8d
xorl %esi, %esi
callq 0x21c0
movq -0x48(%rbp), %rdx
cmpq 0x8(%r14), %rdx
jne 0x53d2
testq %rdx, %rdx
je 0x5249
movq (%r14), %rsi
movq -0x50(%rbp), %rdi
callq 0x2160
testl %eax, %eax
jne 0x53d2
leaq 0x11c6(%rip), %rsi      # 0x6416
movq %r14, %rdi
callq 0x2060
testl %eax, %eax
je 0x5278
leaq 0x1197(%rip), %rsi      # 0x63fa
movq %r14, %rdi
callq 0x2060
testl %eax, %eax
jne 0x5285
leaq 0x3f0a(%rip), %rax      # 0x9180
jmp 0x527f
leaq 0x3ed9(%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 0x52b7
movq -0x50(%rbp), %r12
xorl %r13d, %r13d
movsbl (%r12,%r13), %edi
callq 0x21a0
movb %al, (%r12,%r13)
incq %r13
cmpq %r13, %r15
jne 0x52a1
leaq 0x1164(%rip), %rsi      # 0x6422
leaq -0x50(%rbp), %rdi
callq 0x2060
testl %eax, %eax
jne 0x5408
leaq -0x2c(%rbp), %r15
leaq -0x54(%rbp), %r12
leaq 0x1138(%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 0x535b
movq %r14, %rdi
movq %r13, %rsi
callq 0x2060
testl %eax, %eax
je 0x533e
movq %r14, %rdi
leaq 0x10df(%rip), %rsi      # 0x63fa
callq 0x2060
testl %eax, %eax
jne 0x5394
movl -0x2c(%rbp), %esi
movl -0x54(%rbp), %edx
leaq 0x3e4f(%rip), %rdi      # 0x9180
callq 0x43e4
movl -0x2c(%rbp), %eax
addl $0x4, %eax
jmp 0x5356
movl -0x2c(%rbp), %esi
movl -0x54(%rbp), %edx
leaq 0x3e0d(%rip), %rdi      # 0x9158
callq 0x453c
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
jmp 0x52de
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 0x5385
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 0x3c55(%rip), %rdi      # 0x8ff0
leaq 0x10a7(%rip), %rsi      # 0x6449
movl $0x24, %edx
callq 0x2170
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x3c35(%rip), %rdi      # 0x8ff0
callq 0x2170
movq %rax, %rdi
callq 0x2090
movl $0x1, %edi
callq 0x2180
movq 0x3c17(%rip), %rdi      # 0x8ff0
leaq 0x101f(%rip), %rsi      # 0x63ff
movl $0x16, %edx
callq 0x2170
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x3bf7(%rip), %rdi      # 0x8ff0
callq 0x2170
movq %rax, %rdi
callq 0x2090
jmp 0x53c8
movq 0x3be1(%rip), %rdi      # 0x8ff0
leaq 0x1013(%rip), %rsi      # 0x6429
movl $0x1f, %edx
callq 0x2170
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x3bc1(%rip), %rdi      # 0x8ff0
callq 0x2170
movq %rax, %rdi
callq 0x2090
jmp 0x53c8
jmp 0x5442
jmp 0x5442
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x545e
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2230