// File: /workspace/github_c_makefile_star2_O1/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 0xe958c
movl $0x48, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
movq %rbx, %rdi
callq 0xfdb0a
movq %rax, (%r14)
movq %r14, 0x40(%rax)
movl $0x1, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb7d1
movq (%r14), %rcx
movl %eax, 0x18(%rcx)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef37e
movl $0x8c655d13, %ecx       # imm = 0x8C655D13
cmpq %rcx, %rax
jne 0xa23d5
leaq 0x8a53b(%rip), %rsi     # 0x12c519
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
leaq 0x20(%rsp), %r12
movq $0xa, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef1ed
movq %rax, %r15
leaq 0x903ae(%rip), %rsi     # 0x1323c6
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef1ed
movq (%r14), %rcx
movq %rax, 0x20(%rcx)
leaq 0x9039a(%rip), %rsi     # 0x1323d9
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq (%r14), %rdi
cmpq $0x1388, 0x20(%rdi)     # imm = 0x1388
jg 0xa23e6
leaq 0x20(%rsp), %r12
movq $0xe, (%r12)
leaq 0x74c82(%rip), %rdx     # 0x116cf3
leaq 0x48(%rsp), %rsi
movl $0x3, %ecx
movq %r12, %r8
callq 0xfdc9b
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef3a0
leaq 0x9035e(%rip), %rsi     # 0x1323f4
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe93cf
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef3a0
leaq 0x90365(%rip), %rsi     # 0x13241b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
testl %r15d, %r15d
je 0xa2130
leaq 0x20(%rsp), %rsi
movq $0x1e, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xef14d
movl %eax, %ebp
testb %al, %al
je 0xa20f8
movzbl %bpl, %edx
leaq 0x90350(%rip), %rsi     # 0x13243e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x20(%rsp), %rsi
callq 0xef14d
movzbl %al, %edx
movl %edx, 0x38(%r14)
leaq 0x9033a(%rip), %rsi     # 0x13244e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
cmpb $0x1, %bpl
jne 0xa212b
cmpl $0x2, 0x38(%r14)
jb 0xa2130
movb $0x1, 0x20(%r14)
leaq 0x20(%rsp), %r15
movq $0x21, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef3a0
leaq 0x90311(%rip), %rsi     # 0x132460
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef3a0
leaq 0x90338(%rip), %rsi     # 0x1324a7
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x29, %esi
callq 0xef37e
movq %rax, 0x8(%r14)
leaq 0x9034a(%rip), %rsi     # 0x1324df
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x31, %esi
callq 0xef1ca
movq %rax, 0x18(%r14)
leaq 0x9033e(%rip), %rsi     # 0x1324f9
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpq $0x3e8, 0x18(%r14)      # imm = 0x3E8
jg 0xa23e6
movq 0x18(%rbx), %rdi
movl $0x33, %esi
callq 0xef37e
movq %rax, 0x10(%r14)
leaq 0x9031e(%rip), %rsi     # 0x13250d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x18(%r14), %rsi
movl $0x8, %edx
movq %rbx, %rdi
callq 0xea259
movq %rax, 0x40(%r14)
cmpq $0x0, 0x18(%r14)
jle 0xa2482
movq 0x8(%r14), %r12
leaq 0x8(%rsp), %rbp
xorl %r13d, %r13d
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r12
jge 0xa22ef
movq %r12, 0x8(%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe958c
movq 0x8(%rsp), %rdx
movq %rbx, %rdi
leaq 0xa0f69(%rip), %rsi     # 0x1431cd
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movb $0x1, %al
movl %eax, 0x18(%rsp)
cmpq %r13, 0x18(%r14)
jle 0xa22d6
movq 0x40(%r14), %rax
movq %rax, 0x30(%rsp)
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef1ed
movq %rbx, %rdi
leaq 0x90285(%rip), %rsi     # 0x132528
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef1ed
movq %rax, %r15
movq %rbx, %rdi
leaq 0x9027d(%rip), %rsi     # 0x132543
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpq $0x6, %r15
jge 0xa231b
xorl %ebp, %ebp
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
cmpb $0x0, 0x18(%rsp)
je 0xa22f3
xorl %eax, %eax
jmp 0xa22fc
xorl %eax, %eax
jmp 0xa2301
testq %rbp, %rbp
setg %al
addq %rbp, %r12
leaq 0x8(%rsp), %rbp
testb %al, %al
je 0xa2482
incq %r13
cmpq 0x18(%r14), %r13
jl 0xa2235
jmp 0xa2482
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef1ed
movq %rax, %rbp
movq %rbx, %rdi
leaq 0x90221(%rip), %rsi     # 0x132555
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpq $0x8000, %rbp           # imm = 0x8000
jg 0xa22d6
leaq (%r15,%r12), %rax
movq 0x8(%rsp), %rcx
movq %rbp, 0x28(%rsp)
addq %rbp, %rcx
movl $0x0, %ebp
cmpq %rax, %rcx
jg 0xa22d8
movq %rbx, %rdi
callq 0xf6870
movq 0x30(%rsp), %rbp
movq %rax, (%rbp,%r13,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 0xf01b0
movq (%rbp,%r13,8), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0x7c654(%rip), %rsi     # 0x11ea08
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq (%rbp,%r13,8), %rdi
movl $0x1, %esi
callq 0xfdb50
movq %r15, %rbp
jmp 0xa22d8
leaq 0x8ffce(%rip), %rsi     # 0x1323aa
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq (%r14), %rax
testq %rax, %rax
je 0xa241e
cmpl $0x0, 0x38(%rax)
jne 0xa241e
movq 0x30(%r14), %rdx
leaq 0x76102(%rip), %rsi     # 0x118501
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe93cf
movq 0x28(%r14), %rdx
leaq 0x76102(%rip), %rsi     # 0x118516
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe93cf
cmpq $0x0, 0x40(%r14)
je 0xa2451
cmpq $0x0, 0x18(%r14)
jle 0xa2445
xorl %r15d, %r15d
movq 0x40(%r14), %rax
movq (%rax,%r15,8), %rdi
callq 0xf6bb0
incq %r15
cmpq 0x18(%r14), %r15
jl 0xa242f
movq 0x40(%r14), %rsi
movq %rbx, %rdi
callq 0xe9752
movq (%r14), %rsi
movq %rbx, %rdi
callq 0xfdb25
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movl 0x3c(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rax
cmpq $0x0, 0x20(%rax)
jle 0xa23e6
movq 0x10(%r14), %rax
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x30(%rsp)
movq 0x18(%rsp), %r15
movq %r15, 0x8(%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe958c
movl $0x14, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r12
movq (%r14), %rsi
movq %rbx, %rdi
callq 0xfda6c
movq %rax, %r13
movq %r12, 0x88(%rax)
movq %rbx, %rdi
leaq 0x740c1(%rip), %rsi     # 0x1165a7
movq %r15, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0xef14d
movzbl %al, %edx
movl %edx, 0x8(%r12)
movq %rbx, %rdi
leaq 0x90047(%rip), %rsi     # 0x132567
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movl %eax, (%r12)
movq %rbx, %rdi
leaq 0x90038(%rip), %rsi     # 0x132579
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movl (%r12), %eax
cmpq %rax, 0x18(%r14)
jle 0xa274d
movq %rax, 0x28(%rsp)
movq 0x40(%r14), %rax
movq %rax, 0x40(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0xfdb9b
movq 0x38(%r13), %rax
addq %rax, 0x28(%r14)
movq %r13, %rdi
movq %r15, %rsi
callq 0xfdbe0
movq 0x30(%r13), %rax
addq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef3a0
movq %rax, 0x40(%r13)
movq (%r14), %rdi
movq 0x50(%r13), %rsi
addq $0x18, %rsi
leaq 0x75af0(%rip), %rdx     # 0x11809e
movl $0x3, %ecx
movq %r15, %r8
callq 0xfdc9b
addq $0x4, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movq %rax, %rbp
movq %rbx, %rdi
leaq 0x8ff69(%rip), %rsi     # 0x132543
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpq $0x1e, %rbp
jl 0xa275e
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %edx
movl %edx, 0xc(%r12)
movq %rbx, %rdi
leaq 0x8ff78(%rip), %rsi     # 0x132584
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movb %al, 0x10(%r12)
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x8ff63(%rip), %rsi     # 0x132594
xorl %eax, %eax
callq 0xe9226
incq 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %ecx
movl %ecx, 0x4(%r12)
movq 0x40(%r13), %rdx
movq %rbx, %rdi
leaq 0x8ff42(%rip), %rsi     # 0x1325a1
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %r15d
movq %rbx, %rdi
leaq 0x8fed9(%rip), %rsi     # 0x132559
movq %r15, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x68(%r13)
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 0xf01b0
movq 0x68(%r13), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0x7feac(%rip), %rsi     # 0x122573
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x68(%r13), %rdi
callq 0xf6bea
testl %eax, %eax
je 0xa26ec
movq 0x68(%r13), %rdi
movl $0x5f, %esi
callq 0xf69a2
movq 0x58(%r13), %rdi
movq 0x28(%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
callq 0xf6969
movq 0x58(%r13), %rdi
movq 0x68(%r13), %rsi
callq 0xf6969
movq 0x58(%r13), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0x8fe9c(%rip), %rsi     # 0x1325bf
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpb $0x0, 0x10(%r12)
je 0xa2765
movq 0x58(%r13), %rdi
callq 0xf7557
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x8fe84(%rip), %rsi     # 0x1325cf
jmp 0xa27b7
movq %rbx, %rdi
leaq 0x71435(%rip), %rsi     # 0x113b8c
xorl %eax, %eax
callq 0xe9df7
movb $0x1, %r15b
xorl %ebp, %ebp
jmp 0xa27c1
movl 0x4(%r12), %eax
cmpl 0x38(%r14), %eax
jne 0xa27a1
orb $0x1, 0x78(%r13)
testb $0x10, 0xc(%r12)
leaq 0x9ec(%rip), %rax       # 0xa316e
leaq 0xa08(%rip), %rcx       # 0xa3191
cmoveq %rcx, %rax
movq %rax, 0xa8(%r13)
movq %r13, %rdi
callq 0xfdec1
xorl %r15d, %r15d
jmp 0xa27c1
movq 0x58(%r13), %rdi
callq 0xf7557
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x8fe3e(%rip), %rsi     # 0x1325f5
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r13, %rsi
callq 0xfdab8
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe9752
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
testb %r15b, %r15b
movq 0x30(%rsp), %rcx
jne 0xa23e6
testq %rbp, %rbp
jle 0xa23e6
testb %r15b, %r15b
movl $0x0, %eax
cmovneq %rax, %rbp
addq %rbp, 0x18(%rsp)
incq %rcx
movq (%r14), %rax
cmpq 0x20(%rax), %rcx
jl 0xa249b
jmp 0xa23e6