// File: /workspace/github_c_makefile_star2_O3/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 0x4208d
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r14
movl $0x1, 0x8(%rsi)
movq 0x10(%rdx), %rdx
cmpq $0x57, %rdx
jg 0x41f84
leaq 0xd9850(%rip), %rsi     # 0x11b7c3
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x4208d
movq 0x8(%r12), %r13
movq 0x18(%r14), %rdi
leaq 0x2c(%r13), %rsi
callq 0xeed61
movq %rax, 0x10(%rbp)
leaq 0xd4acd(%rip), %rsi     # 0x116a6e
xorl %r15d, %r15d
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
leaq 0x30(%r13), %rsi
callq 0xeed61
leaq 0xd9835(%rip), %rsi     # 0x11b7f9
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
leaq 0x34(%r13), %rsi
callq 0xeed61
movq %rax, 0x18(%rbp)
leaq 0xd9828(%rip), %rsi     # 0x11b811
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
leaq 0x38(%r13), %rsi
callq 0xeebc8
leaq 0xd9826(%rip), %rsi     # 0x11b82f
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
leaq 0x3c(%r13), %rsi
callq 0xeed61
movq %rax, %rbp
movq 0x18(%r14), %rdi
leaq 0x40(%r13), %rsi
callq 0xeed61
leaq 0xd9802(%rip), %rsi     # 0x11b83b
movq %r14, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
addq $0x44, %r13
movq %r13, %rsi
callq 0xeed61
leaq 0xd807b(%rip), %rsi     # 0x11a0e0
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
testq %rbp, %rbp
jle 0x42090
movq 0x10(%rsp), %r13
leaq (,%rbp,2), %rax
addq %r13, %rax
cmpq 0x10(%r12), %rax
jle 0x420a9
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xf6753
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 0xf6410
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 0xefc2a
movq 0x10(%r15), %rsi
testq %rsi, %rsi
jle 0x420fe
movq 0x8(%r15), %rax
cmpl $0x0, -0x4(%rax,%rsi,4)
jne 0x420fe
decq %rsi
movq %r15, %rdi
callq 0xf642a
jmp 0x420dd
movq %r15, %rdi
callq 0xf705c
leaq 0xe5e67(%rip), %rsi     # 0x127f74
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
jmp 0x42090