// File: /workspace/github_cpp_makefile_star2_O3/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:
cmpl %edx, 0x36f1314(%rdi)
jbe 0xcde8
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r12d
movq %rsi, %rbx
movq %rdi, %r14
movq 0x36f1320(%rdi), %rax
movl %edx, %ecx
movq (%rax,%rcx,8), %r13
movl 0x20(%r13), %eax
movq 0x208(%rdi,%rax,8), %r15
testq %r15, %r15
je 0xcdf7
movl %r12d, 0x50(%rbx)
movb $0x0, 0x78(%rbx)
movl 0x24(%r13), %esi
movq %r15, %rdi
xorl %edx, %edx
callq 0x2190
movl %r12d, 0x12ac4(%rip)    # 0x1f800
movl 0x28(%r13), %esi
xorl %eax, %eax
movq %rax, 0x68(%rbx)
movq %rax, 0x54(%rbx)
movl 0x20(%r13), %eax
movl %eax, 0x5c(%rbx)
movl 0x24(%r13), %eax
movl %eax, 0x60(%rbx)
movl %esi, (%rbx)
movl 0x36f1314(%r14), %eax
addl $-0x2, %eax
cmpl %r12d, %eax
jbe 0xcd80
movq 0x36f1320(%r14), %rax
addl $0x2, %r12d
movq (%rax,%r12,8), %rax
addq $0x2c, %rax
movq %rax, 0x70(%rbx)
leaq 0x2f12e8(%r14), %r12
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x2250
cmpq $0x1, %rax
jne 0xcdeb
leaq 0x30(%rbx), %r15
movq %r12, %rdi
movl $0x50, %esi
movq %r15, %rdx
callq 0xa7a4
movq %r15, %rdi
movl $0x20, %esi
movq %r15, %rdx
callq 0xa7a4
movl (%rbx), %edx
leaq 0x16f12e8(%r14), %rcx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x10f02
testb %al, %al
je 0xcdf7
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11138
movb $0x1, %al
jmp 0xcdf9
xorl %eax, %eax
retq
leaq 0xcc9e(%rip), %rdi      # 0x19a90
callq 0x2260
xorl %eax, %eax
movb 0x12a05(%rip), %cl      # 0x1f804
movb %cl, 0x78(%rbx)
movb $0x0, 0x129fb(%rip)     # 0x1f804
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq