// File: jeffchan[P]blockchain-parser/BlockChain.cpp
// Function: BlockChainImpl::readBlock(BlockImpl&, unsigned int)
virtual bool readBlock(BlockImpl &block,uint32_t blockIndex)
	{
		bool ret = false;

		if ( blockIndex >= mBlockCount ) return false;
		BlockHeader &header = *mBlockHeaders[blockIndex];
		FILE *fph = mBlockChain[header.mFileIndex];
		if ( fph )
		{
			block.blockIndex = blockIndex;
			block.warning = false;
			fseek(fph,header.mFileOffset,SEEK_SET);
			gBlockIndex = blockIndex;
			block.blockLength = header.mBlockLength;
			block.blockReward = 0;
			block.totalInputCount = 0;
			block.totalOutputCount = 0;
			block.fileIndex = header.mFileIndex;
			block.fileOffset = header.mFileOffset;
			block.blockLength = header.mBlockLength;

			if ( blockIndex < (mBlockCount-2) )
			{
				BlockHeader *nextNext = mBlockHeaders[blockIndex+2];
				block.nextBlockHash =  nextNext->mPreviousBlockHash;
			}

			uint8_t *blockData = mBlockDataBuffer;
			size_t r = fread(blockData,block.blockLength,1,fph); // read the rest of the block (less the 8 byte header we have already consumed)
			if ( r == 1 )
			{
				BLOCKCHAIN_SHA256::computeSHA256(blockData,4+32+32+4+4+4,block.computedBlockHash);
				BLOCKCHAIN_SHA256::computeSHA256(block.computedBlockHash,32,block.computedBlockHash);
				ret = block.processBlockData(blockData,block.blockLength,mTransactionCount);
				if ( ret )
				{
					processTransactions(block);
				}
			}
			else
			{
				printf("Failed to read input block.  BlockChain corrupted.\r\n");
			}
		}
		block.warning = gIsWarning;
		gIsWarning = false;
		return ret;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movb $0x0, -0x1d(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x36f1314(%rcx), %eax
jb 0x1bfc3
movb $0x0, -0x1(%rbp)
jmp 0x1c187
movq -0x50(%rbp), %rax
movq 0x36f1320(%rax), %rcx
movl -0x1c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movl 0x20(%rcx), %ecx
movq 0x208(%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1c168
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0x78(%rax)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2170
movq -0x50(%rbp), %rcx
movl -0x1c(%rbp), %eax
movl %eax, 0x1d7b6(%rip)     # 0x397e0
movq -0x28(%rbp), %rax
movl 0x28(%rax), %edx
movq -0x18(%rbp), %rax
movl %edx, (%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x68(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x54(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x28(%rbp), %rax
movl 0x20(%rax), %edx
movq -0x18(%rbp), %rax
movl %edx, 0x5c(%rax)
movq -0x28(%rbp), %rax
movl 0x24(%rax), %edx
movq -0x18(%rbp), %rax
movl %edx, 0x60(%rax)
movq -0x28(%rbp), %rax
movl 0x28(%rax), %edx
movq -0x18(%rbp), %rax
movl %edx, (%rax)
movl -0x1c(%rbp), %eax
movl 0x36f1314(%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jae 0x1c0bd
movq -0x50(%rbp), %rax
movq 0x36f1320(%rax), %rax
movl -0x1c(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
addq $0x2c, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x50(%rbp), %rax
addq $0x2f12e8, %rax         # imm = 0x2F12E8
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, %esi
movq -0x30(%rbp), %rcx
movl $0x1, %edx
callq 0x2220
movq %rax, -0x48(%rbp)
cmpq $0x1, -0x48(%rbp)
jne 0x1c158
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x30, %rdx
movl $0x50, %esi
callq 0x186b0
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rdx
addq $0x30, %rdx
movl $0x20, %esi
callq 0x186b0
movq -0x50(%rbp), %rcx
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x18(%rbp), %rax
movl (%rax), %edx
addq $0x16f12e8, %rcx        # imm = 0x16F12E8
callq 0x23320
andb $0x1, %al
movb %al, -0x1d(%rbp)
testb $0x1, -0x1d(%rbp)
je 0x1c156
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x23450
jmp 0x1c166
leaq 0x16911(%rip), %rdi     # 0x32a70
movb $0x0, %al
callq 0x2050
jmp 0x1c168
movb 0x1d676(%rip), %cl      # 0x397e4
movq -0x18(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x78(%rax)
movb $0x0, 0x1d665(%rip)     # 0x397e4
movb -0x1d(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)