// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x4c(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x5a899
movl $0x1, -0x4c(%rbp)
jmp 0x5aacc
movq -0x10(%rbp), %rax
movl $0x1, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x58, 0x10(%rax)
jge 0x5a8ce
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x14cb4d(%rip), %rsi    # 0x1a740f
movb $0x0, %al
callq 0x15bfb0
jmp 0x5aacc
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x24, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %edx
leaq 0x147f77(%rip), %rsi    # 0x1a288a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x28, %rsi
callq 0x165540
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x14cb03(%rip), %rsi    # 0x1a7445
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x2c, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x14cadf(%rip), %rsi    # 0x1a745d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x30, %rsi
callq 0x165280
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
leaq 0x14cacc(%rip), %rsi    # 0x1a747b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x34, %rsi
callq 0x165540
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x38, %rsi
callq 0x165540
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x14ca8c(%rip), %rsi    # 0x1a7487
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x3c, %rsi
callq 0x165540
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq 0x14b32a(%rip), %rsi    # 0x1a5d56
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x38(%rbp)
jle 0x5aac5
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jg 0x5aac5
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
addq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
shlq %rdx
movq -0x58(%rbp), %r8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %r9d, %r9d
movl $0x3, (%rsp)
callq 0x166a40
movq -0x58(%rbp), %rdi
callq 0x5b490
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
callq 0x172500
movq -0x60(%rbp), %rdi
movq %rax, %rdx
leaq 0x158c5e(%rip), %rsi    # 0x1b371c
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x4c(%rbp)
movq -0x58(%rbp), %rdi
callq 0x171750
movl -0x4c(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop