// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/os2pack.c
// Function: do_run_os2pack12
static void do_run_os2pack12(deark *c, de_module_params *mparams, UI ver)
{
	de_arch_lctx *d = NULL;
	struct de_arch_member_data *md = NULL;
	i64 pos;
	const char *pname = "PACK";

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

	if(ver==2) {
		d->fmtcode = 0xfffd;
	}
	else {
		d->fmtcode = (UI)de_getu16le(2);
		if(d->fmtcode!=0x1400 && d->fmtcode!=0x0a14 && d->fmtcode!=0xffff &&
			d->fmtcode!=0xfffe)
		{
			d->need_errmsg = 1;
			goto done;
		}
	}

	if(d->fmtcode==0xfffd) {
		pname = "PACK2";
		de_declare_fmt(c, "OS/2 PACK2 archive");
	}
	else {
		de_declare_fmtf(c, "OS/2 PACK archive (type 0x%04x)", d->fmtcode);
	}

	// TODO: What encoding to use?
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_WINDOWS1252);

	pos = 0;

	while(1) {
		if(pos+OS2PACK_MINHEADERLEN > c->infile->len) {
			d->need_errmsg = 1;
			goto done;
		}

		if(!os2pack12_is_member_at(d, pos)) {
			d->need_errmsg = 1;
			goto done;
		}

		if(md) {
			de_arch_destroy_md(c, md);
			md = NULL;
		}
		md = de_arch_create_md(c, d);
		md->member_hdr_pos = pos;

		do_os2pack12_member(c, d, md);

		if(d->fatalerrflag) goto done;
		if(!md->next_member_exists) goto done;
		if(md->next_member_pos <= pos) {
			d->need_errmsg = 1;
			goto done;
		}
		pos = md->next_member_pos;
	}

done:
	if(md) {
		de_arch_destroy_md(c, md);
		md = NULL;
	}
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Bad or unsupported OS/2 %s archive", pname);
		}
		de_arch_destroy_lctx(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %esi, %ebp
movq %rdi, %rbx
callq 0xfdb0a
movq %rax, %r14
movl $0x1, 0x10(%rax)
cmpl $0x2, %ebp
jne 0x9e812
movl $0xfffd, 0x54(%r14)     # imm = 0xFFFD
jmp 0x9e841
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xef1ca
movl %eax, 0x54(%r14)
leal -0xfffe(%rax), %ecx
cmpl $0x2, %ecx
jb 0x9e841
cmpl $0x1400, %eax           # imm = 0x1400
je 0x9e841
cmpl $0xa14, %eax            # imm = 0xA14
jne 0x9eec1
movl 0x54(%r14), %edx
cmpl $0xfffd, %edx           # imm = 0xFFFD
jne 0x9e865
leaq 0x9322b(%rip), %rsi     # 0x131a7f
movq %rbx, %rdi
callq 0xeb6d6
leaq 0x9322f(%rip), %rax     # 0x131a92
jmp 0x9e87d
leaq 0x9322c(%rip), %rsi     # 0x131a98
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb703
leaq 0xad27a(%rip), %rax     # 0x14baf7
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb7d1
movl %eax, 0x18(%r14)
xorl %r12d, %r12d
xorl %ebp, %ebp
leaq 0xa(%rbp), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jg 0x9eed0
cmpl $0xfffd, 0x54(%r14)     # imm = 0xFFFD
jne 0x9e98e
movq 0x8(%r14), %rdi
movq %rbp, %rsi
callq 0x9ef24
testl %eax, %eax
je 0x9eed0
testq %r12, %r12
je 0x9e8de
movq %rbx, %rdi
movq %r12, %rsi
callq 0xfdab8
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfda6c
movq %rax, %r12
movq %rbp, 0x18(%rax)
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
callq 0xe958c
movq 0x18(%r12), %rdx
movq %rbx, %rdi
leaq 0x9ced7(%rip), %rsi     # 0x13b7e3
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%r12), %rax
addq $0x4, %rax
movq %rax, 0x10(%rsp)
movq 0x50(%r12), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0x7975d(%rip), %rdx     # 0x11809e
movl $0x3, %ecx
leaq 0x10(%rsp), %r15
movq %r15, %r8
callq 0xfdc9b
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %esi
movq %r12, %rdi
callq 0xfdc20
movl 0x54(%r14), %eax
cmpl $0xa14, %eax            # imm = 0xA14
je 0x9e987
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x9e9d6
cmpl $0x1400, %eax           # imm = 0x1400
jne 0x9eaba
incq 0x10(%rsp)
jmp 0x9e9dc
movq 0x8(%r14), %rdi
movq %rbp, %rsi
callq 0xef32a
movq %rax, %rcx
movl $0x1, %eax
cmpl $0xa5960014, %ecx       # imm = 0xA5960014
je 0x9e8c6
cmpl $0xa596feff, %ecx       # imm = 0xA596FEFF
je 0x9e8c6
cmpl $0xa596ffff, %ecx       # imm = 0xA596FFFF
je 0x9e8c6
xorl %eax, %eax
cmpl $0xa596140a, %ecx       # imm = 0xA596140A
sete %al
jmp 0x9e8c6
addq $0x6, 0x10(%rsp)
xorl %r15d, %r15d
cmpl $0xfffd, 0x54(%r14)     # imm = 0xFFFD
jne 0x9ea52
addq $0x7, 0x10(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0xef1ed
movq %rbx, %rdi
leaq 0x93101(%rip), %rsi     # 0x131b0b
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ed
movq %rbx, %rdi
leaq 0x930eb(%rip), %rsi     # 0x131b14
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef3a0
movq %rbx, %rdi
leaq 0x930d5(%rip), %rsi     # 0x131b1d
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movl 0x54(%r14), %eax
movl $0xd, %r13d
cmpl $0xa14, %eax            # imm = 0xA14
je 0x9eb7b
cmpl $0x1400, %eax           # imm = 0x1400
je 0x9eb7b
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x9eb5b
movq $0x0, 0x68(%rsp)
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rdx
movl $0x104, %ecx            # imm = 0x104
xorl %esi, %esi
leaq 0x68(%rsp), %r8
callq 0xf0057
testl %eax, %eax
je 0x9eb6e
movq 0x68(%rsp), %r13
subq 0x10(%rsp), %r13
incq %r13
jmp 0x9eb73
addq $0x3, 0x10(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0xef3a0
movq %rax, %r15
movq %rbx, %rdi
leaq 0x93004(%rip), %rsi     # 0x131ae2
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %r12, %rdi
movq %r13, %rsi
callq 0xfdb9b
cmpl $0xfffe, 0x54(%r14)     # imm = 0xFFFE
jne 0x9eb14
cmpq $0x1, 0x38(%r12)
jne 0x9eb14
movq $0x0, 0x38(%r12)
movb $0x0, 0x4c(%r12)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xef3a0
movq %rax, 0x98(%r12)
movq %rbx, %rdi
leaq 0x92fc2(%rip), %rsi     # 0x131af6
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpq $0x0, 0x98(%r12)
je 0x9e9df
movb $0x1, 0xa0(%r12)
jmp 0x9e9df
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xef1ed
movq %rax, %r13
jmp 0x9eb7b
movb $0x1, 0x14(%r14)
testl %eax, %eax
je 0x9ee8d
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x58(%r12), %r8
movl 0x18(%r14), %eax
movl %eax, (%rsp)
movl $0x200, %ecx            # imm = 0x200
movq %r13, %rdx
movl $0x1, %r9d
callq 0xf0203
movq 0x58(%r12), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0x9ce1d(%rip), %rsi     # 0x13b9d4
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq %r13, 0x10(%rsp)
movq 0x58(%r12), %rdi
xorl %esi, %esi
callq 0xfdb50
orb $0x1, 0x78(%r12)
movq 0x10(%rsp), %rax
movq %rax, 0x40(%r12)
cmpb $0x0, 0xa0(%r12)
je 0x9ebf9
movq %r12, %rcx
addq $0x98, %rcx
jmp 0x9ec01
movq 0x18(%rbx), %rcx
addq $0x18, %rcx
movq (%rcx), %r13
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %r13
jg 0x9ede8
movq %r13, %rcx
subq %rax, %rcx
movq %rcx, 0x30(%r12)
testq %r15, %r15
je 0x9ec3e
movq %r15, %rcx
subq %rax, %rcx
jl 0x9ede8
subq %r15, %r13
jl 0x9ede8
movq %rcx, 0x30(%r12)
jmp 0x9ec41
xorl %r13d, %r13d
cmpq $0x0, 0x30(%r12)
js 0x9ede8
testq %r13, %r13
jle 0x9ec9b
movq %rbx, %rdi
leaq 0x92ecb(%rip), %rsi     # 0x131b27
movq %r15, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
cmpl $0xfffd, 0x54(%r14)     # imm = 0xFFFD
jne 0x9ec8e
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x9ef6c
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x30(%r12), %rcx
movq 0x40(%r12), %rdx
movq %rbx, %rdi
leaq 0x92e98(%rip), %rsi     # 0x131b47
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
cmpl $0xfffd, 0x54(%r14)     # imm = 0xFFFD
jne 0x9ecdf
movq 0x30(%r12), %rdx
movq 0x40(%r12), %rsi
movq %rbx, %rdi
callq 0x9ef6c
movl 0x54(%r14), %eax
leal -0xfffe(%rax), %ecx
cmpl $0x2, %ecx
jb 0x9ed00
cmpl $0x1400, %eax           # imm = 0x1400
je 0x9ed00
cmpl $0xa14, %eax            # imm = 0xA14
jne 0x9ee80
leaq 0x2a7(%rip), %rax       # 0x9efae
movq %rax, 0xa8(%r12)
movq %r12, %rdi
callq 0xfdec1
testq %r15, %r15
jle 0x9ee80
testq %r13, %r13
jle 0x9ee80
movq %rbx, %rdi
leaq 0x24(%rsp), %rsi
callq 0xe958c
movq %rbx, %rdi
leaq 0x92e31(%rip), %rsi     # 0x131b71
movq %r15, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf0faf
movq %rax, 0x28(%rsp)
movl $0x100000, %esi         # imm = 0x100000
movq %rax, %rdi
callq 0xf1066
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0x68(%rsp), %rcx
callq 0xfa6e0
movq 0x18(%rbx), %rax
movq %rax, 0x30(%rsp)
movq %r15, 0x38(%rsp)
movq %r13, 0x40(%rsp)
movq 0x28(%rsp), %r13
movq %r13, 0x50(%rsp)
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0x68(%rsp), %rcx
xorl %r8d, %r8d
callq 0x103b56
movq %r13, %rdi
callq 0xf0ea4
cmpl $0x0, 0x68(%rsp)
je 0x9edfa
movq %rbx, %rdi
leaq 0x92da7(%rip), %rsi     # 0x131b83
xorl %eax, %eax
callq 0xe9b27
xorl %r15d, %r15d
jmp 0x9ee61
movl $0x1, 0x38(%r14)
movb $0x1, 0x14(%r14)
jmp 0x9ee8d
movq 0x18(%r13), %rdx
movq %rbx, %rdi
leaq 0x7eedf(%rip), %rsi     # 0x11dce7
xorl %eax, %eax
callq 0xe9226
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r15
leaq 0xacda0(%rip), %rax     # 0x14bbc6
movq %rax, (%r15)
movq 0x58(%r12), %rdi
callq 0xf6c00
testl %eax, %eax
je 0x9ee45
movq 0x58(%r12), %rax
movq %rax, 0x30(%r15)
orb $0x8, 0x8(%r15)
movq 0x18(%r13), %r9
movq %rbx, %rdi
leaq 0x8394a(%rip), %rsi     # 0x12279d
movq %r15, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xea5fa
movq %r13, %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
movl 0x24(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movl 0x20(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
cmpl $0x0, 0x38(%r14)
jne 0x9eed5
cmpb $0x0, 0xa0(%r12)
je 0x9eed5
movq 0x98(%r12), %rax
cmpq %rbp, %rax
movq %rax, %rbp
jg 0x9e89a
jmp 0x9eed0
leaq 0xacc2f(%rip), %rax     # 0x14baf7
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
movb $0x1, 0x14(%r14)
testq %r12, %r12
je 0x9eee5
movq %rbx, %rdi
movq %r12, %rsi
callq 0xfdab8
testq %r14, %r14
je 0x9ef12
cmpb $0x0, 0x14(%r14)
je 0x9ef07
leaq 0x92bc0(%rip), %rsi     # 0x131ab8
movq %rbx, %rdi
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfdb25
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq