// File: /workspace/github_c_makefile_star2_O0/uobikiemukot[P]yaft/./fb/common.h
// Function: init_indexcolor
bool init_indexcolor(int fd, struct fb_info_t *info, cmap_t **cmap, cmap_t **cmap_orig)
{
	int colors, max_length;

	if (info->visual == YAFT_FB_VISUAL_DIRECTCOLOR) {
		switch(info->bits_per_pixel) {
		case 15: /* XXX: 15 bpp is not tested */
		case 16:
		case 24: /* XXX: 24 bpp is not tested */
		case 32:
			break;
		default:
			logging(ERROR, "directcolor %d bpp not supported\n", info->bits_per_pixel);
			return false;
		}
		logging(DEBUG, "red.length:%d gree.length:%d blue.length:%d\n",
			info->red.length, info->green.length, info->blue.length);

		max_length = (info->red.length > info->green.length) ? info->red.length: info->green.length;
		max_length = (max_length > info->blue.length) ? max_length: info->blue.length;
	} else { /* YAFT_FB_VISUAL_PSEUDOCOLOR */
		switch(info->bits_per_pixel) {
		case 8:
			break;
		default:
			logging(ERROR, "pseudocolor %d bpp not supported\n", info->bits_per_pixel);
			return false;
		}

		/* in pseudo color, we use fixed palette (red/green: 3bit, blue: 2bit).
			this palette is not compatible with xterm 256 colors,
			but we can convert 24bit color into palette number easily. */
		info->red.length   = 3;
		info->green.length = 3;
		info->blue.length  = 2;

		info->red.offset   = 5;
		info->green.offset = 2;
		info->blue.offset  = 0;

		/* XXX: not 3 but 8, each color has 256 colors palette */
		max_length = 8;
	}

	colors = 1 << max_length;
	logging(DEBUG, "colors:%d max_length:%d\n", colors, max_length);

	*cmap      = cmap_create(colors);
	*cmap_orig = cmap_create(colors);

	if (!(*cmap) || !(*cmap_orig))
		goto cmap_init_err;

	if (!cmap_save(fd, *cmap_orig)) {
		logging(WARN, "couldn't save original cmap\n");
		cmap_die(*cmap_orig);
		*cmap_orig = NULL;
	}

	if (!cmap_init(fd, info, *cmap, colors, max_length))
		goto cmap_init_err;

	return true;

cmap_init_err:
	cmap_die(*cmap);
	cmap_die(*cmap_orig);
	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x38(%rax)
jne 0x3bd7
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x2c(%rbp)
addl $-0xf, %eax
subl $0x2, %eax
jb 0x3b3d
jmp 0x3b29
movl -0x2c(%rbp), %eax
subl $0x18, %eax
je 0x3b3d
jmp 0x3b33
movl -0x2c(%rbp), %eax
subl $0x20, %eax
jne 0x3b3f
jmp 0x3b3d
jmp 0x3b62
movq -0x10(%rbp), %rax
movl 0x30(%rax), %edx
movl $0x2, %edi
leaq 0x51eca(%rip), %rsi     # 0x55a1c
movb $0x0, %al
callq 0x2450
movb $0x0, -0x1(%rbp)
jmp 0x3d2e
movq -0x10(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0x10(%rax), %r8d
xorl %edi, %edi
leaq 0x51ebe(%rip), %rsi     # 0x55a3e
movb $0x0, %al
callq 0x2450
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jle 0x3ba1
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x3bab
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jle 0x3bc5
movl -0x28(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x3bcf
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x3c52
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
subl $0x8, %eax
jne 0x3be7
jmp 0x3be5
jmp 0x3c0a
movq -0x10(%rbp), %rax
movl 0x30(%rax), %edx
movl $0x2, %edi
leaq 0x51e71(%rip), %rsi     # 0x55a6b
movb $0x0, %al
callq 0x2450
movb $0x0, -0x1(%rbp)
jmp 0x3d2e
movq -0x10(%rbp), %rax
movl $0x3, (%rax)
movq -0x10(%rbp), %rax
movl $0x3, 0x8(%rax)
movq -0x10(%rbp), %rax
movl $0x2, 0x10(%rax)
movq -0x10(%rbp), %rax
movl $0x5, 0x4(%rax)
movq -0x10(%rbp), %rax
movl $0x2, 0xc(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x14(%rax)
movl $0x8, -0x28(%rbp)
movl -0x28(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
xorl %edi, %edi
leaq 0x51e1f(%rip), %rsi     # 0x55a8d
movb $0x0, %al
callq 0x2450
movl -0x24(%rbp), %edi
callq 0x36b0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x24(%rbp), %edi
callq 0x36b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3cad
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x3caf
jmp 0x3d12
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
callq 0x37c0
testb $0x1, %al
jne 0x3cec
movl $0x1, %edi
leaq 0x51dd8(%rip), %rsi     # 0x55aa6
movb $0x0, %al
callq 0x2450
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x3660
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movl -0x24(%rbp), %ecx
movl -0x28(%rbp), %r8d
callq 0x3810
testb $0x1, %al
jne 0x3d0c
jmp 0x3d12
movb $0x1, -0x1(%rbp)
jmp 0x3d2e
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3660
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x3660
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)