// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil.c
// Function: do_box
static int do_box(deark *c, struct de_boxesctx *bctx, i64 pos, i64 len,
	int level, i64 *pbytes_consumed)
{
	i64 size32, size64;
	i64 header_len; // Not including UUIDs
	i64 payload_len; // Including UUIDs
	i64 total_len;
	struct de_fourcc box4cc;
	int ret;
	int retval = 0;
	struct de_boxdata *parentbox;
	struct de_boxdata *curbox;
	struct boxes_parser_data *pctx = (struct boxes_parser_data*)bctx->private_data;

	parentbox = bctx->curbox;
	bctx->curbox = de_malloc(c, sizeof(struct de_boxdata));
	curbox = bctx->curbox;
	curbox->parent = parentbox;

	if(len<8) {
		de_dbg(c, "(ignoring %d extra bytes at %"I64_FMT")", (int)len, pos);
		goto done;
	}

	size32 = dbuf_getu32be(bctx->f, pos);
	dbuf_read_fourcc(bctx->f, pos+4, &box4cc, 4, 0x0);
	curbox->boxtype = box4cc.id;

	if(size32>=8) {
		header_len = 8;
		payload_len = size32-8;
	}
	else if(size32==0) {
		header_len = 8;
		payload_len = len-8;
	}
	else if(size32==1) {
		if(len<16) {
			de_dbg(c, "(ignoring %d extra bytes at %"I64_FMT")", (int)len, pos);
			goto done;
		}
		header_len = 16;
		size64 = dbuf_geti64be(bctx->f, pos+8);
		de_sanitize_length(&size64);
		if(size64<16) goto done;
		payload_len = size64-16;
	}
	else {
		de_err(c, "Invalid or unsupported box format");
		goto done;
	}

	total_len = header_len + payload_len;

	if(curbox->boxtype==DE_BOX_uuid && payload_len>=16) {
		curbox->is_uuid = 1;
		dbuf_read(bctx->f, curbox->uuid, pos+header_len, 16);
	}

	curbox->level = level;
	curbox->box_pos = pos;
	curbox->box_len = total_len;
	curbox->payload_pos = pos+header_len;
	curbox->payload_len = payload_len;
	if(curbox->is_uuid) {
		curbox->payload_pos += 16;
		curbox->payload_len -= 16;
	}

	if(bctx->identify_box_fn) {
		bctx->identify_box_fn(c, bctx);
	}

	if(c->debug_level>0) {
		if(curbox->box_name) {
			de_snprintf(pctx->name_str, sizeof(pctx->name_str), " (%s)", curbox->box_name);
		}
		else {
			pctx->name_str[0] = '\0';
		}

		if(curbox->is_uuid) {
			fmtutil_render_uuid(c, curbox->uuid, pctx->uuid_string, sizeof(pctx->uuid_string));
			de_dbg(c, "box '%s'{%s}%s at %"I64_FMT", len=%"I64_FMT,
				box4cc.id_dbgstr, pctx->uuid_string, pctx->name_str,
				pos, total_len);
		}
		else {
			de_dbg(c, "box '%s'%s at %"I64_FMT", len=%"I64_FMT", dlen=%"I64_FMT,
				box4cc.id_dbgstr, pctx->name_str, pos,
				total_len, payload_len);
		}
	}

	if(total_len > len) {
		de_err(c, "Invalid oversized box, or unexpected end of file "
			"(box at %"I64_FMT" ends at %"I64_FMT", "
			"parent ends at %"I64_FMT")",
			pos, pos+total_len, pos+len);
		goto done;
	}

	de_dbg_indent(c, 1);
	ret = bctx->handle_box_fn(c, bctx);
	de_dbg_indent(c, -1);
	if(!ret) goto done;

	if(curbox->is_superbox) {
		i64 children_pos, children_len;
		i64 max_nchildren;

		de_dbg_indent(c, 1);
		children_pos = curbox->payload_pos + curbox->extra_bytes_before_children;
		children_len = curbox->payload_len - curbox->extra_bytes_before_children;
		max_nchildren = (curbox->num_children_is_known) ? curbox->num_children : -1;
		do_box_sequence(c, bctx, children_pos, children_len, max_nchildren, level+1);
		de_dbg_indent(c, -1);
	}

	*pbytes_consumed = total_len;
	retval = 1;

done:
	de_free(c, bctx->curbox);
	bctx->curbox = parentbox; // Restore the curbox pointer
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x90(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rdi
movl $0x78, %esi
callq 0x15b780
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x8, -0x20(%rbp)
jge 0x176e3c
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rcx
leaq 0x5f637(%rip), %rsi     # 0x1d6467
movb $0x0, %al
callq 0x15b0d0
jmp 0x177292
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165470
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
leaq -0x88(%rbp), %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movl -0x84(%rbp), %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0xc(%rax)
cmpq $0x8, -0x38(%rbp)
jl 0x176ea5
movq $0x8, -0x48(%rbp)
movq -0x38(%rbp), %rax
subq $0x8, %rax
movq %rax, -0x50(%rbp)
jmp 0x176f53
cmpq $0x0, -0x38(%rbp)
jne 0x176ec5
movq $0x8, -0x48(%rbp)
movq -0x20(%rbp), %rax
subq $0x8, %rax
movq %rax, -0x50(%rbp)
jmp 0x176f51
cmpq $0x1, -0x38(%rbp)
jne 0x176f38
cmpq $0x10, -0x20(%rbp)
jge 0x176ef4
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rcx
leaq 0x5f57f(%rip), %rsi     # 0x1d6467
movb $0x0, %al
callq 0x15b0d0
jmp 0x177292
movq $0x10, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
callq 0x165730
movq %rax, -0x40(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x15f830
cmpq $0x10, -0x40(%rbp)
jge 0x176f2a
jmp 0x177292
movq -0x40(%rbp), %rax
subq $0x10, %rax
movq %rax, -0x50(%rbp)
jmp 0x176f4f
movq -0x8(%rbp), %rdi
leaq 0x5f545(%rip), %rsi     # 0x1d6488
movb $0x0, %al
callq 0x15bfb0
jmp 0x177292
jmp 0x176f51
jmp 0x176f53
movq -0x48(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0xa0(%rbp), %rax
cmpl $0x75756964, 0xc(%rax)  # imm = 0x75756964
jne 0x176fa9
cmpq $0x10, -0x50(%rbp)
jl 0x176fa9
movq -0xa0(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0xa0(%rbp), %rsi
addq $0x14, %rsi
movq -0x18(%rbp), %rdx
addq -0x48(%rbp), %rdx
movl $0x10, %ecx
callq 0x164d10
movl -0x24(%rbp), %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x58(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rcx
addq -0x48(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x50(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0xa0(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x177029
movq -0xa0(%rbp), %rax
movq 0x38(%rax), %rcx
addq $0x10, %rcx
movq %rcx, 0x38(%rax)
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %rcx
subq $0x10, %rcx
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x177046
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq *%rax
movq -0x8(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x177136
movq -0xa0(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x177088
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rax
movq 0x50(%rax), %rcx
movl $0x50, %esi
leaq 0x4086b(%rip), %rdx     # 0x1b78ea
movb $0x0, %al
callq 0x15a980
jmp 0x177092
movq -0xa8(%rbp), %rax
movb $0x0, (%rax)
movq -0xa0(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x177100
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
addq $0x14, %rsi
movq -0xa8(%rbp), %rdx
addq $0x50, %rdx
movl $0x32, %ecx
callq 0x173ee0
movq -0x8(%rbp), %rdi
leaq -0x88(%rbp), %rdx
addq $0x10, %rdx
movq -0xa8(%rbp), %rcx
addq $0x50, %rcx
movq -0xa8(%rbp), %r8
movq -0x18(%rbp), %r9
movq -0x58(%rbp), %rax
leaq 0x5f3b7(%rip), %rsi     # 0x1d64aa
movq %rax, (%rsp)
movb $0x0, %al
callq 0x15b0d0
jmp 0x177134
movq -0x8(%rbp), %rdi
leaq -0x88(%rbp), %rdx
addq $0x10, %rdx
movq -0xa8(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x58(%rbp), %r9
movq -0x50(%rbp), %rax
leaq 0x5f3a0(%rip), %rsi     # 0x1d64c9
movq %rax, (%rsp)
movb $0x0, %al
callq 0x15b0d0
jmp 0x177136
movq -0x58(%rbp), %rax
cmpq -0x20(%rbp), %rax
jle 0x17716b
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x18(%rbp), %rcx
addq -0x58(%rbp), %rcx
movq -0x18(%rbp), %r8
addq -0x20(%rbp), %r8
leaq 0x5f38f(%rip), %rsi     # 0x1d64ee
movb $0x0, %al
callq 0x15bfb0
jmp 0x177292
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq *%rax
movl %eax, -0x8c(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
cmpl $0x0, -0x8c(%rbp)
jne 0x1771ad
jmp 0x177292
movq -0xa0(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
je 0x17727d
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0xa0(%rbp), %rax
movq 0x38(%rax), %rax
movq -0xa0(%rbp), %rcx
addq 0x70(%rcx), %rax
movq %rax, -0xb0(%rbp)
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %rax
movq -0xa0(%rbp), %rcx
subq 0x70(%rcx), %rax
movq %rax, -0xb8(%rbp)
movq -0xa0(%rbp), %rax
cmpl $0x0, 0x60(%rax)
je 0x177227
movq -0xa0(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0xc8(%rbp)
jmp 0x177237
movq $-0x1, %rax
movq %rax, -0xc8(%rbp)
jmp 0x177237
movq -0xc8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0xb0(%rbp), %rdx
movq -0xb8(%rbp), %rcx
movq -0xc0(%rbp), %r8
movl -0x24(%rbp), %r9d
addl $0x1, %r9d
callq 0x1743b0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x90(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x15b820
movq -0x98(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movl -0x90(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)