// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movl $0x48, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x17c220
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x9, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x165540
movl $0x8c655d13, %ecx       # imm = 0x8C655D13
cmpq %rcx, %rax
je 0xee4be
movq -0x8(%rbp), %rdi
leaq 0xcfc38(%rip), %rsi     # 0x1be0ea
movb $0x0, %al
callq 0x15bfb0
jmp 0xee7d0
movq -0x8(%rbp), %rdi
leaq 0xc9e14(%rip), %rsi     # 0x1b82dd
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq $0xa, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %edx
leaq 0xcfbfe(%rip), %rsi     # 0x1be106
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rdx
leaq 0xcfbd5(%rip), %rsi     # 0x1be119
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpq $0x1388, 0x20(%rax)     # imm = 0x1388
jle 0xee561
jmp 0xee7d0
movq $0xe, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
leaq -0x30(%rbp), %rsi
leaq 0xb4628(%rip), %rdx     # 0x1a2ba3
movl $0x3, %ecx
leaq -0x48(%rbp), %r8
callq 0x17c580
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165580
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0xcfb87(%rip), %rsi     # 0x1be134
movb $0x0, %al
callq 0x15b350
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165580
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0xcfb83(%rip), %rsi     # 0x1be15b
movb $0x0, %al
callq 0x15b0d0
cmpl $0x0, -0x34(%rbp)
je 0xee671
movq $0x1e, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0xee623
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %edx
leaq 0xcfb62(%rip), %rsi     # 0x1be17e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165170
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x38(%rax), %edx
leaq 0xcfb3e(%rip), %rsi     # 0x1be18e
movb $0x0, %al
callq 0x15b0d0
cmpl $0x1, -0x38(%rbp)
jne 0xee667
movq -0x18(%rbp), %rax
cmpl $0x1, 0x38(%rax)
jbe 0xee66f
movq -0x18(%rbp), %rax
movb $0x1, 0x20(%rax)
jmp 0xee671
movq $0x21, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165580
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0xcfb03(%rip), %rsi     # 0x1be1a0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165580
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0xcfb1f(%rip), %rsi     # 0x1be1e7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x29, %esi
callq 0x165540
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0xcfb20(%rip), %rsi     # 0x1be21f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x31, %esi
callq 0x165280
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0xcfb03(%rip), %rsi     # 0x1be239
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpq $0x3e8, 0x18(%rax)      # imm = 0x3E8
jle 0xee750
jmp 0xee7d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x33, %esi
callq 0x165540
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0xcfacd(%rip), %rsi     # 0x1be24d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movl $0x8, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xeef30
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xeefd0
cmpq $0x0, -0x18(%rbp)
je 0xee898
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0xee826
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x38(%rax)
jne 0xee826
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdx
leaq 0xb5b51(%rip), %rsi     # 0x1a4356
movb $0x0, %al
callq 0x15b350
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0xb5b4c(%rip), %rsi     # 0x1a436b
movb $0x0, %al
callq 0x15b350
movq -0x18(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xee87b
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0xee86a
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x171750
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xee839
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x17c270
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x15b5a0
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)