// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
pushq %rax
movq 0x28(%rdx), %r12
cmpq $0x4, 0x40(%r12)
jl 0x2be26
movq %rdx, %r14
movq %rdi, %rbx
movq 0x38(%r12), %rsi
movq %rsi, (%rsp)
movq 0x10(%rdx), %rdi
callq 0xef32a
movq %rax, %r15
movl %r15d, %ecx
andl $0xffffff, %ecx         # imm = 0xFFFFFF
movl %r15d, %edx
shrl $0x18, %edx
leaq 0xe9d9d(%rip), %rsi     # 0x115a88
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq (%rsp), %rax
leaq 0x4(%rax), %rcx
movq %rcx, (%rsp)
andl $0xff000000, %r15d      # imm = 0xFF000000
movq 0x40(%r12), %rdx
cmpq $0x1000000, %r15        # imm = 0x1000000
jne 0x2bd26
movl $0x14, %ecx
cmpq $0x70, %rdx
jge 0x2bd35
jmp 0x2be26
movl $0xc, %ecx
cmpq $0x64, %rdx
jl 0x2be26
addq %rax, %rcx
movq %rsp, %rsi
movq %rcx, (%rsi)
movq 0x10(%r14), %rdi
callq 0xef34e
movq %rax, %r12
leaq 0xe9ec6(%rip), %rsi     # 0x115c17
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x10(%r14), %rdi
cmpl $0x1000000, %r15d       # imm = 0x1000000
jne 0x2bd7b
movq (%rsp), %rsi
callq 0xef4c3
addq $0x8, (%rsp)
jmp 0x2bd83
movq %rsp, %rsi
callq 0xef34e
testq %r12, %r12
jg 0x2bd8e
xorpd %xmm0, %xmm0
jmp 0x2bd9c
cvtsi2sd %rax, %xmm0
cvtsi2sd %r12, %xmm1
divsd %xmm1, %xmm0
leaq 0xe9e98(%rip), %rsi     # 0x115c3b
movq %rbx, %rdi
movl %eax, %edx
movb $0x1, %al
callq 0xe9226
movq 0x10(%r14), %rdi
movq %rsp, %r15
movq (%r15), %rsi
callq 0xf8544
addq $0x4, (%r15)
leaq 0xe9e99(%rip), %rsi     # 0x115c62
movq %rbx, %rdi
movb $0x1, %al
callq 0xe9226
movq 0x10(%r14), %rdi
movq %r15, %rsi
callq 0xef193
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0xe94c1(%rip), %xmm0    # 0x1152b0
leaq 0xe9e77(%rip), %rsi     # 0x115c6d
movq %rbx, %rdi
movb $0x1, %al
callq 0xe9226
movq (%r15), %rsi
addq $0x46, %rsi
movq %rsi, (%r15)
movq 0x10(%r14), %rdi
callq 0xef32a
leaq 0xe9e60(%rip), %rsi     # 0x115c7a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq