// File: /workspace/github_cpp_makefile_star2_O1/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 0xcc32
movl 0x3771328(%rbx), %edi
callq 0xb5d3
movq %rax, %r15
movl 0x3771328(%rbx), %edi
subl 0x36f1300(%rbx), %edi
callq 0xb5d3
leaq 0xc642(%rip), %rdi      # 0x19100
xorl %r14d, %r14d
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0xcf9b(%rip), %rdi      # 0x19a70
callq 0x2260
movq 0x36f1318(%rbx), %rcx
testq %rcx, %rcx
je 0xcc28
movq 0x2c(%rcx), %rax
movq 0x34(%rcx), %rdx
movq 0x3c(%rcx), %rsi
movq 0x44(%rcx), %rdi
movq %rdx, %rcx
xorq %rax, %rcx
movq %rsi, %r8
xorq %rdi, %r8
xorq %rcx, %r8
shrq $0x20, %r8
movl %edx, %ecx
xorl %eax, %ecx
movl %esi, %r9d
xorl %ecx, %r9d
movl %edi, %ecx
xorl %r9d, %ecx
xorl %r8d, %ecx
movzwl %cx, %ecx
movq 0x36f1328(%rbx,%rcx,8), %rcx
testq %rcx, %rcx
je 0xcb4c
cmpq %rax, (%rcx)
jne 0xcb46
cmpq %rdx, 0x8(%rcx)
jne 0xcb46
cmpq %rsi, 0x10(%rcx)
jne 0xcb46
cmpq %rdi, 0x18(%rcx)
je 0xcb4e
movq 0x50(%rcx), %rcx
jmp 0xcb2a
xorl %ecx, %ecx
incl %r14d
testq %rcx, %rcx
jne 0xcaea
movl %r14d, 0x36f1314(%rbx)
movl %r14d, %edi
callq 0xb5d3
movq %rax, %r14
movl 0x3771328(%rbx), %edi
subl 0x36f1314(%rbx), %edi
callq 0xb5d3
leaq 0xc5b6(%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), %rax
testq %rax, %rax
je 0xcc28
decl %r14d
movq 0x36f1320(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x2c(%rax), %rcx
movq 0x34(%rax), %rdx
movq 0x3c(%rax), %rsi
movq 0x44(%rax), %rdi
movq %rdx, %rax
xorq %rcx, %rax
movq %rsi, %r8
xorq %rdi, %r8
xorq %rax, %r8
shrq $0x20, %r8
movl %edx, %eax
xorl %ecx, %eax
movl %esi, %r9d
xorl %eax, %r9d
movl %edi, %eax
xorl %r9d, %eax
xorl %r8d, %eax
movzwl %ax, %eax
movq 0x36f1328(%rbx,%rax,8), %rax
testq %rax, %rax
je 0xcc24
cmpq %rcx, (%rax)
jne 0xcc1e
cmpq %rdx, 0x8(%rax)
jne 0xcc1e
cmpq %rsi, 0x10(%rax)
jne 0xcc1e
cmpq %rdi, 0x18(%rax)
je 0xcbaf
movq 0x50(%rax), %rax
jmp 0xcc02
xorl %eax, %eax
jmp 0xcbaf
movl $0x0, 0x36f1310(%rbx)
movl 0x36f1314(%rbx), %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop