// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/cfb.c
// Function: do_CorelImages_internal
static void do_CorelImages_internal(deark *c, lctx *d, struct dir_entry_info *dei,
	dbuf *f)
{
	i64 pos = 0;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	while(1) {
		unsigned int imgtype1_or_size;
		unsigned int imgtype1;
		i64 size1 = 0;

		if(pos >= f->len-8) break;

		de_dbg(c, "image at [%"I64_FMT"]", pos);
		de_dbg_indent(c, 1);

		// Seems like sometimes this first 'type' field is present, and
		// sometimes it isn't (and we treat it like it's 0).
		imgtype1_or_size = (unsigned int)dbuf_getu32le_p(f, &pos);
		if(imgtype1_or_size<8) {
			imgtype1 = imgtype1_or_size;

			if(imgtype1==0) {
				size1 = dbuf_getu32le_p(f, &pos);
			}
		}
		else {
			imgtype1 = 0;
			size1 = (i64)imgtype1_or_size;
		}

		de_dbg(c, "low level imgtype: %u", imgtype1);

		if(imgtype1==0) {
			unsigned int imgtype2;

			imgtype2 = (unsigned int)dbuf_getu32le_p(f, &pos);
			de_dbg(c, "high level imgtype: %u", imgtype2);
			de_dbg(c, "len: %"I64_FMT, size1);

			if(pos+size1 > f->len) break;

			if(imgtype2==0) { // "Uncompressed Image"?
				do_Corel_UIformat(c, d, dei, f, pos, size1, 0);
			}
			else if(imgtype2==1) { // JPEG?
				dbuf_create_file_from_slice(f, pos, size1, "jpg", NULL, 0);
			}
			else {
				de_dbg(c, "[unsupported image type: %u:%u]", imgtype1, imgtype2);
			}
		}
		else if(imgtype1==1) {
			size1 = dbuf_getu32le(f, pos+8);
			do_Corel_simple_image(c, d, dei, f, pos);
			pos += 8 + 4;
		}
		else {
			de_dbg(c, "[unsupported image type (%u), can't continue]", imgtype1);
			goto done;
		}

		pos += size1;
		de_dbg_indent(c, -1);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x15b580
movq $0x0, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq $0x8, %rcx
cmpq %rcx, %rax
jl 0x557df
jmp 0x559a3
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x1505a5(%rip), %rsi    # 0x1a5d93
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165580
movl %eax, -0x30(%rbp)
cmpl $0x8, -0x30(%rbp)
jae 0x55838
movl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x55836
movq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165580
movq %rax, -0x40(%rbp)
jmp 0x55846
movl $0x0, -0x34(%rbp)
movl -0x30(%rbp), %eax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %edx
leaq 0x15054e(%rip), %rsi    # 0x1a5da2
movb $0x0, %al
callq 0x15b0d0
cmpl $0x0, -0x34(%rbp)
jne 0x55929
movq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165580
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %edx
leaq 0x150535(%rip), %rsi    # 0x1a5db8
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0x17b92c(%rip), %rsi    # 0x1d11c5
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
addq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jle 0x558b7
jmp 0x559a3
cmpl $0x0, -0x44(%rbp)
jne 0x558e5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x40(%rbp), %r9
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x55280
jmp 0x55927
cmpl $0x1, -0x44(%rbp)
jne 0x5590d
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq 0x1699fb(%rip), %rcx    # 0x1bf2f9
xorl %eax, %eax
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x166be0
jmp 0x55925
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %edx
movl -0x44(%rbp), %ecx
leaq 0x1504b1(%rip), %rsi    # 0x1a5dcf
movb $0x0, %al
callq 0x15b0d0
jmp 0x55927
jmp 0x55984
cmpl $0x1, -0x34(%rbp)
jne 0x5596b
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
callq 0x165540
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
callq 0x559c0
movq -0x28(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x28(%rbp)
jmp 0x55982
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %edx
leaq 0x150476(%rip), %rsi    # 0x1a5def
movb $0x0, %al
callq 0x15b0d0
jmp 0x559a5
jmp 0x55984
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x557bd
jmp 0x559a5
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x15b5a0
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)