// File: /workspace/github_c_makefile_star2_O3/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 0xe8b2b
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %r8
testq %r8, %r8
jle 0x81071
xorl %ecx, %ecx
subq %rcx, %r8
movl $0x3, %edx
leaq 0x9375c(%rip), %rsi     # 0x1145a9
leaq 0x20(%rsp), %r9
callq 0xf149c
testl %eax, %eax
je 0x81071
movl 0x20(%rsp), %edx
movq %rbx, %rdi
leaq 0xaabf2(%rip), %rsi     # 0x12ba5f
xorl %eax, %eax
callq 0xe8617
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 0x81045
movl $0x0, 0x14(%rsp)
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
movq 0x18(%rsp), %rbp
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeead3
cmpb $-0x1, %al
je 0x80ecc
incq %rbp
jmp 0x80f06
movq 0x18(%rbx), %rdi
leaq 0x1(%rbp), %r13
movq %r13, %rsi
callq 0xeead3
testb %al, %al
je 0x80f02
movl %eax, %r15d
movzbl %al, %eax
cmpl $0xff, %eax
je 0x80f09
testb %r15b, %r15b
js 0x80f16
movq 0x8(%rsp), %rcx
cmpb $0x0, 0x8(%rcx)
je 0x80f16
testl %r12d, %r12d
je 0x80f16
addq $0x2, %rbp
movq %rbp, %r13
movq %r13, %rbp
cmpq %r14, %r13
jl 0x80eb7
jmp 0x81045
cmpb $-0x9, %r15b
je 0x80f48
cmpl $0xd9, %eax
je 0x80fd9
movl %r15d, %ecx
andb $-0x10, %cl
cmpb $-0x40, %cl
jne 0x80f6c
addl $0xffffff3c, %eax       # imm = 0xFFFFFF3C
cmpl $0x8, %eax
ja 0x80f62
movl $0x111, %ecx            # imm = 0x111
btl %eax, %ecx
jb 0x80f72
jmp 0x80f62
movq %rbx, %rdi
leaq 0xaab5b(%rip), %rsi     # 0x12baad
xorl %eax, %eax
callq 0xe8617
movq 0x8(%rsp), %rax
movb $0x1, 0x8(%rax)
movl $0x1, 0x4(%rsp)
jmp 0x80f72
cmpb $-0x26, %r15b
je 0x80fbe
movl %r15d, %eax
andb $-0x8, %al
cmpb $-0x30, %al
movl $0x0, %eax
cmovnel %eax, %r12d
cmpb $0x1, %r15b
je 0x80fd3
addb $0x30, %r15b
cmpb $0xa, %r15b
jbe 0x80fd3
movq 0x18(%rbx), %rdi
leaq 0x2(%rbp), %rsi
callq 0xeeb67
cmpq $0x2, %rax
jl 0x81045
addq %rax, %rbp
addq $0x2, %rbp
cmpq %r14, %rbp
jl 0x80eb7
jmp 0x81045
movl $0x1, 0x14(%rsp)
movl $0x1, %r12d
cmpl $0x0, 0x4(%rsp)
je 0x81045
addq $0x2, %rbp
jmp 0x80fb0
cmpl $0x0, 0x4(%rsp)
setne %al
cmpl $0x0, 0x14(%rsp)
setne %cl
testb %cl, %al
je 0x81045
movq 0x18(%rsp), %r15
subq %r15, %rbp
addq $0x2, %rbp
movq 0x8(%rsp), %r14
movq %rbp, (%r14)
movq %rbx, %rdi
leaq 0xaaa73(%rip), %rsi     # 0x12ba7e
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
cmpb $0x0, 0x8(%r14)
movq (%r14), %rdx
leaq 0xaaa61(%rip), %rcx     # 0x12ba88
leaq 0xb2884(%rip), %rax     # 0x1338b2
cmoveq %rax, %rcx
movq %r15, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xefd48
movq (%r14), %rcx
jmp 0x8105b
movq %rbx, %rdi
leaq 0xaaa3d(%rip), %rsi     # 0x12ba8c
xorl %eax, %eax
callq 0xe8617
movl $0x1, %ecx
addq 0x18(%rsp), %rcx
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %r8
cmpq %r8, %rcx
jl 0x80e3e
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0xe8be2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq