// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x24(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl $0xb0, %esi
callq 0x15b780
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x32, %edx
callq 0x15d1d0
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, 0x1(%rax)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x20(%rbp), %rcx
callq 0xbbd00
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0xbb50f
jmp 0xbb67c
movq -0x20(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x1, -0x20(%rbp)
jge 0xbb527
jmp 0xbb67c
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0xbb53e
jmp 0xbb67c
movq -0x8(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jle 0xbb54d
jmp 0xbb67c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
subq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x4, -0x38(%rbp)
jge 0xbb56d
jmp 0xbb67c
cmpq $0x18, -0x38(%rbp)
jl 0xbb5e7
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x54(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdx
subq $0xc, %rdx
movl $0xc, %ecx
callq 0x164d10
movzbl -0x54(%rbp), %eax
cmpl $0x41, %eax
jne 0xbb5e5
movzbl -0x53(%rbp), %eax
cmpl $0x58, %eax
jne 0xbb5e5
movzbl -0x52(%rbp), %eax
cmpl $0x53, %eax
jne 0xbb5e5
movzbl -0x51(%rbp), %eax
cmpl $0x21, %eax
je 0xbb5c7
movzbl -0x51(%rbp), %eax
cmpl $0x2a, %eax
jne 0xbb5e5
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdx
callq 0xbbf70
jmp 0xbb67c
jmp 0xbb5e7
movq -0x48(%rbp), %rax
cmpb $0x0, 0x8(%rax)
je 0xbb5f6
jmp 0xbb67c
movq -0x38(%rbp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x15ccf0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %r8
leaq 0xe4d6f(%rip), %rsi     # 0x1a038e
movl $0x3, %edx
leaq -0x30(%rbp), %r9
callq 0x169370
cmpl $0x0, %eax
je 0xbb646
movq -0x8(%rbp), %rdi
leaq 0xfae78(%rip), %rsi     # 0x1b64b5
movb $0x0, %al
callq 0x15c0c0
jmp 0xbb67c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x169d30
cmpl $0x0, %eax
je 0xbb662
jmp 0xbb67c
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0xf05d6(%rip), %rsi     # 0x1abc4b
movb $0x0, %al
callq 0x15c0c0
cmpq $0x0, -0x48(%rbp)
je 0xbb6a3
cmpl $0x0, -0x24(%rbp)
je 0xbb696
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xbbff0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xbc4b0
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)