// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/wpg.c
// Function: de_run_wpg
static void de_run_wpg(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	const char *s;
	i64 pos;

	d = de_malloc(c, sizeof(lctx));

	d->opt_fixpal = 1;
	s = de_get_ext_option(c, "wpg:fixpal");
	if(s) d->opt_fixpal = de_atoi(s);

	pos = 0;
	if(!do_read_header(c, d, pos)) goto done;
	pos = d->start_of_data;

	do_set_default_palette(c, d);

	if(!do_record_area(c, d, pos)) goto done;

	// This debug line is mainly to help find interesting WPG files.
	de_dbg(c, "summary: ver=%d.%d dataver=%d pal=%d bitmaps=%d "
		"bitmapver=%d bpp=%d dimensions=%d"DE_CHAR_TIMES"%d%s%s",
		(int)d->ver_major, (int)d->ver_minor, d->start_wpg_data_record_ver,
		(int)d->num_pal_entries,
		(int)d->bitmap_count, d->bitmap_record_ver,
		(int)d->bpp_of_first_bitmap,
		(int)d->width_of_first_bitmap, (int)d->height_of_first_bitmap,
		d->has_eps1?" eps1":"", d->has_eps2?" eps2":"");

done:
	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r13
movl $0x450, %esi            # imm = 0x450
callq 0xdecaf
movq %rax, %rbx
movl $0x1, 0xc(%rax)
leaq 0x69449(%rip), %rsi     # 0x133eb9
movq %r13, %rdi
callq 0xdfa87
testq %rax, %rax
je 0xcaa88
movq %rax, %rdi
callq 0xdfb36
movl %eax, 0xc(%rbx)
leaq 0x6195f(%rip), %rsi     # 0x12c3ee
movq %r13, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %r13, %rdi
callq 0xdeba7
movq 0x18(%r13), %rdi
pushq $0x4
popq %rsi
callq 0xe409f
movq %rax, (%rbx)
leaq 0x6946e(%rip), %rsi     # 0x133f2a
movq %r13, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r13), %rdi
pushq $0xa
popq %rsi
callq 0xe3eb4
movb %al, 0x8(%rbx)
movq 0x18(%r13), %rdi
pushq $0xb
popq %rsi
callq 0xe3eb4
movb %al, 0x9(%rbx)
movzbl 0x8(%rbx), %edx
movzbl %al, %ecx
leaq 0x49e93(%rip), %rsi     # 0x114987
movq %r13, %rdi
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %r13, %rdi
callq 0xdeba7
movq (%rbx), %rbp
cmpb $0x1, 0x8(%rbx)
ja 0xcab2e
movq %rbx, %rcx
addq $0x14, %rcx
pushq $0x28
popq %rdi
movl $0x100, %r8d            # imm = 0x100
xorl %esi, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0xe1b11
movq %rbx, 0x18(%rsp)
leaq 0x69402(%rip), %rsi     # 0x133f3c
movq %r13, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %r13, %rdi
callq 0xdeba7
movq %r13, 0x20(%rsp)
movq 0x18(%r13), %rdi
cmpq 0x18(%rdi), %rbp
jge 0xcac84
leaq 0x1(%rbp), %r14
movq %rbp, %rsi
callq 0xe3eb4
pushq $0x1b
popq %r12
leaq 0xc5ffd(%rip), %rcx     # 0x190b78
decq %r12
je 0xcab92
leaq 0x18(%rcx), %rbx
cmpb %al, 0x18(%rcx)
movq %rbx, %rcx
jne 0xcab7b
movq 0x8(%rbx), %rcx
jmp 0xcab9b
xorl %ebx, %ebx
leaq 0x54346(%rip), %rcx     # 0x11eee1
movzbl %al, %edx
movq 0x20(%rsp), %r13
movq %r13, %rdi
leaq 0x693a1(%rip), %rsi     # 0x133f4e
movl %edx, 0x14(%rsp)
movl %ebp, %r8d
xorl %eax, %eax
callq 0xde896
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%r13), %rdi
leaq 0x2(%rbp), %r15
movq %r14, 0x8(%rsp)
movq %r14, %rsi
callq 0xe3eb4
cmpb $-0x1, %al
je 0xcabe5
movzbl %al, %r14d
jmp 0xcac1c
movq 0x18(%r13), %rdi
movq %r15, %rsi
callq 0xe3fa3
movq %rax, %r14
leaq 0x4(%rbp), %r15
testw %r14w, %r14w
jns 0xcac1c
movq 0x18(%r13), %rdi
movq %r15, %rsi
callq 0xe3fa3
leaq 0x6(%rbp), %r15
shll $0x10, %r14d
andl $0x7fff0000, %r14d      # imm = 0x7FFF0000
orq %rax, %r14
movl %r15d, %ecx
subl 0x8(%rsp), %ecx
movq 0x20(%rsp), %r13
movq %r13, %rdi
leaq 0x6933a(%rip), %rsi     # 0x133f6c
movl %r15d, %edx
movl %r14d, %r8d
xorl %eax, %eax
callq 0xde896
testq %r12, %r12
je 0xcac61
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0xcac61
movq %r13, %rdi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %edx
movq %r15, %rcx
movq %r14, %r8
callq *%rax
movq %r14, %rbx
subq %rbp, %rbx
addq %r15, %rbx
movq %r13, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
addq %r14, %r15
movq %r15, %rbp
testq %rbx, %rbx
jg 0xcab56
pushq $-0x1
popq %rsi
movq %r13, %rdi
callq 0xdeba7
movq 0x18(%rsp), %rbx
movzbl 0x8(%rbx), %edx
movzbl 0x9(%rbx), %ecx
movl 0x418(%rbx), %r9d
movl 0x420(%rbx), %r8d
movl 0x428(%rbx), %eax
movq %rax, 0x8(%rsp)
movl 0x424(%rbx), %r11d
movl 0x430(%rbx), %r10d
movl 0x438(%rbx), %r14d
cmpb $0x0, 0x448(%rbx)
leaq 0x6cf88(%rip), %rax     # 0x137c60
leaq 0x6923f(%rip), %r15     # 0x133f1e
cmoveq %rax, %r15
cmpb $0x0, 0x449(%rbx)
movl 0x440(%rbx), %r12d
movq %r13, %rbp
leaq 0x69229(%rip), %r13     # 0x133f24
cmoveq %rax, %r13
subq $0x8, %rsp
leaq 0x691ba(%rip), %rsi     # 0x133ec4
movq %rbp, %rdi
xorl %eax, %eax
pushq %r13
pushq %r15
pushq %r12
pushq %r14
pushq %r10
pushq %r11
pushq 0x40(%rsp)
callq 0xde896
addq $0x40, %rsp
movq %rbp, %rdi
movq %rbx, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xded32