// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %rdi, %r13
movl $0x450, %esi            # imm = 0x450
callq 0xe8b2b
movq %rax, %rbx
movl $0x1, 0xc(%rax)
leaq 0x6db71(%rip), %rsi     # 0x141309
movq %r13, %rdi
callq 0xe9b74
testq %rax, %rax
je 0xd37b0
movq %rax, %rdi
callq 0xe9c2a
movl %eax, 0xc(%rbx)
leaq 0x65f37(%rip), %rsi     # 0x1396ee
movq %r13, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe8617
movq %r13, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%r13), %rdi
movl $0x4, %esi
callq 0xeed61
movq %rax, (%rbx)
leaq 0x6db92(%rip), %rsi     # 0x14137a
movq %r13, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r13), %rdi
movl $0xa, %esi
callq 0xeead3
movb %al, 0x8(%rbx)
movq 0x18(%r13), %rdi
movl $0xb, %esi
callq 0xeead3
movb %al, 0x9(%rbx)
movzbl 0x8(%rbx), %edx
movzbl %al, %ecx
leaq 0x4e253(%rip), %rsi     # 0x121a77
movq %r13, %rdi
xorl %eax, %eax
callq 0xe8617
movq %r13, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq (%rbx), %r15
cmpb $0x1, 0x8(%rbx)
ja 0xd3862
movq %rbx, %rcx
addq $0x14, %rcx
movl $0x100, %r8d            # imm = 0x100
movl $0x28, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0xec55a
movq %rbx, 0x18(%rsp)
leaq 0x6db1e(%rip), %rsi     # 0x14138c
movq %r13, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r13, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0xba301(%rip), %rbx     # 0x18db90
movq %r13, 0x28(%rsp)
movq 0x18(%r13), %rdi
cmpq 0x18(%rdi), %r15
jge 0xd39e3
leaq 0x1(%r15), %r14
movq %r15, %rsi
callq 0xeead3
movl %eax, %ebp
xorl %eax, %eax
movb (%rax,%rbx), %r12b
cmpb %bpl, %r12b
je 0xd38d9
addq $0x18, %rax
cmpq $0x270, %rax            # imm = 0x270
jne 0xd38b2
movq $0x0, 0x20(%rsp)
leaq 0x5887a(%rip), %rcx     # 0x12c151
jmp 0xd38e7
leaq (%rbx,%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x8(%rax,%rbx), %rcx
movzbl %bpl, %edx
movq %r13, %rdi
leaq 0x6daa9(%rip), %rsi     # 0x14139e
movl %edx, 0x14(%rsp)
movl %r15d, %r8d
xorl %eax, %eax
callq 0xe8617
movq %r13, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%r13), %rdi
movq %r15, %rbx
addq $0x2, %r15
movq %r14, 0x30(%rsp)
movq %r14, %rsi
callq 0xeead3
cmpb $-0x1, %al
movq %rbx, 0x8(%rsp)
je 0xd3937
movzbl %al, %r14d
jmp 0xd396e
movq 0x18(%r13), %rdi
movq %r15, %rsi
callq 0xeebc8
movq %rax, %r14
leaq 0x4(%rbx), %r15
testw %r14w, %r14w
jns 0xd396e
movq 0x18(%r13), %rdi
movq %r15, %rsi
callq 0xeebc8
leaq 0x6(%rbx), %r15
shll $0x10, %r14d
andl $0x7fff0000, %r14d      # imm = 0x7FFF0000
orq %rax, %r14
movl %r15d, %ecx
subl 0x30(%rsp), %ecx
movq 0x28(%rsp), %r13
movq %r13, %rdi
leaq 0x6da38(%rip), %rsi     # 0x1413bc
movl %r15d, %edx
movl %r14d, %r8d
xorl %eax, %eax
callq 0xe8617
cmpb %bpl, %r12b
leaq 0xba1f5(%rip), %rbx     # 0x18db90
jne 0xd39bf
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
je 0xd39bf
movq %r13, %rdi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %edx
movq %r15, %rcx
movq %r14, %r8
callq *%rax
movq %r14, %r12
subq 0x8(%rsp), %r12
addq %r15, %r12
movq %r13, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
addq %r14, %r15
testq %r12, %r12
jg 0xd3894
movq %r13, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
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 0x71677(%rip), %rax     # 0x1450b0
leaq 0x6d92e(%rip), %r15     # 0x14136e
cmoveq %rax, %r15
cmpb $0x0, 0x449(%rbx)
movl 0x440(%rbx), %r12d
movq %r13, %rbp
leaq 0x6d918(%rip), %r13     # 0x141374
cmoveq %rax, %r13
subq $0x8, %rsp
leaq 0x6d8a9(%rip), %rsi     # 0x141314
movq %rbp, %rdi
xorl %eax, %eax
pushq %r13
pushq %r15
pushq %r12
pushq %r14
pushq %r10
pushq %r11
pushq 0x40(%rsp)
callq 0xe8617
addq $0x40, %rsp
movq %rbp, %rdi
movq %rbx, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe8be2