// File: /workspace/github_cpp_makefile_star2_O1/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 0x443c
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 0x423a
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 0x4281
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 0x42c8
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 0x4321
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x32b0
movzbl %r13b, %ecx
movq 0x8(%r15), %rax
addq $-0xc, %rax
cmpq %rcx, %rax
jne 0x44bc
movq %r15, -0x40(%rbp)
movl %ecx, %eax
shrl %eax
addl %r14d, %r12d
addl %eax, %r12d
addb 0x2(%rbx), %r12b
testb %cl, %cl
je 0x43cb
movq %rcx, %r13
xorl %r15d, %r15d
leaq -0x80(%rbp), %r14
leal 0x9(%r15), %edx
movl $0x2, %ecx
movq %r14, %rdi
movq -0x40(%rbp), %rsi
callq 0x32c0
movq %r14, %rsi
callq 0x3380
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x438f
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 0x43ab
movb %bl, (%rsi)
incq 0x10(%rax)
jmp 0x43bb
movq -0x38(%rbp), %rdi
leaq -0x2a8(%rbp), %rdx
callq 0x31d0
addb %bl, %r12b
addl $0x2, %r15d
movzbl %r15b, %r15d
cmpl %r13d, %r15d
jb 0x4356
movq -0x40(%rbp), %rsi
movq 0x8(%rsi), %rdx
addq $-0x3, %rdx
leaq -0xa0(%rbp), %rdi
movl $0x2, %ecx
callq 0x32c0
leaq -0xa0(%rbp), %rsi
callq 0x3380
movq %rax, %r15
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4416
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x32b0
movzbl %r12b, %r12d
movzbl %r15b, %r13d
addl %r12d, %r13d
testb %r13b, %r13b
jne 0x455f
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 0x1c48(%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 -0x60(%rbp), %rdi
callq 0x33e0
movb $0x1, %r15b
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x34d0
xorl %r15d, %r15d
movq 0x4b10(%rip), %rsi      # 0x8fb8
movq 0x4b21(%rip), %rdx      # 0x8fd0
movq %r14, %rdi
callq 0x3440
jmp 0x467c
movq %rcx, %rbx
leaq -0x2a8(%rbp), %rdi
callq 0x31f0
leaq -0x298(%rbp), %r14
leaq 0x1bd9(%rip), %rsi      # 0x60b2
movl $0x24, %edx
movq %r14, %rdi
callq 0x3310
movq %r14, %rdi
movq %rbx, %rsi
callq 0x31e0
leaq 0x1bdf(%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 -0x60(%rbp), %rdi
callq 0x33e0
movb $0x1, %r15b
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x34d0
xorl %r15d, %r15d
movq 0x4a6d(%rip), %rsi      # 0x8fb8
movq 0x4a7e(%rip), %rdx      # 0x8fd0
movq %r14, %rdi
callq 0x3440
jmp 0x467c
movq 0x4a72(%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 0x1b1b(%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 0x1afe(%rip), %rsi      # 0x60fd
movl $0x16, %edx
movq %r14, %rdi
callq 0x3310
movq %r14, %rdi
movq %r12, %rsi
callq 0x31e0
leaq 0x1af6(%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 -0x60(%rbp), %rdi
callq 0x33e0
movb $0x1, %r15b
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x34d0
xorl %r15d, %r15d
movq 0x494b(%rip), %rsi      # 0x8fb8
movq 0x495c(%rip), %rdx      # 0x8fd0
movq %r14, %rdi
callq 0x3440
jmp 0x4684
jmp 0x46a2
jmp 0x4684
jmp 0x46a2
movq %rax, %rbx
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x46a8
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x32b0
jmp 0x46a8
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x46c3
movq %r14, %rdi
callq 0x3210
jmp 0x46c3
jmp 0x46c0
jmp 0x47ae
jmp 0x46c0
movq %rax, %rbx
movq 0x48f6(%rip), %rsi      # 0x8fc0
leaq -0x2a8(%rbp), %rdi
callq 0x3220
leaq -0x228(%rbp), %rdi
callq 0x3080
jmp 0x47b1
jmp 0x47ae
jmp 0x47ae
movq %rax, %rbx
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47b1
movq -0x90(%rbp), %rsi
jmp 0x47a4
movq %rax, %rbx
leaq -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47b1
movq -0xb0(%rbp), %rsi
jmp 0x47a4
movq %rax, %rbx
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47b1
movq -0xd0(%rbp), %rsi
jmp 0x47a4
movq %rax, %rbx
leaq -0xf0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47b1
movq -0xf0(%rbp), %rsi
jmp 0x47a4
jmp 0x47ae
movq %rax, %rbx
leaq -0x110(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47b1
movq -0x110(%rbp), %rsi
jmp 0x47a4
jmp 0x47ae
jmp 0x47ae
jmp 0x47ae
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x47b1
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x32b0
jmp 0x47b1
movq %rax, %rbx
movq -0x38(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x47cd
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rsi
subq %rdi, %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x3460
nop