// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/misc3.c
// Function: de_run_binary_ii
static void de_run_binary_ii(deark *c, de_module_params *mparams)
{
	de_arch_lctx *d = NULL;
	struct de_arch_member_data *md = NULL;
	struct binary_ii_extra_md *b2_md = NULL;
	i64 pos = 0;

	b2_md = de_malloc(c, sizeof(struct binary_ii_extra_md));

	d = de_arch_create_lctx(c);
	d->is_le = 1;
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_ASCII);

	if(!binary_ii_is_member_at(c->infile, 0, 0, 0)) {
		d->need_errmsg = 1;
		goto done;
	}

	while(1) {
		i64 npos1, npos2;
		int ret;

		if(md) {
			de_arch_destroy_md(c, md);
			md = NULL;
		}
		md = de_arch_create_md(c, d);
		de_zeromem(b2_md, sizeof(struct binary_ii_extra_md));

		md->member_hdr_pos = pos;
		do_binary_ii_member(c, d, md, b2_md);
		if(d->fatalerrflag) goto done;
		if(b2_md->num_members_remaining<1) goto done;

		// I'm not sure how we're supposed to find the next archive member.
		// We'll check two places.

		// This is where "ibmnulib" seems to look for the next member:
		npos1 = de_pad_to_n(md->cmpr_pos + md->cmpr_len, 128);
		// This is where the Raymond Clay document says to look:
		npos2 = md->cmpr_pos + 512*b2_md->filesize;

		ret = binary_ii_is_member_at(c->infile, npos1, 1, b2_md->num_members_remaining-1);
		if(ret) {
			pos = npos1;
		}
		else if(npos2!=npos1) {
			ret = binary_ii_is_member_at(c->infile, npos2, 1, b2_md->num_members_remaining-1);
			if(ret) {
				pos = npos2;
			}
		}

		if(!ret) {
			d->need_errmsg = 1;
			goto done;
		}
	}

done:
	if(md) {
		de_arch_destroy_md(c, md);
	}
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Bad or unsupported Binary II file");
		}
		de_arch_destroy_lctx(c, d);
	}
	de_free(c, b2_md);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
pushq $0x10
popq %rsi
callq 0xdecaf
movq %rax, %r12
movq %rbx, %rdi
callq 0xf16ce
movq %rax, %rbp
movl $0x1, 0x10(%rax)
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x18(%rbp)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x6df6d
testl %eax, %eax
je 0x6cf42
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %r12, 0x30(%rsp)
movq %rbp, 0x20(%rsp)
testq %r13, %r13
je 0x6caeb
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf167c
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xf1630
movq %rax, %r15
movq %rax, 0x38(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movq %r14, 0x18(%rax)
movq %rbx, %rdi
leaq 0x1c(%rsp), %rsi
callq 0xdebae
movq 0x18(%r15), %r14
movq %r14, 0x28(%rsp)
movq %rbx, %rdi
leaq 0xc1d43(%rip), %rsi     # 0x12e86d
movq %r14, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
leaq 0x6d(%r14), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0xe3fc4
movq %rax, %r15
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %ebp
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %r12d
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %r14d
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fc4
movq %rax, 0x40(%rsp)
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movb %al, 0xf(%rsp)
movq 0x28(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %eax
shll $0x8, %ebp
orl %eax, %ebp
movq %rbx, %rdi
leaq 0xac88d(%rip), %rsi     # 0x119465
movl %ebp, %edx
movq %r13, %rbp
movq 0x38(%rsp), %r13
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movzbl %al, %eax
shll $0x8, %r12d
orl %eax, %r12d
movq %rbx, %rdi
leaq 0x9b5a6(%rip), %rsi     # 0x1081af
movl %r12d, %edx
movq 0x30(%rsp), %r12
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3fc4
shll $0x10, %r15d
orl %eax, %r15d
movq %rbx, %rdi
leaq 0xac83f(%rip), %rsi     # 0x119474
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movzbl %al, %eax
shll $0x8, %r14d
orl %eax, %r14d
movq %rbx, %rdi
leaq 0xac826(%rip), %rsi     # 0x119485
movl %r14d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3fc4
movl 0x40(%rsp), %edx
shlq $0x10, %rdx
orq %rax, %rdx
movq %rdx, (%r12)
movq %rbx, %rdi
leaq 0xac80c(%rip), %rsi     # 0x11949a
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3fc4
movq %rax, %r14
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3fc4
movq 0x50(%r13), %rdi
addq $0x18, %rdi
movl %r14d, %esi
movl %eax, %edx
callq 0xe0377
movq 0x50(%r13), %rsi
addq $0x18, %rsi
movq %rbx, %rdi
leaq 0xb4110(%rip), %rdx     # 0x120de4
callq 0x6dfce
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3fc4
movq %rax, %r14
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3fc4
movq 0x50(%r13), %rdi
addq $0x28, %rdi
movl %r14d, %esi
pushq $0x1
popq %r15
movl %eax, %edx
callq 0xe0377
movq 0x50(%r13), %rsi
addq $0x28, %rsi
movq %rbx, %rdi
leaq 0xb547c(%rip), %rdx     # 0x122198
callq 0x6dfce
movq 0x28(%rsp), %rax
movq %rax, %r14
leaq 0x14(%rax), %rsi
movq %rsi, 0x10(%rsp)
movq 0x18(%rbx), %rdi
pushq $0x3
popq %rdx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0xe424b
movl %eax, %eax
movzbl 0xf(%rsp), %edx
shll $0x18, %edx
orq %rax, %rdx
movq %rdx, 0x38(%r13)
movq (%r13), %rdi
leaq 0x9e39c(%rip), %rsi     # 0x10b0fc
xorl %eax, %eax
callq 0xde896
movb $0x1, 0x4c(%r13)
movq 0x38(%r13), %rax
movq %rax, 0x30(%r13)
addq $0x3, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3f2a
cmpb $0x41, %al
jb 0x6cd98
movq 0x20(%rsp), %rbp
movb $0x1, 0x14(%rbp)
jmp 0x6ceac
movzbl %al, %edx
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x58(%r13), %rcx
movl %r15d, %r8d
movq 0x20(%rsp), %r15
movl 0x18(%r15), %r9d
callq 0xe4c9a
movq 0x58(%r13), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0xc1c92(%rip), %rsi     # 0x12ea5e
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq $0x75, %r14
movq %r14, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe40bf
movq %rbx, %rdi
leaq 0xac6cb(%rip), %rsi     # 0x1194c0
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xac6d3(%rip), %rsi     # 0x1194eb
xorl %eax, %eax
callq 0xde896
addq $0x3, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xac6bd(%rip), %rsi     # 0x1194fb
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xac6b0(%rip), %rsi     # 0x11950e
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movzbl %al, %edx
movl %edx, 0x8(%r12)
movq %rbx, %rdi
leaq 0xac69b(%rip), %rsi     # 0x11951e
xorl %eax, %eax
callq 0xde896
movq 0x10(%rsp), %rax
movq %rax, 0x40(%r13)
leaq 0xc71(%rip), %rax       # 0x6db0b
movq %rax, 0xa8(%r13)
movq %r13, %rdi
callq 0xf1a85
movq %r15, %rbp
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
cmpl $0x0, 0x38(%rbp)
jne 0x6cf2f
cmpl $0x0, 0x8(%r12)
jle 0x6cf2f
movq 0x30(%r13), %rdi
addq 0x40(%r13), %rdi
movl $0x80, %esi
callq 0xdfbb6
movq (%r12), %r15
shlq $0x9, %r15
addq 0x40(%r13), %r15
movq %rax, %r14
movq 0x18(%rbx), %rdi
movl 0x8(%r12), %ecx
decl %ecx
movq %rax, %rsi
pushq $0x1
popq %rdx
callq 0x6df6d
testl %eax, %eax
jne 0x6cadb
cmpq %r14, %r15
je 0x6cf2b
movq 0x18(%rbx), %rdi
movl 0x8(%r12), %ecx
decl %ecx
movq %r15, %rsi
pushq $0x1
popq %rdx
callq 0x6df6d
movq %r15, %r14
testl %eax, %eax
jne 0x6cadb
movb $0x1, 0x14(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf167c
cmpb $0x0, 0x14(%rbp)
jne 0x6cf46
jmp 0x6cf57
movb $0x1, 0x14(%rbp)
leaq 0xac4f2(%rip), %rsi     # 0x11943f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xf16e7
movq %rbx, %rdi
movq %r12, %rsi
callq 0xded32
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq