// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/divgs.c
// Function: de_run_div_fpg
static void de_run_div_fpg(deark *c, de_module_params *mparams)
{
	struct div_ctx *d = NULL;
	struct div_image_ctx *md = NULL;
	i64 pos;

	d = de_malloc(c, sizeof(struct div_ctx));
	d->fmt = identify_div_fmt(c);
	if(d->fmt==DIVFMT_FPG) {
		de_declare_fmt(c, "DIV FPG");
	}
	else if(d->fmt==DIVFMT_F16) {
		de_declare_fmt(c, "DIV F16");
	}
	else {
		d->need_errmsg = 1;
		goto done;
	}
	d->is_archive = 1;
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_CP850);

	if(de_getbyte(7) != 0) {
		d->need_errmsg = 1;
		goto done;
	}

	pos = 8;
	if(d->fmt==DIVFMT_FPG) {
		div_read_pal_p(c, d, &pos);
	}

	de_dbg(c, "item sequence at: %"I64_FMT, pos);

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

		if(md) {
			div_image_destroy(c, md);
		}

		md = de_malloc(c, sizeof(struct div_image_ctx));
		md->imgpos = pos;
		div_fpg_image(c, d, md);
		if(md->item_len < FPG_MIN_ITEM_LEN) goto done;
		pos += md->item_len;
	}

done:
	div_image_destroy(c, md);
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Bad or unsupported FPG file");
		}
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl $0x408, %esi            # imm = 0x408
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6baa0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x18(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x2, %eax
jne 0x6b8d3
movq -0x8(%rbp), %rdi
leaq 0x13ebc8(%rip), %rsi    # 0x1aa494
callq 0x15e380
jmp 0x6b901
movq -0x18(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x3, %eax
jne 0x6b8f2
movq -0x8(%rbp), %rdi
leaq 0x13ebb1(%rip), %rsi    # 0x1aa49c
callq 0x15e380
jmp 0x6b8ff
movq -0x18(%rbp), %rax
movb $0x1, 0x6(%rax)
jmp 0x6b9ff
jmp 0x6b901
movq -0x18(%rbp), %rax
movb $0x1, 0x5(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xe, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x7, %esi
callq 0x165060
movzbl %al, %eax
cmpl $0x0, %eax
je 0x6b94a
movq -0x18(%rbp), %rax
movb $0x1, 0x6(%rax)
jmp 0x6b9ff
movq $0x8, -0x28(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x2, %eax
jne 0x6b970
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0x6bb80
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x13eb25(%rip), %rsi    # 0x1aa4a4
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
addq $0x40, %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x6b99e
jmp 0x6b9ff
cmpq $0x0, -0x20(%rbp)
je 0x6b9b2
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x6bd80
movq -0x8(%rbp), %rdi
movl $0x40, %esi
callq 0x15b780
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x6beb0
movq -0x20(%rbp), %rax
cmpq $0x40, 0x8(%rax)
jge 0x6b9ed
jmp 0x6b9ff
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x6b986
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x6bd80
cmpq $0x0, -0x18(%rbp)
je 0x6ba3c
movq -0x18(%rbp), %rax
cmpb $0x0, 0x6(%rax)
je 0x6ba2f
movq -0x8(%rbp), %rdi
leaq 0x13ea92(%rip), %rsi    # 0x1aa4ba
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)