// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x1347fc(%rip), %rsi    # 0x1ac407
callq 0x15e380
movq -0x8(%rbp), %rdi
leaq 0x134802(%rip), %rsi    # 0x1ac41d
movl $0x1, %edx
callq 0x15cbc0
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x2, %esi
callq 0x165060
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x11(%rbp), %edx
leaq 0x1347dc(%rip), %rsi    # 0x1ac428
movb $0x0, %al
callq 0x15b0d0
movzbl -0x11(%rbp), %eax
cmpl $0x65, %eax
jg 0x77c61
jmp 0x77d50
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x1c, %esi
callq 0x165540
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x1347b7(%rip), %rsi    # 0x1ac43d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x12984e(%rip), %rdx    # 0x1a1505
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0x15d4c0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x77cf8
movq -0x38(%rbp), %rax
leaq 0x13475f(%rip), %rcx    # 0x1ac452
movq %rcx, (%rax)
jmp 0x77d06
movq -0x38(%rbp), %rax
leaq 0x134753(%rip), %rcx    # 0x1ac456
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x20(%rbp), %r8
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %r9
subq -0x20(%rbp), %r9
leaq 0x137074(%rip), %rsi    # 0x1aedb1
callq 0x15c9f0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x28(%rbp), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)