// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/wmf.c
// Function: de_run_wmf
static void de_run_wmf(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 pos = 0;

	d = de_malloc(c, sizeof(lctx));

	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_WINDOWS1252);

	if(!dbuf_memcmp(c->infile, 0, "\xd7\xcd\xc6\x9a", 4)) {
		d->has_aldus_header = 1;
		de_declare_fmt(c, "WMF (placeable)");
	}
	else {
		de_declare_fmt(c, "WMF (non-placeable)");
	}

	if(d->has_aldus_header) {
		do_read_aldus_header(c, d);
		pos = 22;
	}

	if(!do_read_wmf_header(c, d, pos)) {
		goto done;
	}
	pos += 18;

	do_wmf_record_list(c, d, pos);

done:
	if(d) {
		if(d->embedded_emf) dbuf_close(d->embedded_emf);
		de_free(c, d->object_table);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movl $0x30, %esi
callq 0xe969b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb7d1
movl %eax, 0x4(%r14)
movq 0x18(%rbx), %rdi
leaq 0x6d1b5(%rip), %rdx     # 0x1403f0
movl $0x4, %ecx
xorl %esi, %esi
callq 0xf025e
testl %eax, %eax
je 0xd3254
leaq 0x6d1b3(%rip), %rsi     # 0x140405
jmp 0xd3262
movl $0x1, (%r14)
leaq 0x6d193(%rip), %rsi     # 0x1403f5
movq %rbx, %rdi
callq 0xeb6d6
cmpl $0x0, (%r14)
je 0xd3326
leaq 0x6d19e(%rip), %rsi     # 0x140419
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x6, %esi
callq 0xef257
movq %rax, %r15
movq 0x18(%rbx), %rdi
movl $0x8, %esi
callq 0xef257
movq %rax, %r12
movq 0x18(%rbx), %rdi
movl $0xa, %esi
callq 0xef257
movq %rax, %r13
movq 0x18(%rbx), %rdi
movl $0xc, %esi
callq 0xef257
leaq 0x6d164(%rip), %rsi     # 0x14043e
movq %rbx, %rdi
movl %r15d, %edx
movl %r12d, %ecx
movl %r13d, %r8d
movl %eax, %r9d
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0xe, %esi
callq 0xef1ca
leaq 0x6d155(%rip), %rsi     # 0x14045a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movl $0x16, %r15d
jmp 0xd3329
xorl %r15d, %r15d
leaq 0x6d146(%rip), %rsi     # 0x140476
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ca
movq %rax, 0x8(%r14)
leaq 0x41a1a(%rip), %rsi     # 0x114d7b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x8(%r14), %rdx
leaq -0x1(%rdx), %rax
cmpq $0x2, %rax
movq %r14, 0x8(%rsp)
jae 0xd366d
movq 0x18(%rbx), %rdi
leaq 0x2(%r15), %rsi
callq 0xef1ca
movq %rax, %r12
leal (%rax,%rax), %edx
leaq 0x6d113(%rip), %rsi     # 0x1404b1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
cmpq $0x9, %r12
jne 0xd3679
movq 0x18(%rbx), %rdi
leaq 0x4(%r15), %rsi
callq 0xef1ca
movq %rax, 0x10(%r14)
movl %eax, %edx
shrl $0x8, %edx
movl $0xff, %ecx
andl %ecx, %edx
andl %eax, %ecx
leaq 0x6d11d(%rip), %rsi     # 0x1404f5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x6(%r15), %rsi
callq 0xef37e
leal (%rax,%rax), %edx
leaq 0x6d113(%rip), %rsi     # 0x14050c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0xa(%r15), %rsi
callq 0xef1ca
movl %eax, 0x18(%r14)
leaq 0x6d10e(%rip), %rsi     # 0x140529
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x28(%r14), %rsi
testq %rsi, %rsi
je 0xd3438
movq %rbx, %rdi
callq 0xe9752
movl 0x18(%r14), %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, 0x28(%r14)
movq 0x18(%rbx), %rdi
leaq 0xc(%r15), %rsi
callq 0xef37e
leal (%rax,%rax), %edx
leaq 0x6d0e0(%rip), %rsi     # 0x14053f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
addq $0x12, %r15
leaq 0x61dd6(%rip), %rsi     # 0x135257
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
cmpq %r15, 0x18(%rdi)
jle 0xd368d
leaq 0xb9c50(%rip), %rbp     # 0x18d100
xorl %r13d, %r13d
movq %r15, %rsi
callq 0xef37e
cmpq $0x3, %rax
jl 0xd368d
leaq (%r15,%rax,2), %r12
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r12
jg 0xd368d
leaq (%rax,%rax), %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movq %r15, 0x18(%rsp)
shlq $0x2, %rax
movq %rax, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
leaq 0x6(%r15), %rax
movq %rax, 0x30(%rsp)
addq $-0x6, %rcx
movq %rcx, 0x38(%rsp)
leaq 0x4(%r15), %rsi
callq 0xef1ca
movw %ax, 0x10(%rsp)
movb %al, 0x12(%rsp)
xorl %r14d, %r14d
cmpb %al, (%r14,%rbp)
je 0xd353f
addq $0x18, %r14
cmpq $0x690, %r14            # imm = 0x690
jne 0xd3527
xorl %r14d, %r14d
jmp 0xd3542
addq %rbp, %r14
movzwl %ax, %r8d
testq %r14, %r14
je 0xd35d2
movq 0x8(%r14), %r9
movl 0x30(%rsp), %r10d
movl 0x38(%rsp), %r11d
movq %rbx, %rdi
leaq 0x6cff2(%rip), %rsi     # 0x140559
movl %r13d, %edx
movl %r15d, %ecx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0xe9226
addq $0x10, %rsp
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
testb $0x1, 0x1(%r14)
je 0xd360f
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
testq %rax, %rax
je 0xd360f
movq 0x8(%rsp), %rcx
movl 0x18(%rcx), %ecx
testq %rcx, %rcx
je 0xd35bf
xorl %edx, %edx
cmpb $0x0, (%rax,%rdx)
je 0xd3656
incq %rdx
cmpq %rdx, %rcx
jne 0xd35ad
movq %rbx, %rdi
leaq 0x6d805(%rip), %rsi     # 0x140dce
xorl %eax, %eax
callq 0xe9b27
jmp 0xd360f
movl 0x30(%rsp), %r10d
movl 0x38(%rsp), %r11d
movq %rbx, %rdi
leaq 0x6cf73(%rip), %rsi     # 0x140559
movl %r13d, %edx
movl %r15d, %ecx
leaq 0x58876(%rip), %r9      # 0x12be69
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0xe9226
addq $0x10, %rsp
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
testq %r14, %r14
je 0xd362c
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xd362c
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq *%rax
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpb $0x0, 0x12(%rsp)
je 0xd368d
incq %r13
movq 0x18(%rbx), %rdi
movq %r12, %r15
cmpq 0x18(%rdi), %r12
jl 0xd34b3
jmp 0xd368d
movb $0x1, (%rax,%rdx)
movq %rbx, %rdi
leaq 0x6d750(%rip), %rsi     # 0x140db4
xorl %eax, %eax
callq 0xe9226
jmp 0xd360f
leaq 0x6ce13(%rip), %rsi     # 0x140487
movq %rbx, %rdi
jmp 0xd3686
leaq 0x6ce47(%rip), %rsi     # 0x1404c7
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x8(%rsp), %r14
movq 0x20(%r14), %rdi
testq %rdi, %rdi
je 0xd36ad
callq 0xf0b13
movq 0x28(%r14), %rsi
movq %rbx, %rdi
callq 0xe9752
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq