// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0x9340a(%rip), %rsi     # 0x1cc4c6
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
leaq 0x67af9(%rip), %rsi     # 0x1a0bfb
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x1, 0x8(%rax)
je 0x139140
movq -0x10(%rbp), %rax
cmpq $0x2, 0x8(%rax)
je 0x139140
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
leaq 0x933a3(%rip), %rsi     # 0x1cc4d7
movb $0x0, %al
callq 0x15bfb0
jmp 0x1392cd
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
callq 0x165280
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
shlq %rax
movl %eax, %edx
leaq 0x93394(%rip), %rsi     # 0x1cc501
movb $0x0, %al
callq 0x15b0d0
cmpq $0x9, -0x20(%rbp)
je 0x139198
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0x9338b(%rip), %rsi     # 0x1cc517
movb $0x0, %al
callq 0x15bfb0
jmp 0x1392cd
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
andq $0xff00, %rax           # imm = 0xFF00
sarq $0x8, %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
andq $0xff, %rax
movl %eax, %ecx
leaq 0x9335e(%rip), %rsi     # 0x1cc545
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x6, %rsi
callq 0x165540
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
shlq %rax
movl %eax, %edx
leaq 0x93341(%rip), %rsi     # 0x1cc55c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0xa, %rsi
callq 0x165280
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edx
leaq 0x93327(%rip), %rsi     # 0x1cc579
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x139275
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x15b780
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0xc, %rsi
callq 0x165540
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
shlq %rax
movl %eax, %edx
leaq 0x932d0(%rip), %rsi     # 0x1cc58f
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x34(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)