// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3a35
movq -0x10(%rbp), %rax
cmpl $0x1, 0x38(%rax)
jne 0x3943
movl -0x30(%rbp), %eax
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rdx
subl (%rdx), %ecx
sarl %cl, %eax
movq -0x10(%rbp), %rcx
movslq (%rcx), %rdx
leaq 0x7bb9(%rip), %rcx      # 0xb420
andl (%rcx,%rdx,4), %eax
movw %ax, -0x28(%rbp)
movl -0x30(%rbp), %eax
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rdx
subl 0x8(%rdx), %ecx
sarl %cl, %eax
movq -0x10(%rbp), %rcx
movslq 0x8(%rcx), %rdx
leaq 0x7b94(%rip), %rcx      # 0xb420
andl (%rcx,%rdx,4), %eax
movw %ax, -0x2a(%rbp)
movl -0x30(%rbp), %eax
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rdx
subl 0x10(%rdx), %ecx
sarl %cl, %eax
movq -0x10(%rbp), %rcx
movslq 0x10(%rcx), %rdx
leaq 0x7b6f(%rip), %rcx      # 0xb420
andl (%rcx,%rdx,4), %eax
movw %ax, -0x2c(%rbp)
movzwl -0x28(%rbp), %eax
movq -0x10(%rbp), %rdx
movl $0x10, %ecx
subl (%rdx), %ecx
shll %cl, %eax
movw %ax, -0x22(%rbp)
movzwl -0x2a(%rbp), %eax
movq -0x10(%rbp), %rdx
movl $0x10, %ecx
subl 0x8(%rdx), %ecx
shll %cl, %eax
movw %ax, -0x24(%rbp)
movzwl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rdx
movl $0x10, %ecx
subl 0x10(%rdx), %ecx
shll %cl, %eax
movw %ax, -0x26(%rbp)
movw -0x22(%rbp), %dx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movzwl -0x28(%rbp), %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movw -0x24(%rbp), %dx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzwl -0x2a(%rbp), %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movw -0x26(%rbp), %dx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movzwl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
jmp 0x3a25
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
sarl %cl, %eax
movq -0x10(%rbp), %rcx
movslq (%rcx), %rdx
leaq 0x7ac3(%rip), %rcx      # 0xb420
andl (%rcx,%rdx,4), %eax
movw %ax, -0x28(%rbp)
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
sarl %cl, %eax
movq -0x10(%rbp), %rcx
movslq 0x8(%rcx), %rdx
leaq 0x7aa1(%rip), %rcx      # 0xb420
andl (%rcx,%rdx,4), %eax
movw %ax, -0x2a(%rbp)
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
sarl %cl, %eax
movq -0x10(%rbp), %rcx
movslq 0x10(%rcx), %rdx
leaq 0x7a7f(%rip), %rcx      # 0xb420
andl (%rcx,%rdx,4), %eax
movw %ax, -0x2c(%rbp)
movzwl -0x28(%rbp), %eax
movq -0x10(%rbp), %rdx
movl $0x10, %ecx
subl (%rdx), %ecx
shll %cl, %eax
movw %ax, -0x22(%rbp)
movzwl -0x2a(%rbp), %eax
movq -0x10(%rbp), %rdx
movl $0x10, %ecx
subl 0x8(%rdx), %ecx
shll %cl, %eax
movw %ax, -0x24(%rbp)
movzwl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rdx
movl $0x10, %ecx
subl 0x10(%rdx), %ecx
shll %cl, %eax
movw %ax, -0x26(%rbp)
movw -0x22(%rbp), %dx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movw -0x24(%rbp), %dx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movw -0x26(%rbp), %dx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x30(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
jmp 0x3a27
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3831
movl -0x8(%rbp), %edi
movq -0x18(%rbp), %rsi
callq 0x3760
testb $0x1, %al
jne 0x3a4b
movb $0x0, -0x1(%rbp)
jmp 0x3a4f
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)