// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl %edx, 0x36f1314(%rdi)
jbe 0xce55
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 0xce66
movl %r12d, 0x50(%rbx)
movb $0x0, 0x78(%rbx)
movl 0x24(%r13), %esi
movq %r15, %rdi
xorl %edx, %edx
callq 0x2180
movl %r12d, 0x12a5a(%rip)    # 0x1f800
movl 0x28(%r13), %esi
movl %esi, (%rbx)
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 0xcdec
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 0xce5a
leaq 0x30(%rbx), %r15
movq %r12, %rdi
movl $0x50, %esi
movq %r15, %rdx
callq 0xa814
movq %r15, %rdi
movl $0x20, %esi
movq %r15, %rdx
callq 0xa814
movl (%rbx), %edx
leaq 0x16f12e8(%r14), %rcx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1104a
movl %eax, %r15d
testb %al, %al
je 0xce69
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11284
jmp 0xce69
xorl %r15d, %r15d
jmp 0xce79
leaq 0xcc2f(%rip), %rdi      # 0x19a90
callq 0x2260
xorl %r15d, %r15d
movb 0x12995(%rip), %al      # 0x1f804
movb %al, 0x78(%rbx)
movb $0x0, 0x1298b(%rip)     # 0x1f804
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop