// File: /workspace/github_c_makefile_star2_O0/inflex[P]ripMIME/ripOLE/olestream-unwrap.c
// Function: OLEUNWRAP_save_stream
int OLEUNWRAP_save_stream( struct OLEUNWRAP_object *oleuw, char *fname, char *decode_path, char *stream, size_t bytes )
{
	char *full_name;
	FILE *f;
	int result = 0;

	DUW LOGGER_log("%s:%d:OLEUNWRAP_save_stream:DEBUG: fname=%s, decodepath=%s, size=%ld"
			,FL
			,fname
			,decode_path
			,bytes
			);

	full_name = PLD_dprintf("%s/%s", decode_path, fname );
	if (full_name == NULL)
	{
		LOGGER_log("%s:%d:OLEUNWRAP_save_stream:ERROR: Unable to create filename string from '%s' and '%s'",FL,fname,decode_path);
		return -1;
	}

	f = fopen(full_name,"w");
	if (f != NULL)
	{
		size_t write_count;

		write_count = fwrite( stream, 1, bytes, f );
		if (write_count != bytes)
		{
			LOGGER_log("%s:%d:OLEUNWRAP_save_stream:WARNING: Only wrote %d of %d bytes to file %s\n",FL, write_count, bytes, full_name );
		}

		fclose(f);


	} else {
		LOGGER_log("%s:%d:OLEUNWRAP_save_stream:ERROR: Unable to open %s for writing (%s)\n",FL,full_name, strerror(errno));
		result = -1;
	}

	if (full_name) free(full_name);

	DUW LOGGER_log("%s:%d:OLEUNWRAP_save_stream:DEBUG: Done saving '%s'",FL, fname);

	return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x17633
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x30(%rbp), %r9
leaq 0x9c77(%rip), %rdi      # 0x21297
leaq 0x9cb5(%rip), %rsi      # 0x212dc
movl $0x9b, %edx
movb $0x0, %al
callq 0x117c0
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x1eba(%rip), %rdi      # 0x194fc
movb $0x0, %al
callq 0x11330
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x17682
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq 0x9c8c(%rip), %rdi      # 0x212ef
leaq 0x9c72(%rip), %rsi      # 0x212dc
movl $0xa4, %edx
movb $0x0, %al
callq 0x117c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1776c
movq -0x38(%rbp), %rdi
leaq 0x273e(%rip), %rsi      # 0x19dcb
callq 0x2330
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x176f2
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl $0x1, %esi
callq 0x2380
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x176e7
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
leaq 0x9c72(%rip), %rdi      # 0x21346
leaq 0x9c01(%rip), %rsi      # 0x212dc
movl $0xb0, %edx
movb $0x0, %al
callq 0x117c0
movq -0x40(%rbp), %rdi
callq 0x20e0
jmp 0x1772e
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x23a0
movq -0x58(%rbp), %rcx
movq %rax, %r8
leaq 0x9c7d(%rip), %rdi      # 0x21391
leaq 0x9bc1(%rip), %rsi      # 0x212dc
movl $0xb7, %edx
movb $0x0, %al
callq 0x117c0
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
cmpq $0x0, -0x38(%rbp)
je 0x1773e
movq -0x38(%rbp), %rdi
callq 0x2030
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x17766
movq -0x18(%rbp), %rcx
leaq 0x9c85(%rip), %rdi      # 0x213d8
leaq 0x9b82(%rip), %rsi      # 0x212dc
movl $0xbd, %edx
movb $0x0, %al
callq 0x117c0
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)