// File: /workspace/github_c_makefile_star2_O1/w4kfu[P]HommI/Icn/icn.c
// Function: icnmakeimg
unsigned char *icnmakeimg(struct icn *icn, int numentry, unsigned short width, unsigned short height,
			unsigned char *pal, unsigned int type)
{
	unsigned char *imgbuf = NULL;
	unsigned char *simgbuf = NULL;
	unsigned char *databuf = NULL;
	unsigned char actual = 0;
	unsigned short actual_width = 0;
	struct color color1;
	struct color color2;
	unsigned int x;

	color1.r = 0xFF; color1.g = 0xFF; color1.b = 0xFF;
	color2.r = 0; color2.g = 0; color2.b = 0;
	if (!icn)
		return NULL;
	if (!(imgbuf = malloc(sizeof (char) * width * height * 3)))
	{
		perror("malloc()");
		return NULL;
	}
	memset(imgbuf, 0x3F, sizeof (char) * width * height * 3);
	simgbuf = imgbuf;
	databuf = icn->entry[numentry].offset + icn->data + 6;
	while (*databuf != 0x80)
	{
		actual = *databuf++;
		if (actual == 0)
		{
			// new line
			for (x = actual_width; x < width; x++)
			{
				memcpy(imgbuf, &color1, sizeof (struct color));
				imgbuf += 3;
			}
			actual_width = 0;
		}
		else if (actual & 0x80)
		{
			actual &= 0x7F;
			for (x = 0; x < actual; x++)
			{
				memcpy(imgbuf, &color1, sizeof (struct color));
				imgbuf += 3;
			}
			actual_width += actual;
		}
		else
		{
			for (x = 0; x < actual; x++)
			{
				if (type == 1)
					memcpy(imgbuf, &pal[*databuf++], 3);
				else
					memcpy(imgbuf, &color2, sizeof (struct color));
				imgbuf += 3;
			}
			actual_width += actual;
		}
		if (actual_width > width)
			actual_width = 0;
	}
	if ((imgbuf - simgbuf) < (width * height * 3))
	{
		x = (width * height * 3) - (imgbuf - simgbuf);
		x /= 3;
		for (; x > 0; x--)
		{
			memcpy(imgbuf, &color1, sizeof (struct color));
			imgbuf += 3;
		}
	}
	return simgbuf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
testq %rdi, %rdi
je 0x1c09
movl %r9d, %ebp
movq %r8, %r15
movl %esi, %r14d
movq %rdi, %r13
movl %edx, 0xc(%rsp)
movzwl %dx, %edx
movzwl %cx, %eax
movq %rdx, 0x20(%rsp)
imulq %rdx, %rax
leaq (%rax,%rax,2), %r12
movq %r12, %rdi
callq 0x1130
testq %rax, %rax
je 0x1bfd
movq %rax, %rbx
movq %rax, %rdi
movl $0x3f, %esi
movq %r12, 0x18(%rsp)
movq %r12, %rdx
callq 0x10b0
movslq %r14d, %rax
leaq (%rax,%rax,2), %rcx
movq 0x8(%r13), %rdx
movq 0x10(%r13), %rax
movl 0x8(%rdx,%rcx,4), %edx
movb 0x6(%rax,%rdx), %cl
movq %rbx, 0x10(%rsp)
movq %rbx, %r13
cmpb $-0x80, %cl
movl 0xc(%rsp), %r12d
je 0x1bb7
leaq (%rax,%rdx), %r14
addq $0x6, %r14
xorl %edi, %edi
movq 0x10(%rsp), %r13
xorl %ebx, %ebx
incq %r14
testb %cl, %cl
je 0x1b38
movzbl %cl, %eax
js 0x1b6d
movl %eax, %ecx
cmpl $0x1, %ebp
jne 0x1b20
movzbl (%r14), %edx
incq %r14
movb 0x2(%r15,%rdx), %sil
movb %sil, 0x2(%r13)
movzwl (%r15,%rdx), %edx
movw %dx, (%r13)
jmp 0x1b2c
movw $0x0, (%r13)
movb $0x0, 0x2(%r13)
addq $0x3, %r13
decl %ecx
jne 0x1aff
addl %eax, %ebx
jmp 0x1ba4
cmpw %r12w, %bx
jae 0x1b69
movzwl %bx, %eax
notl %eax
addl 0x20(%rsp), %eax
leaq (%rax,%rax,2), %rbx
leaq (%rax,%rax,2), %rdx
addq $0x3, %rdx
movq %r13, %rdi
movl $0xff, %esi
callq 0x10b0
xorl %edi, %edi
addq %rbx, %r13
addq $0x3, %r13
xorl %ebx, %ebx
jmp 0x1ba4
andb $0x7f, %cl
movzbl %cl, %r12d
je 0x1b9c
andl $0x7f, %eax
leaq (%rax,%rax,2), %rdx
movq %r13, %rdi
movl $0xff, %esi
callq 0x10b0
xorl %edi, %edi
leal -0x1(%r12), %eax
leaq (%rax,%rax,2), %rax
addq %rax, %r13
addq $0x3, %r13
addl %r12d, %ebx
movl 0xc(%rsp), %r12d
cmpw %r12w, %bx
cmoval %edi, %ebx
movb (%r14), %cl
cmpb $-0x80, %cl
jne 0x1af1
movq %r13, %rax
movq 0x10(%rsp), %rbx
subq %rbx, %rax
movq 0x18(%rsp), %rdx
movl %edx, %ecx
cmpq %rcx, %rax
jge 0x1c0b
subl %eax, %edx
cmpl $0x3, %edx
jb 0x1c0b
movl %edx, %eax
movl $0xaaaaaaab, %ecx       # imm = 0xAAAAAAAB
imulq %rax, %rcx
shrq $0x21, %rcx
decl %ecx
leaq (%rcx,%rcx,2), %rdx
addq $0x3, %rdx
movq %r13, %rdi
movl $0xff, %esi
callq 0x10b0
jmp 0x1c0b
leaq 0x4d5(%rip), %rdi       # 0x20d9
callq 0x1170
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)