// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
leaq 0x8(%rdi), %rax
movq %rax, -0x38(%rbp)
xorps %xmm0, %xmm0
andq $0x0, 0x18(%rdi)
movups %xmm0, 0x8(%rdi)
movq (%rsi), %rax
cmpb $0x3a, (%rax)
jne 0x551f
movq %rdi, %r14
leaq -0x100(%rbp), %rdi
pushq $0x1
popq %rdx
pushq $0x2
popq %rcx
movq %rbx, %rsi
callq 0x4390
leaq -0x100(%rbp), %rsi
callq 0x44b0
movq %rax, %r13
leaq -0x100(%rbp), %rdi
callq 0x4140
leaq -0xe0(%rbp), %rdi
pushq $0x3
popq %rdx
pushq $0x2
popq %rcx
movq %rbx, %rsi
callq 0x4390
leaq -0xe0(%rbp), %rsi
callq 0x44b0
movq %rax, %r12
leaq -0xe0(%rbp), %rdi
callq 0x4140
leaq -0xc0(%rbp), %rdi
pushq $0x5
popq %rdx
pushq $0x2
popq %rcx
movq %rbx, %rsi
callq 0x4390
leaq -0xc0(%rbp), %rsi
callq 0x44b0
movq %rax, %r15
leaq -0xc0(%rbp), %rdi
callq 0x4140
movl %r12d, %eax
shll $0x8, %eax
movzbl %r15b, %ecx
orl %eax, %ecx
movw %cx, (%r14)
leaq -0xa0(%rbp), %rdi
pushq $0x7
popq %rdx
pushq $0x2
popq %rcx
movq %rbx, %rsi
callq 0x4390
leaq -0xa0(%rbp), %rsi
callq 0x44b0
addb %r13b, %r13b
movb %al, 0x2(%r14)
leaq -0xa0(%rbp), %rdi
callq 0x4140
movzbl %r13b, %r13d
movq %rbx, -0x30(%rbp)
movq 0x8(%rbx), %rax
addq $-0xc, %rax
cmpq %r13, %rax
jne 0x5595
movl %r13d, %eax
shrl %eax
addl %r15d, %r12d
addl %eax, %r12d
movq %r14, -0x60(%rbp)
addb 0x2(%r14), %r12b
xorl %r14d, %r14d
leaq -0x120(%rbp), %r15
movzbl %r14b, %r14d
cmpl %r13d, %r14d
jae 0x54cc
leal 0x9(%r14), %edx
movq %r15, %rdi
movq -0x30(%rbp), %rsi
pushq $0x2
popq %rcx
callq 0x4390
movq %r15, %rsi
callq 0x44b0
movq %rax, %rbx
movq %r15, %rdi
callq 0x4140
movb %bl, -0x2a8(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x4040
addb %bl, %r12b
addl $0x2, %r14d
jmp 0x547e
movq -0x30(%rbp), %rsi
movq 0x8(%rsi), %rdx
addq $-0x3, %rdx
leaq -0x80(%rbp), %rdi
pushq $0x2
popq %rcx
callq 0x4390
leaq -0x80(%rbp), %rsi
callq 0x44b0
movq %rax, %r14
leaq -0x80(%rbp), %rdi
callq 0x4140
movzbl %r12b, %r12d
movzbl %r14b, %r13d
addl %r12d, %r13d
testb %r13b, %r13b
jne 0x562b
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %r14
leaq -0x2a8(%rbp), %rdi
callq 0x4270
leaq -0x298(%rbp), %rbx
leaq 0x1b52(%rip), %rsi      # 0x708e
movq %rbx, %rdi
callq 0x4360
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4310
pushq $0x20
popq %rdi
callq 0x4170
movq %rax, %r15
leaq -0x290(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x4520
movb $0x1, %bl
leaq -0x58(%rbp), %rsi
movq %r15, %rdi
callq 0x4680
xorl %ebx, %ebx
movq 0x4a3f(%rip), %rsi      # 0x9fc0
movq 0x4a48(%rip), %rdx      # 0x9fd0
movq %r15, %rdi
callq 0x45c0
jmp 0x5735
leaq -0x2a8(%rbp), %rdi
callq 0x4270
leaq -0x298(%rbp), %rbx
leaq 0x1af3(%rip), %rsi      # 0x70a2
movq %rbx, %rdi
callq 0x4360
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4260
leaq 0x1afe(%rip), %rsi      # 0x70c7
movq %rbx, %rdi
callq 0x4360
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
addq $-0xc, %rsi
movq %rbx, %rdi
callq 0x4260
pushq $0x20
popq %rdi
callq 0x4170
movq %rax, %r15
leaq -0x290(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x4520
movb $0x1, %bl
leaq -0x58(%rbp), %rsi
movq %r15, %rdi
callq 0x4680
xorl %ebx, %ebx
movq 0x49a9(%rip), %rsi      # 0x9fc0
movq 0x49b2(%rip), %rdx      # 0x9fd0
movq %r15, %rdi
callq 0x45c0
jmp 0x5735
movq 0x49a6(%rip), %rbx      # 0x9fd8
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq -0x60(%rbp), %rax
movzwl (%rax), %esi
movq %rbx, %rdi
callq 0x4260
movq %rax, %rdi
callq 0x4160
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 0x4270
leaq -0x298(%rbp), %r15
leaq 0x1a3f(%rip), %rsi      # 0x70cc
movq %r15, %rdi
callq 0x4360
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 %r15, %rdi
callq 0x4260
leaq 0x1a27(%rip), %rsi      # 0x70ed
movq %r15, %rdi
callq 0x4360
movq %r15, %rdi
movq %r12, %rsi
callq 0x4260
leaq 0x1a24(%rip), %rsi      # 0x7104
movq %r15, %rdi
callq 0x4360
movzbl %r14b, %esi
movq %r15, %rdi
callq 0x4260
pushq $0x20
popq %rdi
callq 0x4170
movq %rax, %r15
leaq -0x290(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x4520
movb $0x1, %bl
leaq -0x58(%rbp), %rsi
movq %r15, %rdi
callq 0x4680
xorl %ebx, %ebx
movq 0x489a(%rip), %rsi      # 0x9fc0
movq 0x48a3(%rip), %rdx      # 0x9fd0
movq %r15, %rdi
callq 0x45c0
jmp 0x573d
jmp 0x574f
jmp 0x573d
jmp 0x574f
movq %rax, %r14
leaq -0x58(%rbp), %rdi
callq 0x4140
testb %bl, %bl
jne 0x5752
jmp 0x5765
movq %rax, %r14
movq %r15, %rdi
callq 0x4290
jmp 0x5765
jmp 0x5762
jmp 0x57c9
jmp 0x5762
movq %rax, %r14
leaq -0x2a8(%rbp), %rdi
callq 0x42a0
jmp 0x57cc
jmp 0x57c9
jmp 0x57c9
movq %rax, %r14
leaq -0x80(%rbp), %rdi
jmp 0x57c2
movq %rax, %r14
leaq -0xa0(%rbp), %rdi
jmp 0x57c2
movq %rax, %r14
leaq -0xc0(%rbp), %rdi
jmp 0x57c2
movq %rax, %r14
leaq -0xe0(%rbp), %rdi
jmp 0x57c2
jmp 0x57c9
movq %rax, %r14
leaq -0x100(%rbp), %rdi
jmp 0x57c2
jmp 0x57c9
jmp 0x57c9
jmp 0x57c9
movq %rax, %r14
leaq -0x120(%rbp), %rdi
callq 0x4140
jmp 0x57cc
movq %rax, %r14
movq -0x38(%rbp), %rdi
callq 0x4510
movq %r14, %rdi
callq 0x45f0
nop