// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/ole1.c
// Function: do_ole_package
static int do_ole_package(deark *c, lctx *d, i64 pos1, i64 len)
{
	i64 endpos = pos1+len;
	i64 pos = pos1;
	struct de_stringreaderdata *caption = NULL;
	struct de_stringreaderdata *iconsrc = NULL;
	de_ucstring *filename = NULL;
	de_finfo *fi = NULL;
	unsigned int type_code1, type_code2;
	i64 n, fnlen, fsize;
	int saved_indent_level;
	int retval = 0;

	de_dbg_indent_save(c, &saved_indent_level);

	de_dbg(c, "package at %"I64_FMT", len=%"I64_FMT, pos, len);
	de_dbg_indent(c, 1);
	type_code1 = (unsigned int)de_getu16le_p(&pos);
	de_dbg(c, "stream header code: %u", type_code1);
	if(type_code1 != 2) {
		de_dbg(c, "[unknown package format]");
		goto done;
	}

	caption = dbuf_read_string(c->infile, pos, de_min_int(256, endpos-pos), 256,
		DE_CONVFLAG_STOP_AT_NUL, d->input_encoding);
	if(!caption->found_nul) goto done;
	de_dbg(c, "caption: \"%s\"", ucstring_getpsz_d(caption->str));
	pos += caption->bytes_consumed;

	iconsrc = dbuf_read_string(c->infile, pos, de_min_int(256, endpos-pos), 256,
		DE_CONVFLAG_STOP_AT_NUL, d->input_encoding);
	if(!iconsrc->found_nul) goto done;
	de_dbg(c, "icon source: \"%s\"", ucstring_getpsz_d(iconsrc->str));
	pos += iconsrc->bytes_consumed;

	n = de_getu16le_p(&pos);
	de_dbg(c, "icon #: %d", (int)n);

	type_code2 = (unsigned int)de_getu16le_p(&pos);
	de_dbg(c, "package type: %u", type_code2);

	if(type_code2!=3) {
		// Code 1 apparently means "run a program".
		de_dbg(c, "[not an embedded file]");
		goto done;
	}

	// A package can contain an arbitrary embedded file, which we'll try to
	// extract.

	fnlen = de_getu32le_p(&pos);
	if(pos+fnlen > endpos) goto done;
	filename = ucstring_create(c);
	dbuf_read_to_ucstring_n(c->infile, pos, fnlen, 256, filename, DE_CONVFLAG_STOP_AT_NUL,
		d->input_encoding);
	de_dbg(c, "filename: \"%s\"", ucstring_getpsz_d(filename));
	pos += fnlen;

	fsize = de_getu32le_p(&pos);
	de_dbg(c, "file size: %"I64_FMT, fsize);
	if(pos+fsize > endpos) goto done;

	fi = de_finfo_create(c);
	de_finfo_set_name_from_ucstring(c, fi, filename, 0);
	dbuf_create_file_from_slice(c->infile, pos, fsize, NULL, fi, 0);
	retval = 1;

done:
	de_destroy_stringreaderdata(c, caption);
	de_destroy_stringreaderdata(c, iconsrc);
	ucstring_destroy(filename);
	de_finfo_destroy(c, fi);
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movl $0x0, -0x78(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x74(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0xd4c99(%rip), %rsi     # 0x1bd63f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rdi
movl -0x54(%rbp), %edx
leaq 0xd4c7a(%rip), %rsi     # 0x1bd657
movb $0x0, %al
callq 0x15b0d0
cmpl $0x2, -0x54(%rbp)
je 0xe8a01
movq -0x8(%rbp), %rdi
leaq 0xd4c79(%rip), %rsi     # 0x1bd66e
movb $0x0, %al
callq 0x15b0d0
jmp 0xe8cd6
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rsi
subq -0x30(%rbp), %rsi
movl $0x100, %edi            # imm = 0x100
callq 0x15ccf0
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq %rax, %rdx
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movl $0x100, %ecx            # imm = 0x100
movl $0x1, %r8d
callq 0x1664c0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0xe8a62
jmp 0xe8cd6
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0xa0(%rbp), %rdi
movq %rax, %rdx
leaq 0xd4bfc(%rip), %rsi     # 0x1bd687
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
movq (%rax), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x28(%rbp), %rsi
subq -0x30(%rbp), %rsi
movl $0x100, %edi            # imm = 0x100
callq 0x15ccf0
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq %rax, %rdx
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movl $0x100, %ecx            # imm = 0x100
movl $0x1, %r8d
callq 0x1664c0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0xe8b08
jmp 0xe8cd6
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0xa8(%rbp), %rdi
movq %rax, %rdx
leaq 0xd4b64(%rip), %rsi     # 0x1bd695
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
movq (%rax), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl %eax, %edx
leaq 0xd4b3a(%rip), %rsi     # 0x1bd6a7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movl -0x58(%rbp), %edx
leaq 0xd4b1c(%rip), %rsi     # 0x1bd6b2
movb $0x0, %al
callq 0x15b0d0
cmpl $0x3, -0x58(%rbp)
je 0xe8bba
movq -0x8(%rbp), %rdi
leaq 0xd4b15(%rip), %rsi     # 0x1bd6c3
movb $0x0, %al
callq 0x15b0d0
jmp 0xe8cd6
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rax
addq -0x68(%rbp), %rax
cmpq -0x28(%rbp), %rax
jle 0xe8be2
jmp 0xe8cd6
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq -0x48(%rbp), %r8
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl $0x100, %ecx            # imm = 0x100
movl $0x1, %r9d
movl %eax, (%rsp)
callq 0x166a40
movq -0x8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x48(%rbp), %rdi
callq 0x172650
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
leaq 0xde942(%rip), %rsi     # 0x1c7583
movb $0x0, %al
callq 0x15b0d0
movq -0x68(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rdx
leaq 0xb98a2(%rip), %rsi     # 0x1a251a
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
addq -0x70(%rbp), %rax
cmpq -0x28(%rbp), %rax
jle 0xe8c8f
jmp 0xe8cd6
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
xorl %ecx, %ecx
callq 0x15d2c0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x50(%rbp), %r8
xorl %eax, %eax
movl %eax, %ecx
xorl %r9d, %r9d
callq 0x166be0
movl $0x1, -0x78(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x166830
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x166830
movq -0x48(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x15b5a0
movl -0x78(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nop