// File: martinferianc[P]CPUSimulator-EIE2/src/test_mips.cpp
// Function: load_instructions(std::vector<test, std::allocator<test>>&)
mips_error load_instructions(vector<test>& instructions){
  ifstream file;
  file.open("mips_cpu_instructions.txt");
  test temp;
  string t1, t2, t3, t4, t5;
  while(file >> t1 >> t2 >> t3 >> t4 >> t5){
    stringstream ss;
    ss << std::hex << t1;
    ss >> temp.instruction_code;
    //Change the endianness
    temp.instruction_code =
      uint32_t((temp.instruction_code & 0x000000FF) << 24) |
      uint32_t((temp.instruction_code & 0x0000FF00) << 8) |
      uint32_t((temp.instruction_code & 0x00FF0000) >> 8) |
      uint32_t((temp.instruction_code & 0xFF000000) >> 24);
    temp.instruction_name = t2;
    temp.instruction_r1 = atoi(t3.c_str());
    temp.instruction_r2 = atoi(t4.c_str());
    temp.instruction_result = atoi(t5.c_str());
    instructions.push_back(temp);
  }
  file.close();
  return mips_Success;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4c0, %rsp            # imm = 0x4C0
movq %rdi, -0x8(%rbp)
leaq -0x210(%rbp), %rdi
movq %rdi, -0x488(%rbp)
callq 0x32f0
movq -0x488(%rbp), %rdi
leaq 0x46e9(%rip), %rsi      # 0x12da9
movl $0x8, %edx
callq 0x3180
jmp 0xe6cc
leaq -0x258(%rbp), %rdi
callq 0xfe80
leaq -0x278(%rbp), %rdi
callq 0x33b0
leaq -0x298(%rbp), %rdi
callq 0x33b0
leaq -0x2b8(%rbp), %rdi
callq 0x33b0
leaq -0x2d8(%rbp), %rdi
callq 0x33b0
leaq -0x2f8(%rbp), %rdi
callq 0x33b0
leaq -0x210(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x3360
movq %rax, -0x490(%rbp)
jmp 0xe730
movq -0x490(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x3360
movq %rax, -0x498(%rbp)
jmp 0xe74c
movq -0x498(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x3360
movq %rax, -0x4a0(%rbp)
jmp 0xe768
movq -0x4a0(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x3360
movq %rax, -0x4a8(%rbp)
jmp 0xe784
movq -0x4a8(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
callq 0x3360
movq %rax, -0x4b0(%rbp)
jmp 0xe7a0
movq -0x4b0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3350
movb %al, -0x4b1(%rbp)
jmp 0xe7be
movb -0x4b1(%rbp), %al
testb $0x1, %al
jne 0xe7cd
jmp 0xe925
leaq -0x480(%rbp), %rdi
callq 0x31b0
jmp 0xe7db
leaq -0x470(%rbp), %rdi
leaq 0x16b7(%rip), %rsi      # 0xfea0
callq 0x30e0
movq %rax, -0x4c0(%rbp)
jmp 0xe7f7
movq -0x4c0(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x3240
jmp 0xe80c
leaq -0x480(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x3060
jmp 0xe821
movl -0x258(%rbp), %ecx
movl %ecx, %eax
shll $0x18, %eax
movl %ecx, %edx
andl $0xff00, %edx           # imm = 0xFF00
shll $0x8, %edx
orl %edx, %eax
movl %ecx, %edx
andl $0xff0000, %edx         # imm = 0xFF0000
shrl $0x8, %edx
orl %edx, %eax
shrl $0x18, %ecx
orl %ecx, %eax
movl %eax, -0x258(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x3050
jmp 0xe866
leaq -0x2b8(%rbp), %rdi
callq 0x3110
movq %rax, %rdi
callq 0x3400
movl %eax, -0x22c(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x3110
movq %rax, %rdi
callq 0x3400
movl %eax, -0x228(%rbp)
leaq -0x2f8(%rbp), %rdi
callq 0x3110
movq %rax, %rdi
callq 0x3400
movl %eax, -0x230(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0xfed0
jmp 0xe8c6
leaq -0x480(%rbp), %rdi
callq 0x31d0
jmp 0xe714
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0xe9da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0xe992
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x480(%rbp), %rdi
callq 0x31d0
jmp 0xe992
leaq -0x210(%rbp), %rdi
callq 0x3090
jmp 0xe933
leaq -0x2f8(%rbp), %rdi
callq 0x3170
leaq -0x2d8(%rbp), %rdi
callq 0x3170
leaq -0x2b8(%rbp), %rdi
callq 0x3170
leaq -0x298(%rbp), %rdi
callq 0x3170
leaq -0x278(%rbp), %rdi
callq 0x3170
leaq -0x258(%rbp), %rdi
callq 0xff40
leaq -0x210(%rbp), %rdi
callq 0x30b0
xorl %eax, %eax
addq $0x4c0, %rsp            # imm = 0x4C0
popq %rbp
retq
leaq -0x2f8(%rbp), %rdi
callq 0x3170
leaq -0x2d8(%rbp), %rdi
callq 0x3170
leaq -0x2b8(%rbp), %rdi
callq 0x3170
leaq -0x298(%rbp), %rdi
callq 0x3170
leaq -0x278(%rbp), %rdi
callq 0x3170
leaq -0x258(%rbp), %rdi
callq 0xff40
leaq -0x210(%rbp), %rdi
callq 0x30b0
movq -0x218(%rbp), %rdi
callq 0x3440
nopw %cs:(%rax,%rax)