// File: /workspace/github_c_makefile_star2_O2/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 0xf16ce
movq %rax, %r13
movq %rax, %r14
movl $0x1, 0x10(%rax)
cmpl $0x2, %ebp
jne 0x983e9
addq $0x54, %r13
movl $0xfffd, 0x54(%r14)     # imm = 0xFFFD
jmp 0x98421
movq 0x18(%rbx), %rdi
pushq $0x2
popq %rsi
callq 0xe3fa3
movl %eax, 0x54(%r14)
leal -0xfffe(%rax), %ecx
cmpl $0x2, %ecx
jb 0x98416
cmpl $0xa14, %eax            # imm = 0xA14
je 0x98416
cmpl $0x1400, %eax           # imm = 0x1400
jne 0x98a93
addq $0x54, %r13
cmpl $0xfffd, %eax           # imm = 0xFFFD
jne 0x98439
leaq 0x8c6ef(%rip), %rsi     # 0x124b17
movq %rbx, %rdi
callq 0xe07f7
leaq 0x8c6f3(%rip), %rax     # 0x124b2a
jmp 0x98453
leaq 0x8c6f0(%rip), %rsi     # 0x124b30
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe0824
leaq 0xa67c4(%rip), %rax     # 0x13ec17
movq %rax, 0x20(%rsp)
pushq $0x9
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x18(%r14)
leaq 0x10(%rsp), %r15
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %r13, 0x28(%rsp)
leaq 0xa(%r12), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jg 0x98a44
cmpl $0xfffd, 0x54(%r14)     # imm = 0xFFFD
movq 0x8(%r14), %rdi
movq %r12, %rsi
jne 0x984a3
callq 0x98aa6
jmp 0x984a8
callq 0x98aec
testl %eax, %eax
je 0x98a44
testq %rbp, %rbp
je 0x984c0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xf167c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf1630
movq %rax, %rbp
movq %r12, 0x18(%rax)
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
callq 0xdebae
movq 0x18(%rbp), %rdx
movq %rbx, %rdi
leaq 0x96380(%rip), %rsi     # 0x12e86d
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rbp), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0x72bc8(%rip), %rdx     # 0x10b0e6
pushq $0x3
popq %rcx
movq %r15, %r8
callq 0xf1866
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %esi
movq %rbp, %rdi
callq 0xf17eb
movl 0x54(%r14), %eax
cmpl $0xa14, %eax            # imm = 0xA14
je 0x98559
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x9856c
cmpl $0x1400, %eax           # imm = 0x1400
jne 0x98588
incq 0x10(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x98610
movq 0x10(%rsp), %rdx
addq $0x6, %rdx
movq %rdx, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x9869d
addq $0x3, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe40bf
movq %rbx, %rdi
leaq 0x8c5d6(%rip), %rsi     # 0x124b7a
movq %rax, 0x18(%rsp)
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbp, %rdi
movq %r15, %rsi
callq 0xf1766
cmpl $0xfffe, (%r13)         # imm = 0xFFFE
jne 0x985d8
cmpq $0x1, 0x38(%rbp)
jne 0x985d8
andq $0x0, 0x38(%rbp)
movb $0x0, 0x4c(%rbp)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe40bf
movq %rax, 0x98(%rbp)
movq %rbx, %rdi
leaq 0x8c599(%rip), %rsi     # 0x124b8e
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
cmpq $0x0, 0x98(%rbp)
je 0x98610
movb $0x1, 0xa0(%rbp)
movl (%r13), %eax
cmpl $0xfffd, %eax           # imm = 0xFFFD
jne 0x98683
addq $0x7, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movq %rbx, %rdi
leaq 0x8c56c(%rip), %rsi     # 0x124ba3
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movq %rbx, %rdi
leaq 0x8c556(%rip), %rsi     # 0x124bac
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe40bf
movq %rbx, %rdi
leaq 0x8c540(%rip), %rsi     # 0x124bb5
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movl (%r13), %eax
cmpl $0xa14, %eax            # imm = 0xA14
je 0x986cf
cmpl $0x1400, %eax           # imm = 0x1400
je 0x986cf
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x986d5
movq 0x10(%rsp), %rdx
andq $0x0, 0x78(%rsp)
movq 0x18(%rbx), %rdi
movl $0x104, %ecx            # imm = 0x104
xorl %esi, %esi
leaq 0x78(%rsp), %r8
callq 0xe4b21
testl %eax, %eax
je 0x98802
movq 0x78(%rsp), %r15
subq 0x10(%rsp), %r15
incq %r15
jmp 0x986e4
pushq $0xd
popq %r15
jmp 0x986e4
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
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
pushq $0x1
popq %r9
callq 0xe4ced
movq 0x58(%rbp), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0x96342(%rip), %rsi     # 0x12ea5e
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq %r15, 0x10(%rsp)
movq 0x58(%rbp), %rdi
xorl %esi, %esi
callq 0xf1712
orb $0x1, 0x78(%rbp)
movq 0x10(%rsp), %rdx
movq %rdx, 0x40(%rbp)
cmpb $0x0, 0xa0(%rbp)
je 0x9875c
movq %rbp, %rcx
addq $0x98, %rcx
movq 0x18(%rbx), %rax
jmp 0x98764
movq 0x18(%rbx), %rax
leaq 0x18(%rax), %rcx
movq (%rcx), %r15
cmpq 0x18(%rax), %r15
jle 0x9877f
movl $0x1, 0x38(%r14)
movb $0x1, 0x14(%r14)
jmp 0x98a09
movq %r15, %rcx
subq %rdx, %rcx
movq %rcx, 0x30(%rbp)
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x9880c
cmpq %rdx, %rax
jl 0x9876d
subq %rax, %r15
jl 0x9876d
movq %rax, %rcx
subq %rdx, %rcx
movq %rcx, 0x30(%rbp)
js 0x9876d
testq %r15, %r15
jle 0x9881d
movq %rbx, %rdi
leaq 0x8c407(%rip), %rsi     # 0x124bbf
movq %rax, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
cmpl $0xfffd, (%r13)         # imm = 0xFFFD
jne 0x987ea
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x98b1d
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
movq 0x30(%rbp), %rcx
movq 0x40(%rbp), %rdx
movb $0x1, %r13b
jmp 0x98820
movb $0x1, 0x14(%r14)
jmp 0x98a0e
testq %rcx, %rcx
js 0x9876d
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x98820
xorl %r13d, %r13d
movq %rbx, %rdi
leaq 0x8c3b5(%rip), %rsi     # 0x124bdf
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x28(%rsp), %rax
movl (%rax), %eax
cmpl $0xfffd, %eax           # imm = 0xFFFD
jne 0x98861
movq 0x30(%rbp), %rdx
movq 0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x98b1d
movq 0x28(%rsp), %rax
movl (%rax), %eax
leal -0xfffe(%rax), %ecx
cmpl $0x2, %ecx
jb 0x9887e
cmpl $0x1400, %eax           # imm = 0x1400
je 0x9887e
cmpl $0xa14, %eax            # imm = 0xA14
jne 0x989f9
leaq 0x2d8(%rip), %rax       # 0x98b5d
movq %rax, 0xa8(%rbp)
movq %rbp, %rdi
callq 0xf1a85
cmpq $0x0, 0x18(%rsp)
setle %al
xorb $0x1, %r13b
orb %al, %r13b
jne 0x989f9
movq %rbx, %rdi
leaq 0x34(%rsp), %rsi
callq 0xdebae
movq %rbx, %rdi
leaq 0x8c348(%rip), %rsi     # 0x124c09
movq 0x18(%rsp), %rdx
movq %rdx, 0x18(%rsp)
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe59cd
movq %rax, 0x38(%rsp)
movl $0x100000, %esi         # imm = 0x100000
movq %rax, %rdi
callq 0xe5a74
movq %rbx, %rdi
leaq 0x58(%rsp), %r13
movq %r13, %rsi
leaq 0x40(%rsp), %rdx
leaq 0x78(%rsp), %rcx
callq 0xee7ee
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 0xf70f5
movq %r13, %rdi
callq 0xe58e8
cmpl $0x0, 0x78(%rsp)
je 0x98977
movq %rbx, %rdi
leaq 0x8c2b0(%rip), %rsi     # 0x124c1b
xorl %eax, %eax
callq 0xdf05a
xorl %r15d, %r15d
jmp 0x989da
movq 0x18(%r13), %rdx
movq %rbx, %rdi
leaq 0x7839e(%rip), %rsi     # 0x110d23
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x70
popq %rsi
callq 0xdecaf
movq %rax, %r15
leaq 0xa6345(%rip), %rax     # 0x13ece6
movq %rax, (%r15)
movq 0x58(%rbp), %rdi
callq 0xeaf8a
testl %eax, %eax
je 0x989be
movq 0x58(%rbp), %rax
movq %rax, 0x30(%r15)
orb $0x8, 0x8(%r15)
movq 0x18(%r13), %r9
movq %rbx, %rdi
leaq 0x7ce19(%rip), %rsi     # 0x1157e5
movq %r15, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xdf9b8
movq %r13, %rdi
callq 0xe5591
movq %rbx, %rdi
movq %r15, %rsi
callq 0xded32
movl 0x34(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
movq 0x28(%rsp), %r13
leaq 0x10(%rsp), %r15
movl 0x30(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
cmpl $0x0, 0x38(%r14)
jne 0x98a4e
cmpb $0x0, 0xa0(%rbp)
je 0x98a4e
movq 0x98(%rbp), %rax
cmpq %r12, %rax
movq %rax, %r12
jg 0x98478
movb $0x1, 0x14(%r14)
jmp 0x98a4e
movb $0x1, 0x14(%r14)
testq %rbp, %rbp
je 0x98a60
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xf167c
cmpb $0x0, 0x14(%r14)
je 0x98a76
leaq 0x8c0e9(%rip), %rsi     # 0x124b50
movq %rbx, %rdi
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf16e7
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, 0x14(%r14)
leaq 0xa6178(%rip), %rax     # 0x13ec17
movq %rax, 0x20(%rsp)
jmp 0x98a60