// File: /workspace/github_c_makefile_star2_O3/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
pushq %r14
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
leaq 0xbb734(%rip), %rsi     # 0x1256bd
callq 0xe9b74
testq %rax, %rax
je 0x69f9d
movq %rax, %rdi
callq 0xe9c2a
jmp 0x69f9f
xorl %eax, %eax
leal -0x5(%rax), %ecx
cmpl $-0x4, %ecx
movl $0x4, %r14d
cmovael %eax, %r14d
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xeead3
movl %eax, %ebp
movzbl %al, %edx
leaq 0xbb702(%rip), %rsi     # 0x1256cb
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe87e4
cmpl $0x1, %r14d
je 0x6a02e
cmpl $0x3, %r14d
je 0x69fff
cmpl $0x2, %r14d
jne 0x6a048
leaq 0xbb6ef(%rip), %rsi     # 0x1256db
leaq 0xbb6f7(%rip), %rdx     # 0x1256ea
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb152
jmp 0x6a073
cmpb $0x3, %bpl
leaq 0xbb6e0(%rip), %rax     # 0x1256ea
leaq 0xbb6d2(%rip), %rdx     # 0x1256e3
cmoveq %rax, %rdx
leaq 0xbb6bf(%rip), %rsi     # 0x1256db
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb152
cmpb $0x3, %bpl
je 0x6a073
jmp 0x6a0a5
leaq 0xbb6a6(%rip), %rsi     # 0x1256db
leaq 0xbb6a7(%rip), %rdx     # 0x1256e3
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb152
jmp 0x6a0a5
testb %bpl, %bpl
leaq 0xbb691(%rip), %rax     # 0x1256e3
leaq 0xbb691(%rip), %rdx     # 0x1256ea
cmoveq %rax, %rdx
leaq 0xbb677(%rip), %rsi     # 0x1256db
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb152
testb %bpl, %bpl
je 0x6a0a5
movaps 0xbabb6(%rip), %xmm0    # 0x124c30
movaps %xmm0, 0x40(%rsp)
movaps 0xbab9a(%rip), %xmm0    # 0x124c20
movaps %xmm0, 0x30(%rsp)
movaps 0xbab7e(%rip), %xmm0    # 0x124c10
movaps %xmm0, 0x20(%rsp)
movaps 0xbab62(%rip), %xmm0    # 0x124c00
movaps %xmm0, 0x10(%rsp)
jmp 0x6a0c1
leaq 0x10(%rsp), %rcx
movl $0x10, %r8d
movl $0x14, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0xec55a
movl $0x20, %esi
movl $0x20, %edx
movq %rbx, %rdi
movl $0x3, %ecx
callq 0xf266a
movq %rax, %r14
movq 0x18(%rbx), %rdi
movl $0x0, (%rsp)
leaq 0x10(%rsp), %r8
movl $0x3, %esi
movl $0x4, %edx
movl $0x10, %ecx
movq %rax, %r9
callq 0xf2f79
movq %r14, %rdi
callq 0xf34d7
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf22dc
movq %r14, %rdi
callq 0xf228d
addq $0x50, %rsp
popq %rbx
popq %r14
popq %rbp
retq