// File: /workspace/github_c_makefile_star2_O1/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
movq $0x0, 0x20(%rsp)
movl $0x10, %esi
callq 0xe969b
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %r8
testq %r8, %r8
jle 0x816ba
xorl %ecx, %ecx
subq %rcx, %r8
movl $0x3, %edx
leaq 0x93065(%rip), %rsi     # 0x1144f9
leaq 0x20(%rsp), %r9
callq 0xf1a9c
testl %eax, %eax
je 0x816ba
movl 0x20(%rsp), %edx
movq %rbx, %rdi
leaq 0xaa2db(%rip), %rsi     # 0x12b78f
xorl %eax, %eax
callq 0xe9226
movq 0x20(%rsp), %rcx
movq 0x18(%rbx), %rax
movq 0x18(%rax), %r14
movq 0x8(%rsp), %rax
movq $0x0, (%rax)
movb $0x0, 0x8(%rax)
movq %rcx, 0x18(%rsp)
cmpq %rcx, %r14
jle 0x8168e
movl $0x0, 0x14(%rsp)
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
movq 0x18(%rsp), %rbp
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef0d5
cmpb $-0x1, %al
je 0x81513
incq %rbp
jmp 0x8154d
movq 0x18(%rbx), %rdi
leaq 0x1(%rbp), %r13
movq %r13, %rsi
callq 0xef0d5
testb %al, %al
je 0x81549
movl %eax, %r15d
movzbl %al, %eax
cmpl $0xff, %eax
je 0x81550
testb %r15b, %r15b
js 0x8155d
movq 0x8(%rsp), %rcx
cmpb $0x0, 0x8(%rcx)
je 0x8155d
testl %r12d, %r12d
je 0x8155d
addq $0x2, %rbp
movq %rbp, %r13
movq %r13, %rbp
cmpq %r14, %r13
jl 0x814fe
jmp 0x8168e
cmpb $-0x9, %r15b
je 0x8158f
cmpl $0xd9, %eax
je 0x8161f
movl %r15d, %ecx
andb $-0x10, %cl
cmpb $-0x40, %cl
jne 0x815b1
addl $0xffffff3c, %eax       # imm = 0xFFFFFF3C
cmpl $0x8, %eax
ja 0x815a9
movl $0x111, %ecx            # imm = 0x111
btl %eax, %ecx
jb 0x815b1
jmp 0x815a9
movq %rbx, %rdi
leaq 0xaa244(%rip), %rsi     # 0x12b7dd
xorl %eax, %eax
callq 0xe9226
movq 0x8(%rsp), %rax
movb $0x1, 0x8(%rax)
movl $0x1, 0x4(%rsp)
cmpb $-0x26, %r15b
jne 0x815d1
movl $0x1, %r12d
movl $0x1, 0x14(%rsp)
cmpl $0x0, 0x4(%rsp)
jne 0x815e1
jmp 0x8168e
movl %r15d, %eax
andb $-0x8, %al
cmpb $-0x30, %al
movl $0x0, %eax
cmovnel %eax, %r12d
leal 0x30(%r15), %eax
cmpb $0xb, %al
setae %al
cmpb $0x1, %r15b
setne %cl
testb %al, %cl
jne 0x815fb
addq $0x2, %rbp
jmp 0x81614
movq 0x18(%rbx), %rdi
addq $0x2, %rbp
movq %rbp, %rsi
callq 0xef169
cmpq $0x2, %rax
jl 0x8168e
addq %rax, %rbp
cmpq %r14, %rbp
jl 0x814fe
jmp 0x8168e
cmpl $0x0, 0x4(%rsp)
setne %al
cmpl $0x0, 0x14(%rsp)
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x8168e
movq 0x18(%rsp), %r15
subq %r15, %rbp
addq $0x2, %rbp
movq 0x8(%rsp), %r14
movq %rbp, (%r14)
movq %rbx, %rdi
leaq 0xaa15a(%rip), %rsi     # 0x12b7ae
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
cmpb $0x0, 0x8(%r14)
movq (%r14), %rdx
leaq 0xaa148(%rip), %rcx     # 0x12b7b8
leaq 0xb1e43(%rip), %rax     # 0x1334ba
cmoveq %rax, %rcx
movq %r15, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xf0321
movq (%r14), %rcx
jmp 0x816a4
movq %rbx, %rdi
leaq 0xaa124(%rip), %rsi     # 0x12b7bc
xorl %eax, %eax
callq 0xe9226
movl $0x1, %ecx
addq 0x18(%rsp), %rcx
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %r8
cmpq %r8, %rcx
jl 0x81485
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0xe9752
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq