// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/jpeg.c
// Function: do_boxformat_segment
static void do_boxformat_segment(deark *c, lctx *d, i64 pos,
	i64 data_size)
{
	i64 n;
	i64 seq;
	i64 bdata_pos;
	i64 bdata_avail;
	i64 blen;

	if(data_size<14) return;
	n = de_getu16be(pos);
	de_dbg(c, "enumerator: %u", (unsigned int)n);
	seq = de_getu32be(pos+2);
	de_dbg(c, "seq number: %u", (UI)seq);

	// TODO: JUMBF / JPEG XT parsing needs a lot of work.
	// We'll try to parse it if seems like there's only one segment, but
	// we're probably not even doing that correctly.
	bdata_pos = pos+6;
	bdata_avail = data_size-6;
	if(seq > 1) return;
	blen = de_getu32be(bdata_pos);

	if(bdata_avail>=12) {
		if(!dbuf_memcmp(c->infile, bdata_pos+4, (const void*)"jumb", 4)) {
			de_dbg(c, "JUMBF detected");
			d->has_jumbf = 1;
		}
		else if(!dbuf_memcmp(c->infile, bdata_pos+4, (const void*)"ftypjpxt", 8)) {
			d->is_jpegxt = 1;
			de_dbg(c, "JPEG XT detected");
		}
	}

	if(blen > bdata_avail) return;

	de_dbg_indent(c, 1);
	de_run_module_by_id_on_slice2(c, "bmff", "T", c->infile, bdata_pos, bdata_avail);
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
cmpq $0xe, -0x20(%rbp)
jge 0xbfcc4
jmp 0xbfe3b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x1651d0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0xf7322(%rip), %rsi     # 0x1b700c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
callq 0x165470
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
leaq 0xf7300(%rip), %rsi     # 0x1b701b
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
subq $0x6, %rax
movq %rax, -0x40(%rbp)
cmpq $0x1, -0x30(%rbp)
jle 0xbfd46
jmp 0xbfe3b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x165470
movq %rax, -0x48(%rbp)
cmpq $0xc, -0x40(%rbp)
jl 0xbfdec
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0x4, %rsi
leaq 0xf72ad(%rip), %rdx     # 0x1b702a
movl $0x4, %ecx
callq 0x166ab0
cmpl $0x0, %eax
jne 0xbfda8
movq -0x8(%rbp), %rdi
leaq 0xf7298(%rip), %rsi     # 0x1b702f
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movb $0x1, 0x11(%rax)
jmp 0xbfdea
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0x4, %rsi
leaq 0xf727f(%rip), %rdx     # 0x1b703e
movl $0x8, %ecx
callq 0x166ab0
cmpl $0x0, %eax
jne 0xbfde8
movq -0x10(%rbp), %rax
movb $0x1, 0x18(%rax)
movq -0x8(%rbp), %rdi
leaq 0xf7266(%rip), %rsi     # 0x1b7047
movb $0x0, %al
callq 0x15b0d0
jmp 0xbfdea
jmp 0xbfdec
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0xbfdf8
jmp 0xbfe3b
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
leaq 0xe13c7(%rip), %rsi     # 0x1a11e8
leaq 0xf47bb(%rip), %rdx     # 0x1b45e3
callq 0x15cab0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)