// File: /workspace/github_cpp_makefile_star2_O3/bstrysko[P]IntelHexParser/src/IntelHexFileEntry.cpp
// Function: IntelHexFileEntry::IntelHexFileEntry(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
IntelHexFileEntry::IntelHexFileEntry(string entry)
{
	if(entry[0] != ':')
	{
		stringstream o;
		o << "Invalid hex entry: ";
		o << entry;
		throw ios_base::failure(o.str());
	}

	uint8_t count = 2*asciiHexTo64(entry.substr(1,2));
	uint8_t hAddress = asciiHexTo64(entry.substr(3,2));
	uint8_t lAddress = asciiHexTo64(entry.substr(5,2));
	address = ((hAddress << 8) | lAddress);
	recordType = asciiHexTo64(entry.substr(7,2));	

	uint8_t cChecksum = (count/2) + lAddress + hAddress + recordType;

	if(count != entry.length()-(9+2+1))
	{
		stringstream o;
		o << "length provided != length of data | ";
		o << (size_t)(count);
		o << " != ";
		o << (entry.length()-(9+2+1));

		throw ios_base::failure(o.str());
	}

	for(uint8_t i = 0; i < count; i+=2)
	{
		uint8_t v = asciiHexTo64(entry.substr(9+i,2));
		cChecksum += v;
		data.push_back(v);
	}

	uint8_t checksum = asciiHexTo64(entry.substr(entry.length()-3,2));

	if(((uint8_t)(cChecksum + checksum)) != ((uint8_t)0))
	{
		cout << hex << (size_t)address << endl;
		cout << dec;

		stringstream o;
		o << "(cChecksum + checksum) != 0 | 0x";
		o << hex;
		o << (size_t)(cChecksum + checksum);
		o << " != 0 | cChecksum = 0x";
		o << (size_t)cChecksum;
		o << ", checksum = 0x";
		o << (size_t)checksum;

		throw ios_base::failure(o.str());
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %rsi, %r15
leaq 0x8(%rdi), %rax
movq %rax, -0x38(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movq $0x0, 0x18(%rdi)
movq (%rsi), %rax
cmpb $0x3a, (%rax)
movq %rdi, -0x30(%rbp)
jne 0x4446
movq %rdi, %rbx
leaq -0x120(%rbp), %rdi
movl $0x1, %edx
movl $0x2, %ecx
movq %r15, %rsi
callq 0x32c0
leaq -0x120(%rbp), %rsi
callq 0x3380
movq %rax, %r13
leaq -0x110(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x423e
movq -0x110(%rbp), %rsi
incq %rsi
callq 0x32b0
leaq -0x100(%rbp), %rdi
movl $0x3, %edx
movl $0x2, %ecx
movq %r15, %rsi
callq 0x32c0
leaq -0x100(%rbp), %rsi
callq 0x3380
movq %rax, %r12
leaq -0xf0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4285
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x32b0
leaq -0xe0(%rbp), %rdi
movl $0x5, %edx
movl $0x2, %ecx
movq %r15, %rsi
callq 0x32c0
leaq -0xe0(%rbp), %rsi
callq 0x3380
movq %rax, %r14
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x42cc
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x32b0
movl %r12d, %eax
shll $0x8, %eax
movzbl %r14b, %ecx
orl %eax, %ecx
movw %cx, (%rbx)
leaq -0xc0(%rbp), %rdi
movl $0x7, %edx
movl $0x2, %ecx
movq %r15, %rsi
callq 0x32c0
leaq -0xc0(%rbp), %rsi
callq 0x3380
addb %r13b, %r13b
movb %al, 0x2(%rbx)
leaq -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4325
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x32b0
movzbl %r13b, %ecx
movq 0x8(%r15), %rdx
leaq -0xc(%rdx), %rax
cmpq %rcx, %rax
jne 0x44c6
movl %ecx, %eax
shrl %eax
addl %r14d, %r12d
addl %eax, %r12d
addb 0x2(%rbx), %r12b
testb %cl, %cl
je 0x43da
movq %rcx, -0x60(%rbp)
movq %r15, %r13
xorl %r15d, %r15d
leaq -0x80(%rbp), %r14
leal 0x9(%r15), %edx
movl $0x2, %ecx
movq %r14, %rdi
movq %r13, %rsi
callq 0x32c0
movq %r14, %rsi
callq 0x3380
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x4396
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x32b0
movb %bl, -0x2a8(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
cmpq 0x18(%rax), %rsi
je 0x43b2
movb %bl, (%rsi)
incq 0x10(%rax)
jmp 0x43c2
movq -0x38(%rbp), %rdi
leaq -0x2a8(%rbp), %rdx
callq 0x31d0
addb %bl, %r12b
addl $0x2, %r15d
movzbl %r15b, %r15d
cmpl -0x60(%rbp), %r15d
jb 0x435e
movq %r13, %r15
movq 0x8(%r13), %rdx
addq $-0x3, %rdx
leaq -0xa0(%rbp), %rdi
movl $0x2, %ecx
movq %r15, %rsi
callq 0x32c0
leaq -0xa0(%rbp), %rsi
callq 0x3380
movq %rax, %r15
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4420
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x32b0
movzbl %r12b, %r12d
movzbl %r15b, %r13d
addl %r12d, %r13d
testb %r13b, %r13b
jne 0x4569
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x2a8(%rbp), %rdi
callq 0x31f0
leaq -0x298(%rbp), %rbx
leaq 0x1c3e(%rip), %rsi      # 0x609e
movl $0x13, %edx
movq %rbx, %rdi
callq 0x3310
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %rbx, %rdi
callq 0x3310
movl $0x20, %edi
callq 0x3120
movq %rax, %r14
leaq -0x290(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x33e0
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x34d0
xorl %r15d, %r15d
movq 0x4b06(%rip), %rsi      # 0x8fb8
movq 0x4b17(%rip), %rdx      # 0x8fd0
movq %r14, %rdi
callq 0x3440
jmp 0x4686
movq %rcx, %rbx
leaq -0x2a8(%rbp), %rdi
callq 0x31f0
leaq -0x298(%rbp), %r14
leaq 0x1bcf(%rip), %rsi      # 0x60b2
movl $0x24, %edx
movq %r14, %rdi
callq 0x3310
movq %r14, %rdi
movq %rbx, %rsi
callq 0x31e0
leaq 0x1bd5(%rip), %rsi      # 0x60d7
movl $0x4, %edx
movq %r14, %rdi
callq 0x3310
movq 0x8(%r15), %rsi
addq $-0xc, %rsi
movq %r14, %rdi
callq 0x31e0
movl $0x20, %edi
callq 0x3120
movq %rax, %r14
leaq -0x290(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x33e0
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x34d0
xorl %r15d, %r15d
movq 0x4a63(%rip), %rsi      # 0x8fb8
movq 0x4a74(%rip), %rdx      # 0x8fd0
movq %r14, %rdi
callq 0x3440
jmp 0x4686
movq 0x4a68(%rip), %rbx      # 0x8fd8
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq -0x30(%rbp), %rax
movzwl (%rax), %esi
movq %rbx, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3110
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq -0x2a8(%rbp), %rdi
callq 0x31f0
leaq -0x298(%rbp), %r14
leaq 0x1b11(%rip), %rsi      # 0x60dc
movl $0x20, %edx
movq %r14, %rdi
callq 0x3310
movq -0x298(%rbp), %rax
movq -0x18(%rax), %rax
movl -0x280(%rbp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, -0x280(%rbp,%rax)
movl %r13d, %esi
movq %r14, %rdi
callq 0x31e0
leaq 0x1af4(%rip), %rsi      # 0x60fd
movl $0x16, %edx
movq %r14, %rdi
callq 0x3310
movq %r14, %rdi
movq %r12, %rsi
callq 0x31e0
leaq 0x1aec(%rip), %rsi      # 0x6114
movl $0xf, %edx
movq %r14, %rdi
callq 0x3310
movzbl %r15b, %esi
movq %r14, %rdi
callq 0x31e0
movl $0x20, %edi
callq 0x3120
movq %rax, %r14
leaq -0x290(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x33e0
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x34d0
xorl %r15d, %r15d
movq 0x4941(%rip), %rsi      # 0x8fb8
movq 0x4952(%rip), %rdx      # 0x8fd0
movq %r14, %rdi
callq 0x3440
jmp 0x468e
jmp 0x46b1
jmp 0x468e
jmp 0x46b1
movq %rax, %rbx
leaq -0x48(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x46aa
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x32b0
testb %r15b, %r15b
jne 0x46b4
jmp 0x46ca
movq %rax, %rbx
movq %r14, %rdi
callq 0x3210
jmp 0x46ca
jmp 0x46c7
jmp 0x47b5
jmp 0x46c7
movq %rax, %rbx
movq 0x48ef(%rip), %rsi      # 0x8fc0
leaq -0x2a8(%rbp), %rdi
callq 0x3220
leaq -0x228(%rbp), %rdi
callq 0x3080
jmp 0x47b8
jmp 0x47b5
jmp 0x47b5
movq %rax, %rbx
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47b8
movq -0x90(%rbp), %rsi
jmp 0x47ab
movq %rax, %rbx
leaq -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47b8
movq -0xb0(%rbp), %rsi
jmp 0x47ab
movq %rax, %rbx
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47b8
movq -0xd0(%rbp), %rsi
jmp 0x47ab
movq %rax, %rbx
leaq -0xf0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47b8
movq -0xf0(%rbp), %rsi
jmp 0x47ab
jmp 0x47b5
movq %rax, %rbx
leaq -0x110(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47b8
movq -0x110(%rbp), %rsi
jmp 0x47ab
jmp 0x47b5
jmp 0x47b5
jmp 0x47b5
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x47b8
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x32b0
jmp 0x47b8
movq %rax, %rbx
movq -0x38(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x47d4
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rsi
subq %rdi, %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x3460