// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/asf.c
// Function: do_metadata_item
static void do_metadata_item(deark *c, lctx *d, i64 pos, i64 val_len,
	unsigned int val_data_type_ori, struct de_stringreaderdata *name_srd,
	u32 object_sid)
{
	de_ucstring *val_str = NULL;
	i64 val_int;
	int handled = 0;
	unsigned int val_data_type; // adjusted type

	de_dbg(c, "value data at %"I64_FMT", len=%d", pos, (int)val_len);

	val_data_type = val_data_type_ori; // default
	if(val_data_type_ori==2) {
		if(object_sid==SID_ECD) {
			val_data_type = 3; // Pretend a 32-bit BOOL is a DWORD
		}
		else {
			val_data_type = 5; // Pretend a 16-bit BOOL is a WORD
		}
	}

	if(val_data_type==0 && val_len>=2) { // Unicode string
		val_str = ucstring_create(c);
		dbuf_read_to_ucstring_n(c->infile, pos, val_len-2, DE_DBG_MAX_STRLEN*2, val_str,
			0, DE_ENCODING_UTF16LE);
		de_dbg(c, "value: \"%s\"", ucstring_getpsz(val_str));
		handled = 1;
	}
	else if(val_data_type==3 && val_len>=4) { // DWORD
		val_int = de_getu32le(pos);
		de_dbg(c, "value: %u", (unsigned int)val_int);
		handled = 1;
	}
	else if(val_data_type==4 && val_len>=8) {
		val_int = de_geti64le(pos);
		if(!de_strcmp(name_srd->sz_utf8, "WM/EncodingTime")) {
			do_WMEncodingTime(c, d, val_int);
		}
		else {
			de_dbg(c, "value: %"I64_FMT, val_int);
		}
		handled = 1;
	}
	else if(val_data_type==5 && val_len>=2) { // WORD
		val_int = de_getu16le(pos);
		de_dbg(c, "value: %u", (unsigned int)val_int);
		handled = 1;
	}
	else if(val_data_type==6 && val_len>=16) { // GUID
		u8 guid_raw[16];
		char guid_string[50];

		read_and_render_guid(c->infile, guid_raw, pos, guid_string, sizeof(guid_string));
		de_dbg(c, "value: {%s}", guid_string);
		handled = 1;
	}
	else if(val_data_type==1) { // binary
		if(!de_strcmp(name_srd->sz_utf8, "ID3")) {
			do_ECD_ID3(c, d, pos, val_len);
			handled = 1;
		}
		else if(!de_strcmp(name_srd->sz_utf8, "WM/Picture")) {
			do_ECD_WMPicture(c, d, pos, val_len);
			handled = 1;
		}
	}

	if(!handled) {
		de_dbg_indent(c, 1);
		de_dbg_hexdump(c, c->infile, pos, val_len, 256, NULL, 0x1);
		de_dbg_indent(c, -1);
	}

	ucstring_destroy(val_str);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, %ebp
movq %r8, %r12
movl %ecx, %r13d
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xe604b(%rip), %rsi     # 0x105731
movq %r14, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0xde896
xorl %eax, %eax
cmpl $0xd2, %ebp
setne %al
cmpl $0x2, %r13d
leal 0x3(%rax,%rax), %eax
cmovnel %r13d, %eax
testl %eax, %eax
setne %cl
cmpq $0x2, %r15
setl %dl
orb %cl, %dl
jne 0x1f768
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r12
movq 0x18(%rbx), %rdi
addq $-0x2, %r15
movl $0x3, (%rsp)
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r14, %rsi
movq %r15, %rdx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xe4ced
movq %r12, %rdi
callq 0xeb7e4
leaq 0xe5ff2(%rip), %rsi     # 0x10574b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
jmp 0x1f79b
cmpl $0x3, %eax
setne %cl
cmpq $0x4, %r15
setl %dl
orb %cl, %dl
jne 0x1f7b2
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe409f
leaq 0x10b706(%rip), %rsi    # 0x12ae92
xorl %r12d, %r12d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq %r12, %rdi
callq 0xeaf3c
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x4, %eax
setne %cl
cmpq $0x8, %r15
setl %dl
orb %cl, %dl
jne 0x1f7fc
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe418b
movq %rax, %r14
movq 0x20(%r12), %rdi
leaq 0xe5f79(%rip), %rsi     # 0x105757
callq 0x181a0
testl %eax, %eax
je 0x1f85d
leaq 0xe5f79(%rip), %rsi     # 0x105767
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r14, %rdx
jmp 0x1f75f
cmpq $0x2, %r15
setl %cl
cmpl $0x5, %eax
setne %dl
orb %cl, %dl
jne 0x1f81e
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe3fa3
jmp 0x1f785
cmpl $0x6, %eax
setne %cl
cmpq $0x10, %r15
setl %dl
orb %cl, %dl
jne 0x1f88c
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x20(%rsp), %r15
movq %r14, %rdx
movq %r15, %rcx
callq 0x1decd
leaq 0xe5f23(%rip), %rsi     # 0x105772
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r15, %rdx
jmp 0x1f75f
leaq 0x20(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x1f60a
leaq 0xe5f19(%rip), %rsi     # 0x10578d
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xde896
jmp 0x1f79b
cmpl $0x1, %eax
jne 0x1f8bc
movq 0x20(%r12), %r12
leaq 0xe5ee1(%rip), %rsi     # 0x10577e
movq %r12, %rdi
callq 0x181a0
testl %eax, %eax
je 0x1f8ee
leaq 0xe5ed2(%rip), %rsi     # 0x105782
movq %r12, %rdi
callq 0x181a0
testl %eax, %eax
je 0x1f927
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rsi
movl $0x1, (%rsp)
xorl %r12d, %r12d
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
xorl %r9d, %r9d
callq 0xded3a
jmp 0x1f96c
leaq 0xe5ea8(%rip), %rsi     # 0x10579d
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rcx
leaq 0xe5e98(%rip), %rsi     # 0x1057b6
leaq 0x1042f4(%rip), %rdx    # 0x123c19
jmp 0x1f95e
leaq 0xe5e8c(%rip), %rsi     # 0x1057ba
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rcx
leaq 0xe5e5f(%rip), %rsi     # 0x1057b6
leaq 0xf7190(%rip), %rdx     # 0x116aee
movq %rbx, %rdi
movq %r14, %r8
movq %r15, %r9
callq 0xdfa28
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
jmp 0x1f79b