// File: /workspace/github_cpp_makefile_star2_O1/jeffchan[P]blockchain-parser/BlockChainAddresses.cpp
// Function: BlockChainAddressesImpl::BlockChainAddressesImpl(char const*)
BlockChainAddressesImpl(const char *fname)
	{
		mRowCount = 0;
		mAddressCount = 0;
		mAddresses = 0;
		mRows = 0;
		mCurrentRow = 0;
		mCurrentRowIndex = 0;
		FILE *fph = fopen(fname,"rb");
		if ( fph )
		{
			char headerBlock[22];
			size_t r = fread(headerBlock,sizeof(headerBlock),1,fph);	// read the block header
			if ( r == 1 )
			{
				const char *headerString = "BLOCK_CHAIN_ADDRESSES";
				if ( headerBlock[21] == 0 && strcmp(headerBlock,headerString) == 0 ) // confirm this is a valid block-header for the data file we are expecting
				{
					uint32_t version=0;
					fread(&version,sizeof(version),1,fph);
					if ( version == CURRENT_VERSION )	// Confirm this is for the same version number of this file we are one.
					{
						r = fread(&mAddressCount,sizeof(mAddressCount),1,fph);	// Read the number of unique public key addresses recorded
						if ( r == 1 )
						{
							mAddresses = new Address[mAddressCount];
							r  = fread(mAddresses,sizeof(Address)*mAddressCount,1,fph);	// Read all of the addresses into memory.
							if ( r == 1 )
							{
								fread(&mRowCount,sizeof(mRowCount),1,fph);		// Read the number of rows (days)
								if ( mRowCount )
								{
									mRows = new Row[mRowCount];
									// For each row read the start time, the number of new addresses, the number of changed addresses, and the number of removed addresses
									// Also allocate memory to hold the change data
									for (uint32_t i=0; i<mRowCount; i++)
									{
										Row &row = mRows[i];
										fread(&row.mStartTime,sizeof(row.mStartTime),1,fph);
										fread(&row.mAddressCount,sizeof(row.mAddressCount),1,fph);
										fread(&row.mChangeAddressCount,sizeof(row.mChangeAddressCount),1,fph);
										fread(&row.mDeleteAddressCount,sizeof(row.mDeleteAddressCount),1,fph);
										if ( row.mAddressCount )
										{
											row.mNewAddresses = new BlockChainAddresses::StatAddress[row.mAddressCount];
										}
										if ( row.mChangeAddressCount )
										{
											row.mChangedAddresses = new BlockChainAddresses::StatAddress[row.mChangeAddressCount];
										}
										if ( row.mDeleteAddressCount )
										{
											row.mDeletedAddresses = new uint32_t[row.mDeleteAddressCount];
										}
									}
									// Now for each row, read the new address data, the change address data, and the deleted address data
									for (uint32_t i=0; i<mRowCount; i++)
									{
										Row &row = mRows[i];
										if ( row.mNewAddresses )
										{
											fread(row.mNewAddresses,sizeof(BlockChainAddresses::StatAddress)*row.mAddressCount,1,fph);
										}
										if ( row.mChangedAddresses )
										{
											fread(row.mChangedAddresses,sizeof(BlockChainAddresses::StatAddress)*row.mChangeAddressCount,1,fph);
										}
										if ( row.mDeletedAddresses )
										{
											fread(row.mDeletedAddresses,sizeof(uint32_t)*row.mDeleteAddressCount,1,fph);
										}
									}
								}
								else
								{
									printf("Failed to read the row counter.\r\n");
								}
							}
							else
							{
								printf("Failed to read public-key addresses.\r\n");
							}
						}
						else
						{
							printf("Failed to read address count.\r\n");
						}
					}
				}
				else
				{
					printf("Invalid header block.\r\n");
				}
			}
			else
			{
				printf("Failed to read header block!\r\n");
			}
			fclose(fph);
		}
		else
		{
			printf("Failed to open BitcoinAddress file: %s\r\n", fname );
		}
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %r14
leaq 0xcec8(%rip), %rax      # 0x1ed00
movq %rax, (%rdi)
xorl %eax, %eax
movl %eax, 0x18(%rdi)
movl %eax, 0x8(%rdi)
movq %rax, 0x10(%rdi)
movq %rax, 0x20(%rdi)
movq %rax, 0x30(%rdi)
movl %eax, 0x28(%rdi)
leaq 0x5c08(%rip), %rsi      # 0x17a61
movq %r15, %rdi
callq 0x21a0
testq %rax, %rax
je 0x11ebd
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
movl $0x16, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x2250
cmpq $0x1, %rax
jne 0x11edc
cmpb $0x0, -0x5b(%rbp)
jne 0x11eb4
movdqa -0x70(%rbp), %xmm0
movdqu -0x6a(%rbp), %xmm1
pcmpeqb 0x7df3(%rip), %xmm1     # 0x19c90
pcmpeqb 0x7dfb(%rip), %xmm0     # 0x19ca0
pand %xmm1, %xmm0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x11efe
leaq 0x7e3c(%rip), %rdi      # 0x19cf7
jmp 0x11ee3
leaq 0x7dec(%rip), %rdi      # 0x19cb0
movq %r15, %rsi
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050
leaq 0x7df6(%rip), %rdi      # 0x19cd9
callq 0x2260
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2150
leaq -0x4c(%rbp), %r15
movl $0x0, (%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x2250
cmpl $0x1, (%r15)
jne 0x11ee8
leaq 0x8(%r14), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2250
cmpq $0x1, %rax
jne 0x121e3
movl 0x8(%r14), %eax
shlq $0x2, %rax
leaq (%rax,%rax,4), %r15
movq %r15, %rdi
callq 0x2040
movq %rax, 0x10(%r14)
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rcx
callq 0x2250
cmpq $0x1, %rax
jne 0x121ef
leaq 0x18(%r14), %r15
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x2250
movq %r15, -0x30(%rbp)
movl (%r15), %eax
testl %eax, %eax
je 0x121fb
movl %eax, %r12d
leaq (,%r12,8), %r13
leaq 0x8(,%r13,4), %rdi
addq %r13, %rdi
callq 0x2040
movq %rax, %r15
movq %r12, (%rax)
addq $0x8, %r15
leaq -0x28(,%r13,4), %rax
addq %r13, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rcx
shrq $0x5, %rdx
leaq (%rdx,%rdx,4), %rax
leaq 0x28(,%rax,8), %rdx
xorl %r13d, %r13d
movq %r15, %rdi
xorl %esi, %esi
callq 0x20b0
movq %r15, 0x20(%r14)
cmpl $0x0, 0x18(%r14)
je 0x1214a
xorl %ecx, %ecx
movq 0x20(%r14), %r12
movq %rcx, -0x48(%rbp)
leaq (%rcx,%rcx,4), %r15
leaq (%r12,%r15,8), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rdi, -0x38(%rbp)
movq %rbx, %rcx
callq 0x2250
leaq (%r12,%r15,8), %rdi
addq $0x4, %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2250
leaq (%r12,%r15,8), %rdi
addq $0x8, %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rdi, -0x40(%rbp)
movq %rbx, %rcx
callq 0x2250
leaq (%r12,%r15,8), %r15
addq $0xc, %r15
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x2250
movl -0x8(%r15), %eax
testq %rax, %rax
je 0x120cd
shlq $0x3, %rax
leaq (%rax,%rax,2), %r12
movq %r12, %rdi
callq 0x2040
movq %rax, %rcx
addq %r12, %rcx
movq %rax, %rdx
movq $0x0, (%rdx)
movl %r13d, 0x8(%rdx)
movl %r13d, 0x10(%rdx)
movl %r13d, 0x13(%rdx)
addq $0x18, %rdx
cmpq %rcx, %rdx
jne 0x120a9
movq -0x38(%rbp), %rcx
movq %rax, 0x10(%rcx)
movq -0x40(%rbp), %rax
movl (%rax), %eax
testq %rax, %rax
je 0x1211b
movq %r15, %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %r15
movq %r15, %rdi
callq 0x2040
movq %rax, %rcx
addq %r15, %rcx
movq %rax, %rdx
movq $0x0, (%rdx)
movl %r13d, 0x8(%rdx)
movl %r13d, 0x10(%rdx)
movl %r13d, 0x13(%rdx)
addq $0x18, %rdx
cmpq %rcx, %rdx
jne 0x120f4
movq -0x38(%rbp), %rcx
movq %rax, 0x18(%rcx)
movq %r12, %r15
movl (%r15), %edi
testq %rdi, %rdi
je 0x12134
shlq $0x2, %rdi
callq 0x2040
movq -0x38(%rbp), %rcx
movq %rax, 0x20(%rcx)
movq -0x48(%rbp), %rcx
incq %rcx
movq -0x30(%rbp), %rax
movl (%rax), %eax
cmpq %rax, %rcx
jb 0x1200c
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x11ee8
movl $0x4, %r15d
xorl %r12d, %r12d
movq 0x20(%r14), %r13
movq 0xc(%r13,%r15), %rdi
testq %rdi, %rdi
je 0x12188
movl (%r13,%r15), %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2250
movq 0x14(%r13,%r15), %rdi
testq %rdi, %rdi
je 0x121ac
movl 0x4(%r13,%r15), %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2250
movq 0x1c(%r13,%r15), %rdi
testq %rdi, %rdi
je 0x121cc
movl 0x8(%r13,%r15), %esi
shlq $0x2, %rsi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2250
incq %r12
movq -0x30(%rbp), %rax
movl (%rax), %eax
addq $0x28, %r15
cmpq %rax, %r12
jb 0x12160
jmp 0x11ee8
leaq 0x7b24(%rip), %rdi      # 0x19d0e
jmp 0x11ee3
leaq 0x7b37(%rip), %rdi      # 0x19d2d
jmp 0x11ee3
leaq 0x7b51(%rip), %rdi      # 0x19d53
jmp 0x11ee3
nop