// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/jpeg.c
// Function: de_run_jpeg
static void de_run_jpeg(deark *c, de_module_params *mparams)
{
	i64 pos;
	i64 bytes_consumed;
	int retval_stream = 0;
	i64 foundpos;
	i64 extra_bytes_at_eof;
	i64 nbytes_to_scan;
	lctx *d = NULL;

	d = de_malloc(c, sizeof(lctx));
	d->is_pegasus_pic2 = (u8)de_havemodcode(c, mparams, '2');

	pos = 0;
	bytes_consumed = 0;
	retval_stream = do_jpeg_stream(c, d, pos, &bytes_consumed);
	if(!retval_stream) goto done;
	pos += bytes_consumed;

	if(bytes_consumed<1) goto done;
	if(pos >= c->infile->len) goto done;

	if(c->module_nesting_level>1) goto done;
	extra_bytes_at_eof = c->infile->len - pos;
	if(extra_bytes_at_eof<4) goto done;

	if(extra_bytes_at_eof>=24) {
		u8 tbuf[12];

		de_read(tbuf, c->infile->len-12, sizeof(tbuf));
		if(tbuf[0]=='A' && tbuf[1]=='X' && tbuf[2]=='S' &&
			(tbuf[3]=='!' || tbuf[3]=='*'))
		{
			do_afcp_segment(c, d, c->infile->len);
			goto done;
		}
	}

	if(d->has_mpf_seg) {
		// In this case, it is normal for there to be multiple JPEG streams,
		// and we should have already extracted the extras.
		goto done;
	}

	nbytes_to_scan = de_min_int(extra_bytes_at_eof, 512);
	if(dbuf_search(c->infile, (const u8*)"\xff\xd8\xff", 3, pos,
		nbytes_to_scan, &foundpos))
	{
		de_info(c, "Note: This file might contain multiple JPEG images. "
			"Use \"-m jpegscan\" to extract them.");
		goto done;
	}

	if(dbuf_is_all_zeroes(c->infile, pos, extra_bytes_at_eof)) goto done;

	de_info(c, "Note: %"I64_FMT" bytes of unidentified data found at end "
		"of file (starting at %"I64_FMT").", extra_bytes_at_eof, pos);

done:
	if(d) {
		if(retval_stream) {
			print_summary(c, d);
		}
		do_destroy_lctx(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r15
movq %rdi, %rbx
movl $0xb0, %esi
callq 0xe969b
movq %rax, %r14
movq %rbx, %rdi
movq %r15, %rsi
movl $0x32, %edx
callq 0xea97e
movb %al, 0x1(%r14)
movq $0x0, 0x10(%rsp)
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0xa0(%r14)
movq 0x10(%rsp), %rax
movq 0x18(%rbx), %rdi
movb $0x1, %r12b
cmpq 0x18(%rdi), %rax
jge 0x80e1c
leaq 0x10(%rsp), %r13
movl $0x0, 0x1c(%rsp)
movb $0x1, %bpl
movq %r13, %rsi
callq 0xef14d
cmpb $-0x1, %al
setne %cl
sete %dl
orb %bpl, %dl
movl %ecx, %ebp
testb $0x1, %dl
jne 0x80b44
movzbl %al, %r15d
movb $0x1, %bpl
testl %r15d, %r15d
je 0x80b44
cmpl $0xf7, %r15d
jne 0x80ad7
cmpb $0x0, 0x29(%r14)
jne 0x80ad7
movb $0x1, (%r14)
movq %r14, %rdi
movl %r15d, %esi
leaq 0x38(%rsp), %rdx
callq 0x81b99
movl 0x3c(%rsp), %eax
btl $0x9, %eax
jae 0x80af6
movb $0x1, 0x29(%r14)
btl $0x8, %eax
jae 0x80b5c
movl 0x10(%rsp), %r8d
addl $-0x2, %r8d
xorl %r12d, %r12d
movq %rbx, %rdi
leaq 0xa9d1a(%rip), %rsi     # 0x12a82c
movl %r15d, %edx
leaq 0x4c(%rsp), %rcx
xorl %eax, %eax
callq 0xe9226
cmpl $0xd8, %r15d
je 0x80b38
cmpl $0xd9, %r15d
jne 0x80b44
jmp 0x80e1c
cmpb $0x0, 0x28(%r14)
jne 0x80b44
movb $0x1, 0x28(%r14)
movq 0x10(%rsp), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jl 0x80a95
jmp 0x80e19
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0xef169
movq 0x10(%rsp), %rbp
movb $0x1, %r12b
cmpq $0x2, %rbp
jl 0x80e1c
addq $0x2, %rbp
movq %rax, 0x28(%rsp)
addq $-0x2, %rax
movzbl 0x38(%rsp), %edx
leal -0x4(%rbp), %r8d
movq %rax, 0x30(%rsp)
movl %eax, (%rsp)
movq %rbx, %rdi
leaq 0xaa9ce(%rip), %rsi     # 0x12b572
leaq 0x4c(%rsp), %rcx
movl %ebp, %r9d
xorl %eax, %eax
callq 0xe9226
cmpq $0x0, 0xa0(%rsp)
je 0x80bf2
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x38(%rsp), %rdx
movq %rbp, %rcx
movq 0x30(%rsp), %r8
callq *0xa0(%rsp)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x28(%rsp), %rax
addq %rax, 0x10(%rsp)
testb $0x2, 0x3d(%rsp)
je 0x80c1b
movl 0x1c(%rsp), %ecx
testl %ecx, %ecx
jne 0x80c15
cmpb $0x0, (%r14)
je 0x80d42
incl %ecx
movl %ecx, 0x1c(%rsp)
cmpl $0xda, %r15d
jne 0x80d2a
movq 0x10(%rsp), %r15
movq %r15, 0x20(%rsp)
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rbp
subq %r15, %rbp
movq %rbx, %rdi
leaq 0xaa9f5(%rip), %rsi     # 0x12b63c
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x20(%rsp), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jge 0x80d18
movq %rbp, 0x28(%rsp)
leaq 0x20(%rsp), %rsi
callq 0xef14d
cmpb $-0x1, %al
je 0x80c95
movq 0x20(%rsp), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jl 0x80c76
jmp 0x80d13
movq 0x18(%rbx), %rdi
leaq 0x20(%rsp), %rsi
callq 0xef14d
testb %al, %al
je 0x80c84
js 0x80caf
cmpb $0x0, (%r14)
jne 0x80c84
movzbl %al, %ebp
andb $-0x8, %al
cmpb $-0x30, %al
jne 0x80cf5
cmpl $0x2, (%rbx)
jl 0x80c84
movq %r14, %rdi
movl %ebp, %esi
leaq 0xa8(%rsp), %rdx
callq 0x81b99
movl 0x20(%rsp), %r8d
addl $-0x2, %r8d
movq %rbx, %rdi
leaq 0xa9b4a(%rip), %rsi     # 0x12a82c
movl %ebp, %edx
leaq 0xbc(%rsp), %rcx
xorl %eax, %eax
callq 0xe93cf
jmp 0x80c84
movq 0x20(%rsp), %rdx
cmpl $0xff, %ebp
jne 0x80df2
decq %rdx
movq %rdx, 0x20(%rsp)
jmp 0x80c84
movq 0x28(%rsp), %rbp
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
addq %rbp, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jl 0x80a92
jmp 0x80e1c
cmpb $0x0, 0x2(%r14)
je 0x80c15
cmpb $0x0, 0x5(%r14)
je 0x80c15
cmpb $0x0, 0xa(%r14)
jne 0x80c15
cmpb $0x1, 0x38(%r14)
jne 0x80c15
movb 0x39(%r14), %al
decb %al
cmpb $0x1, %al
ja 0x80c15
cmpl $0x2, 0x3c(%r14)
jb 0x80db4
movl $0x1, %edi
callq 0xf9381
movq %rax, %rbp
movl 0x3c(%r14), %edi
callq 0xf9381
movq %rbx, %rdi
leaq 0xaa7fb(%rip), %rsi     # 0x12b59e
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9226
movl 0x1c(%rsp), %ecx
cmpb $0x0, 0x20(%r14)
je 0x80c15
cmpl $0x0, 0x98(%r14)
je 0x80c15
cmpq $0x2, 0x30(%r14)
jl 0x80c15
movq %rbx, %rdi
leaq 0xaa801(%rip), %rsi     # 0x12b5e3
xorl %eax, %eax
callq 0xe9226
movl 0x1c(%rsp), %ecx
jmp 0x80c15
addq $-0x2, %rdx
movq %rdx, 0x20(%rsp)
movq %rdx, %rbp
subq %r15, %rbp
movq %rbx, %rdi
leaq 0xaa841(%rip), %rsi     # 0x12b64c
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe9226
jmp 0x80d18
movb $0x1, %r12b
movq 0x48(%r14), %rdi
callq 0xf0b13
xorl %r15d, %r15d
movq %r15, 0x48(%r14)
movq 0x50(%r14), %rdi
callq 0xf0b13
movq %r15, 0x50(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x84628
cmpq %r15, 0x68(%r14)
je 0x80e87
cmpl $0x0, 0x60(%r14)
jne 0x80e87
leaq 0xb68fe(%rip), %rsi     # 0x137756
movq %rbx, %rdi
xorl %edx, %edx
movl $0x1, %ecx
callq 0xf037a
movq %rax, %r15
movq 0x68(%r14), %rdi
movq 0x90(%r14), %rdx
xorl %esi, %esi
movq %rax, %rcx
callq 0xefabc
movq %r15, %rdi
callq 0xf0b13
movq 0x68(%r14), %rdi
callq 0xf0b13
movq $0x0, 0x68(%r14)
movq 0x10(%rsp), %r15
testq %r15, %r15
setle %al
orb %r12b, %al
jne 0x80fad
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
movq %rdx, %rbp
subq %r15, %rbp
jle 0x80fad
cmpl $0x1, 0x10(%rbx)
jg 0x80fad
cmpq $0x4, %rbp
jl 0x80fad
cmpq $0x18, %rbp
jl 0x80f35
addq $-0xc, %rdx
leaq 0xa8(%rsp), %r13
movl $0xc, %ecx
movq %r13, %rsi
callq 0xeeee8
cmpb $0x41, (%r13)
jne 0x80f35
cmpb $0x58, 0xa9(%rsp)
jne 0x80f35
cmpb $0x53, 0xaa(%rsp)
jne 0x80f35
movzbl 0xab(%rsp), %eax
cmpl $0x2a, %eax
je 0x80f20
cmpl $0x21, %eax
jne 0x80f35
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x81b41
jmp 0x80fad
cmpb $0x0, 0x8(%r14)
jne 0x80fad
movl $0x200, %esi            # imm = 0x200
movq %rbp, %rdi
callq 0xea792
movq 0x18(%rbx), %rdi
leaq 0x935a5(%rip), %rsi     # 0x1144f9
leaq 0xa8(%rsp), %r9
movl $0x3, %edx
movq %r15, %rcx
movq %rax, %r8
callq 0xf1a9c
testl %eax, %eax
je 0x80f83
leaq 0xa985e(%rip), %rsi     # 0x12a7d5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9ef5
jmp 0x80fad
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xf1efb
testl %eax, %eax
jne 0x80fad
leaq 0x9f01e(%rip), %rsi     # 0x11ffbb
movq %rbx, %rdi
movq %rbp, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xe9ef5
testq %r14, %r14
je 0x80fe6
testb %r12b, %r12b
jne 0x80fcf
cmpb $0x0, (%r14)
jne 0x80fc4
cmpb $0x0, 0x1(%r14)
je 0x80ff8
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xf6bb0
movq 0xa0(%r14), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x29(%r14)
je 0x80fc4
cmpb $0x0, 0x28(%r14)
je 0x80fc4
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r15
cmpb $0x0, 0x12(%r14)
je 0x8102c
leaq 0xaa675(%rip), %rsi     # 0x12b694
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x14(%r14)
je 0x81047
leaq 0xaa664(%rip), %rsi     # 0x12b69e
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x13(%r14)
je 0x81062
leaq 0xaa653(%rip), %rsi     # 0x12b6a8
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x15(%r14)
je 0x8107d
leaq 0xaa645(%rip), %rsi     # 0x12b6b5
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x16(%r14)
je 0x81098
leaq 0xaa636(%rip), %rsi     # 0x12b6c1
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
movl 0x30(%r14), %ecx
leaq 0xaa62c(%rip), %rdx     # 0x12b6cf
movq %r15, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf6ab0
cmpl $0x0, 0x98(%r14)
je 0x810df
leaq 0xaa616(%rip), %rsi     # 0x12b6d9
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
movq 0xa0(%r14), %rsi
movq %r15, %rdi
callq 0xf6969
movzbl 0x1c(%r14), %ecx
leaq 0xaa5fc(%rip), %rdx     # 0x12b6e7
movq %r15, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf6ab0
cmpb $0x0, 0x1b(%r14)
je 0x81115
leaq 0xaa5e8(%rip), %rsi     # 0x12b6f0
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x2(%r14)
je 0x8113c
movzbl 0x38(%r14), %ecx
movzbl 0x39(%r14), %r8d
leaq 0xaa5c8(%rip), %rdx     # 0x12b6f5
movq %r15, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf6ab0
cmpb $0x0, 0x7(%r14)
je 0x81157
leaq 0xaa5b9(%rip), %rsi     # 0x12b703
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x5(%r14)
je 0x811e9
leaq 0xaa5a1(%rip), %rsi     # 0x12b70a
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
movl 0x40(%r14), %ebp
testl %ebp, %ebp
je 0x811e9
movl %ebp, %edi
shrl $0x18, %edi
callq 0xecff6
leaq 0x38(%rsp), %r12
movb %al, (%r12)
movl %ebp, %edi
shrl $0x10, %edi
movl $0xff, %r13d
andl %r13d, %edi
callq 0xecff6
movb %al, 0x1(%r12)
movl %ebp, %edi
shrl $0x8, %edi
andl %r13d, %edi
callq 0xecff6
movb %al, 0x2(%r12)
andl %r13d, %ebp
movl %ebp, %edi
callq 0xecff6
movb %al, 0x3(%r12)
movb $0x0, 0x4(%r12)
leaq 0x9fec5(%rip), %rdx     # 0x12109c
movq %r15, %rdi
movl $0x5, %esi
movq %r12, %rcx
xorl %eax, %eax
callq 0xf6ab0
cmpb $0x0, 0x1d(%r14)
je 0x8120b
movzbl 0x1e(%r14), %ecx
leaq 0xaa514(%rip), %rdx     # 0x12b710
movq %r15, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf6ab0
cmpb $0x0, 0x1f(%r14)
je 0x81226
leaq 0xaa506(%rip), %rsi     # 0x12b71f
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x3(%r14)
je 0x81241
leaq 0xaa4fb(%rip), %rsi     # 0x12b72f
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x4(%r14)
je 0x8125c
leaq 0xaa4ef(%rip), %rsi     # 0x12b73e
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x10(%r14)
je 0x81277
leaq 0xaa4da(%rip), %rsi     # 0x12b744
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x17(%r14)
je 0x81292
leaq 0xaa4c9(%rip), %rsi     # 0x12b74e
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x18(%r14)
je 0x812ad
leaq 0xaa4b3(%rip), %rsi     # 0x12b753
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x11(%r14)
je 0x812cf
cmpb $0x0, 0x18(%r14)
jne 0x812cf
leaq 0xaa495(%rip), %rsi     # 0x12b757
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x8(%r14)
je 0x812ea
leaq 0xaa481(%rip), %rsi     # 0x12b75e
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x1a(%r14)
je 0x81305
leaq 0xaa46b(%rip), %rsi     # 0x12b763
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0xf(%r14)
je 0x81320
leaq 0xaa455(%rip), %rsi     # 0x12b768
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0xd(%r14)
je 0x8133b
leaq 0xaa43f(%rip), %rsi     # 0x12b76d
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0xe(%r14)
je 0x81356
leaq 0xaa429(%rip), %rsi     # 0x12b772
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0xb(%r14)
je 0x81371
leaq 0xb16c9(%rip), %rsi     # 0x132a2d
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0xc(%r14)
je 0x8138c
leaq 0xc8b57(%rip), %rsi     # 0x149ed6
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x6(%r14)
je 0x813a7
leaq 0xaa3e0(%rip), %rsi     # 0x12b77a
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
cmpb $0x0, 0x9(%r14)
je 0x813c2
leaq 0xaa3ca(%rip), %rsi     # 0x12b77f
movq %r15, %rdi
movl $0x5, %edx
callq 0xf6a40
movl 0x24(%r14), %ecx
cmpl $0x1, %ecx
je 0x813e1
leaq 0xaa3b3(%rip), %rdx     # 0x12b785
movq %r15, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf6ab0
movq %r15, %rdi
callq 0xf74bd
leaq 0xa8066(%rip), %rsi     # 0x129456
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
jmp 0x80fc7