// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x64, -0x44(%rbp)
movl $0x0, -0x94(%rbp)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x2150
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq 0x40(%rax), %rsi
leaq -0x90(%rbp), %rdx
movl $0x40, %ecx
callq 0x14ec0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16b96
leaq -0x90(%rbp), %rcx
leaq 0xa071(%rip), %rdi      # 0x20bf4
leaq 0x90c1(%rip), %rsi      # 0x1fc4b
movl $0x68b, %edx            # imm = 0x68B
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16bbd
leaq 0xa07e(%rip), %rdi      # 0x20c28
leaq 0x909a(%rip), %rsi      # 0x1fc4b
movl $0x68d, %edx            # imm = 0x68D
movb $0x0, %al
callq 0x117c0
leaq -0x40(%rbp), %rdi
callq 0x17550
movq -0x10(%rbp), %rax
movl 0x444(%rax), %esi
leaq -0x40(%rbp), %rdi
callq 0x17580
movq -0x10(%rbp), %rax
movl 0x448(%rax), %esi
leaq -0x40(%rbp), %rdi
callq 0x175a0
movq -0x10(%rbp), %rax
movq 0x470(%rax), %rsi
leaq -0x40(%rbp), %rdi
callq 0x180e0
movq -0x10(%rbp), %rax
movl 0x450(%rax), %esi
leaq -0x40(%rbp), %rdi
callq 0x175c0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16c3a
leaq 0xa03e(%rip), %rdi      # 0x20c65
leaq 0x901d(%rip), %rsi      # 0x1fc4b
movl $0x693, %edx            # imm = 0x693
movb $0x0, %al
callq 0x117c0
movq -0x18(%rbp), %rax
movl 0x80(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x27c(%rcx), %eax
jb 0x16d60
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16c83
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rcx
leaq 0xa027(%rip), %rdi      # 0x20c97
leaq 0x8fd4(%rip), %rsi      # 0x1fc4b
movl $0x69a, %edx            # imm = 0x69A
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movl %eax, %esi
callq 0x163d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x16cd4
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16cc8
leaq 0xa033(%rip), %rdi      # 0x20ce8
leaq 0x8f8f(%rip), %rsi      # 0x1fc4b
movl $0x69e, %edx            # imm = 0x69E
movb $0x0, %al
callq 0x117c0
movl $0x21, -0x4(%rbp)
jmp 0x16f1e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16d0d
leaq -0x90(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x80(%rax), %r8d
leaq 0xa037(%rip), %rdi      # 0x20d31
leaq 0x8f4a(%rip), %rsi      # 0x1fc4b
movl $0x6a2, %edx            # imm = 0x6A2
movb $0x0, %al
callq 0x117c0
leaq -0x90(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x80(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %r8
leaq -0x40(%rbp), %rdi
callq 0x17fd0
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16d5b
leaq 0xa044(%rip), %rdi      # 0x20d8c
leaq 0x8efc(%rip), %rsi      # 0x1fc4b
movl $0x6a4, %edx            # imm = 0x6A4
movb $0x0, %al
callq 0x117c0
jmp 0x16e57
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16d8f
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rcx
leaq 0xa043(%rip), %rdi      # 0x20dbf
leaq 0x8ec8(%rip), %rsi      # 0x1fc4b
movl $0x6ac, %edx            # imm = 0x6AC
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movl %eax, %esi
callq 0x161e0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x16de0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16dd4
leaq 0xa045(%rip), %rdi      # 0x20e06
leaq 0x8e83(%rip), %rsi      # 0x1fc4b
movl $0x6b2, %edx            # imm = 0x6B2
movb $0x0, %al
callq 0x117c0
movl $0x22, -0x4(%rbp)
jmp 0x16f1e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16e07
leaq 0xa05a(%rip), %rdi      # 0x20e4e
leaq 0x8e50(%rip), %rsi      # 0x1fc4b
movl $0x6b6, %edx            # imm = 0x6B6
movb $0x0, %al
callq 0x117c0
leaq -0x90(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x80(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %r8
leaq -0x40(%rbp), %rdi
callq 0x17fd0
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16e55
leaq 0xa03c(%rip), %rdi      # 0x20e7e
leaq 0x8e02(%rip), %rsi      # 0x1fc4b
movl $0x6b8, %edx            # imm = 0x6B8
movb $0x0, %al
callq 0x117c0
jmp 0x16e57
cmpq $0x0, -0x28(%rbp)
je 0x16f05
cmpl $0x64, -0x44(%rbp)
jne 0x16f05
movq -0x10(%rbp), %rax
cmpl $0x0, 0x450(%rax)
je 0x16f05
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rsi
leaq 0xa021(%rip), %rdi      # 0x20ead
movb $0x0, %al
callq 0x11330
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
je 0x16f03
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16ed2
movq -0xa0(%rbp), %rcx
leaq 0x9ffc(%rip), %rdi      # 0x20ebb
leaq 0x8d85(%rip), %rsi      # 0x1fc4b
movl $0x6c2, %edx            # imm = 0x6C2
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x80(%rax), %eax
movl %eax, %r8d
callq 0x168b0
movq -0xa0(%rbp), %rdi
callq 0x2030
jmp 0x16f05
cmpq $0x0, -0x28(%rbp)
je 0x16f15
movq -0x28(%rbp), %rdi
callq 0x2030
movl -0x94(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)