// File: jeffchan[P]blockchain-parser/BlockChain.cpp
// Function: BlockImpl::readOutput(BlockChain::BlockOutput&)
bool readOutput(BlockChain::BlockOutput &output)
	{
		bool ret = true;

		output.value = readU64();	// Read the value of the transaction
		output.publicKey = NULL;
		blockReward+=output.value;
		output.challengeScriptLength = readVariableLengthInteger();
		assert ( output.challengeScriptLength < MAX_REASONABLE_SCRIPT_LENGTH );

		if ( output.challengeScriptLength < MAX_REASONABLE_SCRIPT_LENGTH )
		{
			output.challengeScript = output.challengeScriptLength ? getReadBufferAdvance(output.challengeScriptLength) : NULL; // get the script buffer pointer and advance the read location
			if ( output.challengeScriptLength == 67 && output.challengeScript[0] == 65  && output.challengeScript[66]== OP_CHECKSIG )
			{
				output.publicKey = output.challengeScript+1;
				output.isRipeMD160 = false;
			}
			else if ( output.challengeScriptLength == 66 && output.challengeScript[65]== OP_CHECKSIG )
			{
				output.publicKey = output.challengeScript;
				output.isRipeMD160 = false;
			}
			else if ( output.challengeScriptLength >= 25 && 
					  output.challengeScript[0] == OP_DUP &&
					  output.challengeScript[1] == OP_HASH160 && 
					  output.challengeScript[2] == 20 )
			{
				output.publicKey = output.challengeScript+3;
				output.isRipeMD160 = true;
			}
			else if ( output.challengeScriptLength == 5 && 
					  output.challengeScript[0] == OP_DUP &&
					  output.challengeScript[1] == OP_HASH160 &&
					  output.challengeScript[2] == OP_0 && 
					  output.challengeScript[3] == OP_EQUALVERIFY &&
					  output.challengeScript[4] == OP_CHECKSIG )
			{
				printf("WARNING: Unusual but expected output script. Block %s : Transaction: %s : OutputIndex: %s\r\n", formatNumber(gBlockIndex), formatNumber(gTransactionIndex), formatNumber(gOutputIndex) );
				gIsWarning = true;
			}
			else
			{
				// Ok..we are going to scan for this pattern.. OP_DUP, OP_HASH160, 0x14 then exactly 20 bytes after 0x88,0xAC
				// 25...
				if ( output.challengeScriptLength > 25 )
				{
					uint32_t endIndex = output.challengeScriptLength-25;

					for (uint32_t i=0; i<endIndex; i++)
					{
						const uint8_t *scan = &output.challengeScript[i];
						if ( scan[0] == OP_DUP &&
							 scan[1] == OP_HASH160 &&
							 scan[2] == 20 &&
							 scan[23] == OP_EQUALVERIFY &&
							 scan[24] == OP_CHECKSIG )
						{
							output.publicKey = &scan[3];
							output.isRipeMD160 = true;
							printf("WARNING: Unusual output script. Block %s : Transaction: %s : OutputIndex: %s\r\n", formatNumber(gBlockIndex), formatNumber(gTransactionIndex), formatNumber(gOutputIndex) );
							gIsWarning = true;
							break;
						}
					}
				}
				if ( !output.publicKey )
				{
					if ( output.challengeScriptLength >= 66 && output.challengeScript[output.challengeScriptLength-1] == OP_CHECKSIG )
					{
						printf("WARNING: Failed to decode public key in output script. Block %s : Transaction: %s : OutputIndex: %s\r\n", formatNumber(gBlockIndex), formatNumber(gTransactionIndex), formatNumber(gOutputIndex) );
						gIsWarning = true;
					}
				}
			}
		}
		else
		{
			ret = false;
		}

		return ret;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x30(%rbp)
movb $0x1, -0x11(%rbp)
callq 0x24190
movq -0x30(%rbp), %rdi
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq 0x68(%rdi), %rax
movq %rax, 0x68(%rdi)
callq 0x23750
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpl $0x2000, 0x8(%rax)      # imm = 0x2000
jae 0x23d77
jmp 0x23d96
leaq 0xf089(%rip), %rdi      # 0x32e07
leaq 0xcecb(%rip), %rsi      # 0x30c50
movl $0x851, %edx            # imm = 0x851
leaq 0xf0b2(%rip), %rcx      # 0x32e43
callq 0x20c0
movq -0x10(%rbp), %rax
cmpl $0x2000, 0x8(%rax)      # imm = 0x2000
jae 0x24110
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x23dc7
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x24120
movq %rax, -0x38(%rbp)
jmp 0x23dcf
xorl %eax, %eax
movq %rax, -0x38(%rbp)
jmp 0x23dcf
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpl $0x43, 0x8(%rax)
jne 0x23e29
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x41, %eax
jne 0x23e29
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x42(%rax), %eax
cmpl $0xac, %eax
jne 0x23e29
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x18(%rax)
jmp 0x2410e
movq -0x10(%rbp), %rax
cmpl $0x42, 0x8(%rax)
jne 0x23e63
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x41(%rax), %eax
cmpl $0xac, %eax
jne 0x23e63
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x18(%rax)
jmp 0x2410c
movq -0x10(%rbp), %rax
cmpl $0x19, 0x8(%rax)
jb 0x23ec2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x76, %eax
jne 0x23ec2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x1(%rax), %eax
cmpl $0xa9, %eax
jne 0x23ec2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x2(%rax), %eax
cmpl $0x14, %eax
jne 0x23ec2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x3, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x18(%rax)
jmp 0x2410a
movq -0x10(%rbp), %rax
cmpl $0x5, 0x8(%rax)
jne 0x23f80
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x76, %eax
jne 0x23f80
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x1(%rax), %eax
cmpl $0xa9, %eax
jne 0x23f80
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x23f80
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x3(%rax), %eax
cmpl $0x88, %eax
jne 0x23f80
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x4(%rax), %eax
cmpl $0xac, %eax
jne 0x23f80
movl 0x158a8(%rip), %edi     # 0x397e0
callq 0x19c20
movq %rax, -0x48(%rbp)
movl 0x158a1(%rip), %edi     # 0x397e8
callq 0x19c20
movq %rax, -0x40(%rbp)
movl 0x15896(%rip), %edi     # 0x397ec
callq 0x19c20
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rax, %rcx
leaq 0xef0c(%rip), %rdi      # 0x32e79
movb $0x0, %al
callq 0x2050
movb $0x1, 0x15869(%rip)     # 0x397e4
jmp 0x24108
movq -0x10(%rbp), %rax
cmpl $0x19, 0x8(%rax)
jbe 0x24087
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x19, %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0x24085
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x76, %eax
jne 0x24075
movq -0x28(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0xa9, %eax
jne 0x24075
movq -0x28(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x14, %eax
jne 0x24075
movq -0x28(%rbp), %rax
movzbl 0x17(%rax), %eax
cmpl $0x88, %eax
jne 0x24075
movq -0x28(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0xac, %eax
jne 0x24075
movq -0x28(%rbp), %rcx
addq $0x3, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x18(%rax)
movl 0x157b0(%rip), %edi     # 0x397e0
callq 0x19c20
movq %rax, -0x58(%rbp)
movl 0x157a9(%rip), %edi     # 0x397e8
callq 0x19c20
movq %rax, -0x50(%rbp)
movl 0x1579e(%rip), %edi     # 0x397ec
callq 0x19c20
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %rax, %rcx
leaq 0xee70(%rip), %rdi      # 0x32ed5
movb $0x0, %al
callq 0x2050
movb $0x1, 0x15771(%rip)     # 0x397e4
jmp 0x24085
jmp 0x24077
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x23fa2
jmp 0x24087
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x24106
movq -0x10(%rbp), %rax
cmpl $0x42, 0x8(%rax)
jb 0x24104
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0xac, %eax
jne 0x24104
movl 0x1571f(%rip), %edi     # 0x397e0
callq 0x19c20
movq %rax, -0x68(%rbp)
movl 0x15718(%rip), %edi     # 0x397e8
callq 0x19c20
movq %rax, -0x60(%rbp)
movl 0x1570d(%rip), %edi     # 0x397ec
callq 0x19c20
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq %rax, %rcx
leaq 0xee2e(%rip), %rdi      # 0x32f24
movb $0x0, %al
callq 0x2050
movb $0x1, 0x156e0(%rip)     # 0x397e4
jmp 0x24106
jmp 0x24108
jmp 0x2410a
jmp 0x2410c
jmp 0x2410e
jmp 0x24114
movb $0x0, -0x11(%rbp)
movb -0x11(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq
nop