// File: /workspace/github_c_makefile_star2_O2/uobikiemukot[P]yaft/./fb/common.h
// Function: cmap_init
bool cmap_init(int fd, struct fb_info_t *info, cmap_t *cmap, int colors, int length)
{
	uint16_t r, g, b, r_index, g_index, b_index;

	for (int i = 0; i < colors; i++) {
		if (info->visual == YAFT_FB_VISUAL_DIRECTCOLOR) {
			r_index = (i >> (length - info->red.length))   & bit_mask[info->red.length];
			g_index = (i >> (length - info->green.length)) & bit_mask[info->green.length];
			b_index = (i >> (length - info->blue.length))  & bit_mask[info->blue.length];

			/* XXX: maybe only upper order byte is used */
			r = r_index << (CMAP_COLOR_LENGTH - info->red.length);
			g = g_index << (CMAP_COLOR_LENGTH - info->green.length);
			b = b_index << (CMAP_COLOR_LENGTH - info->blue.length);

			*(cmap->red   + r_index) = r;
			*(cmap->green + g_index) = g;
			*(cmap->blue  + b_index) = b;
		} else { /* YAFT_FB_VISUAL_PSEUDOCOLOR */
			r_index = (i >> info->red.offset)   & bit_mask[info->red.length];
			g_index = (i >> info->green.offset) & bit_mask[info->green.length];
			b_index = (i >> info->blue.offset)  & bit_mask[info->blue.length];

			r = r_index << (CMAP_COLOR_LENGTH - info->red.length);
			g = g_index << (CMAP_COLOR_LENGTH - info->green.length);
			b = b_index << (CMAP_COLOR_LENGTH - info->blue.length);

			*(cmap->red   + i) = r;
			*(cmap->green + i) = g;
			*(cmap->blue  + i) = b;
		}
	}

	if (!cmap_update(fd, cmap))
		return false;

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %ecx, %eax
movl %edi, -0x4(%rsp)
xorl %r10d, %r10d
testl %ecx, %ecx
cmovlel %r10d, %eax
leaq 0x4358(%rip), %r11      # 0x74f0
movl $0xffff, %edi           # imm = 0xFFFF
cmpq %r10, %rax
je 0x3298
cmpl $0x1, 0x38(%rsi)
jne 0x322b
movslq (%rsi), %r15
movl %r8d, %ecx
subl %r15d, %ecx
movl %r10d, %r9d
shrl %cl, %r9d
andl (%r11,%r15,4), %r9d
movslq 0x8(%rsi), %r12
movl %r8d, %ecx
subl %r12d, %ecx
movl %r10d, %ebp
shrl %cl, %ebp
movslq 0x10(%rsi), %r13
movl %r8d, %ecx
subl %r13d, %ecx
movl %r10d, %r14d
shrl %cl, %r14d
andl (%r11,%r12,4), %ebp
andl (%r11,%r13,4), %r14d
movl %r9d, %ebx
movb $0x10, %cl
subb %r15b, %cl
shll %cl, %r9d
movl %ebp, %r15d
movb $0x10, %cl
subb %r12b, %cl
shll %cl, %ebp
andl %edi, %ebx
movl %r14d, %r12d
movb $0x10, %cl
subb %r13b, %cl
shll %cl, %r14d
andl %edi, %r15d
andl %edi, %r12d
movq 0x8(%rdx), %rcx
movw %r9w, (%rcx,%rbx,2)
movq 0x10(%rdx), %rcx
movw %bp, (%rcx,%r15,2)
movq 0x18(%rdx), %rcx
movw %r14w, (%rcx,%r12,2)
jmp 0x3290
movb 0x4(%rsi), %cl
movb 0xc(%rsi), %r9b
movl %r10d, %ebp
shrl %cl, %ebp
movslq (%rsi), %rbx
andl (%r11,%rbx,4), %ebp
movl %r10d, %r14d
movl %r9d, %ecx
shrl %cl, %r14d
movslq 0x8(%rsi), %r15
movb 0x14(%rsi), %cl
movl %r10d, %r9d
shrl %cl, %r9d
andl (%r11,%r15,4), %r14d
movb $0x10, %cl
subb %bl, %cl
shll %cl, %ebp
movslq 0x10(%rsi), %rbx
movb $0x10, %cl
subb %r15b, %cl
shll %cl, %r14d
andl (%r11,%rbx,4), %r9d
movb $0x10, %cl
subb %bl, %cl
shll %cl, %r9d
movq 0x8(%rdx), %rcx
movw %bp, (%rcx,%r10,2)
movq 0x10(%rdx), %rcx
movw %r14w, (%rcx,%r10,2)
movq 0x18(%rdx), %rcx
movw %r9w, (%rcx,%r10,2)
incq %r10
jmp 0x319d
movl -0x4(%rsp), %edi
movq %rdx, %rsi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x312c