// File: /workspace/github_c_makefile_star2_O2/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 0xc1b2e(%rip), %rsi     # 0x11382e
callq 0xe07f7
leaq 0xc1b38(%rip), %rsi     # 0x113844
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0xdfae5
movl %eax, %ebp
movq 0x18(%rbx), %rdi
pushq $0x2
popq %rsi
callq 0xe3eb4
movzbl %al, %r15d
leaq 0xc1b1f(%rip), %rsi     # 0x11384f
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
cmpb $0x66, %r15b
jae 0x51d4e
xorl %r12d, %r12d
jmp 0x51df9
movq 0x18(%rbx), %rdi
pushq $0x1c
popq %rsi
callq 0xe409f
movq %rax, %r15
leaq 0xc1b00(%rip), %rsi     # 0x113864
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r14
leaq 0xb689f(%rip), %rdx     # 0x10862d
pushq $0x5
popq %r8
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0xdffbd
addq $0x2, %r15
pushq $0x70
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r12
testl %ebp, %ebp
leaq 0xc1ac3(%rip), %rax     # 0x11387d
leaq 0xc1ab8(%rip), %rcx     # 0x113879
cmoveq %rax, %rcx
movq %rcx, (%r12)
movq %r14, 0x28(%r12)
movq 0x18(%rbx), %rcx
movq 0x18(%rcx), %r9
subq %r15, %r9
leaq 0xc442d(%rip), %rsi     # 0x11620d
movq %rbx, %rdi
movq %r12, %rdx
movq %r15, %r8
callq 0xdf9b8
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
xorl %edi, %edi
callq 0xe7084
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdfd24
movq %rbx, %rdi
movq %r12, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xded32