// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/installshld.c
// Function: de_run_is_z
static void de_run_is_z(deark *c, de_module_params *mparams)
{
	struct isz_ctx *d = NULL;
	int saved_indent_level;
	struct de_timestamp tmp_timestamp;
	UI multivol_flag;
	UI volume_count = 0;
	i64 n;
	i64 pos;

	de_dbg_indent_save(c, &saved_indent_level);
	d = de_malloc(c, sizeof(struct isz_ctx));
	d->da = de_arch_create_lctx(c);
	d->da->userdata = (void*)d;
	d->da->is_le = 1;

	d->da->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_WINDOWS1252);

	// 0   13 5D 65 8C   = signature
	// 4   3A 01 02 00   = ?
	// 8... ?
	// 10  ui16  multivolume flag
	// 12  ui16  number of files
	// 14  ui16  date
	// 16  ui16  time
	// 18... ?
	// 18  ui32 ? approx sum of cmpr sizes or volume sizes
	// 22  ui32 sum of orig sizes
	// 30  u8    volume count (sometimes)
	// 31  u8    volume
	// 32... ?
	// 33  ui32  split begin addr (sometimes)
	// 37  ui32  split end addr
	// 41  ui32  offset of directory sequence
	// 45... ?
	// 49  ui16  number of dirs
	// 51  ui32  offset of files sequence

	if(de_getu32le(0)!=ISZ_SIGNATURE) {
		de_err(c, "Not an InstallShield Z file");
		goto done;
	}

	de_dbg(c, "main header");
	de_dbg_indent(c, 1);

	pos = 10;
	multivol_flag = (UI)de_getu16le_p(&pos);
	de_dbg(c, "is multivolume: %u", multivol_flag);

	d->da->num_members = de_getu16le_p(&pos);
	de_dbg(c, "total number of files: %"I64_FMT, d->da->num_members);
	if(d->da->num_members>ISZ_MAX_FILES) goto done;

	pos = 14;
	de_arch_read_field_dttm_p(d->da, &tmp_timestamp, "archive",
		DE_ARCH_TSTYPE_DOS_DT, &pos);

	n = de_getu32le_p(&pos);
	de_dbg2(c, "archive cmpr size (approx total?): %"I64_FMT, n);
	n = de_getu32le_p(&pos);
	de_dbg(c, "archive orig size (sum total): %"I64_FMT, n);

	if(multivol_flag) {
		pos = 30;
		volume_count = (UI)de_getbyte_p(&pos);
		if(volume_count) {
			de_dbg(c, "num volumes: %u", (UI)volume_count);
		}
		d->volume_number = (UI)de_getbyte_p(&pos);
		de_dbg(c, "volume number: %u", (UI)d->volume_number);

		if(volume_count!=1 || d->volume_number>1) {
			d->is_multivol = 1;
		}
	}

	pos = 33;
	n = de_getu32le_p(&pos);
	// Not sure what all this field does.
	// = 255 (start of data segment) on vol 1 if no split file.
	// = 0 on last volume of a multivolume set.
	de_dbg(c, "offset of start of split file (cont'd to next vol), "
		"if applicable: %"I64_FMT, n);

	n = de_getu32le_p(&pos);
	de_dbg(c, "offset of end of split file (cont'd from prev vol): %"I64_FMT, n);

	d->directory_pos = de_getu32le(41);
	de_dbg(c, "start of dir entries: %"I64_FMT, d->directory_pos);

	d->num_dirs = de_getu16le(49);
	de_dbg(c, "number of dirs: %"I64_FMT, d->num_dirs);
	if(d->num_dirs>ISZ_MAX_DIRS) goto done;

	d->filelist_pos = de_getu32le(51);
	de_dbg(c, "start of file entries: %"I64_FMT, d->filelist_pos);

	de_dbg_indent(c, -1);

	d->dir_array = de_mallocarray(c, d->num_dirs, sizeof(struct isz_dir_array_item));

	isz_do_dirlist(c, d);
	isz_do_filelist(c, d);

done:
	if(d) {
		if(d->da && !d->da->fatalerrflag) {
			de_dbg2(c, "total cmpr size: %"I64_FMT, d->tot_cmpr_size);
			de_dbg2(c, "total orig size: %"I64_FMT, d->tot_orig_size);
		}

		if(d->dir_array) {
			i64 i;

			for(i=0; i<d->num_dirs; i++) {
				ucstring_destroy(d->dir_array[i].dname);
			}
			de_free(c, d->dir_array);
		}
		de_arch_destroy_lctx(c, d->da);
		de_free(c, d);
	}
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x3c(%rsp), %rsi
callq 0xdebae
pushq $0x48
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r14
movq %rbx, %rdi
callq 0xf16ce
movq %rax, (%r14)
movq %r14, 0x40(%rax)
movl $0x1, 0x10(%rax)
pushq $0x9
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movq (%r14), %rcx
movl %eax, 0x18(%rcx)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xe409f
movl $0x8c655d13, %ecx       # imm = 0x8C655D13
cmpq %rcx, %rax
jne 0x9bd8a
leaq 0x83bcf(%rip), %rsi     # 0x11f591
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
leaq 0x20(%rsp), %r12
movq $0xa, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
movq %rax, %r15
leaq 0x89a64(%rip), %rsi     # 0x12545e
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
movq (%r14), %rcx
movq %rax, 0x20(%rcx)
leaq 0x89a50(%rip), %rsi     # 0x125471
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq (%r14), %rdi
cmpq $0x1388, 0x20(%rdi)     # imm = 0x1388
jg 0x9bda3
leaq 0x20(%rsp), %r12
movq $0xe, (%r12)
leaq 0x6e2c0(%rip), %rdx     # 0x109d13
leaq 0x48(%rsp), %rsi
pushq $0x3
popq %rcx
movq %r12, %r8
callq 0xf1866
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
leaq 0x89a16(%rip), %rsi     # 0x12548c
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde9f1
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
leaq 0x89a1d(%rip), %rsi     # 0x1254b3
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
testl %r15d, %r15d
je 0x9bb10
leaq 0x20(%rsp), %rsi
movq $0x1e, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xe3f2a
movl %eax, %ebp
testb %al, %al
je 0x9bad8
movzbl %bpl, %edx
leaq 0x89a08(%rip), %rsi     # 0x1254d6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x20(%rsp), %rsi
callq 0xe3f2a
movzbl %al, %edx
movl %edx, 0x38(%r14)
leaq 0x899f2(%rip), %rsi     # 0x1254e6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
cmpb $0x1, %bpl
jne 0x9bb0b
cmpl $0x2, 0x38(%r14)
jb 0x9bb10
movb $0x1, 0x20(%r14)
leaq 0x20(%rsp), %r15
movq $0x21, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe40bf
leaq 0x899c9(%rip), %rsi     # 0x1254f8
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe40bf
leaq 0x899f0(%rip), %rsi     # 0x12553f
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x29
popq %rsi
callq 0xe409f
movq %rax, 0x8(%r14)
leaq 0x89a04(%rip), %rsi     # 0x125577
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x31
popq %rsi
callq 0xe3fa3
movq %rax, 0x18(%r14)
leaq 0x899fa(%rip), %rsi     # 0x125591
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
cmpq $0x3e8, 0x18(%r14)      # imm = 0x3E8
jg 0x9bd9b
movq 0x18(%rbx), %rdi
pushq $0x33
popq %rsi
callq 0xe409f
movq %rax, 0x10(%r14)
leaq 0x899dc(%rip), %rsi     # 0x1255a5
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%r14), %rsi
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0xdf66f
movq %rax, 0x40(%r14)
movq 0x8(%r14), %r15
xorl %r12d, %r12d
cmpq 0x18(%r14), %r12
jge 0x9be2e
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r15
jge 0x9be2e
movq %r15, 0x8(%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xdebae
movq %rbx, %rdi
leaq 0x9a62e(%rip), %rsi     # 0x13625d
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movb $0x1, %al
movl %eax, 0x18(%rsp)
cmpq %r12, 0x18(%r14)
jle 0x9bca7
movq 0x40(%r14), %rax
movq %rax, 0x30(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0xe3fc4
movq %rbx, %rdi
leaq 0x8994c(%rip), %rsi     # 0x1255c0
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fc4
movq %rax, %rbp
movq %rbx, %rdi
leaq 0x89944(%rip), %rsi     # 0x1255db
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
cmpq $0x6, %rbp
jge 0x9bcd5
xorl %r13d, %r13d
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
cmpb $0x0, 0x18(%rsp)
jne 0x9be2e
testq %r13, %r13
je 0x9be2e
addq %r13, %r15
incq %r12
jmp 0x9bbfb
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fc4
movq %rax, %r13
movq %rbx, %rdi
leaq 0x898ff(%rip), %rsi     # 0x1255ed
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
cmpq $0x8000, %r13           # imm = 0x8000
jg 0x9bca7
leaq (%r15,%rbp), %rax
movq 0x8(%rsp), %rcx
movq %r13, 0x28(%rsp)
addq %r13, %rcx
movl $0x0, %r13d
cmpq %rax, %rcx
jg 0x9bcaa
movq %rbx, %rdi
callq 0xeac74
movq 0x30(%rsp), %r13
movq %rax, (%r13,%r12,8)
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movq (%r14), %rcx
movl 0x18(%rcx), %r9d
movl $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xe4c9a
movq (%r13,%r12,8), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0x75cd5(%rip), %rsi     # 0x111a40
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq (%r13,%r12,8), %rdi
pushq $0x1
popq %rsi
callq 0xf1712
movq %rbp, %r13
jmp 0x9bcaa
leaq 0x896b1(%rip), %rsi     # 0x125442
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq (%r14), %rdi
testq %rdi, %rdi
je 0x9bdd3
cmpl $0x0, 0x38(%rdi)
jne 0x9bdd3
movq 0x30(%r14), %rdx
leaq 0x6f795(%rip), %rsi     # 0x10b549
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde9f1
movq 0x28(%r14), %rdx
leaq 0x6f795(%rip), %rsi     # 0x10b55e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde9f1
cmpq $0x0, 0x40(%r14)
je 0x9bdfd
xorl %r15d, %r15d
movq 0x40(%r14), %rsi
cmpq 0x18(%r14), %r15
jge 0x9bdf5
movq (%rsi,%r15,8), %rdi
callq 0xeaf3c
incq %r15
jmp 0x9bddd
movq %rbx, %rdi
callq 0xded32
movq (%r14), %rsi
movq %rbx, %rdi
callq 0xf16e7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
movl 0x3c(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%r14), %r15
leaq 0x8(%rsp), %r13
xorl %eax, %eax
movq (%r14), %rdi
cmpq 0x20(%rdi), %rax
jge 0x9bda3
movq %rax, 0x30(%rsp)
movq %r15, 0x8(%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xdebae
movq %rbx, %rdi
pushq $0x14
popq %rsi
callq 0xdecaf
movq %rax, %rbp
movq (%r14), %rsi
movq %rbx, %rdi
callq 0xf1630
movq %rax, %r12
movq %rbp, 0x88(%rax)
movq %rbx, %rdi
leaq 0x6d73d(%rip), %rsi     # 0x1095c7
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %edx
movl %edx, 0x8(%rbp)
movq %rbx, %rdi
leaq 0x89744(%rip), %rsi     # 0x1255ff
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fc4
movl %eax, (%rbp)
movq %rbx, %rdi
leaq 0x89736(%rip), %rsi     # 0x125611
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movl (%rbp), %eax
cmpq %rax, 0x18(%r14)
movq %r15, 0x18(%rsp)
jle 0x9c0f0
movq %rax, 0x28(%rsp)
movq 0x40(%r14), %rax
movq %rax, 0x40(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xf1766
movq 0x38(%r12), %rax
addq %rax, 0x28(%r14)
movq %r12, %rdi
movq %r13, %rsi
callq 0xf17ab
movq 0x30(%r12), %rax
addq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe40bf
movq %rax, 0x40(%r12)
movq (%r14), %rdi
movq 0x50(%r12), %rsi
addq $0x18, %rsi
leaq 0x6f196(%rip), %rdx     # 0x10b0e6
pushq $0x3
popq %rcx
movq %r13, %r8
callq 0xf1866
addq $0x4, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fc4
movq %r13, %r15
movq %rax, %r13
movq %rbx, %rdi
leaq 0x8965e(%rip), %rsi     # 0x1255db
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
cmpq $0x1e, %r13
jl 0x9c101
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %edx
movl %edx, 0xc(%rbp)
movq %rbx, %rdi
leaq 0x8966f(%rip), %rsi     # 0x12561c
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movb %al, 0x10(%rbp)
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x8965c(%rip), %rsi     # 0x12562c
xorl %eax, %eax
callq 0xde896
incq 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %ecx
movl %ecx, 0x4(%rbp)
movq 0x40(%r12), %rdx
movq %rbx, %rdi
leaq 0x8963c(%rip), %rsi     # 0x125639
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %r15d
movq %rbx, %rdi
leaq 0x895d3(%rip), %rsi     # 0x1255f1
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
callq 0xeac74
movq %rax, 0x68(%r12)
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movq (%r14), %rcx
movl 0x18(%rcx), %r9d
movq %r15, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xe4c9a
movq 0x68(%r12), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0x79554(%rip), %rsi     # 0x1155bb
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x68(%r12), %rdi
callq 0xeaf76
testl %eax, %eax
je 0x9c08c
movq 0x68(%r12), %rdi
pushq $0x5f
popq %rsi
callq 0xeada5
movq 0x58(%r12), %rdi
movq 0x28(%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
callq 0xead71
movq 0x58(%r12), %rdi
movq 0x68(%r12), %rsi
callq 0xead71
movq 0x58(%r12), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0x89590(%rip), %rsi     # 0x125657
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
cmpb $0x0, 0x10(%rbp)
je 0x9c109
movq 0x58(%r12), %rdi
callq 0xeb877
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x89579(%rip), %rsi     # 0x125667
jmp 0x9c15a
movq %rbx, %rdi
leaq 0x6aae2(%rip), %rsi     # 0x106bdc
xorl %eax, %eax
callq 0xdf2a5
movb $0x1, %r15b
xorl %r13d, %r13d
jmp 0x9c164
movl 0x4(%rbp), %eax
cmpl 0x38(%r14), %eax
jne 0x9c143
orb $0x1, 0x78(%r12)
testb $0x10, 0xc(%rbp)
leaq 0x996(%rip), %rax       # 0x9cab9
leaq 0x9b2(%rip), %rcx       # 0x9cadc
cmoveq %rcx, %rax
movq %rax, 0xa8(%r12)
movq %r12, %rdi
callq 0xf1a85
xorl %r15d, %r15d
jmp 0x9c164
movq 0x58(%r12), %rdi
callq 0xeb877
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x89533(%rip), %rsi     # 0x12568d
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf167c
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xded32
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
testb %r15b, %r15b
jne 0x9bd9b
testq %r13, %r13
je 0x9bd9b
movq 0x18(%rsp), %r15
addq %r13, %r15
movq 0x30(%rsp), %rax
incq %rax
leaq 0x8(%rsp), %r13
jmp 0x9be39