// File: /workspace/github_c_makefile_star2_O1/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 0xcbe16(%rip), %rsi     # 0x1207f6
callq 0xeb6d6
leaq 0xcbe20(%rip), %rsi     # 0x12080c
movq %rbx, %rdi
movl $0x1, %edx
callq 0xea727
movl %eax, %ebp
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xef0d5
movzbl %al, %r15d
leaq 0xcbe03(%rip), %rsi     # 0x120817
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
cmpb $0x66, %r15b
jae 0x54a32
xorl %r12d, %r12d
jmp 0x54ae7
movq 0x18(%rbx), %rdi
movl $0x1c, %esi
callq 0xef37e
movq %rax, %r15
leaq 0xcbde2(%rip), %rsi     # 0x12082c
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r14
leaq 0xc0b97(%rip), %rdx     # 0x11560d
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0xeac7c
addq $0x2, %r15
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r12
testl %ebp, %ebp
leaq 0xcbd9f(%rip), %rax     # 0x120845
leaq 0xcbd94(%rip), %rcx     # 0x120841
cmoveq %rax, %rcx
movq %rcx, (%r12)
movq %r14, 0x28(%r12)
movq 0x18(%rbx), %rcx
movq 0x18(%rcx), %r9
subq %r15, %r9
leaq 0xce721(%rip), %rsi     # 0x1231ed
movq %rbx, %rdi
movq %r12, %rdx
movq %r15, %r8
callq 0xea5fa
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
xorl %edi, %edi
callq 0xf28d4
movq %rbx, %rdi
movq %r14, %rsi
callq 0xea9b3
movq %rbx, %rdi
movq %r12, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xe9752