// File: TNanukem[P]chip8-emulator/emulator.cpp
// Function: emulator::loadGame(unsigned char, chip8*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
chip8 emulator::loadGame(uint8_t SaveStateSlot, chip8 *Chip8, std::string game){
	FILE* loadGame;

	std::string extension = std::string("_") + std::to_string(SaveStateSlot)
							+ std::string(".sav");
	game.append(extension);

	loadGame = fopen(game.c_str(),"rb");

	if(loadGame == NULL){
		return *Chip8;
	}

	chip8 aux;

	fread(&aux, sizeof(chip8), 1, loadGame);
	return aux;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %r8, -0x108(%rbp)
movq %rdi, -0x100(%rbp)
movb %dl, %al
movq %rdi, -0xf8(%rbp)
movq %rsi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
leaq -0x89(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x23f0
movq -0xf0(%rbp), %rdx
leaq 0x237e(%rip), %rsi      # 0x6100
leaq -0x88(%rbp), %rdi
callq 0x49b0
jmp 0x3d90
movzbl -0x9(%rbp), %esi
leaq -0xc0(%rbp), %rdi
callq 0x4a60
jmp 0x3da2
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x48e0
jmp 0x3dbb
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x23f0
movq -0x110(%rbp), %rdx
leaq 0x2326(%rip), %rsi      # 0x6102
leaq -0xe0(%rbp), %rdi
callq 0x49b0
jmp 0x3dea
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
callq 0x48e0
jmp 0x3e00
leaq -0xe0(%rbp), %rdi
callq 0x2190
leaq -0xe1(%rbp), %rdi
callq 0x2280
leaq -0x68(%rbp), %rdi
callq 0x2190
leaq -0xc0(%rbp), %rdi
callq 0x2190
leaq -0x88(%rbp), %rdi
callq 0x2190
leaq -0x89(%rbp), %rdi
callq 0x2280
movq -0x108(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2450
jmp 0x3e57
movq -0x108(%rbp), %rdi
callq 0x2130
movq %rax, %rdi
leaq 0x21d3(%rip), %rsi      # 0x6040
callq 0x22e0
movq %rax, -0x118(%rbp)
jmp 0x3e7b
movq -0x118(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3f7e
movq -0x100(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x3050, %edx           # imm = 0x3050
callq 0x2220
movl $0x1, -0xe8(%rbp)
jmp 0x3fb0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x3f53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x3f47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x3f3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x3f26
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x2190
leaq -0xe1(%rbp), %rdi
callq 0x2280
leaq -0x68(%rbp), %rdi
callq 0x2190
leaq -0xc0(%rbp), %rdi
callq 0x2190
leaq -0x88(%rbp), %rdi
callq 0x2190
leaq -0x89(%rbp), %rdi
callq 0x2280
jmp 0x3fc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2190
jmp 0x3fc9
movq -0x100(%rbp), %rdi
callq 0x4b80
movq -0x100(%rbp), %rdi
movq -0x28(%rbp), %rcx
movl $0x3050, %esi           # imm = 0x3050
movl $0x1, %edx
callq 0x2380
jmp 0x3fa6
movl $0x1, -0xe8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2190
movq -0xf8(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x98(%rbp), %rdi
callq 0x23e0
nopw %cs:(%rax,%rax)