// File: /workspace/github_c_makefile_star2_O3/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
movq %r15, %rdi
movl $0x40, %ecx
callq 0xeb9d
cmpl $0x0, 0x444(%r14)
je 0xff4c
leaq 0x9ed2(%rip), %rdi      # 0x19de2
leaq 0x8f22(%rip), %rsi      # 0x18e39
leaq 0x20(%rsp), %rcx
movl $0x68b, %edx            # imm = 0x68B
xorl %eax, %eax
callq 0xc84f
cmpl $0x0, 0x444(%r14)
je 0xff4c
leaq 0x9edd(%rip), %rdi      # 0x19e16
leaq 0x8ef9(%rip), %rsi      # 0x18e39
movl $0x68d, %edx            # imm = 0x68D
xorl %eax, %eax
callq 0xc84f
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x1069c
movl 0x444(%r14), %esi
movq %r12, %rdi
callq 0x106a5
movl 0x448(%r14), %esi
movq %r12, %rdi
callq 0x106ab
movq 0x470(%r14), %rsi
movq %r12, %rdi
callq 0x10ed1
movl 0x450(%r14), %esi
movq %r12, %rdi
callq 0x106b1
cmpl $0x0, 0x444(%r14)
je 0xffb9
leaq 0x9ead(%rip), %rdi      # 0x19e53
leaq 0x8e8c(%rip), %rsi      # 0x18e39
movl $0x693, %edx            # imm = 0x693
xorl %eax, %eax
callq 0xc84f
movl 0x80(%r15), %ecx
movl 0x444(%r14), %eax
cmpl 0x27c(%r14), %ecx
jae 0x10077
testl %eax, %eax
je 0xfff6
movq 0x78(%r15), %rcx
leaq 0x9fca(%rip), %rdi      # 0x19fad
leaq 0x8e4f(%rip), %rsi      # 0x18e39
movl $0x6ac, %edx            # imm = 0x6AC
xorl %eax, %eax
callq 0xc84f
movl 0x78(%r15), %esi
movq %r14, %rdi
callq 0xf8b5
movq %rax, %r12
movl 0x444(%r14), %eax
testq %r12, %r12
je 0x101a0
testl %eax, %eax
je 0x10033
leaq 0xa01c(%rip), %rdi      # 0x1a03c
leaq 0x8e12(%rip), %rsi      # 0x18e39
movl $0x6b6, %edx            # imm = 0x6B6
xorl %eax, %eax
callq 0xc84f
movl 0x80(%r15), %ecx
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r12, %rdx
movq %rbx, %r8
callq 0x10e09
movl %eax, %ebp
cmpl $0x0, 0x444(%r14)
je 0x10124
leaq 0xa006(%rip), %rdi      # 0x1a06c
leaq 0x8dcc(%rip), %rsi      # 0x18e39
movl $0x6b8, %edx            # imm = 0x6B8
jmp 0x1011d
testl %eax, %eax
je 0x10099
movq 0x78(%r15), %rcx
leaq 0x9dff(%rip), %rdi      # 0x19e85
leaq 0x8dac(%rip), %rsi      # 0x18e39
movl $0x69a, %edx            # imm = 0x69A
xorl %eax, %eax
callq 0xc84f
movl 0x78(%r15), %esi
movq %r14, %rdi
callq 0xfa26
movq %rax, %r12
movl 0x444(%r14), %eax
testq %r12, %r12
je 0x101be
testl %eax, %eax
je 0x100e2
movl 0x80(%r15), %r8d
leaq 0x9e55(%rip), %rdi      # 0x19f1f
leaq 0x8d68(%rip), %rsi      # 0x18e39
leaq 0x20(%rsp), %rcx
movl $0x6a2, %edx            # imm = 0x6A2
xorl %eax, %eax
callq 0xc84f
movl 0x80(%r15), %ecx
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r12, %rdx
movq %rbx, %r8
callq 0x10e09
movl %eax, %ebp
cmpl $0x0, 0x444(%r14)
je 0x10124
leaq 0x9e69(%rip), %rdi      # 0x19f7a
leaq 0x8d21(%rip), %rsi      # 0x18e39
movl $0x6a4, %edx            # imm = 0x6A4
xorl %eax, %eax
callq 0xc84f
cmpl $0x64, %ebp
jne 0x10194
cmpl $0x0, 0x450(%r14)
je 0x10194
movq 0x78(%r15), %rsi
leaq 0x9f5d(%rip), %rdi      # 0x1a09b
xorl %eax, %eax
callq 0xc566
testq %rax, %rax
je 0x10194
movq %rax, %r13
cmpl $0x0, 0x444(%r14)
je 0x10174
leaq 0x9f4b(%rip), %rdi      # 0x1a0a9
leaq 0x8cd4(%rip), %rsi      # 0x18e39
movl $0x6c2, %edx            # imm = 0x6C2
movq %r13, %rcx
xorl %eax, %eax
callq 0xc84f
movl 0x80(%r15), %r8d
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xfd37
movq %r13, %rdi
callq 0x2030
movq %r12, %rdi
callq 0x2030
xorl %ebx, %ebx
jmp 0x101e1
movl $0x22, %ebx
testl %eax, %eax
je 0x101e1
leaq 0x9e44(%rip), %rdi      # 0x19ff4
leaq 0x8c82(%rip), %rsi      # 0x18e39
movl $0x6b2, %edx            # imm = 0x6B2
jmp 0x101da
movl $0x21, %ebx
testl %eax, %eax
je 0x101e1
leaq 0x9d08(%rip), %rdi      # 0x19ed6
leaq 0x8c64(%rip), %rsi      # 0x18e39
movl $0x69e, %edx            # imm = 0x69E
xorl %eax, %eax
callq 0xc84f
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq