// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl $0x10, %esi
callq 0x15b780
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x17c220
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0xa4340
cmpl $0x0, %eax
jne 0xa094c
movq -0x18(%rbp), %rax
movb $0x1, 0x14(%rax)
jmp 0xa0a89
jmp 0xa094e
cmpq $0x0, -0x20(%rbp)
je 0xa096a
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x17c1a0
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x17c120
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x19140
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0xa43f0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0xa09bb
jmp 0xa0a89
movq -0x28(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jge 0xa09ca
jmp 0xa0a89
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x20(%rbp), %rax
addq 0x30(%rax), %rdi
movl $0x80, %esi
callq 0x15ce90
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
shlq $0x9, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
subl $0x1, %ecx
movl $0x1, %edx
callq 0xa4340
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0xa0a35
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xa0a74
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0xa0a72
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
subl $0x1, %ecx
movl $0x1, %edx
callq 0xa4340
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0xa0a70
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xa0a72
jmp 0xa0a74
cmpl $0x0, -0x44(%rbp)
jne 0xa0a84
movq -0x18(%rbp), %rax
movb $0x1, 0x14(%rax)
jmp 0xa0a89
jmp 0xa094e
cmpq $0x0, -0x20(%rbp)
je 0xa0a9d
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x17c1a0
cmpq $0x0, -0x18(%rbp)
je 0xa0acd
movq -0x18(%rbp), %rax
cmpb $0x0, 0x14(%rax)
je 0xa0ac0
movq -0x8(%rbp), %rdi
leaq 0x1113c3(%rip), %rsi    # 0x1b1e7c
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x17c270
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15b820
addq $0x50, %rsp
popq %rbp
retq