// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movl $0x450, %esi            # imm = 0x450
callq 0xe969b
movq %rax, %r14
movl $0x1, 0xc(%rax)
leaq 0x6ca21(%rip), %rsi     # 0x140e29
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0xd4421
movq %rax, %rdi
callq 0xea781
movl %eax, 0xc(%r14)
leaq 0x64f36(%rip), %rsi     # 0x13935e
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef37e
movq %rax, (%r14)
leaq 0x6ca41(%rip), %rsi     # 0x140e9a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0xa, %esi
callq 0xef0d5
movb %al, 0x8(%r14)
movq 0x18(%rbx), %rdi
movl $0xb, %esi
callq 0xef0d5
movb %al, 0x9(%r14)
movzbl 0x8(%r14), %edx
movzbl %al, %ecx
leaq 0x4d4d3(%rip), %rsi     # 0x12196b
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq (%r14), %r15
cmpb $0x1, 0x8(%r14)
ja 0xd44d7
movq %r14, %rcx
addq $0x14, %rcx
movl $0x100, %r8d            # imm = 0x100
movl $0x28, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0xecbbc
movq %r14, 0x18(%rsp)
leaq 0x6c9c9(%rip), %rsi     # 0x140eac
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
leaq 0xb968c(%rip), %r12     # 0x18db90
movq %rbx, 0x20(%rsp)
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r15
jge 0xd4539
leaq 0x1(%r15), %r14
movq %r15, %rsi
callq 0xef0d5
xorl %ebp, %ebp
cmpb %al, (%rbp,%r12)
je 0xd4540
addq $0x18, %rbp
cmpq $0x270, %rbp            # imm = 0x270
jne 0xd4521
xorl %ebp, %ebp
jmp 0xd4543
xorl %eax, %eax
jmp 0xd4639
addq %r12, %rbp
leaq 0x5791f(%rip), %rcx     # 0x12be69
testq %rbp, %rbp
je 0xd4553
movq 0x8(%rbp), %rcx
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x6c95e(%rip), %rsi     # 0x140ebe
movl %edx, 0x14(%rsp)
movl %r15d, %r8d
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
leaq 0x2(%r15), %r13
movq %r14, 0x8(%rsp)
movq %r14, %rsi
callq 0xef0d5
cmpb $-0x1, %al
je 0xd459a
movzbl %al, %r14d
jmp 0xd45d1
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ca
movq %rax, %r14
leaq 0x4(%r15), %r13
testw %r14w, %r14w
jns 0xd45d1
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ca
leaq 0x6(%r15), %r13
shll $0x10, %r14d
andl $0x7fff0000, %r14d      # imm = 0x7FFF0000
orq %rax, %r14
movl %r13d, %ecx
subl 0x8(%rsp), %ecx
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
leaq 0x6c8f5(%rip), %rsi     # 0x140edc
movl %r13d, %edx
movl %r14d, %r8d
xorl %eax, %eax
callq 0xe9226
testq %rbp, %rbp
je 0xd4616
movq 0x10(%rbp), %rax
testq %rax, %rax
je 0xd4616
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %edx
movq %r13, %rcx
movq %r14, %r8
callq *%rax
movq %r14, %rbp
subq %r15, %rbp
addq %r13, %rbp
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
addq %r14, %r13
testq %rbp, %rbp
setg %al
cmovgq %r13, %r15
testb %al, %al
jne 0xd4509
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x18(%rsp), %r14
movzbl 0x8(%r14), %edx
movzbl 0x9(%r14), %ecx
movl 0x418(%r14), %r9d
movl 0x420(%r14), %r8d
movl 0x428(%r14), %eax
movq %rax, 0x8(%rsp)
movl 0x424(%r14), %r11d
movl 0x430(%r14), %r10d
movl 0x438(%r14), %r15d
cmpb $0x0, 0x448(%r14)
leaq 0x70535(%rip), %rax     # 0x144bd0
leaq 0x6c7ec(%rip), %r12     # 0x140e8e
cmoveq %rax, %r12
cmpb $0x0, 0x449(%r14)
movl 0x440(%r14), %r13d
leaq 0x6c7d8(%rip), %rbp     # 0x140e94
cmoveq %rax, %rbp
subq $0x8, %rsp
leaq 0x6c769(%rip), %rsi     # 0x140e34
movq %rbx, %rdi
xorl %eax, %eax
pushq %rbp
pushq %r12
pushq %r13
pushq %r15
pushq %r10
pushq %r11
pushq 0x40(%rsp)
callq 0xe9226
addq $0x40, %rsp
movq %rbx, %rdi
movq %r14, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9752