// File: /workspace/github_c_makefile_star2_O1/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
movq $0x0, 0x8(%rsp)
callq 0xfdb0a
movq %rax, %r14
movl %ebp, 0x54(%rax)
movl $0x1, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb7d1
movl %eax, 0x18(%r14)
cmpl $0x1, 0x54(%r14)
movq 0x8(%rsp), %rax
jne 0x71967
addq $0x34, %rax
leaq 0x8(%rsp), %r15
movq %rax, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movl %eax, 0x58(%r14)
leaq 0xb4631(%rip), %rsi     # 0x125f5b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
addq $0x28, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movq %rax, 0x20(%r14)
leaq 0xa2d0b(%rip), %rsi     # 0x11465c
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq (%r15), %rsi
addq $0x20, %rsi
jmp 0x7199d
addq $0x3c, %rax
leaq 0x8(%rsp), %r15
movq %rax, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movl %eax, 0x58(%r14)
leaq 0xb45df(%rip), %rsi     # 0x125f69
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq (%r15), %rsi
addq $0x3c, %rsi
movq %rsi, 0x8(%rsp)
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rsi
jge 0x71c62
movq %rsp, %r15
xorl %ebp, %ebp
xorl %r13d, %r13d
movl 0x54(%r14), %eax
testl %eax, %eax
je 0x719d3
cmpl $0x1, %eax
jne 0x719e0
cmpq 0x20(%r14), %rbp
jge 0x71c65
testl %eax, %eax
jne 0x719e0
callq 0xef0d5
cmpb $0x1, %al
jne 0x71c65
testq %r13, %r13
je 0x719f0
movq %rbx, %rdi
movq %r13, %rsi
callq 0xfdab8
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfda6c
movq %rax, %r13
movq 0x8(%rsp), %rax
movq %rax, 0x18(%r13)
movq %rax, (%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe958c
movq 0x18(%r13), %rdx
movq %rbx, %rdi
leaq 0xb4552(%rip), %rsi     # 0x125f78
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movl 0x54(%r14), %eax
cmpl $0x1, %eax
je 0x71a4d
testl %eax, %eax
jne 0x71a63
incq (%rsp)
jmp 0x71a63
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %eax
movl %eax, 0x90(%r13)
movq (%rsp), %r15
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r12
movq 0x18(%rbx), %rdi
movl 0x18(%r14), %r9d
movl $0x8, %edx
movq %r15, %rsi
movq %rax, %rcx
movl $0x1, %r8d
callq 0xf01b0
movq %r12, %rdi
callq 0xf6900
movq 0x58(%r13), %rdi
movq %r12, %rsi
callq 0xf6969
movq %r12, %rdi
callq 0xf6883
movq 0x18(%rbx), %rdi
addq $0x8, %r15
movl 0x18(%r14), %r9d
movl $0x4, %edx
movq %r15, %rsi
movq %r12, %rcx
movl $0x1, %r8d
callq 0xf01b0
movq %r12, %rdi
callq 0xf6900
cmpq $0x2, 0x10(%r12)
jl 0x71aea
movq 0x58(%r13), %rdi
movq %r12, %rsi
callq 0xf6969
movq %r12, %rdi
callq 0xf6bb0
movq 0x58(%r13), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0xc9ecf(%rip), %rsi     # 0x13b9d4
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0xd, (%rsp)
cmpl $0x1, 0x54(%r14)
movq %rsp, %r15
jne 0x71b42
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef3a0
movq %rax, 0x40(%r13)
movq %rbx, %rdi
leaq 0xb42c7(%rip), %rsi     # 0x125dff
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %r13, %rdi
movq %r15, %rsi
callq 0xfdbe0
movq 0x50(%r13), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0xa653f(%rip), %rdx     # 0x11809e
movl $0x3, %ecx
movq %r15, %r8
callq 0xfdc9b
cmpl $0x0, 0x54(%r14)
jne 0x71b86
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movl %eax, 0x90(%r13)
movl 0x90(%r13), %edx
movq %rbx, %rdi
leaq 0xb43f4(%rip), %rsi     # 0x125f8b
xorl %eax, %eax
callq 0xe9226
movl 0x90(%r13), %edx
testl %edx, %edx
je 0x71bbc
movq %rbx, %rdi
leaq 0xa1bef(%rip), %rsi     # 0x1137a2
xorl %eax, %eax
callq 0xe9df7
jmp 0x71c29
movq 0x30(%r13), %rax
movq %rax, 0x38(%r13)
movb $0x1, 0x4c(%r13)
cmpl $0x0, 0x54(%r14)
jne 0x71be0
movq (%rsp), %rax
addq $0x3c, %rax
movq %rax, (%rsp)
movq %rax, 0x40(%r13)
movq %r13, %rdi
callq 0xfde12
testl %eax, %eax
je 0x71bf9
cmpl $0x1, 0x54(%r14)
jne 0x71c03
movq (%rsp), %rax
jmp 0x71c0b
movl $0x1, 0x38(%r14)
jmp 0x71c29
movq 0x30(%r13), %rax
addq 0x40(%r13), %rax
subq 0x18(%r13), %rax
movq %rax, 0x28(%r13)
leaq 0x75(%rip), %rax        # 0x71c8f
movq %rax, 0xa8(%r13)
movq %r13, %rdi
callq 0xfdec1
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
cmpl $0x0, 0x38(%r14)
jne 0x71c65
movq 0x28(%r13), %rsi
testq %rsi, %rsi
jle 0x71c65
addq 0x8(%rsp), %rsi
movq %rsi, 0x8(%rsp)
incq %rbp
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rsi
jl 0x719b8
jmp 0x71c65
xorl %r13d, %r13d
testq %r13, %r13
je 0x71c75
movq %rbx, %rdi
movq %r13, %rsi
callq 0xfdab8
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfdb25
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq