// File: /workspace/github_c_makefile_star2_O1/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 0xfdb0a
movq %rax, %r14
movl $0x1, 0x10(%rax)
leaq 0x7(%rsp), %rsi
movq %rbx, %rdi
callq 0x71d6e
movl %eax, 0x58(%r14)
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jae 0x6f498
leaq 0xaa357(%rip), %rsi     # 0x119784
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
xorl %eax, %eax
cmpl $0x2, 0x58(%r14)
sete %al
movq 0x18(%rbx), %rdi
leaq 0xe(,%rax,2), %rsi
callq 0xef1ca
movq %rax, 0x20(%r14)
leaq 0xb6c5f(%rip), %rsi     # 0x1260be
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb7d1
movl %eax, 0x18(%r14)
xorl %eax, %eax
cmpl $0x2, 0x58(%r14)
sete %cl
cmpb $0x0, 0x7(%rsp)
je 0x6f4db
leaq 0xb6c3e(%rip), %rsi     # 0x1260d4
jmp 0x6f49f
leaq 0xb6c0a(%rip), %rsi     # 0x1260a9
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
testq %r15, %r15
je 0x6f4bc
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfdab8
testq %r14, %r14
je 0x6f4cc
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfdb25
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x20(%r14)
jle 0x6f6bc
movb %cl, %al
leaq 0x38(,%rax,2), %rbp
xorl %r15d, %r15d
xorl %r12d, %r12d
leaq 0x30(%rbp), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x6f6c4
testq %r15, %r15
je 0x6f518
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfdab8
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfda6c
movq %rax, %r15
movq %rbp, 0x18(%rax)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe958c
movq 0x18(%r15), %rdx
movq %rdx, 0x8(%rsp)
movq %rbx, %rdi
leaq 0xcc299(%rip), %rsi     # 0x13b7e3
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
cmpl $0x2, 0x58(%r14)
movl $0xe, %r13d
movl $0x80, %eax
cmoveq %rax, %r13
movl 0x18(%r14), %r9d
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movq 0x58(%r15), %rcx
movq %r13, %rdx
movl $0x1, %r8d
callq 0xf01b0
movq 0x58(%r15), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0xcc430(%rip), %rsi     # 0x13b9d4
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpl $0x2, 0x58(%r14)
jne 0x6f5c5
movq 0x58(%r15), %rdi
xorl %esi, %esi
callq 0xfdb50
orb $0x1, 0x78(%r15)
movq 0x8(%rsp), %rax
leaq (%rax,%r13), %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
xorl %ecx, %ecx
cmpl $0x2, 0x58(%r14)
leaq (%rax,%r13), %rax
sete %cl
leaq (%rax,%rcx,2), %rax
addq $0x6, %rax
movq %rax, 0x8(%rsp)
movq %r15, %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0xfdbe0
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 0xa8a7a(%rip), %rdx     # 0x11809e
movq %r13, %r8
callq 0xfdc9b
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 0xb69a6(%rip), %rsi     # 0x125ffb
xorl %eax, %eax
callq 0xe9226
movq %r15, %rdi
callq 0xfde12
testl %eax, %eax
je 0x6f6d0
movq 0x30(%r15), %rax
addq 0x40(%r15), %rax
subq 0x18(%r15), %rax
movq %rax, 0x28(%r15)
leaq 0x2218(%rip), %rax      # 0x71897
movq %rax, 0xa8(%r15)
movq %r15, %rdi
callq 0xfdec1
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq 0x28(%r15), %rax
testq %rax, %rax
jle 0x6f4ac
addq %rax, %rbp
incq %r12
cmpq 0x20(%r14), %r12
jl 0x6f4f6
jmp 0x6f4ac
xorl %r15d, %r15d
jmp 0x6f4ac
leaq 0xa3639(%rip), %rsi     # 0x112d04
jmp 0x6f4a2
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
jmp 0x6f4ac