// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc2.c
// Function: do_a2i_one_icon
static void do_a2i_one_icon(deark *c, struct a2icons_ctx *d, i64 pos1)
{
	de_bitmap *img =  NULL;
	de_bitmap *mask =  NULL;
	int saved_indent_level;
	UI icon_type;
	i64 w, h;
	i64 rowspan;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "icon at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);
	icon_type = (UI)de_getu16le(pos1);
	de_dbg(c, "icon type: 0x%04x", icon_type);
	d->last_icon_len = de_getu16le(pos1+2);
	de_dbg(c, "icon size: %"I64_FMT, d->last_icon_len);
	h = de_getu16le(pos1+4);
	w = de_getu16le(pos1+6);
	de_dbg_dimensions(c, w, h);
	if(!de_good_image_dimensions(c, w, h)) goto done;
	rowspan = de_pad_to_n(w*4, 8)/8;

	img = de_bitmap_create(c, w, h, 4);
	de_convert_image_paletted(c->infile, pos1+8, 4, rowspan, d->pal, img, 0);

	mask = de_bitmap_create(c, w, h, 1);
	de_convert_image_paletted(c->infile, pos1+8+d->last_icon_len, 4,
		rowspan, d->maskpal, mask, 0);

	de_bitmap_apply_mask(img, mask, 0);
	de_bitmap_write_to_file(img, NULL, DE_CREATEFLAG_OPT_IMAGE);

done:
	de_bitmap_destroy(img);
	de_bitmap_destroy(mask);
	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 $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x1131b5(%rip), %rsi    # 0x1b0d25
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165280
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %edx
leaq 0x11341b(%rip), %rsi    # 0x1b0fc2
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x98(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rdx
leaq 0x1133ed(%rip), %rsi    # 0x1b0fd4
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x165280
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x6, %rsi
callq 0x165280
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x9dc4c
jmp 0x9dd2e
movq -0x38(%rbp), %rdi
shlq $0x2, %rdi
movl $0x8, %esi
callq 0x15ce90
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl $0x4, %ecx
callq 0x16b750
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %r8
movq -0x20(%rbp), %r9
movl $0x4, %edx
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl $0x1, %ecx
callq 0x16b750
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
movq -0x10(%rbp), %rax
addq 0x98(%rax), %rsi
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %r8
addq $0x40, %r8
movq -0x28(%rbp), %r9
movl $0x4, %edx
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x16cf60
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x16afd0
movq -0x20(%rbp), %rdi
callq 0x16af60
movq -0x28(%rbp), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x15b5a0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)