// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/misc3.c
// Function: de_run_pcshrink
static void de_run_pcshrink(deark *c, de_module_params *mparams)
{
	de_arch_lctx *d = NULL;
	i64 pos = 0;
	i64 idx;
	u8 multipart_flag;
	struct de_arch_member_data *md = NULL;

	d = de_arch_create_lctx(c);
	d->is_le = 1;

	// Detect version
	d->fmtver = detect_pcshrink_internal(c, &multipart_flag);
	if(d->fmtver!=1 && d->fmtver!=2) {
		de_err(c, "Not a PC-Shrink file");
		goto done;
	}
	de_dbg(c, "format version: %d", d->fmtver);

	// Read archive header
	if(d->fmtver==2) {
		d->num_members = de_getu16le(16);
	}
	else {
		d->num_members = de_getu16le(14);
	}
	de_dbg(c, "number of members: %d", (int)d->num_members);

	// TODO: Can we tell Windows files from DOS files?
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_CP437);

	if(d->fmtver==2) {
		pos = 58;
	}
	else {
		pos = 56;
	}

	if(multipart_flag) {
		de_err(c, "Multi-part PC-Shrink files are not supported");
		goto done;
	}

	for(idx=0; idx<d->num_members; idx++) {
		if(pos+PCSHRINK_MINHEADERLEN >= c->infile->len) {
			de_err(c, "Unexpected end of file");
			goto done;
		}

		if(md) {
			de_arch_destroy_md(c, md);
			md = NULL;
		}
		md = de_arch_create_md(c, d);
		md->member_hdr_pos = pos;
		if(!do_pcshrink_member(c, d, md)) goto done;
		if(md->member_total_size<=0) goto done;
		pos += md->member_total_size;
	}

done:
	if(md) {
		de_arch_destroy_md(c, md);
		md = NULL;
	}
	if(d) {
		de_arch_destroy_lctx(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
callq 0xf16ce
movq %rax, %r14
movl $0x1, 0x10(%rax)
leaq 0xb(%rsp), %rsi
movq %rbx, %rdi
callq 0x6dc23
movl %eax, 0x58(%r14)
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jae 0x6b47d
leaq 0xa1396(%rip), %rsi     # 0x10c7b4
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
xorl %eax, %eax
cmpl $0x2, 0x58(%r14)
sete %al
movq 0x18(%rbx), %rdi
leaq 0xe(,%rax,2), %rsi
callq 0xe3fa3
movq %rax, 0x20(%r14)
leaq 0xadc9e(%rip), %rsi     # 0x1190ee
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
pushq $0xd
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x18(%r14)
cmpb $0x0, 0xb(%rsp)
je 0x6b4a8
leaq 0xadc89(%rip), %rsi     # 0x119104
jmp 0x6b484
leaq 0xadc55(%rip), %rsi     # 0x1190d9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf16e7
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
cmpl $0x2, 0x58(%r14)
sete %al
leaq 0x38(,%rax,2), %r12
xorl %edx, %edx
xorl %r15d, %r15d
pushq $0x1
popq %r13
cmpq 0x20(%r14), %rdx
jge 0x6b691
leaq 0x30(%r12), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x6b680
movq %rdx, 0x10(%rsp)
testq %r15, %r15
je 0x6b4f5
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf167c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf1630
movq %rax, %r15
movq %r12, 0x18(%rsp)
movq %r12, 0x18(%rax)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0xdebae
movq 0x18(%r15), %r12
movq %rbx, %rdi
leaq 0xc3346(%rip), %rsi     # 0x12e86d
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movl %r13d, %esi
callq 0xdeba7
movl 0x18(%r14), %r9d
cmpl $0x2, 0x58(%r14)
pushq $0xe
popq %rbp
movl $0x80, %eax
cmoveq %rax, %rbp
movq 0x18(%rbx), %rdi
movq 0x58(%r15), %rcx
movq %r12, %rsi
movq %rbp, %rdx
movl %r13d, %r8d
callq 0xe4c9a
movq 0x58(%r15), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0xc34e4(%rip), %rsi     # 0x12ea5e
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
cmpl $0x2, 0x58(%r14)
pushq $0x6
popq %rax
jne 0x6b5b0
movq 0x58(%r15), %rdi
xorl %esi, %esi
callq 0xf1712
orb $0x1, 0x78(%r15)
xorl %eax, %eax
cmpl $0x2, 0x58(%r14)
sete %al
leaq 0x6(,%rax,2), %rax
addq %r12, %rbp
addq %rax, %rbp
movq %rbp, 0x20(%rsp)
movq %r15, %rdi
leaq 0x20(%rsp), %r12
movq %r12, %rsi
callq 0xf17ab
xorl %eax, %eax
cmpl $0x2, 0x58(%r14)
sete %al
movq 0x50(%r15), %rsi
addq $0x18, %rsi
leal 0x3(,%rax,2), %ecx
movq %r14, %rdi
leaq 0x9faf8(%rip), %rdx     # 0x10b0e6
movq %r12, %r8
callq 0xf1866
cmpl $0x2, 0x58(%r14)
pushq $0x30
popq %rdx
movl $0xa8, %eax
cmoveq %rax, %rdx
addq 0x18(%r15), %rdx
movq %rdx, 0x40(%r15)
movq 0x30(%r15), %rcx
movq %rbx, %rdi
leaq 0xada0e(%rip), %rsi     # 0x11902b
xorl %eax, %eax
callq 0xde896
movq %r15, %rdi
callq 0xf19d5
testl %eax, %eax
je 0x6b69b
movq 0x30(%r15), %rax
addq 0x40(%r15), %rax
subq 0x18(%r15), %rax
movq %rax, 0x28(%r15)
leaq 0x20c6(%rip), %rax      # 0x6d70d
movq %rax, 0xa8(%r15)
movq %r15, %rdi
callq 0xf1a85
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq 0x28(%r15), %rax
testq %rax, %rax
jle 0x6b6a7
movq 0x18(%rsp), %r12
addq %rax, %r12
movq 0x10(%rsp), %rdx
incq %rdx
jmp 0x6b4c3
leaq 0x9a66d(%rip), %rsi     # 0x105cf4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
testq %r15, %r15
jne 0x6b6a7
jmp 0x6b48e
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf167c
jmp 0x6b48e