// File: /workspace/github_c_makefile_star2_O1/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 0xeca6
cmpl $0x0, 0x444(%r14)
je 0x100f1
leaq 0x9d19(%rip), %rdi      # 0x19df2
leaq 0x8d69(%rip), %rsi      # 0x18e49
leaq 0x20(%rsp), %rcx
movl $0x68b, %edx            # imm = 0x68B
xorl %eax, %eax
callq 0xc960
cmpl $0x0, 0x444(%r14)
je 0x10115
leaq 0x9d24(%rip), %rdi      # 0x19e26
leaq 0x8d40(%rip), %rsi      # 0x18e49
movl $0x68d, %edx            # imm = 0x68D
xorl %eax, %eax
callq 0xc960
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x10888
movl 0x444(%r14), %esi
movq %r12, %rdi
callq 0x10891
movl 0x448(%r14), %esi
movq %r12, %rdi
callq 0x10897
movq 0x470(%r14), %rsi
movq %r12, %rdi
callq 0x110df
movl 0x450(%r14), %esi
movq %r12, %rdi
callq 0x1089d
cmpl $0x0, 0x444(%r14)
je 0x10182
leaq 0x9cf4(%rip), %rdi      # 0x19e63
leaq 0x8cd3(%rip), %rsi      # 0x18e49
movl $0x693, %edx            # imm = 0x693
xorl %eax, %eax
callq 0xc960
movl 0x80(%r15), %ecx
movl 0x444(%r14), %eax
cmpl 0x27c(%r14), %ecx
jae 0x10240
testl %eax, %eax
je 0x101bf
movq 0x78(%r15), %rcx
leaq 0x9e11(%rip), %rdi      # 0x19fbd
leaq 0x8c96(%rip), %rsi      # 0x18e49
movl $0x6ac, %edx            # imm = 0x6AC
xorl %eax, %eax
callq 0xc960
movl 0x78(%r15), %esi
movq %r14, %rdi
callq 0xfa42
movq %rax, %r12
movl 0x444(%r14), %eax
testq %r12, %r12
je 0x10369
testl %eax, %eax
je 0x101fc
leaq 0x9e63(%rip), %rdi      # 0x1a04c
leaq 0x8c59(%rip), %rsi      # 0x18e49
movl $0x6b6, %edx            # imm = 0x6B6
xorl %eax, %eax
callq 0xc960
movl 0x80(%r15), %ecx
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r12, %rdx
movq %rbx, %r8
callq 0x11017
movl %eax, %ebp
cmpl $0x0, 0x444(%r14)
je 0x102ed
leaq 0x9e4d(%rip), %rdi      # 0x1a07c
leaq 0x8c13(%rip), %rsi      # 0x18e49
movl $0x6b8, %edx            # imm = 0x6B8
jmp 0x102e6
testl %eax, %eax
je 0x10262
movq 0x78(%r15), %rcx
leaq 0x9c46(%rip), %rdi      # 0x19e95
leaq 0x8bf3(%rip), %rsi      # 0x18e49
movl $0x69a, %edx            # imm = 0x69A
xorl %eax, %eax
callq 0xc960
movl 0x78(%r15), %esi
movq %r14, %rdi
callq 0xfbb6
movq %rax, %r12
movl 0x444(%r14), %eax
testq %r12, %r12
je 0x10387
testl %eax, %eax
je 0x102ab
movl 0x80(%r15), %r8d
leaq 0x9c9c(%rip), %rdi      # 0x19f2f
leaq 0x8baf(%rip), %rsi      # 0x18e49
leaq 0x20(%rsp), %rcx
movl $0x6a2, %edx            # imm = 0x6A2
xorl %eax, %eax
callq 0xc960
movl 0x80(%r15), %ecx
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r12, %rdx
movq %rbx, %r8
callq 0x11017
movl %eax, %ebp
cmpl $0x0, 0x444(%r14)
je 0x102ed
leaq 0x9cb0(%rip), %rdi      # 0x19f8a
leaq 0x8b68(%rip), %rsi      # 0x18e49
movl $0x6a4, %edx            # imm = 0x6A4
xorl %eax, %eax
callq 0xc960
cmpl $0x64, %ebp
jne 0x1035d
cmpl $0x0, 0x450(%r14)
je 0x1035d
movq 0x78(%r15), %rsi
leaq 0x9da4(%rip), %rdi      # 0x1a0ab
xorl %eax, %eax
callq 0xc66c
testq %rax, %rax
je 0x1035d
movq %rax, %r13
cmpl $0x0, 0x444(%r14)
je 0x1033d
leaq 0x9d92(%rip), %rdi      # 0x1a0b9
leaq 0x8b1b(%rip), %rsi      # 0x18e49
movl $0x6c2, %edx            # imm = 0x6C2
movq %r13, %rcx
xorl %eax, %eax
callq 0xc960
movl 0x80(%r15), %r8d
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xfef7
movq %r13, %rdi
callq 0x2030
movq %r12, %rdi
callq 0x2030
xorl %ebx, %ebx
jmp 0x103aa
movl $0x22, %ebx
testl %eax, %eax
je 0x103aa
leaq 0x9c8b(%rip), %rdi      # 0x1a004
leaq 0x8ac9(%rip), %rsi      # 0x18e49
movl $0x6b2, %edx            # imm = 0x6B2
jmp 0x103a3
movl $0x21, %ebx
testl %eax, %eax
je 0x103aa
leaq 0x9b4f(%rip), %rdi      # 0x19ee6
leaq 0x8aab(%rip), %rsi      # 0x18e49
movl $0x69e, %edx            # imm = 0x69E
xorl %eax, %eax
callq 0xc960
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq