// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/emf.c
// Function: emf_handler_01
static int emf_handler_01(deark *c, lctx *d, struct decoder_params *dp)
{
	i64 pos;
	i64 file_size;
	i64 handles;
	i64 desc_len;
	i64 desc_offs;
	i64 num_pal_entries;
	int retval = 0;
	de_ucstring *desc = NULL;

	if(d->emf_found_header) { retval = 1; goto done; }
	d->emf_found_header = 1;

	if(dp->recsize_bytes<88) {
		de_err(c, "Invalid EMF header size (is %"I64_FMT", must be at least 88)",
			dp->recsize_bytes);
		goto done;
	}

	// 2.2.9 Header Object
	pos = dp->recpos + 8;
	d->emf_version = de_getu32le(pos+36);
	de_dbg(c, "version: 0x%08x", (UI)d->emf_version);
	file_size = de_getu32le(pos+40);
	de_dbg(c, "reported file size: %"I64_FMT, file_size);
	d->emf_num_records = de_getu32le(pos+44);
	de_dbg(c, "number of records in file: %d", (int)d->emf_num_records);
	handles = de_getu16le(pos+48);
	de_dbg(c, "handles: %d", (int)handles);
	desc_len = de_getu32le(pos+52);
	desc_offs = de_getu32le(pos+56);
	de_dbg(c, "description offset=%"I64_FMT", len=%"I64_FMT, desc_offs, desc_len);
	num_pal_entries = de_getu32le(pos+60);
	de_dbg(c, "num pal entries: %d", (int)num_pal_entries);

	if((desc_len>0) && (desc_offs+desc_len*2 <= dp->recsize_bytes)) {
		desc = ucstring_create(c);
		dbuf_read_to_ucstring_n(c->infile, dp->recpos+desc_offs, desc_len*2, DE_DBG_MAX_STRLEN*2,
			desc, 0, DE_ENCODING_UTF16LE);
		ucstring_strip_trailing_NULs(desc);
		de_dbg(c, "description: \"%s\"", ucstring_getpsz(desc));
	}

	retval = 1;
done:
	ucstring_destroy(desc);
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl $0x1, %ebx
cmpl $0x0, 0x8(%rsi)
jne 0x420db
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r14
movl $0x1, 0x8(%rsi)
movq 0x10(%rdx), %rdx
cmpq $0x57, %rdx
jg 0x41fd2
leaq 0xd96da(%rip), %rsi     # 0x11b69b
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x420db
movq 0x8(%r12), %r13
movq 0x18(%r14), %rdi
leaq 0x2c(%r13), %rsi
callq 0xef37e
movq %rax, 0x10(%rbp)
leaq 0xd49cf(%rip), %rsi     # 0x1169be
xorl %r15d, %r15d
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
leaq 0x30(%r13), %rsi
callq 0xef37e
leaq 0xd96bf(%rip), %rsi     # 0x11b6d1
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
leaq 0x34(%r13), %rsi
callq 0xef37e
movq %rax, 0x18(%rbp)
leaq 0xd96b2(%rip), %rsi     # 0x11b6e9
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
leaq 0x38(%r13), %rsi
callq 0xef1ca
leaq 0xd96b0(%rip), %rsi     # 0x11b707
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
leaq 0x3c(%r13), %rsi
callq 0xef37e
movq %rax, %rbp
movq 0x18(%r14), %rdi
leaq 0x40(%r13), %rsi
callq 0xef37e
leaq 0xd968c(%rip), %rsi     # 0x11b713
movq %r14, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
addq $0x44, %r13
movq %r13, %rsi
callq 0xef37e
leaq 0xd7f0d(%rip), %rsi     # 0x119fc0
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
testq %rbp, %rbp
jle 0x420de
movq 0x10(%rsp), %r13
leaq (,%rbp,2), %rax
addq %r13, %rax
cmpq 0x10(%r12), %rax
jle 0x420f7
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xf6bb0
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %rbp, %rbp
movq %r14, %rdi
callq 0xf6870
movq %rax, %r15
movq 0x18(%r14), %rdi
addq 0x8(%r12), %r13
movl $0x3, (%rsp)
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r13, %rsi
movq %rbp, %rdx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xf0203
movq 0x10(%r15), %rsi
testq %rsi, %rsi
jle 0x4214c
movq 0x8(%r15), %rax
cmpl $0x0, -0x4(%rax,%rsi,4)
jne 0x4214c
decq %rsi
movq %r15, %rdi
callq 0xf688a
jmp 0x4212b
movq %r15, %rdi
callq 0xf74bd
leaq 0xe5be9(%rip), %rsi     # 0x127d44
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
jmp 0x420de