// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x50(%rbp), %rsi
callq 0x21a0
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %r12
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x4d3f
movsbl (%r15,%r13), %edi
callq 0x21b0
movb %al, (%r15,%r13)
incq %r13
jmp 0x4d27
movq (%r14), %r15
movq 0x8(%r14), %r12
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x4d61
movsbl (%r15,%r13), %edi
callq 0x21b0
movb %al, (%r15,%r13)
incq %r13
jmp 0x4d49
leaq 0x1678(%rip), %rsi      # 0x63e0
leaq -0x50(%rbp), %rdi
callq 0x2954
testb %al, %al
je 0x4d85
leaq 0x1662(%rip), %rsi      # 0x63de
leaq -0x50(%rbp), %rdi
callq 0x2280
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x50b2
testb %al, %al
jne 0x4f00
leaq 0x165a(%rip), %rsi      # 0x63fa
movq %r14, %rdi
callq 0x2954
testb %al, %al
je 0x4db5
leaq 0x43bd(%rip), %rax      # 0x9170
jmp 0x4dcf
leaq 0x1622(%rip), %rsi      # 0x63de
movq %r14, %rdi
callq 0x2954
testb %al, %al
je 0x4dd5
leaq 0x43c9(%rip), %rax      # 0x9198
movl 0x18(%rax), %eax
movl %eax, -0x2c(%rbp)
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
callq 0x21a0
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %r12
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x4e04
movsbl (%r15,%r13), %edi
callq 0x21b0
movb %al, (%r15,%r13)
incq %r13
jmp 0x4dec
leaq 0x15fb(%rip), %rsi      # 0x6406
leaq -0x50(%rbp), %rdi
callq 0x50bf
testb %al, %al
jne 0x4f29
leaq -0x2c(%rbp), %r15
leaq -0x30(%rbp), %r12
leaq 0x15cf(%rip), %r13      # 0x63fa
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2240
movq %rax, %rdi
movq %r12, %rsi
callq 0x2240
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4ea8
movq %r14, %rdi
movq %r13, %rsi
callq 0x2954
testb %al, %al
je 0x4e78
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
leaq 0x4305(%rip), %rdi      # 0x9170
callq 0x4312
movl -0x2c(%rbp), %eax
addl $0x2, %eax
jmp 0x4ea3
movq %r14, %rdi
leaq 0x155c(%rip), %rsi      # 0x63de
callq 0x2954
testb %al, %al
je 0x4ed1
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
leaq 0x4300(%rip), %rdi      # 0x9198
callq 0x41e4
movl -0x2c(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4e2b
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2220
leaq -0x50(%rbp), %rdi
callq 0x20b0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4118(%rip), %rdi      # 0x8ff0
leaq 0x154e(%rip), %rsi      # 0x642d
callq 0x2150
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20c0
pushq $0x1
popq %rdi
callq 0x2190
movq 0x40e9(%rip), %rdi      # 0x8ff0
leaq 0x14d5(%rip), %rsi      # 0x63e3
callq 0x2150
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20c0
jmp 0x4ef8
movq 0x40c0(%rip), %rdi      # 0x8ff0
leaq 0x14d6(%rip), %rsi      # 0x640d
callq 0x2150
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20c0
jmp 0x4ef8
jmp 0x4f56
jmp 0x4f56
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2250