// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/bmff.c
// Function: do_box_mvhd
static void do_box_mvhd(deark *c, lctx *d, struct de_boxesctx *bctx)
{
	u8 version;
	u32 flags;
	i64 pos;
	i64 n;
	i64 timescale;
	double nd;
	struct de_boxdata *curbox = bctx->curbox;

	if(curbox->payload_len<4) return;

	pos = curbox->payload_pos;
	do_read_version_and_flags(c, d, bctx, &version, &flags, 1);
	pos+=4;

	if(version==1) {
		if(curbox->payload_len<112) return;
	}
	else {
		if(curbox->payload_len<100) return;
	}

	// creation time, mod time
	if(version==1)
		pos += 8 + 8;
	else
		pos += 4 + 4;

	timescale = dbuf_getu32be_p(bctx->f, &pos);
	de_dbg(c, "timescale: %d time units per second", (int)timescale);

	// duration
	if(version==1) {
		n = dbuf_geti64be(bctx->f, pos);
		pos += 8;
	}
	else {
		n = dbuf_getu32be_p(bctx->f, &pos);
	}
	if(timescale>0)
		nd = (double)n / (double)timescale;
	else
		nd = 0.0;
	de_dbg(c, "duration: %d time units (%.2f seconds)", (int)n, nd);

	nd = dbuf_fmtutil_read_fixed_16_16(bctx->f, pos);
	pos += 4; // rate
	de_dbg(c, "rate: %.3f", nd);

	n = dbuf_getu16be_p(bctx->f, &pos);
	de_dbg(c, "volume: %.3f", ((double)n)/256.0);

	pos += 2; // reserved
	pos += 4*2; // reserved
	pos += 4*9; // matrix
	pos += 4*6; // pre_defined

	n = dbuf_getu32be(bctx->f, pos);
	de_dbg(c, "next track id: %d", (int)n);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq 0x28(%rdx), %r13
cmpq $0x4, 0x40(%r13)
jl 0x2bd52
movq %rdx, %r14
movq %rdi, %rbx
movq 0x38(%r13), %r12
movq 0x10(%rdx), %rdi
movq %r12, %rsi
callq 0xeed0d
movq %rax, %r15
movl %r15d, %ecx
andl $0xffffff, %ecx         # imm = 0xFFFFFF
movl %r15d, %edx
shrl $0x18, %edx
leaq 0xe9f1c(%rip), %rsi     # 0x115b38
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
andl $0xff000000, %r15d      # imm = 0xFF000000
movq 0x40(%r13), %rcx
cmpq $0x1000000, %r15        # imm = 0x1000000
jne 0x2bc4a
movl $0x14, %eax
cmpq $0x70, %rcx
jge 0x2bc59
jmp 0x2bd52
movl $0xc, %eax
cmpq $0x64, %rcx
jl 0x2bd52
addq %r12, %rax
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq 0x10(%r14), %rdi
callq 0xeed31
movq %rax, %r12
leaq 0xea050(%rip), %rsi     # 0x115cc7
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x10(%r14), %rdi
cmpl $0x1000000, %r15d       # imm = 0x1000000
jne 0x2bca3
movq 0x8(%rsp), %rsi
callq 0xeee96
addq $0x8, 0x8(%rsp)
jmp 0x2bcad
leaq 0x8(%rsp), %rsi
callq 0xeed31
testq %r12, %r12
jg 0x2bcb8
xorpd %xmm0, %xmm0
jmp 0x2bcc6
cvtsi2sd %rax, %xmm0
cvtsi2sd %r12, %xmm1
divsd %xmm1, %xmm0
leaq 0xea01e(%rip), %rsi     # 0x115ceb
movq %rbx, %rdi
movl %eax, %edx
movb $0x1, %al
callq 0xe8617
movq 0x10(%r14), %rdi
leaq 0x8(%rsp), %r15
movq (%r15), %rsi
callq 0xf8078
addq $0x4, (%r15)
leaq 0xea01d(%rip), %rsi     # 0x115d12
movq %rbx, %rdi
movb $0x1, %al
callq 0xe8617
movq 0x10(%r14), %rdi
movq %r15, %rsi
callq 0xeeb91
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0xe9645(%rip), %xmm0    # 0x115360
leaq 0xe9ffb(%rip), %rsi     # 0x115d1d
movq %rbx, %rdi
movb $0x1, %al
callq 0xe8617
movq (%r15), %rsi
addq $0x46, %rsi
movq %rsi, (%r15)
movq 0x10(%r14), %rdi
callq 0xeed0d
leaq 0xe9fe4(%rip), %rsi     # 0x115d2a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq