// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movl %esi, %ebp
movq %rdi, %rbx
callq 0xfd4b2
movq %rax, %r14
movl %ebp, 0x54(%rax)
movl $0x1, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb220
movl %eax, 0x18(%r14)
cmpl $0x1, 0x54(%r14)
jne 0x716b7
leaq 0x8(%rsp), %r15
movq $0x34, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
movl %eax, 0x58(%r14)
leaq 0xb4b11(%rip), %rsi     # 0x12618b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
addq $0x28, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
movq %rax, 0x20(%r14)
leaq 0xa3096(%rip), %rsi     # 0x114737
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq (%r15), %rsi
addq $0x20, %rsi
jmp 0x716ed
leaq 0x8(%rsp), %r15
movq $0x3c, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
movl %eax, 0x58(%r14)
leaq 0xb4abf(%rip), %rsi     # 0x126199
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq (%r15), %rsi
addq $0x3c, %rsi
movq %rsi, 0x8(%rsp)
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rsi
jge 0x719db
movq %rsp, %rbp
xorl %r13d, %r13d
xorl %r12d, %r12d
movl 0x54(%r14), %eax
testl %eax, %eax
je 0x71721
cmpl $0x1, %eax
jne 0x7172e
cmpq 0x20(%r14), %r13
jl 0x7172e
jmp 0x719cb
callq 0xeead3
cmpb $0x1, %al
jne 0x719cb
testq %r12, %r12
je 0x7173e
movq %rbx, %rdi
movq %r12, %rsi
callq 0xfd460
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfd414
movq %rax, %r12
movq 0x8(%rsp), %r15
movq %r15, 0x18(%rax)
movq %r15, (%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe8a1c
movq 0x18(%r12), %rdx
movq %rbx, %rdi
leaq 0xb4a33(%rip), %rsi     # 0x1261a8
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl 0x54(%r14), %eax
cmpl $0x1, %eax
je 0x7179f
testl %eax, %eax
jne 0x717ba
incq %r15
movq %r15, (%rsp)
jmp 0x717ba
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeeb4b
movzbl %al, %eax
movl %eax, 0x90(%r12)
movq (%rsp), %r15
movq %rbx, %rdi
callq 0xf6410
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movl 0x18(%r14), %r9d
movl $0x8, %edx
movq %r15, %rsi
movq %rax, %rcx
movl $0x1, %r8d
callq 0xefbd7
movq %rbp, %rdi
callq 0xf64a0
movq 0x58(%r12), %rdi
movq %rbp, %rsi
callq 0xf6509
movq %rbp, %rdi
callq 0xf6423
movq 0x18(%rbx), %rdi
addq $0x8, %r15
movl 0x18(%r14), %r9d
movl $0x4, %edx
movq %r15, %rsi
movq %rbp, %rcx
movl $0x1, %r8d
callq 0xefbd7
movq %rbp, %rdi
callq 0xf64a0
cmpq $0x2, 0x10(%rbp)
jl 0x7183e
movq 0x58(%r12), %rdi
movq %rbp, %rsi
callq 0xf6509
movq %rbp, %rdi
callq 0xf6753
movq 0x58(%r12), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0xca4f4(%rip), %rsi     # 0x13bd4e
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0xd, (%rsp)
cmpl $0x1, 0x54(%r14)
movq %rsp, %rbp
jne 0x71898
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeed83
movq %rax, 0x40(%r12)
movq %rbx, %rdi
leaq 0xb47a1(%rip), %rsi     # 0x12602f
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r12, %rdi
movq %rbp, %rsi
callq 0xfd57d
movq 0x50(%r12), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0xa6920(%rip), %rdx     # 0x1181d6
movl $0x3, %ecx
movq %rbp, %r8
callq 0xfd638
cmpl $0x0, 0x54(%r14)
je 0x718d4
movl 0x90(%r12), %edx
jmp 0x718eb
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeebeb
movq %rax, %rdx
movl %edx, 0x90(%r12)
movq %rbx, %rdi
leaq 0xb48c6(%rip), %rsi     # 0x1261bb
xorl %eax, %eax
callq 0xe8617
movl 0x90(%r12), %edx
testl %edx, %edx
je 0x7191b
movq %rbx, %rdi
leaq 0xa1f40(%rip), %rsi     # 0x113852
xorl %eax, %eax
callq 0xe9295
jmp 0x71991
movq 0x30(%r12), %rax
movq %rax, 0x38(%r12)
movb $0x1, 0x4c(%r12)
cmpl $0x0, 0x54(%r14)
jne 0x71943
movq (%rsp), %rax
addq $0x3c, %rax
movq %rax, (%rsp)
movq %rax, 0x40(%r12)
movq %r12, %rdi
callq 0xfd7af
testl %eax, %eax
je 0x7195c
cmpl $0x1, 0x54(%r14)
jne 0x71966
movq (%rsp), %rax
jmp 0x71970
movl $0x1, 0x38(%r14)
jmp 0x71991
movq 0x30(%r12), %rax
addq 0x40(%r12), %rax
subq 0x18(%r12), %rax
movq %rax, 0x28(%r12)
leaq 0x74(%rip), %rax        # 0x719f5
movq %rax, 0xa8(%r12)
movq %r12, %rdi
callq 0xfd85e
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
cmpl $0x0, 0x38(%r14)
jne 0x719d0
movq 0x28(%r12), %rsi
testq %rsi, %rsi
jle 0x719d0
addq 0x8(%rsp), %rsi
movq %rsi, 0x8(%rsp)
incq %r13
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rsi
jl 0x71709
jmp 0x719d0
testq %r12, %r12
je 0x719db
movq %rbx, %rdi
movq %r12, %rsi
callq 0xfd460
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfd4cd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq