// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rsi, %rbx
leaq 0x8(%rdi), %rax
movl $0x0, 0x8(%rdi)
xorl %ecx, %ecx
movq %rcx, 0x10(%rdi)
movq %rax, 0x18(%rdi)
movq %rax, 0x20(%rdi)
movq %rdi, -0x30(%rbp)
movq %rcx, 0x28(%rdi)
movq (%rsi), %rsi
leaq -0x428(%rbp), %r14
movq %r14, %rdi
movl $0x8, %edx
callq 0x34a0
leaq -0x3b0(%rbp), %rdi
callq 0x3040
testb %al, %al
je 0x390c
leaq -0x40(%rbp), %r12
leaq -0x218(%rbp), %r15
leaq -0x78(%rbp), %rbx
movq -0x428(%rbp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %ecx
movl $0x20c, %edx            # imm = 0x20C
movq %r14, %rdi
leaq -0x640(%rbp), %rsi
callq 0x34e0
movq -0x428(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x408(%rbp,%rax)
jne 0x383f
movq %r12, -0x50(%rbp)
leaq -0x640(%rbp), %r14
movq %r14, %rdi
callq 0x3100
leaq (%rax,%rbp), %rdx
addq $-0x640, %rdx           # imm = 0xF9C0
leaq -0x50(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x30c0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3150
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x3753
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x3470
testb %al, %al
je 0x376f
movq %rbx, %rdi
callq 0x3470
cmpb $0x1, %al
jne 0x3862
movq %rbx, %rdi
callq 0x3270
movw %ax, -0x220(%rbp)
movb -0x76(%rbp), %al
movb %al, 0x2(%r15)
movzwl -0x78(%rbp), %eax
movw %ax, (%r15)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rax
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r15)
movq $0x0, 0x18(%r15)
subq %rsi, %r14
je 0x37ce
js 0x385d
movq %r14, %rdi
callq 0x32a0
movq %rax, %r13
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rax
movq %rax, %r12
subq %rsi, %r12
jmp 0x37d4
movq %r14, %r12
xorl %r13d, %r13d
movq %r13, -0x210(%rbp)
movq %r13, -0x208(%rbp)
addq %r13, %r14
movq %r14, -0x200(%rbp)
cmpq %rsi, %rax
je 0x37fc
movq %r13, %rdi
movq %r12, %rdx
callq 0x3400
addq %r12, %r13
movq %r13, -0x208(%rbp)
movb -0x58(%rbp), %al
movb %al, -0x1f8(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x3240
movq %r15, %rdi
callq 0x3140
movq %rbx, %rdi
callq 0x3140
leaq -0x428(%rbp), %r14
leaq -0x40(%rbp), %r12
jmp 0x36be
leaq -0x428(%rbp), %rdi
callq 0x3060
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x30a0
leaq -0x220(%rbp), %rdi
callq 0x31f0
leaq -0x210(%rbp), %rbx
leaq 0x27a6(%rip), %rsi      # 0x6022
movl $0x1b, %edx
movq %rbx, %rdi
callq 0x3310
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 0x3470
movzbl %al, %esi
movq %rbx, %rdi
callq 0x31e0
movl $0x20, %edi
callq 0x3120
movq %rax, %rbx
leaq -0x208(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x33e0
movb $0x1, %r15b
leaq -0x98(%rbp), %rsi
movq %rbx, %rdi
callq 0x34d0
xorl %r15d, %r15d
movq 0x56c0(%rip), %rsi      # 0x8fb8
movq 0x56d1(%rip), %rdx      # 0x8fd0
movq %rbx, %rdi
callq 0x3440
jmp 0x398d
leaq -0x640(%rbp), %rdi
callq 0x31f0
leaq -0x630(%rbp), %r14
leaq 0x26ea(%rip), %rsi      # 0x6010
movl $0x11, %edx
movq %r14, %rdi
callq 0x3310
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x3310
movl $0x20, %edi
callq 0x3120
movq %rax, %rbx
leaq -0x628(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x33e0
movb $0x1, %r15b
leaq -0x220(%rbp), %rsi
movq %rbx, %rdi
callq 0x34d0
xorl %r15d, %r15d
movq 0x563a(%rip), %rsi      # 0x8fb8
movq 0x564b(%rip), %rdx      # 0x8fd0
movq %rbx, %rdi
callq 0x3440
movq %rax, %r14
leaq -0x210(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39af
movq -0x210(%rbp), %rsi
incq %rsi
callq 0x32b0
testb %r15b, %r15b
jne 0x39b9
jmp 0x39c6
movq %rax, %r14
movq %rbx, %rdi
callq 0x3210
jmp 0x39c6
movq %rax, %r14
movq 0x55f3(%rip), %rsi      # 0x8fc0
leaq -0x640(%rbp), %rdi
callq 0x3220
leaq -0x5c0(%rbp), %rdi
callq 0x3080
jmp 0x3a8e
jmp 0x3a7d
movq %rax, %r14
leaq -0x88(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3a11
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x32b0
testb %r15b, %r15b
jne 0x3a1b
jmp 0x3a2d
movq %rax, %r14
movq %rbx, %rdi
callq 0x3210
jmp 0x3a2d
movq %rax, %r14
jmp 0x3a9a
movq %rax, %r14
movq 0x558c(%rip), %rsi      # 0x8fc0
leaq -0x220(%rbp), %rdi
callq 0x3220
leaq -0x1a0(%rbp), %rdi
callq 0x3080
jmp 0x3a85
jmp 0x3a82
movq %rax, %r14
movq %r15, %rdi
callq 0x3140
jmp 0x3a85
movq %rax, %r14
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x3a8e
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x32b0
jmp 0x3a8e
jmp 0x3a7d
jmp 0x3a82
jmp 0x3a82
movq %rax, %r14
jmp 0x3a8e
movq %rax, %r14
leaq -0x78(%rbp), %rdi
callq 0x3140
leaq -0x428(%rbp), %rdi
callq 0x3060
movq -0x30(%rbp), %rdi
callq 0x3190
movq %r14, %rdi
callq 0x3460
nop