// File: /workspace/github_c_makefile_star2_O3/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 0xe8b2b
movq %rax, %r14
movq %rbx, %rdi
movq %r15, %rsi
movl $0x32, %edx
callq 0xea4d9
movb %al, 0x1(%r14)
movq $0x0, 0x10(%rsp)
movq %rbx, %rdi
callq 0xf6410
movq %rax, 0xa0(%r14)
movq 0x18(%rbx), %rdi
cmpq $0x0, 0x18(%rdi)
jle 0x807d0
leaq 0x10(%rsp), %r13
movl $0x0, 0x2c(%rsp)
movb $0x1, %bpl
movq %r13, %rsi
callq 0xeeb4b
cmpb $-0x1, %al
setne %cl
sete %dl
orb %bpl, %dl
movl %ecx, %ebp
testb $0x1, %dl
jne 0x80501
movzbl %al, %r15d
movb $0x1, %bpl
testl %r15d, %r15d
je 0x80501
cmpl $0xf7, %r15d
jne 0x80494
cmpb $0x0, 0x29(%r14)
jne 0x80494
movb $0x1, (%r14)
movq %r14, %rdi
movl %r15d, %esi
leaq 0x38(%rsp), %rdx
callq 0x8153d
movl 0x3c(%rsp), %eax
btl $0x9, %eax
jae 0x804b3
movb $0x1, 0x29(%r14)
btl $0x8, %eax
jae 0x80519
movl 0x10(%rsp), %r8d
addl $-0x2, %r8d
xorl %r12d, %r12d
movq %rbx, %rdi
leaq 0xaa62d(%rip), %rsi     # 0x12aafc
movl %r15d, %edx
leaq 0x4c(%rsp), %rcx
xorl %eax, %eax
callq 0xe8617
cmpl $0xd8, %r15d
je 0x804f5
cmpl $0xd9, %r15d
jne 0x80501
jmp 0x807d3
cmpb $0x0, 0x28(%r14)
jne 0x80501
movb $0x1, 0x28(%r14)
movq 0x10(%rsp), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jl 0x80452
jmp 0x807d0
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0xeeb67
movq 0x10(%rsp), %rbp
movb $0x1, %r12b
cmpq $0x2, %rbp
jl 0x807d3
addq $0x2, %rbp
movq %rax, 0x20(%rsp)
addq $-0x2, %rax
movzbl 0x38(%rsp), %edx
leal -0x4(%rbp), %r8d
movq %rax, 0x30(%rsp)
movl %eax, (%rsp)
movq %rbx, %rdi
leaq 0xab2e1(%rip), %rsi     # 0x12b842
leaq 0x4c(%rsp), %rcx
movl %ebp, %r9d
xorl %eax, %eax
callq 0xe8617
cmpq $0x0, 0xa0(%rsp)
je 0x805af
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
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 0xe8a15
movq 0x20(%rsp), %rax
addq 0x10(%rsp), %rax
movq %rax, 0x10(%rsp)
testb $0x2, 0x3d(%rsp)
je 0x805df
cmpl $0x0, 0x2c(%rsp)
jne 0x805d6
cmpb $0x0, (%r14)
je 0x806d9
incl 0x2c(%rsp)
movq 0x10(%rsp), %rax
cmpl $0xda, %r15d
jne 0x807c0
movq %rax, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq 0x18(%rbx), %rax
movq 0x18(%rax), %r15
subq 0x20(%rsp), %r15
movq %rbx, %rdi
leaq 0xab2ff(%rip), %rsi     # 0x12b90c
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq 0x20(%rsp), %rax
cmpq %rax, 0x18(%rdi)
jle 0x807a6
leaq 0x18(%rsp), %rsi
callq 0xeeb4b
cmpb $-0x1, %al
je 0x8065b
movq 0x18(%rsp), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jl 0x80639
jmp 0x807a6
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xeeb4b
testb %al, %al
je 0x80647
js 0x80675
cmpb $0x0, (%r14)
jne 0x80647
movzbl %al, %ebp
andb $-0x8, %al
cmpb $-0x30, %al
jne 0x806bb
cmpl $0x2, (%rbx)
jl 0x80647
movq %r14, %rdi
movl %ebp, %esi
leaq 0xa8(%rsp), %rdx
callq 0x8153d
movl 0x18(%rsp), %r8d
addl $-0x2, %r8d
movq %rbx, %rdi
leaq 0xaa454(%rip), %rsi     # 0x12aafc
movl %ebp, %edx
leaq 0xbc(%rsp), %rcx
xorl %eax, %eax
callq 0xe87e4
jmp 0x80647
movq 0x18(%rsp), %rdx
cmpl $0xff, %ebp
jne 0x80781
decq %rdx
movq %rdx, 0x18(%rsp)
jmp 0x80647
cmpb $0x0, 0x2(%r14)
je 0x805d6
cmpb $0x0, 0x5(%r14)
je 0x805d6
cmpb $0x0, 0xa(%r14)
jne 0x805d6
cmpb $0x1, 0x38(%r14)
jne 0x805d6
movb 0x39(%r14), %al
decb %al
cmpb $0x1, %al
ja 0x805d6
cmpl $0x2, 0x3c(%r14)
jb 0x80747
movl $0x1, %edi
callq 0xf8e67
movq %rax, %rbp
movl 0x3c(%r14), %edi
callq 0xf8e67
movq %rbx, %rdi
leaq 0xab134(%rip), %rsi     # 0x12b86e
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
cmpb $0x0, 0x20(%r14)
je 0x805d6
cmpl $0x0, 0x98(%r14)
je 0x805d6
cmpq $0x2, 0x30(%r14)
jl 0x805d6
movq %rbx, %rdi
leaq 0xab13e(%rip), %rsi     # 0x12b8b3
xorl %eax, %eax
callq 0xe8617
jmp 0x805d6
addq $-0x2, %rdx
movq %rdx, 0x18(%rsp)
movq %rdx, %r15
subq 0x20(%rsp), %r15
movq %rbx, %rdi
leaq 0xab180(%rip), %rsi     # 0x12b91c
movl %r15d, %ecx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
addq 0x10(%rsp), %r15
movq %r15, 0x10(%rsp)
movq %r15, %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jl 0x8044f
jmp 0x807d3
movb $0x1, %r12b
movq 0x48(%r14), %rdi
callq 0xf052b
xorl %r15d, %r15d
movq %r15, 0x48(%r14)
movq 0x50(%r14), %rdi
callq 0xf052b
movq %r15, 0x50(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x83f7a
movq 0x68(%r14), %rax
testq %rax, %rax
je 0x80848
cmpl $0x0, 0x60(%r14)
movq %rax, %r15
jne 0x80848
leaq 0xb72c9(%rip), %rsi     # 0x137ade
movq %rbx, %rdi
xorl %edx, %edx
movl $0x1, %ecx
callq 0xefda1
movq %rax, %r15
movq 0x68(%r14), %rdi
movq 0x90(%r14), %rdx
xorl %esi, %esi
movq %rax, %rcx
callq 0xef481
movq %r15, %rdi
callq 0xf052b
movq 0x68(%r14), %r15
movq %r15, %rdi
callq 0xf052b
movq $0x0, 0x68(%r14)
testb %r12b, %r12b
jne 0x80988
movq 0x10(%rsp), %r15
testq %r15, %r15
jle 0x80970
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
movq %rdx, %r12
subq %r15, %r12
jle 0x80970
cmpl $0x1, 0x10(%rbx)
jg 0x80970
cmpq $0x4, %r12
jl 0x80970
cmpq $0x18, %r12
jb 0x808f8
addq $-0xc, %rdx
leaq 0xa8(%rsp), %r13
movl $0xc, %ecx
movq %r13, %rsi
callq 0xee8d4
cmpb $0x41, (%r13)
jne 0x808f8
cmpb $0x58, 0xa9(%rsp)
jne 0x808f8
cmpb $0x53, 0xaa(%rsp)
jne 0x808f8
movzbl 0xab(%rsp), %eax
cmpl $0x21, %eax
je 0x808e3
cmpl $0x2a, %eax
jne 0x808f8
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x814e5
jmp 0x80970
cmpb $0x0, 0x8(%r14)
jne 0x80970
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdi
callq 0xe9c3b
movq 0x18(%rbx), %rdi
leaq 0x93c92(%rip), %rsi     # 0x1145a9
leaq 0xa8(%rsp), %r9
movl $0x3, %edx
movq %r15, %rcx
movq %rax, %r8
callq 0xf149c
testl %eax, %eax
je 0x80946
leaq 0xaa16b(%rip), %rsi     # 0x12aaa5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9393
jmp 0x80970
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xf1856
testl %eax, %eax
jne 0x80970
leaq 0x9f783(%rip), %rsi     # 0x1200e3
movq %rbx, %rdi
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xe9393
cmpb $0x0, (%r14)
jne 0x8097d
cmpb $0x0, 0x1(%r14)
je 0x809b1
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xf6753
movq 0xa0(%r14), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x29(%r14)
je 0x8097d
cmpb $0x0, 0x28(%r14)
je 0x8097d
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r15
cmpb $0x0, 0x12(%r14)
je 0x809e5
leaq 0xaaf8c(%rip), %rsi     # 0x12b964
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x14(%r14)
je 0x80a00
leaq 0xaaf7b(%rip), %rsi     # 0x12b96e
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x13(%r14)
je 0x80a1b
leaq 0xaaf6a(%rip), %rsi     # 0x12b978
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x15(%r14)
je 0x80a36
leaq 0xaaf5c(%rip), %rsi     # 0x12b985
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x16(%r14)
je 0x80a51
leaq 0xaaf4d(%rip), %rsi     # 0x12b991
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
movl 0x30(%r14), %ecx
leaq 0xaaf43(%rip), %rdx     # 0x12b99f
movq %r15, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf6653
cmpl $0x0, 0x98(%r14)
je 0x80a98
leaq 0xaaf2d(%rip), %rsi     # 0x12b9a9
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
movq 0xa0(%r14), %rsi
movq %r15, %rdi
callq 0xf6509
movzbl 0x1c(%r14), %ecx
leaq 0xaaf13(%rip), %rdx     # 0x12b9b7
movq %r15, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf6653
cmpb $0x0, 0x1b(%r14)
je 0x80ace
leaq 0xaaeff(%rip), %rsi     # 0x12b9c0
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x2(%r14)
je 0x80af5
movzbl 0x38(%r14), %ecx
movzbl 0x39(%r14), %r8d
leaq 0xaaedf(%rip), %rdx     # 0x12b9c5
movq %r15, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf6653
cmpb $0x0, 0x7(%r14)
je 0x80b10
leaq 0xaaed0(%rip), %rsi     # 0x12b9d3
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x5(%r14)
je 0x80ba2
leaq 0xaaeb8(%rip), %rsi     # 0x12b9da
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
movl 0x40(%r14), %ebp
testl %ebp, %ebp
je 0x80ba2
movl %ebp, %edi
shrl $0x18, %edi
callq 0xec9b9
leaq 0x38(%rsp), %r12
movb %al, (%r12)
movl %ebp, %edi
shrl $0x10, %edi
movl $0xff, %r13d
andl %r13d, %edi
callq 0xec9b9
movb %al, 0x1(%r12)
movl %ebp, %edi
shrl $0x8, %edi
andl %r13d, %edi
callq 0xec9b9
movb %al, 0x2(%r12)
andl %r13d, %ebp
movl %ebp, %edi
callq 0xec9b9
movb %al, 0x3(%r12)
movb $0x0, 0x4(%r12)
leaq 0xa061c(%rip), %rdx     # 0x1211ac
movq %r15, %rdi
movl $0x5, %esi
movq %r12, %rcx
xorl %eax, %eax
callq 0xf6653
cmpb $0x0, 0x1d(%r14)
je 0x80bc4
movzbl 0x1e(%r14), %ecx
leaq 0xaae2b(%rip), %rdx     # 0x12b9e0
movq %r15, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf6653
cmpb $0x0, 0x1f(%r14)
je 0x80bdf
leaq 0xaae1d(%rip), %rsi     # 0x12b9ef
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x3(%r14)
je 0x80bfa
leaq 0xaae12(%rip), %rsi     # 0x12b9ff
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x4(%r14)
je 0x80c15
leaq 0xaae06(%rip), %rsi     # 0x12ba0e
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x10(%r14)
je 0x80c30
leaq 0xaadf1(%rip), %rsi     # 0x12ba14
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x17(%r14)
je 0x80c4b
leaq 0xaade0(%rip), %rsi     # 0x12ba1e
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x18(%r14)
je 0x80c66
leaq 0xaadca(%rip), %rsi     # 0x12ba23
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x11(%r14)
je 0x80c88
cmpb $0x0, 0x18(%r14)
jne 0x80c88
leaq 0xaadac(%rip), %rsi     # 0x12ba27
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x8(%r14)
je 0x80ca3
leaq 0xaad98(%rip), %rsi     # 0x12ba2e
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x1a(%r14)
je 0x80cbe
leaq 0xaad82(%rip), %rsi     # 0x12ba33
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0xf(%r14)
je 0x80cd9
leaq 0xaad6c(%rip), %rsi     # 0x12ba38
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0xd(%r14)
je 0x80cf4
leaq 0xaad56(%rip), %rsi     # 0x12ba3d
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0xe(%r14)
je 0x80d0f
leaq 0xaad40(%rip), %rsi     # 0x12ba42
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0xb(%r14)
je 0x80d2a
leaq 0xb2108(%rip), %rsi     # 0x132e25
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0xc(%r14)
je 0x80d45
leaq 0xc974e(%rip), %rsi     # 0x14a486
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x6(%r14)
je 0x80d60
leaq 0xaacf7(%rip), %rsi     # 0x12ba4a
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
cmpb $0x0, 0x9(%r14)
je 0x80d7b
leaq 0xaace1(%rip), %rsi     # 0x12ba4f
movq %r15, %rdi
movl $0x5, %edx
callq 0xf65e3
movl 0x24(%r14), %ecx
cmpl $0x1, %ecx
je 0x80d9a
leaq 0xaacca(%rip), %rdx     # 0x12ba55
movq %r15, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf6653
movq %r15, %rdi
callq 0xf705c
leaq 0xa88dd(%rip), %rsi     # 0x129686
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
jmp 0x80980