// File: /workspace/github_c_makefile_star2_O2/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 $0x108, %rsp            # imm = 0x108
movq %rsi, %r15
movq %rdi, %rbx
movl $0xb0, %esi
callq 0xdecaf
movq %rax, %r14
pushq $0x32
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xdfcf4
movb %al, 0x1(%r14)
leaq 0x10(%rsp), %r15
andq $0x0, (%r15)
movq %rbx, %rdi
callq 0xeac74
movq %rax, 0xa0(%r14)
movl $0x0, 0xc(%rsp)
movb $0x1, %r13b
movq 0x10(%rsp), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
setge %bpl
jge 0x7bc9c
movq %r15, %rsi
callq 0xe3f2a
cmpb $-0x1, %al
setne %cl
sete %dl
orb %dl, %r13b
testb $0x1, %r13b
movl %ecx, %r13d
jne 0x7b934
movzbl %al, %r12d
movb $0x1, %r13b
testl %r12d, %r12d
je 0x7b934
cmpl $0xf7, %r12d
jne 0x7b987
cmpb $0x0, 0x29(%r14)
jne 0x7b987
movb $0x1, (%r14)
movq %r14, %rdi
movl %r12d, %esi
leaq 0x28(%rsp), %rdx
callq 0x7c94e
movl 0x2c(%rsp), %eax
btl $0x9, %eax
jae 0x7b9a6
movb $0x1, 0x29(%r14)
btl $0x8, %eax
jae 0x7ba04
movl 0x10(%rsp), %r8d
addl $-0x2, %r8d
movq %rbx, %rdi
leaq 0xa1ecd(%rip), %rsi     # 0x11d88c
movl %r12d, %edx
leaq 0x3c(%rsp), %rcx
xorl %eax, %eax
callq 0xde896
cmpl $0xd8, %r12d
je 0x7b9ec
movb $0x1, %r13b
cmpl $0xd9, %r12d
jne 0x7b934
jmp 0x7bc9c
cmpb $0x0, 0x28(%r14)
movb $0x1, %r13b
jne 0x7b934
movb $0x1, 0x28(%r14)
jmp 0x7b934
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0xe3f46
movq 0x10(%rsp), %rbp
cmpq $0x2, %rbp
jl 0x7bc99
movq %rax, %r13
addq $0x2, %rbp
addq $-0x2, %rax
movzbl 0x28(%rsp), %edx
leal -0x4(%rbp), %r8d
movq %rax, 0x20(%rsp)
movl %eax, (%rsp)
movq %rbx, %rdi
leaq 0xa2b8b(%rip), %rsi     # 0x11e5d2
leaq 0x3c(%rsp), %rcx
movl %ebp, %r9d
xorl %eax, %eax
callq 0xde896
cmpq $0x0, 0x90(%rsp)
je 0x7ba91
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x28(%rsp), %rdx
movq %rbp, %rcx
movq 0x20(%rsp), %r8
callq *0x90(%rsp)
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
addq %r13, 0x10(%rsp)
testb $0x2, 0x2d(%rsp)
jne 0x7baa4
leaq 0x18(%rsp), %r13
jmp 0x7bac1
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
leaq 0x18(%rsp), %r13
jne 0x7babb
cmpb $0x0, (%r14)
je 0x7bbbe
incl %ecx
movl %ecx, 0xc(%rsp)
cmpl $0xda, %r12d
jne 0x7b931
movq 0x10(%rsp), %r12
movq %r12, 0x18(%rsp)
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rax
subq %r12, %rax
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
leaq 0xa2baa(%rip), %rsi     # 0x11e69c
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq %r12, %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jge 0x7bba4
movq %r13, %rsi
callq 0xe3f2a
cmpb $-0x1, %al
je 0x7bb2b
movq 0x18(%rsp), %rax
jmp 0x7bb0a
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
testb %al, %al
je 0x7bb24
js 0x7bb43
cmpb $0x0, (%r14)
jne 0x7bb24
movzbl %al, %ebp
andb $-0x8, %al
cmpb $-0x30, %al
jne 0x7bb89
cmpl $0x2, (%rbx)
jl 0x7bb24
movq %r14, %rdi
movl %ebp, %esi
leaq 0x98(%rsp), %rdx
callq 0x7c94e
movl 0x18(%rsp), %r8d
addl $-0x2, %r8d
movq %rbx, %rdi
leaq 0xa1d16(%rip), %rsi     # 0x11d88c
movl %ebp, %edx
leaq 0xac(%rsp), %rcx
xorl %eax, %eax
callq 0xde9f1
jmp 0x7bb24
movq 0x18(%rsp), %rdx
cmpl $0xff, %ebp
jne 0x7bc71
decq %rdx
movq %rdx, 0x18(%rsp)
jmp 0x7bb24
movq 0x20(%rsp), %r13
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
addq %r13, 0x10(%rsp)
jmp 0x7b931
cmpb $0x0, 0x2(%r14)
je 0x7babb
cmpb $0x0, 0x5(%r14)
je 0x7babb
cmpb $0x0, 0xa(%r14)
jne 0x7babb
cmpb $0x1, 0x38(%r14)
jne 0x7babb
movb 0x39(%r14), %al
decb %al
cmpb $0x1, %al
ja 0x7babb
cmpl $0x2, 0x3c(%r14)
jb 0x7bc33
pushq $0x1
popq %rdi
callq 0xed531
movq %rax, %r13
movl 0x3c(%r14), %edi
callq 0xed531
movq %rbx, %rdi
leaq 0xa29e1(%rip), %rsi     # 0x11e5fe
movq %r13, %rdx
leaq 0x18(%rsp), %r13
movq %rax, %rcx
xorl %eax, %eax
callq 0xde896
movl 0xc(%rsp), %ecx
cmpb $0x0, 0x20(%r14)
je 0x7babb
cmpl $0x0, 0x98(%r14)
je 0x7babb
cmpq $0x2, 0x30(%r14)
jl 0x7babb
movq %rbx, %rdi
leaq 0xa29e2(%rip), %rsi     # 0x11e643
xorl %eax, %eax
callq 0xde896
movl 0xc(%rsp), %ecx
jmp 0x7babb
addq $-0x2, %rdx
movq %rdx, 0x18(%rsp)
movq %rdx, %r13
subq %r12, %r13
movq %rbx, %rdi
leaq 0xa2a22(%rip), %rsi     # 0x11e6ac
movl %r13d, %ecx
xorl %eax, %eax
callq 0xde896
jmp 0x7bba9
movb $0x1, %bpl
movq 0x48(%r14), %rdi
callq 0xe5591
andq $0x0, 0x48(%r14)
movq 0x50(%r14), %rdi
callq 0xe5591
andq $0x0, 0x50(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7f236
movq 0x68(%r14), %rdi
testq %rdi, %rdi
je 0x7bd0d
cmpl $0x0, 0x60(%r14)
jne 0x7bd0f
leaq 0xaeb24(%rip), %rsi     # 0x12a7fe
pushq $0x1
popq %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe4e62
movq %rax, %r15
movq 0x68(%r14), %rdi
movq 0x90(%r14), %rdx
xorl %esi, %esi
movq %rax, %rcx
callq 0xe45f4
movq %r15, %rdi
callq 0xe5591
movq 0x68(%r14), %rdi
jmp 0x7bd0f
xorl %edi, %edi
callq 0xe5591
andq $0x0, 0x68(%r14)
testb %bpl, %bpl
jne 0x7be85
movq 0x10(%rsp), %r15
testq %r15, %r15
jle 0x7be6d
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
movq %rdx, %r12
subq %r15, %r12
jle 0x7be6d
cmpl $0x1, 0x10(%rbx)
jg 0x7be6d
cmpq $0x4, %r12
jl 0x7be6d
cmpq $0x18, %r12
jb 0x7bdf7
addq $-0xc, %rdx
leaq 0x98(%rsp), %r13
pushq $0xc
popq %rcx
movq %r13, %rsi
callq 0xe3cb7
cmpb $0x41, (%r13)
jne 0x7bdf7
cmpb $0x58, 0x99(%rsp)
jne 0x7bdf7
cmpb $0x53, 0x9a(%rsp)
jne 0x7bdf7
movzbl 0x9b(%rsp), %eax
cmpl $0x21, %eax
je 0x7bda6
cmpl $0x2a, %eax
jne 0x7bdf7
movq 0x18(%rbx), %rax
movq 0x18(%rax), %r15
movb $0x1, 0x9(%r14)
leaq 0xa2918(%rip), %rsi     # 0x11e6d2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rcx
leaq 0x8b61b(%rip), %rsi     # 0x1073f5
movq %rbx, %rdi
xorl %edx, %edx
xorl %r8d, %r8d
movq %r15, %r9
callq 0xdf9b8
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
jmp 0x7be6d
cmpb $0x0, 0x8(%r14)
jne 0x7be6d
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdi
callq 0xdfb45
movq 0x18(%rbx), %rdi
leaq 0x8b733(%rip), %rsi     # 0x107549
pushq $0x3
popq %rdx
leaq 0x98(%rsp), %r9
movq %r15, %rcx
movq %rax, %r8
callq 0xe62f1
testl %eax, %eax
je 0x7be43
leaq 0xa19fe(%rip), %rsi     # 0x11d835
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf37f
jmp 0x7be6d
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xe66d2
testl %eax, %eax
jne 0x7be6d
leaq 0x971da(%rip), %rsi     # 0x113037
movq %rbx, %rdi
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xdf37f
cmpb $0x0, (%r14)
jne 0x7be7a
cmpb $0x0, 0x1(%r14)
je 0x7beae
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xeaf3c
movq 0xa0(%r14), %rdi
callq 0xeaf3c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x29(%r14)
je 0x7be7a
cmpb $0x0, 0x28(%r14)
je 0x7be7a
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r15
cmpb $0x0, 0x12(%r14)
je 0x7bee0
leaq 0xa281f(%rip), %rsi     # 0x11e6f4
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x14(%r14)
je 0x7bef9
leaq 0xa2810(%rip), %rsi     # 0x11e6fe
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x13(%r14)
je 0x7bf12
leaq 0xa2801(%rip), %rsi     # 0x11e708
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x15(%r14)
je 0x7bf2b
leaq 0xa27f5(%rip), %rsi     # 0x11e715
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x16(%r14)
je 0x7bf44
leaq 0xa27e8(%rip), %rsi     # 0x11e721
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
movl 0x30(%r14), %ecx
leaq 0xa27e0(%rip), %rdx     # 0x11e72f
pushq $0x5
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0xeae8b
cmpl $0x0, 0x98(%r14)
je 0x7bf87
leaq 0xa27cc(%rip), %rsi     # 0x11e739
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
movq 0xa0(%r14), %rsi
movq %r15, %rdi
callq 0xead71
movzbl 0x1c(%r14), %ecx
leaq 0xa27b4(%rip), %rdx     # 0x11e747
pushq $0x5
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0xeae8b
cmpb $0x0, 0x1b(%r14)
je 0x7bfb9
leaq 0xa27a2(%rip), %rsi     # 0x11e750
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x2(%r14)
je 0x7bfde
movzbl 0x38(%r14), %ecx
movzbl 0x39(%r14), %r8d
leaq 0xa2784(%rip), %rdx     # 0x11e755
pushq $0x5
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0xeae8b
cmpb $0x0, 0x7(%r14)
je 0x7bff7
leaq 0xa2777(%rip), %rsi     # 0x11e763
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x5(%r14)
je 0x7c085
leaq 0xa2761(%rip), %rsi     # 0x11e76a
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
movl 0x40(%r14), %ebp
testl %ebp, %ebp
je 0x7c085
movl %ebp, %edi
shrl $0x18, %edi
callq 0xe1f0f
leaq 0x28(%rsp), %r12
movb %al, (%r12)
movl %ebp, %edi
shrl $0x10, %edi
movl $0xff, %r13d
andl %r13d, %edi
callq 0xe1f0f
movb %al, 0x1(%r12)
movl %ebp, %edi
shrl $0x8, %edi
andl %r13d, %edi
callq 0xe1f0f
movb %al, 0x2(%r12)
andl %r13d, %ebp
movl %ebp, %edi
callq 0xe1f0f
movb %al, 0x3(%r12)
movb $0x0, 0x4(%r12)
leaq 0x98047(%rip), %rdx     # 0x1140bc
pushq $0x5
popq %rsi
movq %r15, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0xeae8b
cmpb $0x0, 0x1d(%r14)
je 0x7c0a5
movzbl 0x1e(%r14), %ecx
leaq 0xa26d8(%rip), %rdx     # 0x11e770
pushq $0x5
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0xeae8b
cmpb $0x0, 0x1f(%r14)
je 0x7c0be
leaq 0xa26cc(%rip), %rsi     # 0x11e77f
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x3(%r14)
je 0x7c0d7
leaq 0xa26c3(%rip), %rsi     # 0x11e78f
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x4(%r14)
je 0x7c0f0
leaq 0xa26b9(%rip), %rsi     # 0x11e79e
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x10(%r14)
je 0x7c109
leaq 0xa26a6(%rip), %rsi     # 0x11e7a4
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x17(%r14)
je 0x7c122
leaq 0xa2697(%rip), %rsi     # 0x11e7ae
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x18(%r14)
je 0x7c13b
leaq 0xa2683(%rip), %rsi     # 0x11e7b3
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x11(%r14)
je 0x7c15b
cmpb $0x0, 0x18(%r14)
jne 0x7c15b
leaq 0xa2667(%rip), %rsi     # 0x11e7b7
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x8(%r14)
je 0x7c174
leaq 0xa2655(%rip), %rsi     # 0x11e7be
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x1a(%r14)
je 0x7c18d
leaq 0xa2641(%rip), %rsi     # 0x11e7c3
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0xf(%r14)
je 0x7c1a6
leaq 0xa262d(%rip), %rsi     # 0x11e7c8
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0xd(%r14)
je 0x7c1bf
leaq 0xa2619(%rip), %rsi     # 0x11e7cd
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0xe(%r14)
je 0x7c1d8
leaq 0xa2605(%rip), %rsi     # 0x11e7d2
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0xb(%r14)
je 0x7c1f1
leaq 0xa9967(%rip), %rsi     # 0x125b4d
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0xc(%r14)
je 0x7c20a
leaq 0xc0db7(%rip), %rsi     # 0x13cfb6
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x6(%r14)
je 0x7c223
leaq 0xa25c2(%rip), %rsi     # 0x11e7da
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
cmpb $0x0, 0x9(%r14)
je 0x7c23c
leaq 0xa25ae(%rip), %rsi     # 0x11e7df
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0xeae42
movl 0x24(%r14), %ecx
cmpl $0x1, %ecx
je 0x7c259
leaq 0xa2599(%rip), %rdx     # 0x11e7e5
pushq $0x5
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0xeae8b
movq %r15, %rdi
callq 0xeb7e4
leaq 0xa01de(%rip), %rsi     # 0x11c446
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
jmp 0x7be7d