// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/wmf.c
// Function: do_read_wmf_header
static int do_read_wmf_header(deark *c, lctx *d, i64 pos)
{
	i64 hsize_words, maxrecsize_words, filesize_words;
	int retval = 0;

	de_dbg(c, "WMF header at %d", (int)pos);
	de_dbg_indent(c, 1);

	d->wmf_file_type = de_getu16le(pos);
	de_dbg(c, "file type: %d", (int)d->wmf_file_type);
	if(d->wmf_file_type!=1 && d->wmf_file_type!=2) {
		de_err(c, "Invalid or unsupported WMF file type (%d)", (int)d->wmf_file_type);
		goto done;
	}
	hsize_words = de_getu16le(pos+2);
	de_dbg(c, "header size: %d bytes", (int)(hsize_words*2));
	if(hsize_words != 9) {
		de_err(c, "Incorrect WMF header size (expected 9, is %d)", (int)hsize_words);
		goto done;
	}
	d->wmf_windows_version = de_getu16le(pos+4);
	de_dbg(c, "Windows version: %d.%d", (int)((d->wmf_windows_version&0xff00)>>8),
		(int)(d->wmf_windows_version&0x00ff));
	filesize_words = de_getu32le(pos+6);
	de_dbg(c, "reported file size: %d bytes", (int)(filesize_words*2));

	d->num_objects = (unsigned int)de_getu16le(pos+10);
	de_dbg(c, "number of objects: %u", d->num_objects);
	if(d->object_table) de_free(c, d->object_table);
	// d->num_objects is untrusted, but it can only be from 0 to 65535.
	d->object_table = de_malloc(c, d->num_objects);

	maxrecsize_words = de_getu32le(pos+12);
	de_dbg(c, "max record size: %d bytes", (int)(maxrecsize_words*2));
	retval = 1;
done:
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x6dea6(%rip), %rsi     # 0x140876
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeebc8
movq %rax, 0x8(%r15)
leaq 0x4242e(%rip), %rsi     # 0x114e2b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%r15), %rdx
leaq -0x1(%rdx), %rax
cmpq $0x2, %rax
jae 0xd2b0c
movq 0x18(%rbx), %rdi
leaq 0x2(%r14), %rsi
callq 0xeebc8
movq %rax, %r12
leal (%rax,%rax), %edx
leaq 0x6de7c(%rip), %rsi     # 0x1408b1
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
cmpq $0x9, %r12
jne 0xd2b18
movq 0x18(%rbx), %rdi
leaq 0x4(%r14), %rsi
callq 0xeebc8
movq %rax, 0x10(%r15)
movl %eax, %edx
shrl $0x8, %edx
movl $0xff, %ecx
andl %ecx, %edx
andl %eax, %ecx
leaq 0x6de84(%rip), %rsi     # 0x1408f5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x6(%r14), %rsi
callq 0xeed61
leal (%rax,%rax), %edx
leaq 0x6de7a(%rip), %rsi     # 0x14090c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0xa(%r14), %rsi
callq 0xeebc8
movl %eax, 0x18(%r15)
leaq 0x6de75(%rip), %rsi     # 0x140929
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x28(%r15), %rsi
testq %rsi, %rsi
je 0xd2ad1
movq %rbx, %rdi
callq 0xe8be2
movl 0x18(%r15), %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, 0x28(%r15)
movq 0x18(%rbx), %rdi
addq $0xc, %r14
movq %r14, %rsi
callq 0xeed61
leal (%rax,%rax), %edx
leaq 0x6de44(%rip), %rsi     # 0x14093f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl $0x1, %ebp
jmp 0xd2b2c
leaq 0x6dd74(%rip), %rsi     # 0x140887
movq %rbx, %rdi
jmp 0xd2b25
leaq 0x6dda8(%rip), %rsi     # 0x1408c7
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq