// File: /workspace/github_c_makefile_star2_O3/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 0x24(%rsp), %rsi
callq 0xe8a1c
movl $0x48, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r14
movq %rbx, %rdi
callq 0xfd4b2
movq %rax, (%r14)
movq %r14, 0x40(%rax)
movl $0x1, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb220
movq (%r14), %rcx
movl %eax, 0x18(%rcx)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xeed61
movl $0x8c655d13, %ecx       # imm = 0x8C655D13
cmpq %rcx, %rax
jne 0xa1afb
leaq 0x8b0b7(%rip), %rsi     # 0x12c801
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0x18(%rsp), %r12
movq $0xa, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq %rax, %r15
leaq 0x90fda(%rip), %rsi     # 0x13275e
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq (%r14), %rcx
movq %rax, 0x20(%rcx)
leaq 0x90fc6(%rip), %rsi     # 0x132771
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq (%r14), %rdi
cmpq $0x1388, 0x20(%rdi)     # imm = 0x1388
jg 0xa1b14
leaq 0x18(%rsp), %r12
movq $0xe, (%r12)
leaq 0x755c6(%rip), %rdx     # 0x116da3
leaq 0x48(%rsp), %rsi
movl $0x3, %ecx
movq %r12, %r8
callq 0xfd638
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
leaq 0x90f8a(%rip), %rsi     # 0x13278c
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe87e4
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
leaq 0x90f91(%rip), %rsi     # 0x1327b3
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
testl %r15d, %r15d
je 0xa189c
leaq 0x18(%rsp), %rsi
movq $0x1e, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xeeb4b
movl %eax, %ebp
testb %al, %al
je 0xa1864
movzbl %bpl, %edx
leaq 0x90f7c(%rip), %rsi     # 0x1327d6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xeeb4b
movzbl %al, %edx
movl %edx, 0x38(%r14)
leaq 0x90f66(%rip), %rsi     # 0x1327e6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
cmpb $0x1, %bpl
jne 0xa1897
cmpl $0x2, 0x38(%r14)
jb 0xa189c
movb $0x1, 0x20(%r14)
leaq 0x18(%rsp), %r15
movq $0x21, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeed83
leaq 0x90f3d(%rip), %rsi     # 0x1327f8
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeed83
leaq 0x90f64(%rip), %rsi     # 0x13283f
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x29, %esi
callq 0xeed61
movq %rax, 0x8(%r14)
leaq 0x90f76(%rip), %rsi     # 0x132877
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x31, %esi
callq 0xeebc8
movq %rax, 0x18(%r14)
leaq 0x90f6a(%rip), %rsi     # 0x132891
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
cmpq $0x3e8, 0x18(%r14)      # imm = 0x3E8
jg 0xa1b0c
movq 0x18(%rbx), %rdi
movl $0x33, %esi
callq 0xeed61
movq %rax, 0x10(%r14)
leaq 0x90f4a(%rip), %rsi     # 0x1328a5
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x18(%r14), %rsi
movl $0x8, %edx
movq %rbx, %rdi
callq 0xe96f7
movq %rax, 0x40(%r14)
cmpq $0x0, 0x18(%r14)
jle 0xa1bb6
movq 0x8(%r14), %r15
xorl %ebp, %ebp
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r15
jge 0xa1bb6
movq %r15, (%rsp)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0xe8a1c
movq %rbx, %rdi
leaq 0xa1ce9(%rip), %rsi     # 0x1436ad
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
cmpq %rbp, 0x18(%r14)
jle 0xa1baa
movq 0x40(%r14), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq %rsp, %r12
movq %r12, %rsi
callq 0xeebeb
movq %rbx, %rdi
leaq 0x90eb9(%rip), %rsi     # 0x1328c0
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq %rax, %r13
movq %rbx, %rdi
leaq 0x90eb1(%rip), %rsi     # 0x1328db
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
cmpq $0x6, %r13
jl 0xa1baa
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xeebeb
movq %rax, %r12
movq %rbx, %rdi
leaq 0x90e96(%rip), %rsi     # 0x1328ed
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
cmpq $0x8000, %r12           # imm = 0x8000
jg 0xa1baa
addq %r13, %r15
movq (%rsp), %rax
addq %r12, %rax
cmpq %r15, %rax
jg 0xa1baa
movq %rbx, %rdi
callq 0xf6410
movq 0x10(%rsp), %r13
movq %rax, (%r13,%rbp,8)
movq 0x18(%rbx), %rdi
movq (%rsp), %rsi
movq (%r14), %rcx
movl 0x18(%rcx), %r9d
movq %r12, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xefbd7
movq (%r13,%rbp,8), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0x7d04c(%rip), %rsi     # 0x11eb10
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq (%r13,%rbp,8), %rdi
movl $0x1, %esi
callq 0xfd4f8
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
incq %rbp
cmpq 0x18(%r14), %rbp
jl 0xa199b
jmp 0xa1bb6
leaq 0x90c40(%rip), %rsi     # 0x132742
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq (%r14), %rdi
testq %rdi, %rdi
je 0xa1b44
cmpl $0x0, 0x38(%rdi)
jne 0xa1b44
movq 0x30(%r14), %rdx
leaq 0x76b14(%rip), %rsi     # 0x118639
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe87e4
movq 0x28(%r14), %rdx
leaq 0x76b14(%rip), %rsi     # 0x11864e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe87e4
movq 0x40(%r14), %rsi
testq %rsi, %rsi
je 0xa1b79
cmpq $0x0, 0x18(%r14)
jle 0xa1b71
xorl %r15d, %r15d
movq 0x40(%r14), %rax
movq (%rax,%r15,8), %rdi
callq 0xf6753
incq %r15
cmpq 0x18(%r14), %r15
jl 0xa1b57
movq 0x40(%r14), %rsi
movq %rbx, %rdi
callq 0xe8be2
movq (%r14), %rsi
movq %rbx, %rdi
callq 0xfd4cd
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movl 0x24(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq (%r14), %rdi
cmpq $0x0, 0x20(%rdi)
jle 0xa1b14
movq 0x10(%r14), %r15
movq %rsp, %rbp
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %r15, (%rsp)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0xe8a1c
movl $0x14, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r12
movq (%r14), %rsi
movq %rbx, %rdi
callq 0xfd414
movq %rax, %r13
movq %r12, 0x88(%rax)
movq %rbx, %rdi
leaq 0x74a45(%rip), %rsi     # 0x116657
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeeb4b
movzbl %al, %edx
movl %edx, 0x8(%r12)
movq %rbx, %rdi
leaq 0x90cb8(%rip), %rsi     # 0x1328ff
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeebeb
movl %eax, (%r12)
movq %rbx, %rdi
leaq 0x90ca9(%rip), %rsi     # 0x132911
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl (%r12), %eax
cmpq %rax, 0x18(%r14)
jle 0xa1d30
movq %rax, 0x38(%rsp)
movq %r15, 0x28(%rsp)
movq 0x40(%r14), %rax
movq %rax, 0x30(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0xfd538
movq 0x38(%r13), %rax
addq %rax, 0x28(%r14)
movq %r13, %rdi
movq %rbp, %rsi
callq 0xfd57d
movq 0x30(%r13), %rax
addq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeed83
movq %rax, 0x40(%r13)
movq (%r14), %rdi
movq 0x50(%r13), %rsi
addq $0x18, %rsi
leaq 0x764fc(%rip), %rdx     # 0x1181d6
movl $0x3, %ecx
movq %rbp, %r8
callq 0xfd638
addq $0x4, (%rsp)
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeebeb
movq %rax, %r15
movq %rbx, %rdi
leaq 0x90bd6(%rip), %rsi     # 0x1328db
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r15, 0x10(%rsp)
cmpq $0x1e, %r15
jge 0xa1d52
movb $0x1, %bpl
movq $0x0, 0x10(%rsp)
movq 0x28(%rsp), %r15
jmp 0xa1f0d
movq %rbx, %rdi
leaq 0x71f02(%rip), %rsi     # 0x113c3c
xorl %eax, %eax
callq 0xe9295
movb $0x1, %bpl
movq $0x0, 0x10(%rsp)
jmp 0xa1f0d
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeeb4b
movzbl %al, %edx
movl %edx, 0xc(%r12)
movq %rbx, %rdi
leaq 0x90bac(%rip), %rsi     # 0x13291c
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeeb4b
movb %al, 0x10(%r12)
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x90b97(%rip), %rsi     # 0x13292c
xorl %eax, %eax
callq 0xe8617
incq (%rsp)
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeeb4b
movzbl %al, %ecx
movl %ecx, 0x4(%r12)
movq 0x40(%r13), %rdx
movq %rbx, %rdi
leaq 0x90b77(%rip), %rsi     # 0x132939
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeeb4b
movzbl %al, %r15d
movq %rbx, %rdi
leaq 0x90b0e(%rip), %rsi     # 0x1328f1
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
callq 0xf6410
movq %rax, 0x68(%r13)
movq 0x18(%rbx), %rdi
movq (%rsp), %rsi
movq (%r14), %rcx
movl 0x18(%rcx), %r9d
movq %r15, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xefbd7
movq 0x68(%r13), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0x80952(%rip), %rsi     # 0x12277b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x68(%r13), %rdi
callq 0xf678d
testl %eax, %eax
je 0xa1e4e
movq 0x68(%r13), %rdi
movl $0x5f, %esi
callq 0xf6542
movq 0x58(%r13), %rdi
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
callq 0xf6509
movq 0x58(%r13), %rdi
movq 0x68(%r13), %rsi
callq 0xf6509
movq 0x58(%r13), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0x90ad2(%rip), %rsi     # 0x132957
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
cmpb $0x0, 0x10(%r12)
movq 0x28(%rsp), %r15
je 0xa1eb3
movq 0x58(%r13), %rdi
callq 0xf70f6
xorl %ebp, %ebp
movq %rbx, %rdi
leaq 0x90ab6(%rip), %rsi     # 0x132967
jmp 0xa1f03
movl 0x4(%r12), %eax
cmpl 0x38(%r14), %eax
jne 0xa1eee
orb $0x1, 0x78(%r13)
testb $0x10, 0xc(%r12)
leaq 0x9da(%rip), %rax       # 0xa28aa
leaq 0x9f6(%rip), %rcx       # 0xa28cd
cmoveq %rcx, %rax
movq %rax, 0xa8(%r13)
movq %r13, %rdi
callq 0xfd85e
xorl %ebp, %ebp
jmp 0xa1f0d
movq 0x58(%r13), %rdi
callq 0xf70f6
xorl %ebp, %ebp
movq %rbx, %rdi
leaq 0x90a8a(%rip), %rsi     # 0x13298d
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r13, %rsi
callq 0xfd460
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe8be2
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
testb %bpl, %bpl
movq 0x10(%rsp), %rax
jne 0xa1b0c
testq %rax, %rax
je 0xa1b0c
addq %rax, %r15
movq 0x40(%rsp), %rax
incq %rax
movq (%r14), %rdi
cmpq 0x20(%rdi), %rax
movq %rsp, %rbp
jl 0xa1bcd
jmp 0xa1b14