// File: 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
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x100(%rbp)
cmpl $0x0, 0x36f1310(%rax)
je 0x1bd7f
movq -0x100(%rbp), %rdi
addq $0x36f1328, %rdi        # imm = 0x36F1328
callq 0x1c5d0
movl %eax, %edi
callq 0x19c20
movq -0x100(%rbp), %rdi
movq %rax, -0x108(%rbp)
addq $0x36f1328, %rdi        # imm = 0x36F1328
callq 0x1c5d0
movl %eax, %edi
movq -0x100(%rbp), %rax
subl 0x36f1300(%rax), %edi
callq 0x19c20
movq -0x108(%rbp), %rsi
movq %rax, %rdx
leaq 0x16c30(%rip), %rdi     # 0x327b0
movb $0x0, %al
callq 0x2050
leaq 0x16c58(%rip), %rdi     # 0x327e6
movb $0x0, %al
callq 0x2050
movq -0x100(%rbp), %rax
cmpq $0x0, 0x36f1318(%rax)
je 0x1bd6e
movq -0x100(%rbp), %rax
movl $0x0, 0x36f1314(%rax)
movq 0x36f1318(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x1bc2e
movq -0x10(%rbp), %rsi
addq $0x2c, %rsi
leaq -0x30(%rbp), %rdi
callq 0x1c660
movq -0x100(%rbp), %rax
addq $0x36f1328, %rax        # imm = 0x36F1328
movq %rax, -0x110(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x22970
movq -0x110(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x228f0
movq %rax, %rcx
movq -0x100(%rbp), %rax
movq %rcx, -0x10(%rbp)
movl 0x36f1314(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x36f1314(%rax)
jmp 0x1bbc6
movq -0x100(%rbp), %rax
movl 0x36f1314(%rax), %edi
callq 0x19c20
movq -0x100(%rbp), %rdi
movq %rax, -0x118(%rbp)
addq $0x36f1328, %rdi        # imm = 0x36F1328
callq 0x1c5d0
movl %eax, %edi
movq -0x100(%rbp), %rax
subl 0x36f1314(%rax), %edi
callq 0x19c20
movq -0x118(%rbp), %rsi
movq %rax, %rdx
leaq 0x16b88(%rip), %rdi     # 0x32807
movb $0x0, %al
callq 0x2050
movq -0x100(%rbp), %rax
movl 0x36f1314(%rax), %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2040
movq %rax, %rcx
movq -0x100(%rbp), %rax
movq %rcx, 0x36f1320(%rax)
movl 0x36f1314(%rax), %ecx
subl $0x1, %ecx
movl %ecx, -0x84(%rbp)
movq 0x36f1318(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x1bd6c
movq -0x100(%rbp), %rax
movq -0x10(%rbp), %rdx
movq 0x36f1320(%rax), %rax
movl -0x84(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rsi
addq $0x2c, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x1c660
movq -0x100(%rbp), %rax
addq $0x36f1328, %rax        # imm = 0x36F1328
movq %rax, -0x120(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x22970
movq -0x120(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x228f0
movq %rax, -0x10(%rbp)
movl -0x84(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x1bcdf
jmp 0x1bd6e
movq -0x100(%rbp), %rax
movl $0x0, 0x36f1310(%rax)
movq -0x100(%rbp), %rax
movl 0x36f1314(%rax), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop