// File: /workspace/github_c_makefile_star2_O2/inflex[P]ripMIME/ripOLE/ole.c
// Function: OLE_decode_stream
int OLE_decode_stream( struct OLE_object *ole,  struct OLE_directory_entry *adir, char *decode_path )
{
	unsigned char *stream_data;
	struct OLEUNWRAP_object oleuw;
	int decode_result = OLEUW_STREAM_NOT_DECODED;
	char element_name[64];
	int result = 0;

	memset(element_name, '\0', 64);
	OLE_dbstosbs( adir->element_name, adir->element_name_byte_count, element_name, 64 );

	DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Decoding stream '%s'",FL, element_name);

	DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Initializing stream unwrapper",FL);
	OLEUNWRAP_init(&oleuw);
	OLEUNWRAP_set_debug(&oleuw,ole->debug);
	OLEUNWRAP_set_verbose(&oleuw,ole->verbose);
	OLEUNWRAP_set_filename_report_fn(&oleuw, ole->filename_report_fn);
	OLEUNWRAP_set_save_unknown_streams(&oleuw, ole->save_unknown_streams);
	DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Unwrap engine set.",FL);

	if (adir->stream_size >= ole->header.mini_cutoff_size)
	{
		/** Standard size sector stored stream **/
		/** Standard size sector stored stream **/
		/** Standard size sector stored stream **/
		DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG:  Loading normal sized chain starting at sector %d",FL, adir->start_sector);
		stream_data = OLE_load_chain( ole, (int)adir->start_sector );
		if (stream_data == NULL)
		{
			DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Terminating from stream data being NULL  ",FL);
			//OLE_decode_file_done(ole);
			return OLEER_MINISTREAM_STREAM_READ_FAIL;
		}
		DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Normal decode START. element name ='%s' stream size = '%ld'",FL, element_name, adir->stream_size);
		decode_result = OLEUNWRAP_decodestream( &oleuw, element_name, (char *)stream_data, adir->stream_size, decode_path );
		DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Normal decode done.",FL);
	} else {


		/** Minichain/Minisector stored stream **/
		/** Minichain/Minisector stored stream **/
		/** Minichain/Minisector stored stream **/
		DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Minichain loader, starting at sector %d"
				,FL
				,adir->start_sector
				);
		stream_data = OLE_load_minichain( ole, adir->start_sector );
		if (stream_data == NULL)
		{
			DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Ministream was non-existant, terminating",FL);
			//OLE_decode_file_done(ole);
			return OLEER_NORMALSTREAM_STREAM_READ_FAIL;
		}
		DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Mini decode START.",FL);
		decode_result = OLEUNWRAP_decodestream( &oleuw, element_name, (char *)stream_data, adir->stream_size, decode_path );
		DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Mini decode done.",FL);
	}

	if ((stream_data != NULL)&&(decode_result == OLEUW_STREAM_NOT_DECODED)&&(ole->save_unknown_streams))
	{
		char *lfname;

		lfname = PLD_dprintf("ole-stream.%d",adir->start_sector);
		if (lfname != NULL)
		{
			DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Saving stream to %s",FL,lfname);
			OLE_store_stream( ole, lfname, decode_path, (char *) stream_data, adir->stream_size );
			free(lfname);
		} 
	} // If we needed to save an unknown stream

	// Clean up an stream_data which we may have 
	// read in from the chain-loader.
	if (stream_data) free(stream_data);

	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, 0x30(%rdx)
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, (%rdx)
movslq 0x40(%rsi), %rsi
pushq $0x40
popq %rcx
movq %r15, %rdi
callq 0xe549
cmpl $0x0, 0x444(%r14)
je 0xf89a
leaq 0x9584(%rip), %rdi      # 0x18de2
leaq 0x85d4(%rip), %rsi      # 0x17e39
leaq 0x20(%rsp), %rcx
movl $0x68b, %edx            # imm = 0x68B
xorl %eax, %eax
callq 0xc2a1
cmpl $0x0, 0x444(%r14)
je 0xf89a
leaq 0x958f(%rip), %rdi      # 0x18e16
leaq 0x85ab(%rip), %rsi      # 0x17e39
movl $0x68d, %edx            # imm = 0x68D
xorl %eax, %eax
callq 0xc2a1
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0xffd4
movl 0x444(%r14), %esi
movq %r12, %rdi
callq 0xffdd
movl 0x448(%r14), %esi
movq %r12, %rdi
callq 0xffe3
movq 0x470(%r14), %rsi
movq %r12, %rdi
callq 0x10814
movl 0x450(%r14), %esi
movq %r12, %rdi
callq 0xffe9
cmpl $0x0, 0x444(%r14)
je 0xf907
leaq 0x955f(%rip), %rdi      # 0x18e53
leaq 0x853e(%rip), %rsi      # 0x17e39
movl $0x693, %edx            # imm = 0x693
xorl %eax, %eax
callq 0xc2a1
movl 0x80(%r15), %ecx
movl 0x444(%r14), %eax
cmpl 0x27c(%r14), %ecx
jae 0xf9c5
testl %eax, %eax
je 0xf944
movq 0x78(%r15), %rcx
leaq 0x967c(%rip), %rdi      # 0x18fad
leaq 0x8501(%rip), %rsi      # 0x17e39
movl $0x6ac, %edx            # imm = 0x6AC
xorl %eax, %eax
callq 0xc2a1
movl 0x78(%r15), %esi
movq %r14, %rdi
callq 0xf22a
movq %rax, %r12
movl 0x444(%r14), %eax
testq %r12, %r12
je 0xfaee
testl %eax, %eax
je 0xf981
leaq 0x96ce(%rip), %rdi      # 0x1903c
leaq 0x84c4(%rip), %rsi      # 0x17e39
movl $0x6b6, %edx            # imm = 0x6B6
xorl %eax, %eax
callq 0xc2a1
movl 0x80(%r15), %ecx
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r12, %rdx
movq %rbx, %r8
callq 0x1074e
movl %eax, %ebp
cmpl $0x0, 0x444(%r14)
je 0xfa72
leaq 0x96b8(%rip), %rdi      # 0x1906c
leaq 0x847e(%rip), %rsi      # 0x17e39
movl $0x6b8, %edx            # imm = 0x6B8
jmp 0xfa6b
testl %eax, %eax
je 0xf9e7
movq 0x78(%r15), %rcx
leaq 0x94b1(%rip), %rdi      # 0x18e85
leaq 0x845e(%rip), %rsi      # 0x17e39
movl $0x69a, %edx            # imm = 0x69A
xorl %eax, %eax
callq 0xc2a1
movl 0x78(%r15), %esi
movq %r14, %rdi
callq 0xf39b
movq %rax, %r12
movl 0x444(%r14), %eax
testq %r12, %r12
je 0xfb0a
testl %eax, %eax
je 0xfa30
movl 0x80(%r15), %r8d
leaq 0x9507(%rip), %rdi      # 0x18f1f
leaq 0x841a(%rip), %rsi      # 0x17e39
leaq 0x20(%rsp), %rcx
movl $0x6a2, %edx            # imm = 0x6A2
xorl %eax, %eax
callq 0xc2a1
movl 0x80(%r15), %ecx
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r12, %rdx
movq %rbx, %r8
callq 0x1074e
movl %eax, %ebp
cmpl $0x0, 0x444(%r14)
je 0xfa72
leaq 0x951b(%rip), %rdi      # 0x18f7a
leaq 0x83d3(%rip), %rsi      # 0x17e39
movl $0x6a4, %edx            # imm = 0x6A4
xorl %eax, %eax
callq 0xc2a1
cmpl $0x64, %ebp
jne 0xfae2
cmpl $0x0, 0x450(%r14)
je 0xfae2
movq 0x78(%r15), %rsi
leaq 0x960f(%rip), %rdi      # 0x1909b
xorl %eax, %eax
callq 0xbfbe
testq %rax, %rax
je 0xfae2
movq %rax, %r13
cmpl $0x0, 0x444(%r14)
je 0xfac2
leaq 0x95fd(%rip), %rdi      # 0x190a9
leaq 0x8386(%rip), %rsi      # 0x17e39
movl $0x6c2, %edx            # imm = 0x6C2
movq %r13, %rcx
xorl %eax, %eax
callq 0xc2a1
movl 0x80(%r15), %r8d
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xf69f
movq %r13, %rdi
callq 0x2030
movq %r12, %rdi
callq 0x2030
xorl %ebx, %ebx
jmp 0xfb2b
pushq $0x22
popq %rbx
testl %eax, %eax
je 0xfb2b
leaq 0x94f8(%rip), %rdi      # 0x18ff4
leaq 0x8336(%rip), %rsi      # 0x17e39
movl $0x6b2, %edx            # imm = 0x6B2
jmp 0xfb24
pushq $0x21
popq %rbx
testl %eax, %eax
je 0xfb2b
leaq 0x93be(%rip), %rdi      # 0x18ed6
leaq 0x831a(%rip), %rsi      # 0x17e39
movl $0x69e, %edx            # imm = 0x69E
xorl %eax, %eax
callq 0xc2a1
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq