// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/bmff.c
// Function: do_box_data
static void do_box_data(deark *c, lctx *d, struct de_boxesctx *bctx)
{
	unsigned int type_field, type_namespace, wkt;
	unsigned int cntry, lang;
	i64 vlen;
	struct de_boxdata *curbox = bctx->curbox;
	struct de_boxdata *par;
	struct de_boxdata *gpar;
	i64 pos = curbox->payload_pos;
	de_ucstring *s = NULL;

	par = curbox->parent;
	if(!par) goto done;
	gpar = par->parent;
	if(!gpar) goto done;
	if(gpar->boxtype != BOX_ilst) goto done;

	if(curbox->payload_len<8) goto done;
	type_field = (unsigned int)dbuf_getu32be_p(bctx->f, &pos);
	type_namespace = type_field>>24;
	wkt = (type_field & 0x00ffffff); // well-known type (if namespace==0)
	de_dbg(c, "type: %u, %u (%s)", type_namespace, wkt,
		get_ilst_type_name(type_namespace, wkt));

	cntry = (unsigned int)dbuf_getu16be_p(bctx->f, &pos);
	lang = (unsigned int)dbuf_getu16be_p(bctx->f, &pos);
	de_dbg(c, "locale: %u, %u", cntry, lang);

	if(type_namespace!=0) goto done;
	vlen = curbox->payload_pos + curbox->payload_len - pos;

	if(wkt==1 || wkt==4) { // UTF-8
		s = ucstring_create(c);
		dbuf_read_to_ucstring_n(bctx->f, pos, vlen,
			DE_DBG_MAX_STRLEN, s, 0, DE_ENCODING_UTF8);
		de_dbg(c, "value: \"%s\"", ucstring_getpsz_d(s));
	}
	else if(wkt==21 && vlen==1) { // 1-byte signed int
		int n;
		n = (int)(signed char)dbuf_getbyte(bctx->f, pos);
		de_dbg(c, "value: %d", n);
	}
	else if(wkt==21 && vlen==2) { // 2-byte BE signed int
		int n;
		n = (int)dbuf_geti16be(bctx->f, pos);
		de_dbg(c, "value: %d", n);
	}
	else if(wkt==0) {
		de_dbg_hexdump(c, bctx->f, pos, vlen, 256, "value", 0x1);
	}
	// TODO: There are lots more types

done:
	ucstring_destroy(s);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x36a2e
jmp 0x36c46
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x36a45
jmp 0x36c46
movq -0x50(%rbp), %rax
cmpl $0x696c7374, 0xc(%rax)  # imm = 0x696C7374
je 0x36a57
jmp 0x36c46
movq -0x40(%rbp), %rax
cmpq $0x8, 0x40(%rax)
jge 0x36a67
jmp 0x36c46
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x1654b0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
shrl $0x18, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x36c60
movq -0x78(%rbp), %rdi
movl -0x70(%rbp), %edx
movl -0x6c(%rbp), %ecx
movq %rax, %r8
leaq 0x16a7dc(%rip), %rsi    # 0x1a129e
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x165210
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x165210
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %edx
movl -0x2c(%rbp), %ecx
leaq 0x16a7ae(%rip), %rsi    # 0x1a12b0
movb $0x0, %al
callq 0x15b0d0
cmpl $0x0, -0x20(%rbp)
je 0x36b14
jmp 0x36c46
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x40(%rbp), %rcx
addq 0x40(%rcx), %rax
subq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x1, -0x24(%rbp)
je 0x36b38
cmpl $0x4, -0x24(%rbp)
jne 0x36b98
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x58(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x60(%rbp), %r8
movl $0x1f4, %ecx            # imm = 0x1F4
xorl %r9d, %r9d
movl $0x2, (%rsp)
callq 0x166a40
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x60(%rbp), %rdi
callq 0x172650
movq -0x80(%rbp), %rdi
movq %rax, %rdx
leaq 0x167c9f(%rip), %rsi    # 0x19e82b
movb $0x0, %al
callq 0x15b0d0
jmp 0x36c44
cmpl $0x15, -0x24(%rbp)
jne 0x36bd3
cmpq $0x1, -0x38(%rbp)
jne 0x36bd3
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x58(%rbp), %rsi
callq 0x165060
movsbl %al, %eax
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rdi
movl -0x64(%rbp), %edx
leaq 0x17fb6a(%rip), %rsi    # 0x1b6734
movb $0x0, %al
callq 0x15b0d0
jmp 0x36c42
cmpl $0x15, -0x24(%rbp)
jne 0x36c0b
cmpq $0x2, -0x38(%rbp)
jne 0x36c0b
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x58(%rbp), %rsi
callq 0x165310
movl %eax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movl -0x68(%rbp), %edx
leaq 0x17fb32(%rip), %rsi    # 0x1b6734
movb $0x0, %al
callq 0x15b0d0
jmp 0x36c40
cmpl $0x0, -0x24(%rbp)
jne 0x36c3e
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x58(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
leaq 0x188926(%rip), %r9     # 0x1bf558
movl $0x1, (%rsp)
callq 0x15b840
jmp 0x36c40
jmp 0x36c42
jmp 0x36c44
jmp 0x36c46
movq -0x60(%rbp), %rdi
callq 0x171750
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)