// File: /workspace/github_cpp_makefile_star2_O2/bstrysko[P]IntelHexParser/src/IntelHexFile.cpp
// Function: IntelHexFile::IntelHexFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
IntelHexFile::IntelHexFile(string filename)
{
	ifstream file(filename.c_str());

	if(!file.is_open())
	{
		stringstream o;
		o << "Cannot load file ";
		o << filename;
		throw ios_base::failure(o.str());
	}

	char buffer[INTEL_HEX_FILE_MAX_ENTRY_SIZE];

	while(true)
	{
		file.getline(buffer, INTEL_HEX_FILE_MAX_ENTRY_SIZE);

		/*
		 * End of file
		 */
		if(!file)
		{
			break;
		}

		IntelHexFileEntry entry(buffer);

		if((entry.getRecordType() != 0x0) && (entry.getRecordType() != 0x1))
		{
			stringstream o;
			o << "Unsupported record type: 0x";
			o << hex << (uint32_t)entry.getRecordType();
			throw ios_base::failure(o.str());
		}

		addressToFileEntries.insert(pair<uint16_t, IntelHexFileEntry>(entry.getAddress(), entry));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x618, %rsp            # imm = 0x618
andl $0x0, 0x8(%rdi)
andq $0x0, 0x10(%rdi)
movq %rsi, %rbx
leaq 0x8(%rdi), %rax
movq %rax, 0x18(%rdi)
movq %rax, 0x20(%rdi)
movq %rdi, -0x30(%rbp)
andq $0x0, 0x28(%rdi)
movq (%rsi), %rsi
leaq -0x428(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x4640
leaq -0x3b0(%rbp), %rdi
callq 0x4070
testb %al, %al
je 0x49cc
leaq -0x218(%rbp), %r15
leaq -0x640(%rbp), %r12
leaq -0x98(%rbp), %r13
leaq -0x220(%rbp), %rbx
leaq -0x78(%rbp), %r14
movl $0x20c, %edx            # imm = 0x20C
leaq -0x428(%rbp), %rdi
movq %r12, %rsi
callq 0x40b0
movq -0x428(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x408(%rbp,%rax)
jne 0x4914
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x45b0
movq %r14, %rdi
movq %r13, %rsi
callq 0x41a0
movq %r13, %rdi
callq 0x4140
movq %r14, %rdi
callq 0x4610
testb %al, %al
je 0x48d9
movq %r14, %rdi
callq 0x4610
cmpb $0x1, %al
jne 0x4932
movq %r14, %rdi
callq 0x4320
movw %ax, -0x220(%rbp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4430
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x42d0
movq %r15, %rdi
callq 0x4190
movq %r14, %rdi
callq 0x4190
jmp 0x4877
leaq -0x428(%rbp), %rdi
callq 0x4090
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x220(%rbp), %rdi
callq 0x4270
leaq -0x210(%rbp), %rbx
leaq 0x26c6(%rip), %rsi      # 0x7012
movq %rbx, %rdi
callq 0x4360
movq -0x210(%rbp), %rax
movq -0x18(%rax), %rax
movl -0x1f8(%rbp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, -0x1f8(%rbp,%rax)
leaq -0x78(%rbp), %rdi
callq 0x4610
movzbl %al, %esi
movq %rbx, %rdi
callq 0x4260
pushq $0x20
popq %rdi
callq 0x4170
movq %rax, %rbx
leaq -0x208(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x4520
movb $0x1, %r15b
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
callq 0x4680
xorl %r15d, %r15d
movq 0x5605(%rip), %rsi      # 0x9fc0
movq 0x560e(%rip), %rdx      # 0x9fd0
movq %rbx, %rdi
callq 0x45c0
jmp 0x4a42
leaq -0x640(%rbp), %rdi
callq 0x4270
leaq -0x630(%rbp), %r14
leaq 0x261a(%rip), %rsi      # 0x7000
movq %r14, %rdi
callq 0x4360
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4310
pushq $0x20
popq %rdi
callq 0x4170
movq %rax, %rbx
leaq -0x628(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x4520
movb $0x1, %r15b
leaq -0x220(%rbp), %rsi
movq %rbx, %rdi
callq 0x4680
xorl %r15d, %r15d
movq 0x558d(%rip), %rsi      # 0x9fc0
movq 0x5596(%rip), %rdx      # 0x9fd0
movq %rbx, %rdi
callq 0x45c0
movq %rax, %r14
leaq -0x220(%rbp), %rdi
callq 0x4140
testb %r15b, %r15b
jne 0x4a5b
jmp 0x4a68
movq %rax, %r14
movq %rbx, %rdi
callq 0x4290
jmp 0x4a68
movq %rax, %r14
leaq -0x640(%rbp), %rdi
callq 0x42a0
jmp 0x4ae3
jmp 0x4ad0
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0x4140
testb %r15b, %r15b
jne 0x4a8e
jmp 0x4aa0
movq %rax, %r14
movq %rbx, %rdi
callq 0x4290
jmp 0x4aa0
movq %rax, %r14
jmp 0x4aef
movq %rax, %r14
leaq -0x220(%rbp), %rdi
callq 0x42a0
jmp 0x4ada
jmp 0x4ad7
jmp 0x4ad0
movq %rax, %r14
movq %r15, %rdi
callq 0x4190
jmp 0x4ada
movq %rax, %r14
leaq -0x98(%rbp), %rdi
callq 0x4140
jmp 0x4ae3
movq %rax, %r14
jmp 0x4ae3
jmp 0x4ad7
movq %rax, %r14
leaq -0x78(%rbp), %rdi
callq 0x4190
leaq -0x428(%rbp), %rdi
callq 0x4090
movq -0x30(%rbp), %rdi
callq 0x41f0
movq %r14, %rdi
callq 0x45f0