// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq 0x80(%rdi), %rsi
movq 0x88(%rdi), %rdx
leaq 0x8(%rsi), %rcx
cmpq %rdx, %rcx
ja 0x11c36
movq (%rsi), %rax
movq %rcx, 0x80(%rdi)
movq %rax, (%rbx)
movq $0x0, 0x20(%rbx)
addq %rax, 0x68(%rdi)
leaq 0x9(%rsi), %rax
cmpq %rdx, %rax
ja 0x11c55
movzbl (%rcx), %ecx
movq %rax, 0x80(%rdi)
cmpl $0xfc, %ecx
ja 0x119dd
leaq 0x8(%rbx), %r12
movl %ecx, 0x8(%rbx)
jmp 0x11a37
leaq 0xb(%rsi), %r8
cmpq %rdx, %r8
ja 0x11c93
movzwl (%rax), %ecx
movq %r8, 0x80(%rdi)
cmpl $0xffff, %ecx           # imm = 0xFFFF
je 0x11a01
movq %r8, %rsi
jmp 0x11a21
addq $0xf, %rsi
cmpq %rdx, %rsi
ja 0x11cd1
movl (%r8), %ecx
movq %rsi, 0x80(%rdi)
cmpl $-0x1, %ecx
je 0x11cf0
movl %ecx, 0x8(%rbx)
cmpl $0x2000, %ecx           # imm = 0x2000
jae 0x11cb2
leaq 0x8(%rbx), %r12
movq %rsi, %rax
testl %ecx, %ecx
je 0x11a74
movl %ecx, %esi
addq %rax, %rsi
movq %rsi, 0x80(%rdi)
cmpq %rdx, %rsi
ja 0x11c74
leaq 0x10(%rbx), %r13
movq %rax, 0x10(%rbx)
cmpl $0x42, %ecx
je 0x11a88
cmpl $0x43, %ecx
jne 0x11a9b
movb (%rax), %dl
cmpb $0x41, %dl
jne 0x11aa2
cmpb $-0x54, 0x42(%rax)
jne 0x11aa0
incq %rax
jmp 0x11a8e
movq $0x0, 0x10(%rbx)
addq $0x10, %rbx
movq %rbx, %r13
jmp 0x11bcb
cmpb $-0x54, 0x41(%rax)
jne 0x11aa0
movq %rax, 0x20(%rbx)
movb $0x0, 0x18(%rbx)
jmp 0x11c25
cmpl $0x19, %ecx
jb 0x11b01
movb (%rax), %dl
cmpb $0x76, %dl
jne 0x11ac4
cmpb $-0x57, 0x1(%rax)
jne 0x11ac4
cmpb $0x14, 0x2(%rax)
jne 0x11ac4
addq $0x3, %rax
movq %rax, 0x20(%rbx)
movb $0x1, 0x18(%rbx)
jmp 0x11c25
cmpl $0x1a, %ecx
jb 0x11bcb
addl $-0x19, %ecx
xorl %edx, %edx
cmpb $0x76, (%rax,%rdx)
jne 0x11af4
cmpb $-0x57, 0x1(%rax,%rdx)
jne 0x11af4
cmpb $0x14, 0x2(%rax,%rdx)
jne 0x11af4
cmpb $-0x78, 0x17(%rax,%rdx)
jne 0x11af4
cmpb $-0x54, 0x18(%rax,%rdx)
je 0x11b6e
incq %rdx
cmpq %rdx, %rcx
jne 0x11ad2
jmp 0x11bcb
cmpl $0x5, %ecx
jne 0x11bcb
cmpb $0x76, (%rax)
jne 0x11bcb
cmpb $-0x57, 0x1(%rax)
jne 0x11bcb
cmpb $0x0, 0x2(%rax)
jne 0x11bcb
cmpb $-0x78, 0x3(%rax)
jne 0x11bcb
cmpb $-0x54, 0x4(%rax)
jne 0x11bcb
movl 0xdcbf(%rip), %edi      # 0x1f800
callq 0xb535
movq %rax, %rbx
movl 0xdcb9(%rip), %edi      # 0x1f808
callq 0xb535
movq %rax, %r14
movl 0xdcaf(%rip), %edi      # 0x1f80c
callq 0xb535
leaq 0x7bc3(%rip), %rdi      # 0x1972c
jmp 0x11c0e
addq %rdx, %rax
addq $0x3, %rax
movq %rax, 0x20(%rbx)
movb $0x1, %al
movb %al, 0x18(%rbx)
movl 0xdc7c(%rip), %edi      # 0x1f800
callq 0xb535
movq %rax, %r14
movl 0xdc76(%rip), %edi      # 0x1f808
callq 0xb535
movq %rax, %r15
movl 0xdc6c(%rip), %edi      # 0x1f80c
callq 0xb535
leaq 0x7bdc(%rip), %rdi      # 0x19788
movq %r14, %rsi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2050
movb $0x1, %al
movb %al, 0xdc40(%rip)       # 0x1f804
cmpq $0x0, 0x20(%rbx)
jne 0x11c25
movl (%r12), %eax
cmpl $0x42, %eax
jb 0x11c25
movq (%r13), %rcx
decl %eax
cmpb $-0x54, (%rcx,%rax)
jne 0x11c25
movl 0xdc1a(%rip), %edi      # 0x1f800
callq 0xb535
movq %rax, %rbx
movl 0xdc14(%rip), %edi      # 0x1f808
callq 0xb535
movq %rax, %r14
movl 0xdc0a(%rip), %edi      # 0x1f80c
callq 0xb535
leaq 0x7bc9(%rip), %rdi      # 0x197d7
movq %rbx, %rsi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2050
movb $0x1, 0xdbdf(%rip)      # 0x1f804
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7c00(%rip), %rdi      # 0x1983d
leaq 0x5bac(%rip), %rsi      # 0x177f0
leaq 0x7c1d(%rip), %rcx      # 0x19868
movl $0x7f7, %edx            # imm = 0x7F7
callq 0x20c0
leaq 0x77b7(%rip), %rdi      # 0x19413
leaq 0x5b8d(%rip), %rsi      # 0x177f0
leaq 0x77d3(%rip), %rcx      # 0x1943d
movl $0x7dc, %edx            # imm = 0x7DC
callq 0x20c0
leaq 0x79ee(%rip), %rdi      # 0x19669
leaq 0x5b6e(%rip), %rsi      # 0x177f0
leaq 0x79f8(%rip), %rcx      # 0x19681
movl $0x82f, %edx            # imm = 0x82F
callq 0x20c0
leaq 0x77bf(%rip), %rdi      # 0x19459
leaq 0x5b4f(%rip), %rsi      # 0x177f0
leaq 0x77dc(%rip), %rcx      # 0x19484
movl $0x7e5, %edx            # imm = 0x7E5
callq 0x20c0
leaq 0x7a01(%rip), %rdi      # 0x196ba
leaq 0x5b30(%rip), %rsi      # 0x177f0
leaq 0x7a2f(%rip), %rcx      # 0x196f6
movl $0x851, %edx            # imm = 0x851
callq 0x20c0
leaq 0x7680(%rip), %rdi      # 0x19358
leaq 0x5b11(%rip), %rsi      # 0x177f0
leaq 0x769d(%rip), %rcx      # 0x19383
movl $0x7ee, %edx            # imm = 0x7EE
callq 0x20c0
leaq 0x6079(%rip), %rdi      # 0x17d70
leaq 0x5af2(%rip), %rsi      # 0x177f0
leaq 0x76de(%rip), %rcx      # 0x193e3
movl $0x821, %edx            # imm = 0x821
callq 0x20c0
nop