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

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

	if(d->fmtcode==FMT_GXLIB) {
		pos += 2;
		pos += 50; // copyright message
		d->fmtver = (int)de_getu16le_p(&pos);
		de_dbg(c, "gxLib ver: %d", d->fmtver);
		pos += 40; // label
		d->num_members = de_getu16le_p(&pos);
		de_dbg(c, "number of members: %"I64_FMT, d->num_members);
		pos += 32; // unused
	}
	else {
		pos += 10;
		pos += 50;
		d->fmtver = (int)de_getu16le_p(&pos);
		de_dbg(c, "pcxLib ver: %d", d->fmtver);
		pos += 40; // TODO: volume label
		pos += 20; // unused
	}

	while(1) {
		if(pos >= c->infile->len) goto done;

		if(d->fmtcode==FMT_GXLIB) {
			if(member_count >= d->num_members) goto done;
		}

		if(d->fmtcode==FMT_PCXLIB) {
			u8 b;

			b = de_getbyte(pos);
			if(b != 0x01) 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_pcxgxlib_member(c, d, md);
		if(d->fatalerrflag) goto done;
		if(md->member_total_size<1) goto done;
		pos += md->member_total_size;
		member_count++;
	}

done:
	if(md) {
		de_arch_destroy_md(c, md);
	}
	de_arch_destroy_lctx(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebp
movq %rdi, %rbx
callq 0xf16ce
movq %rax, %r14
movl %ebp, 0x54(%rax)
movl $0x1, 0x10(%rax)
pushq $0xd
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x18(%r14)
cmpl $0x1, 0x54(%r14)
jne 0x6d7cd
leaq 0x10(%rsp), %r15
movq $0x34, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movl %eax, 0x58(%r14)
leaq 0xab7fb(%rip), %rsi     # 0x118f8b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
addq $0x28, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movq %rax, 0x20(%r14)
leaq 0x99ef5(%rip), %rsi     # 0x1076ac
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq (%r15), %rsi
addq $0x20, %rsi
jmp 0x6d803
leaq 0x10(%rsp), %r15
movq $0x3c, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movl %eax, 0x58(%r14)
leaq 0xab7a9(%rip), %rsi     # 0x118f99
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq (%r15), %rsi
addq $0x3c, %rsi
movq %rsi, 0x10(%rsp)
leaq 0x8(%rsp), %r13
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rsi
jge 0x6dae1
movl 0x54(%r14), %eax
testl %eax, %eax
je 0x6d839
cmpl $0x1, %eax
jne 0x6d846
cmpq 0x20(%r14), %r15
jl 0x6d846
jmp 0x6dae1
callq 0xe3eb4
cmpb $0x1, %al
jne 0x6dae1
movq %r15, 0x20(%rsp)
testq %r12, %r12
je 0x6d85b
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf167c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf1630
movq %rax, %r12
movq 0x10(%rsp), %r15
movq %r15, 0x18(%rax)
movq %r15, 0x8(%rsp)
movq %rbx, %rdi
leaq 0x1c(%rsp), %rsi
callq 0xdebae
movq 0x18(%r12), %rdx
movq %rbx, %rdi
leaq 0xab715(%rip), %rsi     # 0x118fa8
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movl 0x54(%r14), %eax
cmpl $0x1, %eax
je 0x6d8bc
testl %eax, %eax
jne 0x6d8d8
incq %r15
movq %r15, 0x8(%rsp)
jmp 0x6d8d8
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %eax
movl %eax, 0x90(%r12)
movq 0x8(%rsp), %r15
movq %rbx, %rdi
callq 0xeac74
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movl 0x18(%r14), %r9d
movq %r15, %rsi
pushq $0x8
popq %rdx
movq %rax, %rcx
pushq $0x1
popq %r13
movl %r13d, %r8d
callq 0xe4c9a
movq %rbp, %rdi
callq 0xead03
movq 0x58(%r12), %rdi
movq %rbp, %rsi
callq 0xead71
movq %rbp, %rdi
callq 0xeac85
movq 0x18(%rbx), %rdi
addq $0x8, %r15
movl 0x18(%r14), %r9d
movq %r15, %rsi
pushq $0x4
popq %rdx
movq %rbp, %rcx
movl %r13d, %r8d
callq 0xe4c9a
movq %rbp, %rdi
callq 0xead03
cmpq $0x2, 0x10(%rbp)
jl 0x6d956
movq 0x58(%r12), %rdi
movq %rbp, %rsi
callq 0xead71
movq %rbp, %rdi
callq 0xeaf3c
movq 0x58(%r12), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0xc10ec(%rip), %rsi     # 0x12ea5e
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq $0xd, 0x8(%rsp)
cmpl $0x1, 0x54(%r14)
leaq 0x8(%rsp), %r13
movq 0x20(%rsp), %r15
jne 0x6d9b8
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe40bf
movq %rax, 0x40(%r12)
movq %rbx, %rdi
leaq 0xab481(%rip), %rsi     # 0x118e2f
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq %r12, %rdi
movq %r13, %rsi
callq 0xf17ab
movq 0x50(%r12), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0x9d710(%rip), %rdx     # 0x10b0e6
pushq $0x3
popq %rcx
movq %r13, %r8
callq 0xf1866
cmpl $0x0, 0x54(%r14)
je 0x6d9f2
movl 0x90(%r12), %edx
jmp 0x6da09
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fc4
movq %rax, %rdx
movl %edx, 0x90(%r12)
movq %rbx, %rdi
leaq 0xab5a8(%rip), %rsi     # 0x118fbb
xorl %eax, %eax
callq 0xde896
movl 0x90(%r12), %edx
testl %edx, %edx
je 0x6da39
movq %rbx, %rdi
leaq 0x98dc2(%rip), %rsi     # 0x1067f2
xorl %eax, %eax
callq 0xdf2a5
jmp 0x6dab2
movq 0x30(%r12), %rax
movq %rax, 0x38(%r12)
movb $0x1, 0x4c(%r12)
cmpl $0x0, 0x54(%r14)
jne 0x6da63
movq 0x8(%rsp), %rax
addq $0x3c, %rax
movq %rax, 0x8(%rsp)
movq %rax, 0x40(%r12)
movq %r12, %rdi
callq 0xf19d5
testl %eax, %eax
je 0x6da7d
cmpl $0x1, 0x54(%r14)
jne 0x6da87
movq 0x8(%rsp), %rax
jmp 0x6da91
movl $0x1, 0x38(%r14)
jmp 0x6dab2
movq 0x30(%r12), %rax
addq 0x40(%r12), %rax
subq 0x18(%r12), %rax
movq %rax, 0x28(%r12)
leaq 0x69(%rip), %rax        # 0x6db0b
movq %rax, 0xa8(%r12)
movq %r12, %rdi
callq 0xf1a85
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
cmpl $0x0, 0x38(%r14)
jne 0x6dae6
movq 0x28(%r12), %rsi
testq %rsi, %rsi
jle 0x6dae6
addq 0x10(%rsp), %rsi
movq %rsi, 0x10(%rsp)
incq %r15
jmp 0x6d813
testq %r12, %r12
je 0x6daf1
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf167c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf16e7
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq