// File: /workspace/github_c_makefile_star2_O1/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 $0x88, %rsp
movq %rdi, %rbx
movl $0x10, %esi
callq 0xe969b
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0xfdb0a
movq %rax, %rbp
movl $0x1, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xeb7d1
movl %eax, 0x18(%rbp)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x720c4
testl %eax, %eax
je 0x710a9
movq %rsp, %r14
movq $0x0, 0x18(%rsp)
xorl %r15d, %r15d
movq %rbp, 0x30(%rsp)
testq %r15, %r15
je 0x70bf5
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfdab8
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xfda6c
movq %rax, %r15
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movq 0x10(%rsp), %rax
movups %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq %rax, 0x18(%r15)
movq %rbx, %rdi
leaq 0x2c(%rsp), %rsi
callq 0xe958c
movq 0x18(%r15), %r12
movq %rbx, %rdi
leaq 0xcabac(%rip), %rsi     # 0x13b7e3
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
leaq 0x6d(%r12), %rax
movq %rax, (%rsp)
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef1ed
movq %rax, %r14
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef14d
movzbl %al, %r13d
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef14d
movzbl %al, %r15d
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef14d
movzbl %al, %ebp
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef1ed
movq %rax, 0x38(%rsp)
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef14d
movb %al, 0xf(%rsp)
leaq 0x3(%r12), %rax
movq %rax, (%rsp)
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef14d
movzbl %al, %eax
shll $0x8, %r13d
orl %eax, %r13d
movq %rbx, %rdi
leaq 0xb5756(%rip), %rsi     # 0x126435
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef14d
movzbl %al, %eax
shll $0x8, %r15d
orl %eax, %r15d
movq %rbx, %rdi
leaq 0xa4482(%rip), %rsi     # 0x11518b
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef1ed
shll $0x10, %r14d
orl %eax, %r14d
movq %rbx, %rdi
leaq 0xb5714(%rip), %rsi     # 0x126444
movl %r14d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef14d
movzbl %al, %eax
shll $0x8, %ebp
orl %eax, %ebp
movq %rbx, %rdi
leaq 0xb56fd(%rip), %rsi     # 0x126455
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef1ed
movl 0x38(%rsp), %edx
shlq $0x10, %rdx
orq %rax, %rdx
movq 0x10(%rsp), %rax
movq %rdx, (%rax)
movq %rbx, %rdi
leaq 0xb56e0(%rip), %rsi     # 0x12646a
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef1ed
movq %rax, %r14
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef1ed
movq 0x20(%rsp), %r13
movq 0x50(%r13), %rdi
addq $0x18, %rdi
movl %r14d, %esi
movl %eax, %edx
callq 0xeb11b
movq 0x50(%r13), %rdi
addq $0x18, %rdi
movl $0x40, %edx
leaq 0x40(%rsp), %r15
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xeb4f8
movq %rbx, %rdi
leaq 0xd8001(%rip), %rbp     # 0x148dea
movq %rbp, %rsi
leaq 0xbcf69(%rip), %rdx     # 0x12dd5c
movq %r15, %rcx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef1ed
movq %rax, %r14
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef1ed
movq 0x50(%r13), %rdi
addq $0x28, %rdi
movl %r14d, %esi
movq %rsp, %r14
movl %eax, %edx
callq 0xeb11b
movq 0x50(%r13), %rdi
addq $0x28, %rdi
movl $0x40, %edx
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xeb4f8
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0xbe2ec(%rip), %rdx     # 0x12f13d
movq %r15, %rcx
movq %r13, %r15
xorl %eax, %eax
callq 0xe9226
movq %r12, %r13
leaq 0x14(%r12), %rsi
movq %rsi, (%rsp)
movq 0x18(%rbx), %rdi
movl $0x3, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0xef6f2
movl %eax, %eax
movzbl 0xf(%rsp), %edx
shll $0x18, %edx
orq %rax, %rdx
movq %rdx, 0x38(%r15)
movq (%r15), %rdi
leaq 0xa7219(%rip), %rsi     # 0x1180b4
xorl %eax, %eax
callq 0xe9226
movb $0x1, 0x4c(%r15)
movq 0x38(%r15), %rax
movq %rax, 0x30(%r15)
addq $0x3, (%rsp)
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef14d
cmpb $0x41, %al
jb 0x70ed2
movq 0x30(%rsp), %rbp
movb $0x1, 0x14(%rbp)
jmp 0x70fe5
movzbl %al, %edx
movq 0x18(%rbx), %rdi
movq (%rsp), %rsi
movq 0x58(%r15), %rcx
movq 0x30(%rsp), %rbp
movl 0x18(%rbp), %r9d
movl $0x1, %r8d
callq 0xf01b0
movq 0x58(%r15), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0xcaacc(%rip), %rsi     # 0x13b9d4
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0x75, %r13
movq %r13, (%rsp)
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef3a0
movq %rbx, %rdi
leaq 0xb5560(%rip), %rsi     # 0x126490
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef14d
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xb5568(%rip), %rsi     # 0x1264bb
xorl %eax, %eax
callq 0xe9226
addq $0x3, (%rsp)
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef14d
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xb5553(%rip), %rsi     # 0x1264cb
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef14d
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xb5546(%rip), %rsi     # 0x1264de
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef14d
movzbl %al, %edx
movq 0x10(%rsp), %rax
movl %edx, 0x8(%rax)
movq %rbx, %rdi
leaq 0xb552e(%rip), %rsi     # 0x1264ee
xorl %eax, %eax
callq 0xe9226
movq (%rsp), %rax
movq %rax, 0x40(%r15)
leaq 0xcb9(%rip), %rax       # 0x71c8f
movq %rax, 0xa8(%r15)
movq %r15, %rdi
callq 0xfdec1
movl 0x2c(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
cmpl $0x0, 0x38(%rbp)
je 0x71006
xorl %eax, %eax
testb %al, %al
jne 0x70be5
jmp 0x710b0
movq 0x10(%rsp), %rax
cmpl $0x0, 0x8(%rax)
jle 0x70ff7
movq 0x30(%r15), %rdi
addq 0x40(%r15), %rdi
movl $0x80, %esi
callq 0xea80b
movq 0x10(%rsp), %rcx
movq (%rcx), %r14
shlq $0x9, %r14
addq 0x40(%r15), %r14
movq %rax, %r15
movq 0x18(%rbx), %rdi
movl 0x8(%rcx), %ecx
decl %ecx
movq %rax, %rsi
movl $0x1, %edx
callq 0x720c4
testl %eax, %eax
je 0x71059
xorl %ecx, %ecx
movq %r15, 0x18(%rsp)
jmp 0x7108e
movb $0x1, %cl
cmpq %r15, %r14
je 0x7108e
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ecx
decl %ecx
movq %r14, %rsi
movl $0x1, %edx
callq 0x720c4
testl %eax, %eax
sete %cl
movq 0x18(%rsp), %rax
cmovneq %r14, %rax
movq %rax, 0x18(%rsp)
movq %rsp, %r14
movq 0x20(%rsp), %r15
movb $0x1, %al
testb %cl, %cl
je 0x70ff9
movb $0x1, 0x14(%rbp)
jmp 0x70ff7
movb $0x1, 0x14(%rbp)
xorl %r15d, %r15d
testq %r15, %r15
je 0x710c0
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfdab8
testq %rbp, %rbp
je 0x710e7
cmpb $0x0, 0x14(%rbp)
je 0x710dc
leaq 0xb533d(%rip), %rsi     # 0x12640f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xfdb25
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xe9752
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq