// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/corel.c
// Function: de_run_cdr_wl
static void de_run_cdr_wl(deark *c, de_module_params *mparams)
{
	u8 version;
	int adjdim_flag;
	i64 pos = 0;
	de_bitmap *img = NULL;
	de_finfo *fi = NULL;
	de_module_params *mparams2 = NULL;

	de_declare_fmt(c, "CorelDRAW (WL format)");

	// For unknown reasons, old CorelDraw-related preview images just have
	// garbage in the rightmost column and bottom row.
	// I haven't found any exceptions to this, so: Deark will crop out the
	// garbage by default.
	// Just in case there are exceptions, we allow the user to disable this
	// feature.
	// (The -padpix option is not sufficient, because, e.g., there are *3*
	// possible rendering widths for a 90x90 image: 89, 90, or 96.
	adjdim_flag = de_get_ext_option_bool(c, "cdr:adjdim", 1);

	version = de_getbyte(2);
	de_dbg(c, "version code: 0x%02x", (unsigned int)version);
	if(version <= (u8)'e') goto done;

	pos = de_getu32le(28);
	de_dbg(c, "preview image at %"I64_FMT, pos);
	de_dbg_indent(c, 1);
	fi = de_finfo_create(c);
	de_finfo_set_name_from_sz(c, fi, "preview", 0, DE_ENCODING_LATIN1);

	pos += 2; // ?
	// Seems to be Windows DDB format, or something like it.
	mparams2 = de_malloc(c, sizeof(de_module_params));
	// N = Image structure starts with a "file type" field.
	// X = Mark the output file as "aux".
	// C = Ignore the rightmost column and bottom row (in most cases).
	if(adjdim_flag) {
		mparams2->in_params.codes = "NXC";
	}
	else {
		mparams2->in_params.codes = "NX";
	}
	mparams2->in_params.fi = fi;
	de_run_module_by_id_on_slice(c, "ddb", mparams2, c->infile, pos, c->infile->len-pos);
	de_dbg_indent(c, -1);

done:
	de_bitmap_destroy(img);
	de_finfo_destroy(c, fi);
	de_free(c, mparams2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
leaq 0xcc036(%rip), %rsi     # 0x12091e
callq 0xeb125
leaq 0xcc040(%rip), %rsi     # 0x120934
movq %rbx, %rdi
movl $0x1, %edx
callq 0xe9bd0
movl %eax, %ebp
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xeead3
movzbl %al, %r15d
leaq 0xcc023(%rip), %rsi     # 0x12093f
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
cmpb $0x66, %r15b
jae 0x5493a
xorl %r12d, %r12d
jmp 0x549ef
movq 0x18(%rbx), %rdi
movl $0x1c, %esi
callq 0xeed61
movq %rax, %r15
leaq 0xcc002(%rip), %rsi     # 0x120954
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
callq 0xea504
movq %rax, %r14
leaq 0xc0d3f(%rip), %rdx     # 0x1156bd
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0xea78f
addq $0x2, %r15
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r12
testl %ebp, %ebp
leaq 0xcbfbf(%rip), %rax     # 0x12096d
leaq 0xcbfb4(%rip), %rcx     # 0x120969
cmoveq %rax, %rcx
movq %rcx, (%r12)
movq %r14, 0x28(%r12)
movq 0x18(%rbx), %rcx
movq 0x18(%rcx), %r9
subq %r15, %r9
leaq 0xce9f9(%rip), %rsi     # 0x1233cd
movq %rbx, %rdi
movq %r12, %rdx
movq %r15, %r8
callq 0xe9aa3
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
xorl %edi, %edi
callq 0xf228d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xea50e
movq %rbx, %rdi
movq %r12, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xe8be2