// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc2.c
// Function: de_run_mdesk_icn
static void de_run_mdesk_icn(deark *c, de_module_params *mparams)
{
	const char *s;
	int pal_req = 0;
	u8 toybox_mode = 0;
	u8 b2;
	de_bitmap *img = NULL;
	de_color pal[16];
	static const de_color pal_mdesk[16] = {
		0xff000000U, 0xffaa0000U, 0xff00aa00U, 0xffaaaa00U,
		0xff0000aaU, 0xffaa00aaU, 0xff00aaaaU, 0xff7d7d7dU,
		0xffbababaU, 0xffff5555U, 0xff55ff55U, 0xffffff55U,
		0xff5555ffU, 0xffff55ffU, 0xff55ffffU, 0xffffffffU
	};

	s = de_get_ext_option(c, "mdesk_icn:pal");
	if(s) {
		pal_req = de_atoi(s);
	}

	if(pal_req<1 || pal_req>4) pal_req = 4; // default = prefer Magic Desk

	b2 = de_getbyte(2);
	de_dbg2(c, "byte[2]: 0x%02x", (UI)b2);

	if(pal_req==1) { //  ToyBox only
		toybox_mode = 1;
	}
	else if(pal_req==2) { // Magic Desk only
		toybox_mode = 0;
	}
	else if(pal_req==3) { // prefer ToyBox
		toybox_mode = (b2 != 0x03);
	}
	else {
		toybox_mode = (b2 == 0x00);
	}

	de_declare_fmtf(c, "%s icon", (toybox_mode?"ToyBox":"Magic Desk"));

	if(toybox_mode) {
		de_copy_std_palette(DE_PALID_PC16, 0, 0, pal, 16, 0);
	}
	else {
		de_memcpy(pal, pal_mdesk, sizeof(pal));
	}

	img = de_bitmap_create(c, 32, 32, 3);
	de_convert_image_paletted(c->infile, 3, 4, 16, pal, img, 0);
	de_bitmap_transpose(img);
	de_bitmap_write_to_file(img, NULL, 0);
	de_bitmap_destroy(img);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movb $0x0, -0x1d(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x1184ac(%rip), %rsi    # 0x1b0b2d
callq 0x15cb30
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x9869d
movq -0x18(%rbp), %rdi
callq 0x15cca0
movl %eax, -0x1c(%rbp)
cmpl $0x1, -0x1c(%rbp)
jl 0x986a9
cmpl $0x4, -0x1c(%rbp)
jle 0x986b0
movl $0x4, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x2, %esi
callq 0x165060
movb %al, -0x1e(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x1e(%rbp), %edx
leaq 0x118467(%rip), %rsi    # 0x1b0b3b
movb $0x0, %al
callq 0x15b350
cmpl $0x1, -0x1c(%rbp)
jne 0x986e7
movb $0x1, -0x1d(%rbp)
jmp 0x98723
cmpl $0x2, -0x1c(%rbp)
jne 0x986f3
movb $0x0, -0x1d(%rbp)
jmp 0x98721
cmpl $0x3, -0x1c(%rbp)
jne 0x9870d
movzbl -0x1e(%rbp), %eax
cmpl $0x3, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movb %al, -0x1d(%rbp)
jmp 0x9871f
movzbl -0x1e(%rbp), %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movb %al, -0x1d(%rbp)
jmp 0x98721
jmp 0x98723
movq -0x8(%rbp), %rdi
movzbl -0x1d(%rbp), %ecx
leaq 0x118428(%rip), %rdx    # 0x1b0b5a
leaq 0x11841a(%rip), %rax    # 0x1b0b53
cmpl $0x0, %ecx
cmovneq %rax, %rdx
leaq 0x118404(%rip), %rsi    # 0x1b0b4b
movb $0x0, %al
callq 0x15e3d0
cmpb $0x0, -0x1d(%rbp)
je 0x98774
leaq -0x70(%rbp), %rcx
movl $0x14, %edi
xorl %r9d, %r9d
xorl %eax, %eax
movl %eax, %edx
movl $0x10, %r8d
movl %r9d, %esi
callq 0x161320
jmp 0x98789
leaq -0x70(%rbp), %rdi
leaq 0x118881(%rip), %rsi    # 0x1b1000
movl $0x40, %edx
callq 0x191e0
movq -0x8(%rbp), %rdi
movl $0x20, %edx
movl $0x3, %ecx
movq %rdx, %rsi
callq 0x16b750
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x70(%rbp), %r8
movq -0x28(%rbp), %r9
movl $0x3, %esi
movl $0x4, %edx
movl $0x10, %ecx
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
movq -0x28(%rbp), %rdi
callq 0x16cb90
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x16afd0
movq -0x28(%rbp), %rdi
callq 0x16af60
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)