// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/jpeg.c
// Function: de_run_jpegscan
static void de_run_jpegscan(deark *c, de_module_params *mparams)
{
	i64 pos = 0;
	i64 foundpos = 0;
	scanctx *d = NULL;
	int ret;

	d = de_malloc(c, sizeof(*d));

	while(1) {
		if(pos >= c->infile->len) break;

		ret = dbuf_search(c->infile, (const u8*)"\xff\xd8\xff", 3,
			pos, c->infile->len-pos, &foundpos);
		if(!ret) break; // No more JPEGs in file.

		de_dbg(c, "Found possible JPEG file at %d", (int)foundpos);

		pos = foundpos;

		if(detect_jpeg_len(c, d, pos, c->infile->len-pos)) {
			de_dbg(c, "length=%d", (int)d->len);
			dbuf_create_file_from_slice(c->infile, pos, d->len,
				d->is_jpegls ? "jls" : "jpg", NULL, 0);
			pos += d->len;
		}
		else {
			de_dbg(c, "Doesn't seem to be a valid JPEG.");
			pos++;
		}
	}

	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x18(%rsp), %rax
andq $0x0, (%rax)
pushq $0x10
popq %rsi
callq 0xdecaf
movq %rax, 0x8(%rsp)
xorl %ecx, %ecx
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %r8
subq %rcx, %r8
jle 0x7c509
leaq 0x8b24b(%rip), %rsi     # 0x107549
pushq $0x3
popq %rdx
leaq 0x18(%rsp), %r9
callq 0xe62f1
testl %eax, %eax
je 0x7c509
movl 0x18(%rsp), %edx
xorl %r14d, %r14d
movq %rbx, %rdi
leaq 0xa24cb(%rip), %rsi     # 0x11e7ef
xorl %eax, %eax
callq 0xde896
movq 0x18(%rsp), %rbp
movq 0x18(%rbx), %rax
movq 0x18(%rax), %r15
movq 0x8(%rsp), %rax
andq $0x0, (%rax)
movb $0x0, 0x8(%rax)
movq %rbp, 0x20(%rsp)
movl $0x0, 0x4(%rsp)
movl $0x0, 0x14(%rsp)
cmpq %r15, %rbp
jge 0x7c4e8
movq %rbp, %r12
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3eb4
cmpb $-0x1, %al
je 0x7c37e
incq %r12
movq %r12, %rbp
jmp 0x7c35a
movq 0x18(%rbx), %rdi
leaq 0x1(%r12), %rbp
movq %rbp, %rsi
callq 0xe3eb4
testb %al, %al
je 0x7c3b5
movl %eax, %r13d
movzbl %al, %eax
cmpl $0xff, %eax
je 0x7c35a
testb %r13b, %r13b
js 0x7c3be
movq 0x8(%rsp), %rcx
cmpb $0x0, 0x8(%rcx)
je 0x7c3be
testl %r14d, %r14d
je 0x7c3be
addq $0x2, %r12
movq %r12, %rbp
jmp 0x7c35a
cmpb $-0x9, %r13b
je 0x7c3f4
cmpl $0xd9, %eax
je 0x7c47b
movl %r13d, %ecx
andb $-0x10, %cl
cmpb $-0x40, %cl
jne 0x7c462
addl $0xffffff3c, %eax       # imm = 0xFFFFFF3C
cmpl $0x8, %eax
ja 0x7c40e
movl $0x111, %ecx            # imm = 0x111
btl %eax, %ecx
jb 0x7c415
jmp 0x7c40e
movq %rbx, %rdi
leaq 0xa243f(%rip), %rsi     # 0x11e83d
xorl %eax, %eax
callq 0xde896
movq 0x8(%rsp), %rax
movb $0x1, 0x8(%rax)
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
movl %r13d, %eax
andb $-0x8, %al
cmpb $-0x30, %al
movl $0x0, %eax
cmovnel %eax, %r14d
leal 0x30(%r13), %eax
cmpb $0xb, %al
setae %al
cmpb $0x1, %r13b
setne %cl
testb %al, %cl
je 0x7c3b5
movq 0x18(%rbx), %rdi
addq $0x2, %r12
movq %r12, %rsi
callq 0xe3f46
cmpq $0x2, %rax
jl 0x7c4e8
movq %rax, %rbp
addq %r12, %rbp
jmp 0x7c35a
cmpb $-0x26, %r13b
jne 0x7c415
pushq $0x1
popq %rax
movl %eax, %r14d
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x4(%rsp)
jne 0x7c425
jmp 0x7c4e8
cmpl $0x0, 0x4(%rsp)
setne %al
cmpl $0x0, 0x14(%rsp)
setne %cl
testb %cl, %al
je 0x7c4e8
movq 0x20(%rsp), %r15
subq %r15, %r12
addq $0x2, %r12
movq 0x8(%rsp), %r14
movq %r12, (%r14)
movq %rbx, %rdi
leaq 0xa2361(%rip), %rsi     # 0x11e80e
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
cmpb $0x0, 0x8(%r14)
movq (%r14), %rdx
leaq 0xa234e(%rip), %rcx     # 0x11e818
leaq 0xaa109(%rip), %rax     # 0x1265da
cmoveq %rax, %rcx
movq %r15, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xe4e0b
movq (%r14), %rcx
jmp 0x7c501
movq %rbx, %rdi
leaq 0xa232a(%rip), %rsi     # 0x11e81c
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rcx
movq 0x20(%rsp), %r15
addq %r15, %rcx
jmp 0x7c2e6
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0xded32
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq