// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc3.c
// Function: de_run_lif_kdc
static void de_run_lif_kdc(deark *c, de_module_params *mparams)
{
	de_arch_lctx *d = NULL;
	i64 pos = 0;
	struct de_arch_member_data *md = NULL;
	dbuf *f2 = NULL;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	d = de_arch_create_lctx(c);
	d->is_le = 0;
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_CP437);
	d->crco = de_crcobj_create(c, DE_CRCOBJ_CRC16_IBM3740);
	f2 = dbuf_create_membuf(c, 17, 0);

	while(1) {
		i64 f2_pos;
		u32 crc1_reported;

		if(pos >= c->infile->len) goto done;
		if(md) {
			de_arch_destroy_md(c, md);
			md = NULL;
		}

		dbuf_empty(f2);
		// Decode the hex-encoded part of the header, so that we can read it
		// more easily.
		if(!lif_kdc_convert_hdr(c, pos, f2)) {
			d->need_errmsg = 1;
			goto done;
		}

		md = de_arch_create_md(c, d);
		md->member_hdr_pos = pos;
		md->member_hdr_size = 54;

		de_dbg(c, "member at %"I64_FMT, md->member_hdr_pos);
		de_dbg_indent(c, 1);

		d->inf = f2;
		f2_pos = 0;

		de_arch_read_field_dttm_p(d, &md->fi->timestamp[DE_TIMESTAMPIDX_MODIFY], "mod",
			DE_ARCH_TSTYPE_DOS_DT, &f2_pos);
		de_arch_read_field_cmpr_len_p(md, &f2_pos);
		de_arch_read_field_orig_len_p(md, &f2_pos);

		crc1_reported = (u32)dbuf_getu16be_p(f2, &f2_pos);
		de_dbg(c, "crc of cmpr. data (reported): 0x%04x", (UI)crc1_reported);
		md->crc_reported = (u32)dbuf_getu16be_p(f2, &f2_pos);
		de_dbg(c, "crc of orig. data (reported): 0x%04x", (UI)md->crc_reported);

		md->cmpr_meth = (UI)dbuf_getbyte_p(f2, &f2_pos);
		de_dbg(c, "cmpr. method: %u", md->cmpr_meth);
		d->inf = c->infile;

		pos = md->member_hdr_pos + 34;
		// TODO: How long is the filename field?
		dbuf_read_to_ucstring(c->infile, pos, 12, md->filename, DE_CONVFLAG_STOP_AT_NUL,
			d->input_encoding);
		de_dbg(c, "filename: \"%s\"", ucstring_getpsz_d(md->filename));

		md->cmpr_pos = md->member_hdr_pos + md->member_hdr_size;
		de_dbg(c, "compressed data at %"I64_FMT", len=%"I64_FMT, md->cmpr_pos, md->cmpr_len);

		md->validate_crc = 1;
		if(md->cmpr_meth==1) {
			md->dfn = noncompressed_decompressor_fn;
			de_arch_extract_member_file(md);
		}
		else if(md->cmpr_meth==2) {
			md->dfn = lif_method2_decompressor_fn;
			de_arch_extract_member_file(md);
		}
		else {
			de_err(c, "Unsupported compression: %u", (UI)md->cmpr_meth);
		}

		de_dbg_indent(c, -1);
		pos = md->cmpr_pos + md->cmpr_len;
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
	if(md) {
		de_arch_destroy_md(c, md);
		md = NULL;
	}
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Bad or unsupported LIF file");
		}
		de_arch_destroy_lctx(c, d);
	}
	dbuf_close(f2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
callq 0x17c220
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xd, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movl $0x23, %esi
callq 0x15eac0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movl $0x11, %esi
xorl %edx, %edx
callq 0x168020
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x9fc74
jmp 0x9ff3e
cmpq $0x0, -0x28(%rbp)
je 0x9fc90
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x17c1a0
movq $0x0, -0x28(%rbp)
movq -0x30(%rbp), %rdi
callq 0x169310
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0xa3aa0
cmpl $0x0, %eax
jne 0x9fcbc
movq -0x18(%rbp), %rax
movb $0x1, 0x14(%rax)
jmp 0x9ff3e
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x17c120
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq $0x36, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x12769a(%rip), %rsi    # 0x1c7392
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rsi
addq $0x18, %rsi
leaq 0x1041bb(%rip), %rdx    # 0x1a3ef3
movl $0x3, %ecx
leaq -0x40(%rbp), %r8
callq 0x17c580
movq -0x28(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x17c400
movq -0x28(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x17c350
movq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165210
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %edx
leaq 0x111edd(%rip), %rsi    # 0x1b1c5b
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165210
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x48(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x48(%rax), %edx
leaq 0x111ed3(%rip), %rsi    # 0x1b1c80
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165170
movzbl %al, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x90(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x90(%rax), %edx
leaq 0x111906(%rip), %rsi    # 0x1b16e9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
addq $0x22, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x18(%rbp), %rax
movl 0x18(%rax), %r9d
movl $0xc, %edx
movl $0x1, %r8d
callq 0x1669f0
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x172650
movq -0x50(%rbp), %rdi
movq %rax, %rdx
leaq 0x12772a(%rip), %rsi    # 0x1c7583
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x28(%rbp), %rax
addq 0x20(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rdx
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
leaq 0x111bd5(%rip), %rsi    # 0x1b1a68
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
movb $0x1, 0xa1(%rax)
movq -0x28(%rbp), %rax
cmpl $0x1, 0x90(%rax)
jne 0x9fecf
movq -0x28(%rbp), %rax
leaq 0x2883(%rip), %rcx      # 0xa2740
movq %rcx, 0xa8(%rax)
movq -0x28(%rbp), %rdi
callq 0x17c920
jmp 0x9ff17
movq -0x28(%rbp), %rax
cmpl $0x2, 0x90(%rax)
jne 0x9fef9
movq -0x28(%rbp), %rax
leaq 0x3c99(%rip), %rcx      # 0xa3b80
movq %rcx, 0xa8(%rax)
movq -0x28(%rbp), %rdi
callq 0x17c920
jmp 0x9ff15
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x90(%rax), %edx
leaq 0xff874(%rip), %rsi     # 0x19f782
movb $0x0, %al
callq 0x15bfb0
jmp 0x9ff17
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x28(%rbp), %rcx
addq 0x30(%rcx), %rax
movq %rax, -0x20(%rbp)
jmp 0x9fc5d
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x15b5a0
cmpq $0x0, -0x28(%rbp)
je 0x9ff66
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x17c1a0
movq $0x0, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x9ff96
movq -0x18(%rbp), %rax
cmpb $0x0, 0x14(%rax)
je 0x9ff89
movq -0x8(%rbp), %rdi
leaq 0x111d23(%rip), %rsi    # 0x1b1ca5
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x17c270
movq -0x30(%rbp), %rdi
callq 0x1676a0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)