// File: /workspace/github_c_makefile_star2_O3/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 0xe8b2b
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0xfd4b2
movq %rax, %rbp
movl $0x1, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xeb220
movl %eax, 0x18(%rbp)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x71e16
testl %eax, %eax
je 0x70e10
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %rbp, 0x20(%rsp)
testq %r13, %r13
je 0x70972
movq %rbx, %rdi
movq %r13, %rsi
callq 0xfd460
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xfd414
movq %rax, %r15
movq %rax, 0x38(%rsp)
xorps %xmm0, %xmm0
movq 0x10(%rsp), %rax
movups %xmm0, (%rax)
movq %r14, 0x18(%r15)
movq %rbx, %rdi
leaq 0x1c(%rsp), %rsi
callq 0xe8a1c
movq 0x18(%r15), %r14
movq %r14, 0x28(%rsp)
movq %rbx, %rdi
leaq 0xcb1a9(%rip), %rsi     # 0x13bb5d
movq %r14, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0x6d(%r14), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0xeebeb
movq %rax, %r15
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %r13d
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %r14d
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %ebp
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq %rax, 0x30(%rsp)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movb %al, 0x7(%rsp)
movq 0x28(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %eax
shll $0x8, %r13d
orl %eax, %r13d
movq %rbx, %rdi
leaq 0xb5bff(%rip), %rsi     # 0x126665
movl %r13d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %eax
shll $0x8, %r14d
orl %eax, %r14d
movq %rbx, %rdi
leaq 0xa47ab(%rip), %rsi     # 0x11523b
movl %r14d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
shll $0x10, %r15d
orl %eax, %r15d
movq %rbx, %rdi
leaq 0xb5bbd(%rip), %rsi     # 0x126674
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %eax
shll $0x8, %ebp
orl %eax, %ebp
movq %rbx, %rdi
leaq 0xb5ba6(%rip), %rsi     # 0x126685
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movl 0x30(%rsp), %edx
shlq $0x10, %rdx
orq %rax, %rdx
movq 0x10(%rsp), %rax
movq %rdx, (%rax)
movq %rbx, %rdi
leaq 0xb5b89(%rip), %rsi     # 0x12669a
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq %rax, %r14
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq 0x38(%rsp), %r13
movq 0x50(%r13), %rdi
addq $0x18, %rdi
movl %r14d, %esi
movl %eax, %edx
callq 0xeabc0
movq 0x50(%r13), %rdi
addq $0x18, %rdi
movl $0x40, %edx
leaq 0x40(%rsp), %r15
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xeaf46
movq %rbx, %rdi
leaq 0xd8812(%rip), %rbp     # 0x149382
movq %rbp, %rsi
leaq 0xbd4da(%rip), %rdx     # 0x12e054
movq %r15, %rcx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq %rax, %r14
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq 0x50(%r13), %rdi
addq $0x28, %rdi
movl %r14d, %esi
movl %eax, %edx
callq 0xeabc0
movq 0x50(%r13), %rdi
addq $0x28, %rdi
movl $0x40, %edx
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xeaf46
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0xbe84b(%rip), %rdx     # 0x12f420
movq %r15, %rcx
movq 0x28(%rsp), %r15
xorl %eax, %eax
callq 0xe8617
leaq 0x14(%r15), %rsi
movq %rsi, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movl $0x3, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0xef0f6
movl %eax, %eax
movzbl 0x7(%rsp), %edx
shll $0x18, %edx
orq %rax, %rdx
movq %rdx, 0x38(%r13)
movq (%r13), %rdi
leaq 0xa75cd(%rip), %rsi     # 0x1181ec
xorl %eax, %eax
callq 0xe8617
movb $0x1, 0x4c(%r13)
movq 0x38(%r13), %rax
movq %rax, 0x30(%r13)
addq $0x3, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
cmpb $0x41, %al
jb 0x70c57
movq 0x20(%rsp), %rbp
movb $0x1, 0x14(%rbp)
jmp 0x70d6e
movzbl %al, %edx
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movq 0x58(%r13), %rcx
movq 0x20(%rsp), %rbp
movl 0x18(%rbp), %r9d
movl $0x1, %r8d
callq 0xefbd7
movq 0x58(%r13), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0xcb0c0(%rip), %rsi     # 0x13bd4e
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0x75, %r15
movq %r15, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
movq %rbx, %rdi
leaq 0xb5a09(%rip), %rsi     # 0x1266c0
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xb5a11(%rip), %rsi     # 0x1266eb
xorl %eax, %eax
callq 0xe8617
addq $0x3, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xb59fb(%rip), %rsi     # 0x1266fb
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xb59ee(%rip), %rsi     # 0x12670e
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %edx
movq 0x10(%rsp), %rax
movl %edx, 0x8(%rax)
movq %rbx, %rdi
leaq 0xb59d6(%rip), %rsi     # 0x12671e
xorl %eax, %eax
callq 0xe8617
movq 0x8(%rsp), %rax
movq %rax, 0x40(%r13)
leaq 0xc96(%rip), %rax       # 0x719f5
movq %rax, 0xa8(%r13)
movq %r13, %rdi
callq 0xfd85e
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
cmpl $0x0, 0x38(%rbp)
jne 0x70dfd
movq 0x10(%rsp), %rax
cmpl $0x0, 0x8(%rax)
jle 0x70dfd
movq 0x30(%r13), %rdi
addq 0x40(%r13), %rdi
movl $0x80, %esi
callq 0xe9cb4
movq 0x10(%rsp), %rcx
movq (%rcx), %r15
shlq $0x9, %r15
addq 0x40(%r13), %r15
movq %rax, %r14
movq 0x18(%rbx), %rdi
movl 0x8(%rcx), %ecx
decl %ecx
movq %rax, %rsi
movl $0x1, %edx
callq 0x71e16
testl %eax, %eax
jne 0x70962
cmpq %r14, %r15
je 0x70df9
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ecx
decl %ecx
movq %r15, %rsi
movl $0x1, %edx
callq 0x71e16
movq %r15, %r14
testl %eax, %eax
jne 0x70962
movb $0x1, 0x14(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xfd460
cmpb $0x0, 0x14(%rbp)
jne 0x70e14
jmp 0x70e25
movb $0x1, 0x14(%rbp)
leaq 0xb5824(%rip), %rsi     # 0x12663f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xfd4cd
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xe8be2
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq