// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/jpeg.c
// Function: pic2_main
static void pic2_main(deark *c, struct pic2_ctx *d)
{
	i64 pos = 4;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	while(1) {
		i64 segpos;
		i64 segdlen;
		i64 segdpos;
		u8 segtype;

		if(pos >= c->infile->len-4) goto done;
		segpos = pos;
		de_dbg(c, "segment at %"I64_FMT, segpos);
		de_dbg_indent(c, 1);
		segtype = de_getbyte_p(&pos);
		de_dbg(c, "type: %u (%s)", (UI)segtype, get_pic2_segname(segtype));
		if(segtype==0) goto done;
		segdlen = de_getu32le_p(&pos);
		segdpos = pos;
		de_dbg(c, "dlen: %"I64_FMT, segdlen);
		if(segdpos+segdlen>c->infile->len) goto done;

		if(segtype==5) {
			// Wild guess. If this segment starts with "JPG", we'll assume the
			// compressed data is in a JPEG-like format.
			if(!dbuf_memcmp(c->infile, segdpos, (const void*)"JPG", 3)) {
				d->is_jpg = 1;
			}
		}

		if(segtype==6) {
			pic2_image_segment(c, d, segdpos, segdlen);
		}
		else {
			de_dbg_hexdump(c, c->infile, segdpos, segdlen, 256, NULL, 0x1);
		}
		pos += segdlen;
		de_dbg_indent(c, -1);
	}
done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x4, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x15b580
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x18(%rcx), %rcx
subq $0x4, %rcx
cmpq %rcx, %rax
jl 0xc11e3
jmp 0xc134d
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x110783(%rip), %rsi    # 0x1d197d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165170
movb %al, -0x39(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movzbl -0x39(%rbp), %eax
movl %eax, -0x40(%rbp)
movzbl -0x39(%rbp), %edi
callq 0xc1360
movq -0x48(%rbp), %rdi
movl -0x40(%rbp), %edx
movq %rax, %rcx
leaq 0xdd5a6(%rip), %rsi     # 0x19e7f2
movb $0x0, %al
callq 0x15b0d0
movzbl -0x39(%rbp), %eax
cmpl $0x0, %eax
jne 0xc1261
jmp 0xc134d
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165580
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x110117(%rip), %rsi    # 0x1d13a4
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
addq -0x30(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xc12af
jmp 0xc134d
movzbl -0x39(%rbp), %eax
cmpl $0x5, %eax
jne 0xc12e3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
leaq 0xf52ca(%rip), %rdx     # 0x1b6595
movl $0x3, %ecx
callq 0x166ab0
cmpl $0x0, %eax
jne 0xc12e1
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0xc12e3
movzbl -0x39(%rbp), %eax
cmpl $0x6, %eax
jne 0xc1303
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0xc13f0
jmp 0xc132e
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
movq -0x30(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0xc11c5
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)