// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rbx
cmpl $0x0, 0x8(%rsi)
jne 0x40270
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r14
movl $0x1, 0x8(%rsi)
movq 0x10(%rdx), %rdx
cmpq $0x57, %rdx
jg 0x40167
leaq 0xce57d(%rip), %rsi     # 0x10e6d3
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x40270
movq 0x8(%r12), %r13
movq 0x18(%r14), %rdi
leaq 0x2c(%r13), %rsi
callq 0xe409f
movq %rax, 0x10(%rbp)
leaq 0xc985a(%rip), %rsi     # 0x1099de
xorl %r15d, %r15d
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
leaq 0x30(%r13), %rsi
callq 0xe409f
leaq 0xce562(%rip), %rsi     # 0x10e709
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
leaq 0x34(%r13), %rsi
callq 0xe409f
movq %rax, 0x18(%rbp)
leaq 0xce555(%rip), %rsi     # 0x10e721
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
leaq 0x38(%r13), %rsi
callq 0xe3fa3
leaq 0xce553(%rip), %rsi     # 0x10e73f
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
leaq 0x3c(%r13), %rsi
callq 0xe409f
movq %rax, %rbp
movq 0x18(%r14), %rdi
leaq 0x40(%r13), %rsi
callq 0xe409f
leaq 0xce52f(%rip), %rsi     # 0x10e74b
movq %r14, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
addq $0x44, %r13
movq %r13, %rsi
callq 0xe409f
leaq 0xccda8(%rip), %rsi     # 0x10cff0
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
testq %rbp, %rbp
jle 0x40273
movq 0x10(%rsp), %r13
leaq (,%rbp,2), %rax
addq %r13, %rax
cmpq 0x10(%r12), %rax
jle 0x4028c
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xeaf3c
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 0xeac74
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 0xe4ced
movq 0x10(%r15), %rsi
testq %rsi, %rsi
jle 0x402e1
movq 0x8(%r15), %rax
cmpl $0x0, -0x4(%rax,%rsi,4)
jne 0x402e1
decq %rsi
movq %r15, %rdi
callq 0xeac8c
jmp 0x402c0
movq %r15, %rdi
callq 0xeb7e4
leaq 0xdaa44(%rip), %rsi     # 0x11ad34
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
jmp 0x40273