// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x80(%rdi), %rax
movq 0x88(%rdi), %rdx
leaq 0x8(%rax), %rcx
cmpq %rdx, %rcx
ja 0x11d1d
movq %rsi, %rbx
movq (%rax), %rsi
movq %rcx, 0x80(%rdi)
movq %rsi, (%rbx)
movq $0x0, 0x20(%rbx)
addq %rsi, 0x68(%rdi)
leaq 0x9(%rax), %r8
cmpq %rdx, %r8
ja 0x11d3c
movzbl (%rcx), %ecx
movq %r8, 0x80(%rdi)
cmpl $0xfc, %ecx
jbe 0x11b20
leaq 0xb(%rax), %rsi
cmpq %rdx, %rsi
ja 0x11d7a
movzwl (%r8), %ecx
movq %rsi, 0x80(%rdi)
cmpl $0xffff, %ecx           # imm = 0xFFFF
jne 0x11b20
addq $0xf, %rax
cmpq %rdx, %rax
ja 0x11d99
movl (%rsi), %ecx
movq %rax, 0x80(%rdi)
cmpl $-0x1, %ecx
je 0x11db8
movl %ecx, 0x8(%rbx)
cmpl $0x2000, %ecx           # imm = 0x2000
jae 0x11d5b
testl %ecx, %ecx
je 0x11b6a
movq 0x80(%rdi), %rax
movl %ecx, %esi
addq %rax, %rsi
movq %rsi, 0x80(%rdi)
cmpq %rdx, %rsi
jbe 0x11b6c
leaq 0x7b17(%rip), %rdi      # 0x19669
leaq 0x5c97(%rip), %rsi      # 0x177f0
leaq 0x7b21(%rip), %rcx      # 0x19681
movl $0x82f, %edx            # imm = 0x82F
callq 0x20c0
xorl %eax, %eax
movq %rax, 0x10(%rbx)
cmpl $0x42, %ecx
je 0x11b8f
cmpl $0x43, %ecx
jne 0x11ba2
cmpb $0x41, (%rax)
jne 0x11b8a
cmpb $-0x54, 0x42(%rax)
jne 0x11b8a
incq %rax
jmp 0x11b95
cmpl $0x42, %ecx
jne 0x11ba2
cmpb $-0x54, 0x41(%rax)
jne 0x11ba2
movq %rax, 0x20(%rbx)
movb $0x0, 0x18(%rbx)
jmp 0x11cb6
cmpl $0x19, %ecx
jb 0x11bc9
cmpb $0x76, (%rax)
jne 0x11bc9
cmpb $-0x57, 0x1(%rax)
jne 0x11bc9
cmpb $0x14, 0x2(%rax)
jne 0x11bc9
addq $0x3, %rax
movq %rax, 0x20(%rbx)
movb $0x1, 0x18(%rbx)
jmp 0x11cb6
cmpl $0x5, %ecx
jne 0x11c1e
cmpb $0x76, (%rax)
jne 0x11c1e
cmpb $-0x57, 0x1(%rax)
jne 0x11c1e
cmpb $0x0, 0x2(%rax)
jne 0x11c1e
cmpb $-0x78, 0x3(%rax)
jne 0x11c1e
cmpb $-0x54, 0x4(%rax)
jne 0x11c1e
movl 0xdc0f(%rip), %edi      # 0x1f800
callq 0xb5d3
movq %rax, %rbx
movl 0xdc09(%rip), %edi      # 0x1f808
callq 0xb5d3
movq %rax, %r14
movl 0xdbff(%rip), %edi      # 0x1f80c
callq 0xb5d3
leaq 0x7b13(%rip), %rdi      # 0x1972c
jmp 0x11c9f
cmpl $0x1a, %ecx
jb 0x11c56
addl $-0x19, %ecx
je 0x11c56
movl %ecx, %ecx
xorl %edx, %edx
cmpb $0x76, (%rax,%rdx)
jne 0x11c4e
cmpb $-0x57, 0x1(%rax,%rdx)
jne 0x11c4e
cmpb $0x14, 0x2(%rax,%rdx)
jne 0x11c4e
cmpb $-0x78, 0x17(%rax,%rdx)
jne 0x11c4e
cmpb $-0x54, 0x18(%rax,%rdx)
je 0x11cc1
incq %rdx
cmpq %rdx, %rcx
jne 0x11c2c
cmpq $0x0, 0x20(%rbx)
jne 0x11cb6
movl 0x8(%rbx), %eax
cmpl $0x42, %eax
jb 0x11cb6
movq 0x10(%rbx), %rcx
decl %eax
cmpb $-0x54, (%rcx,%rax)
jne 0x11cb6
movl 0xdb89(%rip), %edi      # 0x1f800
callq 0xb5d3
movq %rax, %rbx
movl 0xdb83(%rip), %edi      # 0x1f808
callq 0xb5d3
movq %rax, %r14
movl 0xdb79(%rip), %edi      # 0x1f80c
callq 0xb5d3
leaq 0x7b38(%rip), %rdi      # 0x197d7
movq %rbx, %rsi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2050
movb $0x1, 0xdb4e(%rip)      # 0x1f804
movb $0x1, %al
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
addq %rdx, %rax
addq $0x3, %rax
movq %rax, 0x20(%rbx)
movb $0x1, %r12b
movb %r12b, 0x18(%rbx)
movl 0xdb27(%rip), %edi      # 0x1f800
callq 0xb5d3
movq %rax, %r14
movl 0xdb21(%rip), %edi      # 0x1f808
callq 0xb5d3
movq %rax, %r15
movl 0xdb17(%rip), %edi      # 0x1f80c
callq 0xb5d3
leaq 0x7a87(%rip), %rdi      # 0x19788
movq %r14, %rsi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2050
movb %r12b, 0xdaec(%rip)     # 0x1f804
jmp 0x11c56
leaq 0x7b19(%rip), %rdi      # 0x1983d
leaq 0x5ac5(%rip), %rsi      # 0x177f0
leaq 0x7b36(%rip), %rcx      # 0x19868
movl $0x7f7, %edx            # imm = 0x7F7
callq 0x20c0
leaq 0x76d0(%rip), %rdi      # 0x19413
leaq 0x5aa6(%rip), %rsi      # 0x177f0
leaq 0x76ec(%rip), %rcx      # 0x1943d
movl $0x7dc, %edx            # imm = 0x7DC
callq 0x20c0
leaq 0x7958(%rip), %rdi      # 0x196ba
leaq 0x5a87(%rip), %rsi      # 0x177f0
leaq 0x7986(%rip), %rcx      # 0x196f6
movl $0x851, %edx            # imm = 0x851
callq 0x20c0
leaq 0x76d8(%rip), %rdi      # 0x19459
leaq 0x5a68(%rip), %rsi      # 0x177f0
leaq 0x76f5(%rip), %rcx      # 0x19484
movl $0x7e5, %edx            # imm = 0x7E5
callq 0x20c0
leaq 0x75b8(%rip), %rdi      # 0x19358
leaq 0x5a49(%rip), %rsi      # 0x177f0
leaq 0x75d5(%rip), %rcx      # 0x19383
movl $0x7ee, %edx            # imm = 0x7EE
callq 0x20c0
leaq 0x5fb1(%rip), %rdi      # 0x17d70
leaq 0x5a2a(%rip), %rsi      # 0x177f0
leaq 0x7616(%rip), %rcx      # 0x193e3
movl $0x821, %edx            # imm = 0x821
callq 0x20c0
nop