// File: 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
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x24c10
movq -0x80(%rbp), %rax
leaq 0x14795(%rip), %rcx     # 0x38cb0
movq %rcx, (%rax)
movl $0x0, 0x18(%rax)
movl $0x0, 0x8(%rax)
movq $0x0, 0x10(%rax)
movq $0x0, 0x20(%rax)
movq $0x0, 0x30(%rax)
movl $0x0, 0x28(%rax)
movq -0x10(%rbp), %rdi
leaq 0xc96e(%rip), %rsi      # 0x30ec4
callq 0x2190
movq %rax, -0x78(%rbp)
jmp 0x24561
movq -0x78(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x24bd1
movq -0x18(%rbp), %rcx
leaq -0x40(%rbp), %rdi
movl $0x16, %esi
movl $0x1, %edx
callq 0x2220
movq %rax, -0x88(%rbp)
jmp 0x24594
movq -0x88(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x1, -0x48(%rbp)
jne 0x24bb2
leaq 0xdc21(%rip), %rax      # 0x321d2
movq %rax, -0x50(%rbp)
movsbl -0x2b(%rbp), %eax
cmpl $0x0, %eax
jne 0x24b9e
leaq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x21f0
cmpl $0x0, %eax
jne 0x24b9e
movl $0x0, -0x54(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x54(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x2220
jmp 0x245f8
cmpl $0x1, -0x54(%rbp)
jne 0x24b9c
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2220
movq %rax, -0x90(%rbp)
jmp 0x24626
movq -0x90(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x1, -0x48(%rbp)
jne 0x24b88
movq -0x80(%rbp), %rax
movl 0x8(%rax), %eax
shlq $0x2, %rax
leaq (%rax,%rax,4), %rdi
callq 0x2040
movq %rax, -0x98(%rbp)
jmp 0x24659
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%rax), %rdi
movl 0x8(%rax), %eax
shlq $0x2, %rax
leaq (%rax,%rax,4), %rsi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
callq 0x2220
movq %rax, -0xa0(%rbp)
jmp 0x2468e
movq -0xa0(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x1, -0x48(%rbp)
jne 0x24b74
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
movq -0x18(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2220
jmp 0x246c1
movq -0x80(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x24b60
movq -0x80(%rbp), %rax
movl 0x18(%rax), %eax
movq %rax, -0xb8(%rbp)
leaq (%rax,%rax,4), %rax
leaq 0x8(,%rax,8), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x2040
movq %rax, -0xa8(%rbp)
jmp 0x246fe
movq -0xb8(%rbp), %rax
movq -0xa8(%rbp), %rcx
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x24779
movq -0xc0(%rbp), %rax
movq -0xb8(%rbp), %rcx
imulq $0x28, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0xd0(%rbp)
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x24c30
jmp 0x2475b
movq -0xd0(%rbp), %rcx
movq -0xd8(%rbp), %rax
addq $0x28, %rax
cmpq %rcx, %rax
movq %rax, -0xc8(%rbp)
jne 0x24746
movq -0x80(%rbp), %rax
movq -0xc0(%rbp), %rcx
movq %rcx, 0x20(%rax)
movl $0x0, -0x58(%rbp)
movq -0x80(%rbp), %rcx
movl -0x58(%rbp), %eax
cmpl 0x18(%rcx), %eax
jae 0x24a93
movq -0x80(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x58(%rbp), %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2220
jmp 0x247cf
movq -0x60(%rbp), %rdi
addq $0x4, %rdi
movq -0x18(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2220
jmp 0x247ec
movq -0x60(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2220
jmp 0x24809
movq -0x60(%rbp), %rdi
addq $0xc, %rdi
movq -0x18(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2220
jmp 0x24826
movq -0x60(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x2497b
movq -0x60(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0xf0(%rbp)
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x2040
movq %rax, -0xe0(%rbp)
jmp 0x2485f
movq -0xf0(%rbp), %rax
cmpq $0x0, %rax
je 0x248c5
movq -0xe0(%rbp), %rax
movq -0xf0(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x100(%rbp)
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x24cf0
jmp 0x248a7
movq -0x100(%rbp), %rcx
movq -0x108(%rbp), %rax
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0xf8(%rbp)
jne 0x24892
movq -0xe0(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x2497b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x24bf0
movq -0xc0(%rbp), %rcx
movq %rax, %rsi
movq -0xd8(%rbp), %rax
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
cmpq %rax, %rcx
movq %rax, -0x110(%rbp)
je 0x2493f
movq -0x110(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x118(%rbp)
callq 0x24c80
movq -0xc0(%rbp), %rcx
movq -0x118(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x110(%rbp)
jne 0x2490e
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdi
callq 0x2280
jmp 0x24bf0
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x2280
jmp 0x24bf0
movq -0x60(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x24a4f
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x130(%rbp)
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
movq %rdi, -0x128(%rbp)
callq 0x2040
movq %rax, -0x120(%rbp)
jmp 0x249b4
movq -0x130(%rbp), %rax
cmpq $0x0, %rax
je 0x24a1a
movq -0x120(%rbp), %rax
movq -0x130(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x140(%rbp)
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x24cf0
jmp 0x249fc
movq -0x140(%rbp), %rcx
movq -0x148(%rbp), %rax
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x138(%rbp)
jne 0x249e7
movq -0x120(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x24a4f
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x2280
jmp 0x24bf0
movq -0x60(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x24a83
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x2040
movq %rax, -0x150(%rbp)
jmp 0x24a74
movq -0x150(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x24a85
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x2478f
movl $0x0, -0x64(%rbp)
movq -0x80(%rbp), %rcx
movl -0x64(%rbp), %eax
cmpl 0x18(%rcx), %eax
jae 0x24b5e
movq -0x80(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x24af0
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rdi
movl 0x4(%rax), %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
callq 0x2220
jmp 0x24aee
jmp 0x24af0
movq -0x70(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x24b20
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rdi
movl 0x8(%rax), %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
callq 0x2220
jmp 0x24b1e
jmp 0x24b20
movq -0x70(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x24b4e
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rdi
movl 0xc(%rax), %eax
movl %eax, %esi
shlq $0x2, %rsi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
callq 0x2220
jmp 0x24b4c
jmp 0x24b4e
jmp 0x24b50
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x24a9a
jmp 0x24b72
leaq 0xe54a(%rip), %rdi      # 0x330b1
xorl %eax, %eax
callq 0x2050
jmp 0x24b70
jmp 0x24b72
jmp 0x24b86
leaq 0xe558(%rip), %rdi      # 0x330d3
xorl %eax, %eax
callq 0x2050
jmp 0x24b84
jmp 0x24b86
jmp 0x24b9a
leaq 0xe56b(%rip), %rdi      # 0x330fa
xorl %eax, %eax
callq 0x2050
jmp 0x24b98
jmp 0x24b9a
jmp 0x24b9c
jmp 0x24bb0
leaq 0xe575(%rip), %rdi      # 0x3311a
xorl %eax, %eax
callq 0x2050
jmp 0x24bae
jmp 0x24bb0
jmp 0x24bc4
leaq 0xe579(%rip), %rdi      # 0x33132
xorl %eax, %eax
callq 0x2050
jmp 0x24bc2
jmp 0x24bc4
movq -0x18(%rbp), %rdi
callq 0x2140
jmp 0x24bcf
jmp 0x24be7
movq -0x10(%rbp), %rsi
leaq 0xe575(%rip), %rdi      # 0x33151
xorl %eax, %eax
callq 0x2050
jmp 0x24be5
jmp 0x24be7
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x24f00
movq -0x20(%rbp), %rdi
callq 0x2260
nopw %cs:(%rax,%rax)
nopl (%rax)