// File: /workspace/github_c_makefile_star2_O3/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 0xf2b49(%rip), %rsi     # 0x112751
movq %r14, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0xe8617
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 0x1fc8a
movq %rbx, %rdi
callq 0xf6410
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 0xefc2a
movq %r12, %rdi
callq 0xf705c
leaq 0xf2af0(%rip), %rsi     # 0x11276b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
jmp 0x1fcbd
cmpl $0x3, %eax
setne %cl
cmpq $0x4, %r15
setl %dl
orb %cl, %dl
jne 0x1fcd4
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeed61
leaq 0x1184e4(%rip), %rsi    # 0x138192
xorl %r12d, %r12d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq %r12, %rdi
callq 0xf6753
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 0x1fd1e
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeef09
movq %rax, %r14
movq 0x20(%r12), %rdi
leaq 0xf2a77(%rip), %rsi     # 0x112777
callq 0x181a0
testl %eax, %eax
je 0x1fd7f
leaq 0xf2a77(%rip), %rsi     # 0x112787
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r14, %rdx
jmp 0x1fc81
cmpq $0x2, %r15
setl %cl
cmpl $0x5, %eax
setne %dl
orb %cl, %dl
jne 0x1fd40
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeebc8
jmp 0x1fca7
cmpl $0x6, %eax
setne %cl
cmpq $0x10, %r15
setl %dl
orb %cl, %dl
jne 0x1fdae
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x20(%rsp), %r15
movq %r14, %rdx
movq %r15, %rcx
callq 0x1e3cf
leaq 0xf2a21(%rip), %rsi     # 0x112792
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r15, %rdx
jmp 0x1fc81
leaq 0x20(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x1fb49
leaq 0xf2a17(%rip), %rsi     # 0x1127ad
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xe8617
jmp 0x1fcbd
cmpl $0x1, %eax
jne 0x1fdde
movq 0x20(%r12), %r12
leaq 0xf29df(%rip), %rsi     # 0x11279e
movq %r12, %rdi
callq 0x181a0
testl %eax, %eax
je 0x1fe22
leaq 0xf29d0(%rip), %rsi     # 0x1127a2
movq %r12, %rdi
callq 0x181a0
testl %eax, %eax
je 0x1fe32
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
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 0xe8bea
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
jmp 0x1fcbd
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1fe48
jmp 0x1fe40
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1fea9
xorl %r12d, %r12d
jmp 0x1fcbd