// File: /workspace/github_c_makefile_star2_O3/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 $0xd8, %rsp
movl %esi, %ebp
movq %rdi, %rbx
callq 0xfd4b2
movq %rax, %r13
movq %rax, %r14
movl $0x1, 0x10(%rax)
cmpl $0x2, %ebp
jne 0x9dff9
addq $0x54, %r13
movl $0xfffd, 0x54(%r14)     # imm = 0xFFFD
jmp 0x9e033
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xeebc8
movl %eax, 0x54(%r14)
leal -0xfffe(%rax), %ecx
cmpl $0x2, %ecx
jb 0x9e028
cmpl $0xa14, %eax            # imm = 0xA14
je 0x9e028
cmpl $0x1400, %eax           # imm = 0x1400
jne 0x9e6ff
addq $0x54, %r13
cmpl $0xfffd, %eax           # imm = 0xFFFD
jne 0x9e04b
leaq 0x93dc9(%rip), %rsi     # 0x131e03
movq %rbx, %rdi
callq 0xeb125
leaq 0x93dcd(%rip), %rax     # 0x131e16
jmp 0x9e065
leaq 0x93dca(%rip), %rsi     # 0x131e1c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xeb152
leaq 0xae0b2(%rip), %rax     # 0x14c117
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb220
movl %eax, 0x18(%r14)
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %r13, 0x28(%rsp)
leaq 0xa(%r12), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jg 0x9e6a9
cmpl $0xfffd, 0x54(%r14)     # imm = 0xFFFD
movq 0x8(%r14), %rdi
movq %r12, %rsi
jne 0x9e183
callq 0x9e712
movl %eax, %ecx
testl %ecx, %ecx
je 0x9e6a9
testq %rbp, %rbp
je 0x9e0ce
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xfd460
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfd414
movq %rax, %rbp
movq %r12, 0x18(%rax)
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
callq 0xe8a1c
movq 0x18(%rbp), %rdx
movq %rbx, %rdi
leaq 0x9da62(%rip), %rsi     # 0x13bb5d
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rbp), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0x7a0a8(%rip), %rdx     # 0x1181d6
movl $0x3, %ecx
leaq 0x10(%rsp), %r15
movq %r15, %r8
callq 0xfd638
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb4b
movzbl %al, %esi
movq %rbp, %rdi
callq 0xfd5bd
movl 0x54(%r14), %eax
cmpl $0xa14, %eax            # imm = 0xA14
je 0x9e170
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x9e1b8
cmpl $0x1400, %eax           # imm = 0x1400
jne 0x9e1d4
incq 0x10(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x9e266
callq 0xeed0d
cmpl $0xa5960014, %eax       # imm = 0xA5960014
je 0x9e0be
cmpl $0xa596feff, %eax       # imm = 0xA596FEFF
je 0x9e0be
cmpl $0xa596ffff, %eax       # imm = 0xA596FFFF
je 0x9e0be
xorl %ecx, %ecx
cmpl $0xa596140a, %eax       # imm = 0xA596140A
sete %cl
jmp 0x9e0b6
movq 0x10(%rsp), %rdx
addq $0x6, %rdx
movq %rdx, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x9e2fe
addq $0x3, 0x10(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0xeed83
movq %rbx, %rdi
leaq 0x93c71(%rip), %rsi     # 0x131e66
movq %rax, 0x18(%rsp)
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbp, %rdi
movq %r15, %rsi
callq 0xfd538
cmpl $0xfffe, (%r13)         # imm = 0xFFFE
jne 0x9e22c
cmpq $0x1, 0x38(%rbp)
jne 0x9e22c
movq $0x0, 0x38(%rbp)
movb $0x0, 0x4c(%rbp)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xeed83
movq %rax, 0x98(%rbp)
movq %rbx, %rdi
leaq 0x93c2f(%rip), %rsi     # 0x131e7a
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
cmpq $0x0, 0x98(%rbp)
je 0x9e266
movb $0x1, 0xa0(%rbp)
movl (%r13), %eax
cmpl $0xfffd, %eax           # imm = 0xFFFD
jne 0x9e2de
addq $0x7, 0x10(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0xeebeb
movq %rbx, %rdi
leaq 0x93bfd(%rip), %rsi     # 0x131e8f
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
movq %rbx, %rdi
leaq 0x93be7(%rip), %rsi     # 0x131e98
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeed83
movq %rbx, %rdi
leaq 0x93bd1(%rip), %rsi     # 0x131ea1
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movl (%r13), %eax
movl $0xd, %r15d
cmpl $0xa14, %eax            # imm = 0xA14
je 0x9e344
cmpl $0x1400, %eax           # imm = 0x1400
je 0x9e344
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x9e333
movq 0x10(%rsp), %rdx
movq $0x0, 0x78(%rsp)
movq 0x18(%rbx), %rdi
movl $0x104, %ecx            # imm = 0x104
xorl %esi, %esi
leaq 0x78(%rsp), %r8
callq 0xefa77
testl %eax, %eax
je 0x9e3d7
movq 0x78(%rsp), %r15
subq 0x10(%rsp), %r15
incq %r15
jmp 0x9e344
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xeebeb
movq %rax, %r15
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x58(%rbp), %r8
movl 0x18(%r14), %eax
movl %eax, (%rsp)
movl $0x200, %ecx            # imm = 0x200
movq %r15, %rdx
movl $0x1, %r9d
callq 0xefc2a
movq 0x58(%rbp), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0x9d9d0(%rip), %rsi     # 0x13bd4e
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq %r15, 0x10(%rsp)
movq 0x58(%rbp), %rdi
xorl %esi, %esi
callq 0xfd4f8
orb $0x1, 0x78(%rbp)
movq 0x10(%rsp), %rdx
movq %rdx, 0x40(%rbp)
cmpb $0x0, 0xa0(%rbp)
je 0x9e3be
movq %rbp, %rcx
addq $0x98, %rcx
movq 0x18(%rbx), %rax
jmp 0x9e3c6
movq 0x18(%rbx), %rax
leaq 0x18(%rax), %rcx
movq (%rcx), %r15
cmpq 0x18(%rax), %r15
jle 0x9e418
movl $0x1, 0x38(%r14)
movb $0x1, 0x14(%r14)
movl 0x30(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
cmpl $0x0, 0x38(%r14)
jne 0x9e6ba
cmpb $0x0, 0xa0(%rbp)
je 0x9e6ba
movq 0x98(%rbp), %rax
cmpq %r12, %rax
movq %rax, %r12
jg 0x9e087
jmp 0x9e6b5
movq %r15, %rcx
subq %rdx, %rcx
movq %rcx, 0x30(%rbp)
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x9e49f
cmpq %rdx, %rax
jl 0x9e3cf
subq %rax, %r15
jl 0x9e3cf
movq %rax, %rcx
subq %rdx, %rcx
movq %rcx, 0x30(%rbp)
js 0x9e3cf
testq %r15, %r15
jle 0x9e4b0
movq %rbx, %rdi
leaq 0x93a5a(%rip), %rsi     # 0x131eab
movq %rax, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
cmpl $0xfffd, (%r13)         # imm = 0xFFFD
jne 0x9e485
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x9e75a
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x30(%rbp), %rcx
movq 0x40(%rbp), %rdx
movb $0x1, %r13b
jmp 0x9e4b3
testq %rcx, %rcx
js 0x9e3cf
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x9e4b3
xorl %r13d, %r13d
movq %rbx, %rdi
leaq 0x93a0e(%rip), %rsi     # 0x131ecb
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x28(%rsp), %rax
movl (%rax), %eax
cmpl $0xfffd, %eax           # imm = 0xFFFD
jne 0x9e4f6
movq 0x30(%rbp), %rdx
movq 0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x9e75a
movq 0x28(%rsp), %rax
movl (%rax), %eax
leal -0xfffe(%rax), %ecx
cmpl $0x2, %ecx
jb 0x9e513
cmpl $0x1400, %eax           # imm = 0x1400
je 0x9e513
cmpl $0xa14, %eax            # imm = 0xA14
jne 0x9e692
leaq 0x282(%rip), %rax       # 0x9e79c
movq %rax, 0xa8(%rbp)
movq %rbp, %rdi
callq 0xfd85e
cmpq $0x0, 0x18(%rsp)
setle %al
xorb $0x1, %r13b
orb %al, %r13b
jne 0x9e692
movq %rbx, %rdi
leaq 0x34(%rsp), %rsi
callq 0xe8a1c
movq %rbx, %rdi
leaq 0x9399f(%rip), %rsi     # 0x131ef5
movq 0x18(%rsp), %rdx
movq %rdx, 0x18(%rsp)
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf09c5
movq %rax, 0x38(%rsp)
movl $0x100000, %esi         # imm = 0x100000
movq %rax, %rdi
callq 0xf0a7c
movq %rbx, %rdi
leaq 0x58(%rsp), %r13
movq %r13, %rsi
leaq 0x40(%rsp), %rdx
leaq 0x78(%rsp), %rcx
callq 0xfa1dc
movq 0x18(%rbx), %rax
movq %rax, 0x58(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %r15, 0x68(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %r13
leaq 0x40(%rsp), %rdx
leaq 0x78(%rsp), %rcx
xorl %r8d, %r8d
callq 0x103713
movq %r13, %rdi
callq 0xf08ba
cmpl $0x0, 0x78(%rsp)
je 0x9e60e
movq %rbx, %rdi
leaq 0x93905(%rip), %rsi     # 0x131f07
xorl %eax, %eax
callq 0xe8faa
xorl %r15d, %r15d
jmp 0x9e673
movq 0x18(%r13), %rdx
movq %rbx, %rdi
leaq 0x7f7db(%rip), %rsi     # 0x11ddf7
xorl %eax, %eax
callq 0xe8617
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r15
leaq 0xadbac(%rip), %rax     # 0x14c1e6
movq %rax, (%r15)
movq 0x58(%rbp), %rdi
callq 0xf67a3
testl %eax, %eax
je 0x9e657
movq 0x58(%rbp), %rax
movq %rax, 0x30(%r15)
orb $0x8, 0x8(%r15)
movq 0x18(%r13), %r9
movq %rbx, %rdi
leaq 0x84340(%rip), %rsi     # 0x1229a5
movq %r15, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xe9aa3
movq %r13, %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe8be2
movl 0x34(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x28(%rsp), %r13
jmp 0x9e3dc
movb $0x1, 0x14(%r14)
testq %rbp, %rbp
jne 0x9e6ba
jmp 0x9e6cc
movb $0x1, 0x14(%r14)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xfd460
cmpb $0x0, 0x14(%r14)
je 0x9e6e2
leaq 0x93769(%rip), %rsi     # 0x131e3c
movq %rbx, %rdi
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfd4cd
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, 0x14(%r14)
leaq 0xada0c(%rip), %rax     # 0x14c117
movq %rax, 0x20(%rsp)
jmp 0x9e6cc