// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rdi, %rbx
callq 0xfd4b2
movq %rax, %r14
movl $0x1, 0x10(%rax)
leaq 0x3(%rsp), %rsi
movq %rbx, %rdi
callq 0x71acf
movl %eax, 0x58(%r14)
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jae 0x6f268
leaq 0xaa6a7(%rip), %rsi     # 0x1198a4
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
xorl %eax, %eax
cmpl $0x2, 0x58(%r14)
sete %al
movq 0x18(%rbx), %rdi
leaq 0xe(,%rax,2), %rsi
callq 0xeebc8
movq %rax, 0x20(%r14)
leaq 0xb70bf(%rip), %rsi     # 0x1262ee
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb220
movl %eax, 0x18(%r14)
xorl %eax, %eax
cmpl $0x2, 0x58(%r14)
sete %cl
cmpb $0x0, 0x3(%rsp)
je 0x6f293
leaq 0xb709e(%rip), %rsi     # 0x126304
jmp 0x6f26f
leaq 0xb706a(%rip), %rsi     # 0x1262d9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfd4cd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x20(%r14)
jle 0x6f279
movb %cl, %al
leaq 0x38(,%rax,2), %r12
xorl %r15d, %r15d
xorl %edx, %edx
leaq 0x30(%r12), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x6f464
movq %rdx, 0x8(%rsp)
testq %r15, %r15
je 0x6f2d1
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfd460
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfd414
movq %rax, %r15
movq %r12, 0x18(%rax)
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0xe8a1c
movq 0x18(%r15), %r13
movq %rbx, %rdi
leaq 0xcc85f(%rip), %rsi     # 0x13bb5d
movq %r13, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl 0x18(%r14), %r9d
cmpl $0x2, 0x58(%r14)
movl $0xe, %ebp
movl $0x80, %eax
cmoveq %rax, %rbp
movq 0x18(%rbx), %rdi
movq 0x58(%r15), %rcx
movq %r13, %rsi
movq %rbp, %rdx
movl $0x1, %r8d
callq 0xefbd7
movq 0x58(%r15), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0xcc9f6(%rip), %rsi     # 0x13bd4e
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movl $0x6, %eax
cmpl $0x2, 0x58(%r14)
jne 0x6f390
movq 0x58(%r15), %rdi
xorl %esi, %esi
callq 0xfd4f8
orb $0x1, 0x78(%r15)
xorl %eax, %eax
cmpl $0x2, 0x58(%r14)
sete %al
leaq 0x6(,%rax,2), %rax
addq %r13, %rbp
addq %rax, %rbp
movq %rbp, 0x10(%rsp)
movq %r15, %rdi
leaq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0xfd57d
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 0xa8e08(%rip), %rdx     # 0x1181d6
movq %r13, %r8
callq 0xfd638
cmpl $0x2, 0x58(%r14)
movl $0x30, %edx
movl $0xa8, %eax
cmoveq %rax, %rdx
addq 0x18(%r15), %rdx
movq %rdx, 0x40(%r15)
movq 0x30(%r15), %rcx
movq %rbx, %rdi
leaq 0xb6e2c(%rip), %rsi     # 0x12622b
xorl %eax, %eax
callq 0xe8617
movq %r15, %rdi
callq 0xfd7af
testl %eax, %eax
je 0x6f47f
movq 0x30(%r15), %rax
addq 0x40(%r15), %rax
subq 0x18(%r15), %rax
movq %rax, 0x28(%r15)
leaq 0x21cc(%rip), %rax      # 0x715f5
movq %rax, 0xa8(%r15)
movq %r15, %rdi
callq 0xfd85e
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq 0x28(%r15), %rax
testq %rax, %rax
movq 0x8(%rsp), %rdx
jle 0x6f48b
addq %rax, %r12
incq %rdx
cmpq 0x20(%r14), %rdx
jl 0x6f2a9
jmp 0x6f48b
leaq 0xa38a9(%rip), %rsi     # 0x112d14
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
testq %r15, %r15
jne 0x6f48b
jmp 0x6f279
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfd460
jmp 0x6f279