// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/ilbm.c
// Function: do_deep_mpic
static void do_deep_mpic(deark *c, struct deep_ctx *d, dbuf *f, i64 pos1, i64 len)
{
	i64 w, h, rowspan;
	i64 pos = pos1;
	UI n;
	u8 ok = 0;
	de_bitmap *img = NULL;

	w = de_getu16be_p(&pos);
	rowspan = w*4;
	h = de_getu16be_p(&pos);
	de_dbg(c, "32-bit thumbnail image, dimensions: %u"DE_CHAR_TIMES"%u", (UI)w, (UI)h);

	// I have no documentation for MPIC.
	// I'm guessing that it's always RGBA or RGBx, and doesn't depend on DPEL.
	// I have some images where DBOD has 3 components, and MPIC has 4 components.
	// So I'm guessing that MPIC is *not* defined to be "the same format as DBOD".

	// Not sure what these fields are. First one might be sample count.
	n = (UI)de_getu32be_p(&pos);
	if(n != 0x00040002) goto done;

	if(pos + rowspan*h > pos1+len) goto done;

	img = de_bitmap_create(c, w, h, 4);
	convert_image_rgba(f, pos, img);

	// If the main image doesn't have an alpha channel, we assume the MPIC
	// thumbnail doesn't have transparency.
	if(d->trans_setting==TRANS_REMOVE || (d->found_DPEL && d->have_alpha_hint==0)) {
		de_bitmap_remove_alpha(img);
	}
	else if(d->trans_setting==TRANS_AUTO) {
		de_bitmap_optimize_alpha(img, 0x1);
	}

	de_bitmap_write_to_file(img, "thumb", DE_CREATEFLAG_IS_AUX|DE_CREATEFLAG_OPT_IMAGE);
	ok = 1;

done:
	if(!ok) {
		de_warn(c, "Unsupported MPIC thumbnail");
	}
	de_bitmap_destroy(img);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movb $0x0, -0x4d(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165210
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
shlq $0x2, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165210
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x38(%rbp), %rax
movl %eax, %ecx
leaq 0xfe6d8(%rip), %rsi     # 0x1b5185
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1654b0
movl %eax, -0x4c(%rbp)
cmpl $0x40002, -0x4c(%rbp)   # imm = 0x40002
je 0xb6ad6
jmp 0xb6b8b
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
imulq -0x38(%rbp), %rcx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
addq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jle 0xb6af8
jmp 0xb6b8b
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl $0x4, %ecx
callq 0x16b750
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0xb7370
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
je 0xb6b4a
movq -0x10(%rbp), %rax
movzbl 0xb(%rax), %eax
cmpl $0x0, %eax
je 0xb6b55
movq -0x10(%rbp), %rax
movzbl 0x51(%rax), %eax
cmpl $0x0, %eax
jne 0xb6b55
movq -0x58(%rbp), %rdi
callq 0x16d070
jmp 0xb6b72
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x2, %eax
jne 0xb6b70
movq -0x58(%rbp), %rdi
movl $0x1, %esi
callq 0x16d190
jmp 0xb6b72
movq -0x58(%rbp), %rdi
leaq 0xfffbe(%rip), %rsi     # 0x1b6b3b
movl $0x3, %edx
callq 0x16afd0
movb $0x1, -0x4d(%rbp)
cmpb $0x0, -0x4d(%rbp)
jne 0xb6ba3
movq -0x8(%rbp), %rdi
leaq 0xfe614(%rip), %rsi     # 0x1b51b0
movb $0x0, %al
callq 0x15bc10
movq -0x58(%rbp), %rdi
callq 0x16af60
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)