// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x28(%rdx), %r13
movq 0x38(%r13), %rax
movq %rax, 0x8(%rsp)
movq (%r13), %rax
testq %rax, %rax
je 0x2ad0a
movq (%rax), %rax
testq %rax, %rax
je 0x2ad0a
cmpl $0x696c7374, 0xc(%rax)  # imm = 0x696C7374
jne 0x2ad0a
cmpq $0x8, 0x40(%r13)
jge 0x2ad24
xorl %r14d, %r14d
movq %r14, %rdi
callq 0xf6753
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r15
movq %rdi, %rbx
movq 0x10(%rdx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xeed31
movq %rax, %r12
movl %r12d, %edx
shrl $0x18, %edx
movl $0xffffff, %eax         # imm = 0xFFFFFF
movl %r12d, %ebp
andl %eax, %ebp
cmpl %eax, %r12d
ja 0x2ad6d
cmpl $0x1c, %ebp
ja 0x2adc5
movl %r12d, %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
leaq 0xeb6ac(%rip), %rcx     # 0x116410
movslq (%rcx,%rax,4), %r8
addq %rcx, %r8
jmp 0x2adcc
leaq 0xea6e2(%rip), %rsi     # 0x115456
leaq 0x1013d6(%rip), %r8     # 0x12c151
xorl %r14d, %r14d
movq %rbx, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8617
movq 0x10(%r15), %rdi
leaq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0xeeb91
movq %rax, %r13
movq 0x10(%r15), %rdi
movq %r12, %rsi
callq 0xeeb91
leaq 0xea6b7(%rip), %rsi     # 0x115468
movq %rbx, %rdi
movl %r13d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0xe8617
jmp 0x2ad0d
leaq 0x101385(%rip), %r8     # 0x12c151
leaq 0xea683(%rip), %rsi     # 0x115456
xorl %r14d, %r14d
movq %rbx, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8617
movq 0x10(%r15), %rdi
leaq 0x8(%rsp), %rsi
callq 0xeeb91
movq %rax, 0x10(%rsp)
movq 0x10(%r15), %rdi
leaq 0x8(%rsp), %rsi
callq 0xeeb91
leaq 0xea65e(%rip), %rsi     # 0x115468
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0xe8617
cmpl $0xffffff, %r12d        # imm = 0xFFFFFF
ja 0x2ad0d
movq 0x40(%r13), %r12
addq 0x38(%r13), %r12
movq 0x8(%rsp), %rdx
subq %rdx, %r12
cmpl $0x4, %ebp
je 0x2ae42
cmpl $0x1, %ebp
jne 0x2ae91
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r14
movq 0x10(%r15), %rdi
movq 0x8(%rsp), %rsi
movl $0x2, (%rsp)
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r12, %rdx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xefc2a
movq %r14, %rdi
callq 0xf70f6
leaq 0xe78ec(%rip), %rsi     # 0x11276b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
jmp 0x2ad0d
cmpl $0x15, %ebp
jne 0x2aeba
cmpq $0x1, %r12
jne 0x2aeba
movq 0x10(%r15), %rdi
movq %rdx, %rsi
callq 0xeead3
movsbl %al, %edx
leaq 0xffe72(%rip), %rsi     # 0x12ad24
xorl %r14d, %r14d
movq %rbx, %rdi
jmp 0x2aee0
cmpl $0x15, %ebp
jne 0x2aeec
cmpq $0x2, %r12
jne 0x2aeec
movq 0x10(%r15), %rdi
movq %rdx, %rsi
callq 0xeec17
leaq 0xffe4c(%rip), %rsi     # 0x12ad24
xorl %r14d, %r14d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
jmp 0x2ad0d
testl %ebp, %ebp
jne 0x2ad0a
movq 0x10(%r15), %rsi
movl $0x1, (%rsp)
leaq 0x108c0b(%rip), %r9     # 0x133b11
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
movq %r12, %rcx
callq 0xe8bea
jmp 0x2ad0a