// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/icns.c
// Function: do_decode_24bit
static void do_decode_24bit(deark *c, lctx *d, struct page_ctx *pg)
{
	dbuf *unc_pixels = NULL;
	de_bitmap *img = NULL;
	i64 w, h;
	i64 skip;

	w = pg->type_info->width;
	h = pg->type_info->height;

	// TODO: Try to support uncompressed 24-bit images, assuming they exist.

	// Apparently, some 'it32' icons begin with four extra 0x00 bytes.
	// Skip over the first four bytes if they are 0x00.
	// (I don't know the reason for these bytes, but this is the same
	// logic libicns uses.)
	skip = 0;
	if(pg->code4cc.id==0x69743332) { // 'it32' (128x128)
		if(!dbuf_memcmp(c->infile, pg->image_pos, "\0\0\0\0", 4)) {
			skip = 4;
		}
	}

	unc_pixels = dbuf_create_membuf(c, w*h*3, 1);
	do_uncompress_24(c, d, pg, unc_pixels, skip);

	img = de_bitmap_create(c, w, h, 4);

	de_bitmap_rect(img, 0, 0, w, h, DE_STOCKCOLOR_BLACK, 0);
	read_image_plane(c, d, unc_pixels, 0, img, 0);
	read_image_plane(c, d, unc_pixels, 1, img, 1);
	read_image_plane(c, d, unc_pixels, 2, img, 2);

	if(pg->mask_ref && pg->mask_ref->img) {
		de_bitmap_apply_mask(img, pg->mask_ref->img, 0);
	}

	de_bitmap_write_to_file(img, pg->filename_token, DE_CREATEFLAG_OPT_IMAGE);
	de_bitmap_destroy(img);
	if(unc_pixels) dbuf_close(unc_pixels);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq 0x4(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x69743332, 0x3c(%rax) # imm = 0x69743332
jne 0xa85f9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
leaq 0x10aae4(%rip), %rdx    # 0x1b30c4
movl $0x4, %ecx
callq 0x166ab0
cmpl $0x0, %eax
jne 0xa85f7
movq $0x4, -0x40(%rbp)
jmp 0xa85f9
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
imulq -0x38(%rbp), %rax
imulq $0x3, %rax, %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %r8
callq 0xa8ae0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl $0x4, %ecx
callq 0x16b750
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
xorl %eax, %eax
movl %eax, %edx
movl $0xff000000, %r9d       # imm = 0xFF000000
xorl %eax, %eax
movq %rdx, %rsi
movl $0x0, (%rsp)
callq 0x16cdc0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rcx
callq 0xa8bf0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %r8
movl $0x1, %r9d
movq %r9, %rcx
callq 0xa8bf0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %r8
movl $0x2, %r9d
movq %r9, %rcx
callq 0xa8bf0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0xa86fc
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x18(%rax)
je 0xa86fc
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rsi
xorl %edx, %edx
callq 0x16cf60
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x6c, %rsi
movl $0x2, %edx
callq 0x16afd0
movq -0x28(%rbp), %rdi
callq 0x16af60
cmpq $0x0, -0x20(%rbp)
je 0xa872b
movq -0x20(%rbp), %rdi
callq 0x1676a0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)