// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/mbk.c
// Function: do_icon
static void do_icon(deark *c, lctx *d, i64 idx, i64 pos)
{
	de_bitmap *fgimg = NULL;
	de_bitmap *maskimg = NULL;
	UI cvtflags = 0;
	i64 format_flag;
	i64 bgcol, fgcol;
	i64 w, h;
	i64 rowspan;
	i64 bitsstart;

	de_dbg(c, "icon #%d, at %d", (int)idx, (int)pos);
	de_dbg_indent(c, 1);

	format_flag = de_getu16be(pos+4);
	de_dbg(c, "format flag: 0x%04x", (unsigned int)format_flag);
	bgcol = de_getu16be(pos+6);
	fgcol = de_getu16be(pos+8);
	de_dbg(c, "bgcol: 0x%04x, fgcol: 0x%04x", (unsigned int)bgcol, (unsigned int)fgcol);

	// TODO: I don't know how to figure out what colors to use.
	if(fgcol==0 && bgcol!=0) {
		;
	}
	else {
		cvtflags |= DE_CVTF_WHITEISZERO;
	}

	w = 16;
	h = 16;
	rowspan = 4;
	fgimg = de_bitmap_create(c, w, h, 2);
	maskimg = de_bitmap_create(c, w, h, 1);

	bitsstart = pos + 10;

	de_convert_image_bilevel(c->infile, bitsstart, rowspan, maskimg, 0);
	de_convert_image_bilevel(c->infile, bitsstart+2, rowspan, fgimg, cvtflags);
	de_bitmap_apply_mask(fgimg, maskimg, 0);

	de_bitmap_write_to_file(fgimg, NULL, DE_CREATEFLAG_OPT_IMAGE);
	de_bitmap_destroy(fgimg);
	de_bitmap_destroy(maskimg);
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movl %eax, %ecx
leaq 0xdf356(%rip), %rsi     # 0x1bbeac
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x4, %rsi
callq 0x1651d0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0xdf327(%rip), %rsi     # 0x1bbebc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x6, %rsi
callq 0x1651d0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x8, %rsi
callq 0x1651d0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
movq -0x50(%rbp), %rax
movl %eax, %ecx
leaq 0xdf2eb(%rip), %rsi     # 0x1bbed0
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x50(%rbp)
jne 0xdcbfc
cmpq $0x0, -0x48(%rbp)
je 0xdcbfc
jmp 0xdcc05
movl -0x34(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x34(%rbp)
movq $0x10, -0x58(%rbp)
movq $0x10, -0x60(%rbp)
movq $0x4, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
movl $0x2, %ecx
callq 0x16b750
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
movl $0x1, %ecx
callq 0x16b750
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
addq $0xa, %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq -0x30(%rbp), %rcx
xorl %r8d, %r8d
callq 0x16bee0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x70(%rbp), %rsi
addq $0x2, %rsi
movq -0x68(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x34(%rbp), %r8d
callq 0x16bee0
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x16cf60
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x16afd0
movq -0x28(%rbp), %rdi
callq 0x16af60
movq -0x30(%rbp), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)