// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/jpeg.c
// Function: do_read_scan_data
static int do_read_scan_data(deark *c, lctx *d,
	i64 pos1, i64 *bytes_consumed)
{
	i64 pos = pos1;
	u8 b0, b1;
	struct marker_info mi;

	*bytes_consumed = c->infile->len - pos1; // default
	de_dbg(c, "scan data at %d", (int)pos1);

	de_dbg_indent(c, 1);

	while(1) {
		if(pos >= c->infile->len) goto done;
		b0 = de_getbyte_p(&pos);
		if(b0==0xff) {
			b1 = de_getbyte_p(&pos);
			if(b1==0x00) {
				; // an escaped 0xff
			}
			else if(d->is_jpegls && b1<0x80) {
				// In JPEG-LS, 0xff bytes are not escaped if they're followed by a
				// a byte less than 0x80.
				;
			}
			else if(b1>=0xd0 && b1<=0xd7) { // an RSTn marker
				if(c->debug_level>=2) {
					get_marker_info(c, d, b1, &mi);
					de_dbg2(c, "marker 0x%02x (%s) at %d", (unsigned int)b1,
						mi.longname, (int)(pos-2));
				}
			}
			else if(b1==0xff) { // a "fill byte" (are they allowed here?)
				pos--;
			}
			else {
				// A marker that is not part of the scan.
				// Subtract the bytes consumed by it, and stop.
				pos -= 2;
				*bytes_consumed = pos - pos1;
				de_dbg(c, "end of scan data found at %d (len=%d)", (int)pos, (int)*bytes_consumed);
				break;
			}
		}
	}

done:
	de_dbg_indent(c, -1);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rcx
subq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xfa8ee(%rip), %rsi     # 0x1b7339
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0xbca77
jmp 0xbcba3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
cmpl $0xff, %eax
jne 0xbcb9c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, -0x2a(%rbp)
movzbl -0x2a(%rbp), %eax
cmpl $0x0, %eax
jne 0xbcabc
jmp 0xbcb9a
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0xbcad8
movzbl -0x2a(%rbp), %eax
cmpl $0x80, %eax
jge 0xbcad8
jmp 0xbcb98
movzbl -0x2a(%rbp), %eax
cmpl $0xd0, %eax
jl 0xbcb3d
movzbl -0x2a(%rbp), %eax
cmpl $0xd7, %eax
jg 0xbcb3d
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0xbcb3b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0xa0(%rbp), %rcx
movzbl -0x2a(%rbp), %edx
callq 0xbc4f0
movq -0x8(%rbp), %rdi
movzbl -0x2a(%rbp), %edx
leaq -0xa0(%rbp), %rcx
addq $0x14, %rcx
movq -0x28(%rbp), %rax
subq $0x2, %rax
movl %eax, %r8d
leaq 0xf99d8(%rip), %rsi     # 0x1b650c
movb $0x0, %al
callq 0x15b350
jmp 0xbcb96
movzbl -0x2a(%rbp), %eax
cmpl $0xff, %eax
jne 0xbcb56
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xbcb94
movq -0x28(%rbp), %rax
subq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rcx
subq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
leaq 0xfa7be(%rip), %rsi     # 0x1b7349
movb $0x0, %al
callq 0x15b0d0
jmp 0xbcba1
jmp 0xbcb96
jmp 0xbcb98
jmp 0xbcb9a
jmp 0xbcb9c
jmp 0xbca60
jmp 0xbcba3
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl $0x1, %eax
addq $0xa0, %rsp
popq %rbp
retq
nop