// File: /workspace/github_cpp_makefile_star2_O3/jeffchan[P]blockchain-parser/BlockChain.cpp
// Function: BlockChainImpl::buildBlockChain()
virtual uint32_t buildBlockChain(void) 
	{
		if ( mScanCount )
		{

			printf("Found %s block headers total. %s in the last block.\r\n",
				formatNumber(mBlockHeaderMap.size()),
				formatNumber( mBlockHeaderMap.size()-mLastBlockHeaderCount) );
			printf("Building complete block-chain.\r\n");
			// need to count the total number of blocks...

			if ( mLastBlockHeader )
			{
				mBlockCount = 0;
				const BlockHeader *scan = mLastBlockHeader;
				while ( scan )
				{
					Hash256 prevBlock(scan->mPreviousBlockHash);
					scan = mBlockHeaderMap.find(prevBlock);
					mBlockCount++;
				}
				printf("Found %s blocks and skipped %s orphan blocks.\r\n", formatNumber(mBlockCount), formatNumber(mBlockHeaderMap.size()-mBlockCount));
				mBlockHeaders = new BlockHeader *[mBlockCount];
				uint32_t index = mBlockCount-1;
				scan = mLastBlockHeader;
				while ( scan )
				{
					mBlockHeaders[index] = (BlockHeader *)scan;
					Hash256 prevBlock(scan->mPreviousBlockHash);
					scan = mBlockHeaderMap.find(prevBlock);
					index--;
				}

			}
			mScanCount = 0;
		}

		return mBlockCount;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x0, 0x36f1310(%rdi)
je 0xcbc4
movl 0x3771328(%rbx), %edi
callq 0xb535
movq %rax, %r15
movl 0x3771328(%rbx), %edi
subl 0x36f1300(%rbx), %edi
callq 0xb535
leaq 0xc6f2(%rip), %rdi      # 0x19100
xorl %r14d, %r14d
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0xd04b(%rip), %rdi      # 0x19a70
callq 0x2260
movq 0x36f1318(%rbx), %rsi
testq %rsi, %rsi
je 0xcbba
movq 0x2c(%rsi), %rax
movq 0x34(%rsi), %rcx
movq 0x3c(%rsi), %rdx
movq 0x44(%rsi), %rsi
movq %rcx, %rdi
xorq %rax, %rdi
movq %rdx, %r8
xorq %rsi, %r8
xorq %rdi, %r8
shrq $0x20, %r8
movl %ecx, %edi
xorl %eax, %edi
movl %edx, %r9d
xorl %edi, %r9d
movl %esi, %edi
xorl %r9d, %edi
xorl %r8d, %edi
movzwl %di, %edi
movq 0x36f1328(%rbx,%rdi,8), %rdi
testq %rdi, %rdi
je 0xcae9
xorl %r14d, %r14d
cmpq %rax, (%rdi)
jne 0xca99
cmpq %rcx, 0x8(%rdi)
jne 0xca99
cmpq %rdx, 0x10(%rdi)
jne 0xca99
cmpq %rsi, 0x18(%rdi)
je 0xcaa4
movq 0x50(%rdi), %rdi
testq %rdi, %rdi
jne 0xca82
jmp 0xcae9
incl %r14d
movq 0x2c(%rdi), %rax
movq 0x34(%rdi), %rcx
movq 0x3c(%rdi), %rdx
movq 0x44(%rdi), %rsi
movq %rcx, %rdi
xorq %rax, %rdi
movq %rdx, %r8
xorq %rsi, %r8
xorq %rdi, %r8
shrq $0x20, %r8
movl %ecx, %edi
xorl %eax, %edi
movl %edx, %r9d
xorl %edi, %r9d
movl %esi, %edi
xorl %r9d, %edi
xorl %r8d, %edi
movzwl %di, %edi
movq 0x36f1328(%rbx,%rdi,8), %rdi
jmp 0xca9d
incl %r14d
movl %r14d, 0x36f1314(%rbx)
movl %r14d, %edi
callq 0xb535
movq %rax, %r14
movl 0x3771328(%rbx), %edi
subl 0x36f1314(%rbx), %edi
callq 0xb535
leaq 0xc620(%rip), %rdi      # 0x19136
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2050
movl 0x36f1314(%rbx), %r14d
leaq (,%r14,8), %rdi
callq 0x2040
movq %rax, 0x36f1320(%rbx)
movq 0x36f1318(%rbx), %rdi
testq %rdi, %rdi
je 0xcbba
decl %r14d
movq 0x36f1320(%rbx), %rax
movq %rdi, (%rax,%r14,8)
movq 0x2c(%rdi), %rax
movq 0x34(%rdi), %rcx
movq 0x3c(%rdi), %rdx
movq 0x44(%rdi), %rsi
movq %rcx, %rdi
xorq %rax, %rdi
movq %rdx, %r8
xorq %rsi, %r8
xorq %rdi, %r8
shrq $0x20, %r8
movl %ecx, %edi
xorl %eax, %edi
movl %edx, %r9d
xorl %edi, %r9d
movl %esi, %edi
xorl %r9d, %edi
xorl %r8d, %edi
movzwl %di, %edi
movq 0x36f1328(%rbx,%rdi,8), %rdi
testq %rdi, %rdi
je 0xcbba
cmpq %rax, (%rdi)
jne 0xcbb4
cmpq %rcx, 0x8(%rdi)
jne 0xcbb4
cmpq %rdx, 0x10(%rdi)
jne 0xcbb4
cmpq %rsi, 0x18(%rdi)
je 0xcb4a
movq 0x50(%rdi), %rdi
jmp 0xcb98
movl $0x0, 0x36f1310(%rbx)
movl 0x36f1314(%rbx), %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop