// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/jpeg.c
// Function: handler_sof
static void handler_sof(deark *c, lctx *d,
	const struct marker_info *mi, i64 pos, i64 data_size)
{
	i64 w, h;
	u8 b;
	i64 i;
	const char *attr_lossy = "DCT";
	const char *attr_cmpr = "huffman";
	const char *attr_progr = "non-progr.";
	const char *attr_hier = "non-hier.";
	u8 seg_type = mi->seg_type;

	if(data_size<6) return;

	if(d->fpxr_data) {
		finalize_all_fpxr_streams(c, d);
	}

	if(seg_type>=0xc1 && seg_type<=0xcf && (seg_type%4)!=0) {
		if((seg_type%4)==3) { d->is_lossless=1; attr_lossy="lossless"; }
		if(seg_type%16>=9) { d->is_arithmetic=1; attr_cmpr="arithmetic"; }
		if((seg_type%4)==2) { d->is_progressive=1; attr_progr="progressive"; }
		if((seg_type%8)>=5) { d->is_hierarchical=1; attr_hier="hierarchical"; }
		de_dbg(c, "image type: %s, %s, %s, %s",
			attr_lossy, attr_cmpr, attr_progr, attr_hier);
	}
	else if(seg_type==0xc0) {
		d->is_baseline = 1;
		de_dbg(c, "image type: baseline (%s, %s, %s, %s)",
			attr_lossy, attr_cmpr, attr_progr, attr_hier);
	}
	else if(seg_type==0xf7) {
		de_dbg(c, "image type: JPEG-LS");
	}

	// By now we have hopefully collected the info we need to decide what JPEG
	// format we're dealing with.
	declare_jpeg_fmt(c, d, seg_type);

	d->precision = de_getbyte(pos);
	de_dbg(c, "precision: %d", (int)d->precision);
	h = de_getu16be(pos+1);
	w = de_getu16be(pos+3);
	de_dbg_dimensions(c, w, h);
	d->ncomp = (i64)de_getbyte(pos+5);
	de_dbg(c, "number of components: %d", (int)d->ncomp);

	// per-component data
	if(data_size<6+3*d->ncomp) goto done;
	for(i=0; i<d->ncomp; i++) {
		u8 comp_id;
		i64 sf1, sf2;
		u8 qtid;
		comp_id = de_getbyte(pos+6+3*i+0);
		b = de_getbyte(pos+6+3*i+1);
		sf1 = (i64)(b>>4);
		sf2 = (i64)(b&0x0f);
		if(sf1!=1 || sf2!=1) d->is_subsampled = 1;
		ucstring_printf(d->sampling_code, DE_ENCODING_LATIN1, "%d%d", (int)sf1, (int)sf2);
		qtid = de_getbyte(pos+6+3*i+2);
		de_dbg(c, "cmp #%d: id=%d sampling=%d"DE_CHAR_TIMES"%d quant_table=Q%d",
			(int)i, (int)comp_id, (int)sf1, (int)sf2, (int)qtid);
	}

done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
leaq 0xfa138(%rip), %rax     # 0x1b715e
movq %rax, -0x50(%rbp)
leaq 0x10dd54(%rip), %rax    # 0x1cad85
movq %rax, -0x58(%rbp)
leaq 0xfa126(%rip), %rax     # 0x1b7162
movq %rax, -0x60(%rbp)
leaq 0xfa126(%rip), %rax     # 0x1b716d
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movb (%rax), %al
movb %al, -0x69(%rbp)
cmpq $0x6, -0x28(%rbp)
jge 0xbd060
jmp 0xbd3cc
movq -0x10(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
je 0xbd07b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xc0cc0
movzbl -0x69(%rbp), %eax
cmpl $0xc1, %eax
jl 0xbd162
movzbl -0x69(%rbp), %eax
cmpl $0xcf, %eax
jg 0xbd162
movzbl -0x69(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0xbd162
movzbl -0x69(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl $0x3, %edx
jne 0xbd0d2
movq -0x10(%rbp), %rax
movb $0x1, 0x14(%rax)
leaq 0xfa2ce(%rip), %rax     # 0x1b739c
movq %rax, -0x50(%rbp)
movzbl -0x69(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
cmpl $0x9, %edx
jl 0xbd0f6
movq -0x10(%rbp), %rax
movb $0x1, 0x15(%rax)
leaq 0xfa2c1(%rip), %rax     # 0x1b73b3
movq %rax, -0x58(%rbp)
movzbl -0x69(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl $0x2, %edx
jne 0xbd11a
movq -0x10(%rbp), %rax
movb $0x1, 0x13(%rax)
leaq 0xfa290(%rip), %rax     # 0x1b73a6
movq %rax, -0x60(%rbp)
movzbl -0x69(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x5, %edx
jl 0xbd13e
movq -0x10(%rbp), %rax
movb $0x1, 0x16(%rax)
leaq 0xfa285(%rip), %rax     # 0x1b73bf
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x68(%rbp), %r9
leaq 0xfa01e(%rip), %rsi     # 0x1b7177
movb $0x0, %al
callq 0x15b0d0
jmp 0xbd1ba
movzbl -0x69(%rbp), %eax
cmpl $0xc0, %eax
jne 0xbd199
movq -0x10(%rbp), %rax
movb $0x1, 0x12(%rax)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x68(%rbp), %r9
leaq 0xfa002(%rip), %rsi     # 0x1b7192
movb $0x0, %al
callq 0x15b0d0
jmp 0xbd1b8
movzbl -0x69(%rbp), %eax
cmpl $0xf7, %eax
jne 0xbd1b6
movq -0x8(%rbp), %rdi
leaq 0xfa009(%rip), %rsi     # 0x1b71b8
movb $0x0, %al
callq 0x15b0d0
jmp 0xbd1b8
jmp 0xbd1ba
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movzbl -0x69(%rbp), %edx
callq 0xc0d60
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165060
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x1c(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x1c(%rax), %edx
leaq 0xf9fd4(%rip), %rsi     # 0x1b71cc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
callq 0x1651d0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x3, %rsi
callq 0x1651d0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x5, %rsi
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, %edx
leaq 0xe4c9c(%rip), %rsi     # 0x1a1f15
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
imulq $0x3, 0x30(%rcx), %rcx
addq $0x6, %rcx
cmpq %rcx, %rax
jge 0xbd29b
jmp 0xbd3cc
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jge 0xbd3ca
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x6, %rsi
imulq $0x3, -0x48(%rbp), %rax
addq %rax, %rsi
addq $0x0, %rsi
callq 0x165060
movb %al, -0x6a(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x6, %rsi
imulq $0x3, -0x48(%rbp), %rax
addq %rax, %rsi
addq $0x1, %rsi
callq 0x165060
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
sarl $0x4, %eax
cltq
movq %rax, -0x78(%rbp)
movzbl -0x39(%rbp), %eax
andl $0xf, %eax
cltq
movq %rax, -0x80(%rbp)
cmpq $0x1, -0x78(%rbp)
jne 0xbd325
cmpq $0x1, -0x80(%rbp)
je 0xbd333
movq -0x10(%rbp), %rax
movl $0x1, 0x98(%rax)
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
movq -0x78(%rbp), %rax
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %eax, %r8d
movl $0x5, %esi
leaq 0xf9e83(%rip), %rdx     # 0x1b71da
movb $0x0, %al
callq 0x171660
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x6, %rsi
imulq $0x3, -0x48(%rbp), %rax
addq %rax, %rsi
addq $0x2, %rsi
callq 0x165060
movb %al, -0x81(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
movzbl -0x6a(%rbp), %ecx
movq -0x78(%rbp), %rax
movl %eax, %r8d
movq -0x80(%rbp), %rax
movl %eax, %r9d
movzbl -0x81(%rbp), %eax
leaq 0xf9e30(%rip), %rsi     # 0x1b71df
movl %eax, (%rsp)
movb $0x0, %al
callq 0x15b0d0
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xbd2a3
jmp 0xbd3cc
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)