// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/emf.c
// Function: emf_handler_46
static int emf_handler_46(deark *c, lctx *d, struct decoder_params *dp)
{
	const char *name;
	i64 datasize;
	int handled = 0;
	enum cmtid_enum { CMTID_UNK, CMTID_EMFSPOOL, CMTID_EMFPLUS, CMTID_PUBLIC,
		CMTID_INKSCAPESCREEN, CMTID_INKSCAPEDRAWING };
	enum cmtid_enum cmtid;

	if(dp->recsize_bytes<16) goto done;

	// Datasize is measured from the beginning of the next field (CommentIdentifier).
	datasize = de_getu32le(dp->recpos+8);
	de_dbg(c, "datasize: %"I64_FMT, datasize);
	if(12+datasize > dp->recsize_bytes) goto done;

	cmtid = CMTID_UNK;
	name="?";

	if(datasize>=4) {
		struct de_fourcc id4cc;

		// The first 4 bytes of comment data might or might not be a signature.
		// The spec expects these bytes to be read as a little-endian int, which is
		// then interpreted as a FOURCC, most-significant byte first.
		// The standard FOURCC codes are designed backwards, so that in the
		// file they appear forward. E.g. the spec says a code is "+FME", but in
		// the file the bytes "EMF+" appear in that order. Our messages respect the
		// spec, though it looks strange.
		dbuf_read_fourcc(c->infile, dp->recpos+12, &id4cc, 4, 0x1);

		if(id4cc.id==0x00000000) {
			cmtid = CMTID_EMFSPOOL;
			name = "EMR_COMMENT_EMFSPOOL";
		}
		else if(id4cc.id==CODE_EMFPLUS) {
			cmtid = CMTID_EMFPLUS;
			name = "EMR_COMMENT_EMFPLUS";
		}
		else if(id4cc.id==CODE_GDIC) {
			cmtid = CMTID_PUBLIC;
			name = "EMR_COMMENT_PUBLIC";
		}

		de_dbg(c, "type: 0x%08x '%s' (%s)", (UI)id4cc.id,
			id4cc.id_dbgstr, name);
	}

	if(cmtid==CMTID_UNK) {
		u8 buf[16];

		// FOURCC not recognized; try other methods
		de_read(buf, dp->recpos+12, 16);
		if(datasize>=7 && !de_memcmp(buf, "Screen=", 7)) {
			cmtid = CMTID_INKSCAPESCREEN;
			name = "Inkscape canvas size";
		}
		else if(datasize>=8 && !de_memcmp(buf, "Drawing=", 8)) {
			cmtid = CMTID_INKSCAPEDRAWING;
			name = "Inkscape image size";
		}

		de_dbg(c, "identified as: %s", name);
	}

	if(cmtid==CMTID_EMFPLUS) {
		do_comment_emfplus(c, d, dp->recpos+16, datasize-4);
		handled = 1;
	}
	else if(cmtid==CMTID_PUBLIC) {
		do_comment_public(c, d, dp->recpos+16, datasize-4);
		handled = 1;
	}

	if(!handled) {
		de_dbg_hexdump(c, c->infile, dp->recpos+12, datasize, 256, NULL, 0x1);
	}

done:
	return 1;
}

// Assembly:
cmpq $0x10, 0x10(%rdx)
jl 0x42ac6
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r14
movq %rdi, %rbx
movq 0x18(%rdi), %rdi
movq 0x8(%rdx), %rsi
addq $0x8, %rsi
callq 0xeed61
movq %rax, %r15
leaq 0xd96db(%rip), %rsi     # 0x11b980
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
leaq 0xc(%r15), %rax
cmpq 0x10(%r14), %rax
jg 0x42ab8
cmpq $0x4, %r15
movq %rbx, 0x10(%rsp)
jl 0x42373
movq 0x18(%rbx), %rdi
movq 0x8(%r14), %rsi
addq $0xc, %rsi
leaq 0x40(%rsp), %r12
movl $0x1, %ebp
movq %r12, %rdx
movl $0x4, %ecx
movl $0x1, %r8d
callq 0xf1762
movl 0x4(%r12), %edx
testl %edx, %edx
je 0x4232d
cmpl $0x43494447, %edx       # imm = 0x43494447
je 0x4231f
cmpl $0x2b464d45, %edx       # imm = 0x2B464D45
jne 0x42351
movl $0x2, %ebp
leaq 0xd9686(%rip), %r8      # 0x11b9a3
jmp 0x42334
movl $0x3, %ebp
leaq 0xd968c(%rip), %r8      # 0x11b9b7
jmp 0x42334
leaq 0xd965a(%rip), %r8      # 0x11b98e
leaq 0x50(%rsp), %rcx
leaq 0xd968a(%rip), %rsi     # 0x11b9ca
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0xe8617
jmp 0x423f4
leaq 0x50(%rsp), %rcx
leaq 0xd966d(%rip), %rsi     # 0x11b9ca
leaq 0xe9ded(%rip), %r8      # 0x12c151
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq 0x8(%r14), %rdx
addq $0xc, %rdx
leaq 0x40(%rsp), %rsi
movl $0x10, %ecx
callq 0xee8d4
cmpq $0x7, %r15
jl 0x423ae
movl $0x65726353, %eax       # imm = 0x65726353
xorl 0x40(%rsp), %eax
movl $0x3d6e6565, %ecx       # imm = 0x3D6E6565
xorl 0x43(%rsp), %ecx
orl %eax, %ecx
je 0x42a69
cmpq $0x8, %r15
setge %al
movabsq $0x3d676e6977617244, %rcx # imm = 0x3D676E6977617244
cmpq %rcx, 0x40(%rsp)
sete %cl
andb %al, %cl
leaq 0xd962e(%rip), %rax     # 0x11b9fe
leaq 0xe9d7a(%rip), %rdx     # 0x12c151
cmovneq %rax, %rdx
movzbl %cl, %eax
leal (%rax,%rax,4), %ebp
leaq 0xe8a72(%rip), %rsi     # 0x12ae5a
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0xe8617
cmpl $0x3, %ebp
je 0x429e6
cmpl $0x2, %ebp
jne 0x42a22
movq 0x8(%r14), %rbx
leaq 0x10(%rbx), %r14
leaq -0x4(%r15), %rcx
leaq 0xd95f9(%rip), %rsi     # 0x11ba12
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r12, %rdi
movl $0x1, %esi
callq 0xe8a15
cmpq $0x5, %r15
jl 0x429d2
leaq (%rbx,%r15), %rax
addq $0xc, %rax
leaq 0x13edaf(%rip), %r13    # 0x181200
xorl %ebp, %ebp
movq %rax, 0x30(%rsp)
movq %rax, %rcx
subq %r14, %rcx
xorl %edx, %edx
cmpq $0xc, %rcx
jl 0x428e2
movq %r13, %r15
movq 0x10(%rsp), %r13
movq 0x18(%r13), %rdi
movq %r14, %rsi
callq 0xeebc8
movq %rax, %r12
movq 0x18(%r13), %rdi
leaq 0x2(%r14), %rsi
callq 0xeebc8
movq %rax, %rbx
movq 0x18(%r13), %rdi
leaq 0x4(%r14), %rsi
callq 0xeed61
movq %rax, 0x38(%rsp)
cmpl $0x4008, %r12d          # imm = 0x4008
sete %al
movq %rbx, 0x20(%rsp)
testw %bx, %bx
sets %bl
andb %al, %bl
movzbl %bl, %eax
movl %eax, 0x2c(%rsp)
movq 0x18(%r13), %rdi
movq %r15, %r13
leaq 0x8(%r14), %rsi
callq 0xeed61
movq %rax, %r15
leaq 0xc(%r14), %rdx
movl $0x8, %eax
cmpl %r12d, -0x8(%rax,%r13)
je 0x424f9
addq $0x10, %rax
cmpq $0x2f8, %rax            # imm = 0x2F8
jne 0x424dd
leaq 0xe9c5a(%rip), %rcx     # 0x12c151
jmp 0x424fd
movq (%rax,%r13), %rcx
movq %r15, 0x8(%rsp)
movq %rdx, 0x18(%rsp)
movq %rdx, (%rsp)
movq 0x10(%rsp), %rdi
leaq 0xd9515(%rip), %rsi     # 0x11ba2c
movl %r12d, %edx
movq %r14, %r8
movq 0x20(%rsp), %r9
xorl %eax, %eax
callq 0xe8617
testl %ebp, %ebp
setne %al
orb %al, %bl
jne 0x428c7
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movl $0x1, %esi
callq 0xe8a15
cmpl $0x4003, %r12d          # imm = 0x4003
jne 0x42588
cmpl $0x2, (%rbp)
jl 0x4264d
movq 0x18(%rbp), %rsi
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbp, %rdi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
leaq 0x102294(%rip), %r9     # 0x144812
callq 0xe8bea
jmp 0x428ba
cmpl $0x4008, %r12d          # imm = 0x4008
jne 0x4266b
movq 0x20(%rsp), %rax
movl %eax, %r12d
shrl $0x8, %r12d
andl $0x7f, %r12d
leaq 0xe9ba5(%rip), %rcx     # 0x12c151
cmpl $0x9, %r12d
ja 0x425c3
movl %r12d, %eax
leaq 0xd9950(%rip), %rdx     # 0x11bf0c
movslq (%rdx,%rax,4), %rcx
addq %rdx, %rcx
movzbl 0x20(%rsp), %r8d
movq %rbp, %rdi
leaq 0xd973e(%rip), %rsi     # 0x11bd11
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbp, %rdi
movl $0x1, %esi
callq 0xe8a15
cmpl $0x5, %r12d
jne 0x428ad
movq %r15, %rbx
movq 0x18(%rbp), %rdi
movq 0x18(%rsp), %rsi
callq 0xeed61
movq %rax, %r15
movq 0x18(%rbp), %rdi
leaq 0x10(%r14), %rsi
callq 0xeed61
movq %rbp, %rdi
leaq 0xd9723(%rip), %rsi     # 0x11bd42
movl %r15d, %edx
cmpq $0x2, %rax
je 0x427c8
cmpq $0x1, %rax
je 0x426fb
testq %rax, %rax
jne 0x4289d
xorl %ecx, %ecx
leaq 0xd96eb(%rip), %r8      # 0x11bd33
jmp 0x428a6
movq %rbp, %rdi
leaq 0xd9668(%rip), %rsi     # 0x11bcbf
movq %r15, %rdx
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0xe8617
jmp 0x428ba
cmpl $0x401c, %r12d          # imm = 0x401C
jne 0x428ba
leaq 0x14(%r14), %rsi
movq 0x18(%rbp), %rdi
callq 0xeed61
movq %rax, %r12
leaq (%r14,%rax,2), %rax
addq $0x28, %rax
addq 0x18(%rsp), %r15
cmpq %r15, %rax
jle 0x4269f
xorl %r15d, %r15d
jmp 0x426ee
leaq 0x28(%r14), %rbx
addq %r12, %r12
movq %rbp, %rdi
callq 0xf6410
movq %rax, %r15
movq 0x18(%rbp), %rdi
movl $0x3, (%rsp)
movl $0x3e8, %ecx            # imm = 0x3E8
movq %rbx, %rsi
movq %r12, %rdx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xefc2a
movq %r15, %rdi
callq 0xf705c
movq %rbp, %rdi
leaq 0xf89c0(%rip), %rsi     # 0x13b0a4
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r15, %rdi
callq 0xf6753
jmp 0x428ba
movl $0x1, %ecx
leaq 0xd9634(%rip), %r8      # 0x11bd3b
xorl %eax, %eax
callq 0xe8617
cmpq $0x9, %rbx
jl 0x428ad
leaq 0x14(%r14), %rsi
movq 0x18(%rbp), %rdi
callq 0xeed61
movq %rax, %r15
movq 0x18(%rbp), %rdi
leaq 0x18(%r14), %rsi
callq 0xeed61
movq %rbp, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0xe8f88
movq 0x18(%rbp), %rdi
leaq 0x24(%r14), %rsi
callq 0xeed61
movq %rax, %r15
cmpq $0x1, %rax
leaq 0xe99f3(%rip), %rcx     # 0x12c151
leaq 0xf8f14(%rip), %rax     # 0x13b679
cmoveq %rax, %rcx
testq %r15, %r15
leaq 0xfabd5(%rip), %rax     # 0x13d348
cmoveq %rax, %rcx
movq %rbp, %rdi
leaq 0x100655(%rip), %rsi    # 0x142dd6
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
cmpq $0x1, %r15
jne 0x428ad
leaq -0x8(%rbx), %rax
cmpq $0x15, %rax
jb 0x427b5
movq 0x18(%rsp), %rcx
addq %rbx, %rcx
movq 0x18(%rbp), %rax
cmpq 0x18(%rax), %rcx
jle 0x428f5
xorl %r15d, %r15d
movq %rbp, %rdi
movq %r15, %rsi
callq 0xe8be2
jmp 0x428ad
movl $0x2, %ecx
leaq 0xdca54(%rip), %r8      # 0x11f228
xorl %eax, %eax
callq 0xe8617
cmpq $0x10, %rbx
jl 0x428ad
leaq 0x14(%r14), %rsi
movq 0x18(%rbp), %rdi
callq 0xeed61
movq %rax, %r15
leaq -0x1(%rax), %rdx
leaq 0xe9951(%rip), %rcx     # 0x12c151
cmpq $0x4, %rdx
ja 0x42814
leaq 0xd972f(%rip), %rax     # 0x11bf3c
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
movq %rdx, 0x20(%rsp)
movq %rbp, %rdi
leaq 0x1005b3(%rip), %rsi    # 0x142dd6
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbp), %rdi
leaq 0x18(%r14), %rsi
callq 0xeed61
movq %rax, %r12
movq %rbp, %rdi
leaq 0xd9589(%rip), %rsi     # 0x11bdd0
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
testq %r12, %r12
setle %al
addq $-0x10, %rbx
cmpq %rbx, %r12
seta %cl
orb %al, %cl
jne 0x428ad
leaq 0xd9d0b(%rip), %rcx     # 0x11c577
cmpq $0x2, 0x20(%rsp)
jb 0x42885
addq $-0x3, %r15
leaq 0xd88f6(%rip), %rcx     # 0x11b175
cmpq $0x2, %r15
ja 0x428ad
movq 0x18(%rbp), %rdi
leaq 0x1c(%r14), %rsi
movq %r12, %rdx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xefd48
jmp 0x428ad
movl %eax, %ecx
leaq 0xe98ab(%rip), %r8      # 0x12c151
xorl %eax, %eax
callq 0xe8617
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x38(%rsp), %rcx
cmpq $0xd, %rcx
movl $0xc, %eax
cmovlq %rax, %rcx
movq 0x30(%rsp), %rax
movl 0x2c(%rsp), %edx
addq %rcx, %r14
movl %edx, %ebp
cmpq %rax, %r14
jl 0x42458
jmp 0x429d2
movq %rcx, 0x18(%rsp)
leaq 0x28(%r14), %r12
addq $-0x1c, %rbx
movq %rbp, %rdi
leaq 0xd9457(%rip), %rsi     # 0x11bd63
movq %r12, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0xe8617
movl $0x78, %esi
movq %rbp, %rdi
callq 0xe8b2b
movq %rax, %r15
movq 0x18(%rbp), %rax
movq %rax, 0x10(%r15)
movq %r12, 0x18(%r15)
movq %rbx, 0x20(%r15)
movb $0x1, (%r15)
movq %rbp, %rdi
movq %r15, %rsi
callq 0xf9e98
movl 0x68(%r15), %eax
cmpl $0xc, %eax
je 0x4296e
testl %eax, %eax
jne 0x429b1
movq %rbp, %rdi
leaq 0xd9422(%rip), %rsi     # 0x11bd81
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8faa
jmp 0x427b8
movq 0x18(%rbp), %rdi
movq 0x18(%rsp), %rdx
addq $-0x4, %rdx
movl $0x4, %ecx
movl $0x82, %esi
leaq 0x40(%rsp), %r8
callq 0xefa77
testl %eax, %eax
je 0x429b1
movq 0x40(%rsp), %rbx
subq %r12, %rbx
movabsq $0x7ffffffffffffffe, %rax # imm = 0x7FFFFFFFFFFFFFFE
cmpq %rax, %rbx
ja 0x428ad
incq %rbx
movq 0x18(%rbp), %rdi
movq %r15, %rcx
addq $0x6c, %rcx
movq %r12, %rsi
movq %rbx, %rdx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xefd48
jmp 0x427b8
movq 0x10(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
jmp 0x42ab8
movq 0x8(%r14), %rsi
addq $0x10, %rsi
movq 0x10(%rsp), %rbx
movq 0x18(%rbx), %rdi
callq 0xeed61
cmpl $0x3f, %eax
jg 0x42a4d
cmpl $0x80000001, %eax       # imm = 0x80000001
je 0x42a7a
cmpl $0x2, %eax
je 0x42a95
cmpl $0x3, %eax
jne 0x42a8c
leaq 0xd93e7(%rip), %rcx     # 0x11be04
jmp 0x42aa5
movq 0x10(%rsp), %rdi
movq 0x18(%rdi), %rsi
movq 0x8(%r14), %rdx
addq $0xc, %rdx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %r15, %rcx
xorl %r9d, %r9d
callq 0xe8bea
jmp 0x42ab8
cmpl $0x40, %eax
je 0x42a83
cmpl $0x80, %eax
je 0x42a9e
cmpl $0x40000004, %eax       # imm = 0x40000004
jne 0x42a8c
leaq 0xd93a6(%rip), %rcx     # 0x11be0d
jmp 0x42aa5
movl $0x4, %ebp
leaq 0xd8f74(%rip), %rdx     # 0x11b9e9
jmp 0x423e1
leaq 0xd9367(%rip), %rcx     # 0x11bde8
jmp 0x42aa5
leaq 0xd9390(%rip), %rcx     # 0x11be1a
jmp 0x42aa5
leaq 0xe96be(%rip), %rcx     # 0x12c151
jmp 0x42aa5
leaq 0xd935d(%rip), %rcx     # 0x11bdf9
jmp 0x42aa5
leaq 0xd9384(%rip), %rcx     # 0x11be29
leaq 0xd9389(%rip), %rsi     # 0x11be35
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl $0x1, %eax
retq