// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0xf2c38(%rip), %rsi     # 0x112741
movq %r15, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0xe9226
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, %r14
setl %dl
orb %cl, %dl
jne 0x1fb8d
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r12
movq 0x18(%rbx), %rdi
leaq -0x2(%r14), %rdx
movl $0x3, (%rsp)
xorl %ebp, %ebp
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rsi
movq %rax, %r8
xorl %r9d, %r9d
callq 0xf0203
movq %r12, %rdi
callq 0xf74bd
leaq 0xf2be0(%rip), %rsi     # 0x11275b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
jmp 0x1fc95
cmpl $0x3, %eax
setne %cl
cmpq $0x4, %r14
setl %dl
orb %cl, %dl
jne 0x1fbc5
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef37e
leaq 0x118255(%rip), %rsi    # 0x137e06
xorl %r12d, %r12d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
jmp 0x1fc93
cmpl $0x4, %eax
setne %cl
cmpq $0x8, %r14
setl %dl
orb %cl, %dl
jne 0x1fc03
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef536
movq %rax, %r13
movq 0x20(%r12), %rdi
leaq 0xf2b76(%rip), %rsi     # 0x112767
callq 0x181a0
testl %eax, %eax
je 0x1fc69
leaq 0xf2b76(%rip), %rsi     # 0x112777
jmp 0x1fc57
cmpq $0x2, %r14
setl %cl
cmpl $0x5, %eax
setne %dl
orb %cl, %dl
jne 0x1fc22
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ca
jmp 0x1fbaa
cmpl $0x6, %eax
setne %cl
cmpq $0x10, %r14
setl %dl
orb %cl, %dl
jne 0x1fced
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x20(%rsp), %r13
movq %r15, %rdx
movq %r13, %rcx
callq 0x1e29d
leaq 0xf2b2b(%rip), %rsi     # 0x112782
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe9226
jmp 0x1fc93
leaq 0x20(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1fa47
leaq 0xf2b1d(%rip), %rsi     # 0x11279d
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xe9226
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x1fcd6
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rsi
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
movq %r15, %rdx
movq %r14, %rcx
xorl %r9d, %r9d
callq 0xe975a
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %r12, %rdi
callq 0xf6bb0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bpl
cmpl $0x1, %eax
jne 0x1fd20
movq 0x20(%r12), %r12
leaq 0xf2a8d(%rip), %rsi     # 0x11278e
movq %r12, %rdi
callq 0x181a0
testl %eax, %eax
je 0x1fd28
leaq 0xf2a7e(%rip), %rsi     # 0x112792
movq %r12, %rdi
callq 0x181a0
testl %eax, %eax
je 0x1fd38
xorl %r12d, %r12d
jmp 0x1fc95
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1fd4e
jmp 0x1fd46
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1fdaf
xorl %r12d, %r12d
jmp 0x1fc93