// File: /workspace/github_c_makefile_star2_O0/uobikiemukot[P]yaft/./ctrlseq/dcs.h
// Function: sixel_color
static inline int sixel_color(struct sixel_canvas_t *sc, char *buf)
{
	char *cp, tmp[BUFSIZE];
	int index, type;
	size_t length;
	uint16_t v1, v2, v3, r, g, b;
	uint32_t color;
	struct parm_t parm;

	cp = buf + 1;
	while (isdigit(*cp) || *cp == ';') /* skip valid params */
		cp++;

	length = (cp - buf);
	strncpy(tmp, buf + 1, length - 1); /* skip '#' */
	*(tmp + length - 1) = '\0';

	reset_parm(&parm);
	parse_arg(tmp, &parm, ';', isdigit);

	if (parm.argc < 1)
		return length;

	index = dec2num(parm.argv[0]);
	if (index < 0)
		index = 0;
	else if (index >= COLORS)
		index = COLORS - 1;

	logging(DEBUG, "sixel_color()\nbuf:%s length:%u\nindex:%d\n",
		tmp, (unsigned) length, index);

	if (parm.argc == 1) { /* select color */
		sc->color_index = index;
		return length;
	}

	if (parm.argc != 5)
		return length;

	type  = dec2num(parm.argv[1]);
	v1    = dec2num(parm.argv[2]);
	v2    = dec2num(parm.argv[3]);
	v3    = dec2num(parm.argv[4]);

	if (type == 1) { /* HLS */
		color = hls2rgb(v1, v2, v3);
	} else {
		r = bit_mask[8] & (0xFF * v1 / 100);
		g = bit_mask[8] & (0xFF * v2 / 100);
		b = bit_mask[8] & (0xFF * v3 / 100);
		color = (r << 16) | (g << 8) | b;
	}

	logging(DEBUG, "type:%d v1:%u v2:%u v3:%u color:0x%.8X\n",
		type, v1, v2, v3, color);

	sc->color_table[index] = color;

	return length;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4e0, %rsp            # imm = 0x4E0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
callq 0x2330
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x800, %ecx            # imm = 0x800
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x4c9(%rbp)
jne 0x7f6b
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3b, %eax
sete %al
movb %al, -0x4c9(%rbp)
movb -0x4c9(%rbp), %al
testb $0x1, %al
jne 0x7f77
jmp 0x7f85
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x7f2f
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x430(%rbp)
leaq -0x420(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x1, %rsi
movq -0x430(%rbp), %rdx
subq $0x1, %rdx
callq 0x2070
movq -0x430(%rbp), %rax
movb $0x0, -0x421(%rbp,%rax)
leaq -0x4c8(%rbp), %rdi
callq 0x2fa0
leaq -0x420(%rbp), %rdi
leaq -0x4c8(%rbp), %rsi
movl $0x3b, %edx
movq 0x50fcd(%rip), %rcx     # 0x58fb8
callq 0x3060
cmpl $0x1, -0x4c8(%rbp)
jge 0x8008
movq -0x430(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x8236
movq -0x4c0(%rbp), %rdi
callq 0x31b0
movl %eax, -0x424(%rbp)
cmpl $0x0, -0x424(%rbp)
jge 0x802f
movl $0x0, -0x424(%rbp)
jmp 0x8047
cmpl $0x100, -0x424(%rbp)    # imm = 0x100
jl 0x8045
movl $0xff, -0x424(%rbp)
jmp 0x8047
leaq -0x420(%rbp), %rdx
movq -0x430(%rbp), %rax
movl %eax, %ecx
movl -0x424(%rbp), %r8d
xorl %edi, %edi
leaq 0x4e08f(%rip), %rsi     # 0x560f6
movb $0x0, %al
callq 0x2450
cmpl $0x1, -0x4c8(%rbp)
jne 0x8095
movl -0x424(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x18(%rax)
movq -0x430(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x8236
cmpl $0x5, -0x4c8(%rbp)
je 0x80ad
movq -0x430(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x8236
movq -0x4b8(%rbp), %rdi
callq 0x31b0
movl %eax, -0x428(%rbp)
movq -0x4b0(%rbp), %rdi
callq 0x31b0
movw %ax, -0x432(%rbp)
movq -0x4a8(%rbp), %rdi
callq 0x31b0
movw %ax, -0x434(%rbp)
movq -0x4a0(%rbp), %rdi
callq 0x31b0
movw %ax, -0x436(%rbp)
cmpl $0x1, -0x428(%rbp)
jne 0x8126
movzwl -0x432(%rbp), %edi
movzwl -0x434(%rbp), %esi
movzwl -0x436(%rbp), %edx
callq 0x9f60
movl %eax, -0x440(%rbp)
jmp 0x81e1
movl 0x3314(%rip), %eax      # 0xb440
movl %eax, -0x4d8(%rbp)
movzwl -0x432(%rbp), %eax
imull $0xff, %eax, %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x4d8(%rbp), %eax
andl %ecx, %eax
movw %ax, -0x438(%rbp)
movl 0x32e2(%rip), %eax      # 0xb440
movl %eax, -0x4d4(%rbp)
movzwl -0x434(%rbp), %eax
imull $0xff, %eax, %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x4d4(%rbp), %eax
andl %ecx, %eax
movw %ax, -0x43a(%rbp)
movl 0x32b0(%rip), %eax      # 0xb440
movl %eax, -0x4d0(%rbp)
movzwl -0x436(%rbp), %eax
imull $0xff, %eax, %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x4d0(%rbp), %eax
andl %ecx, %eax
movw %ax, -0x43c(%rbp)
movzwl -0x438(%rbp), %eax
shll $0x10, %eax
movzwl -0x43a(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzwl -0x43c(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x440(%rbp)
movl -0x428(%rbp), %edx
movzwl -0x432(%rbp), %ecx
movzwl -0x434(%rbp), %r8d
movzwl -0x436(%rbp), %r9d
movl -0x440(%rbp), %eax
xorl %edi, %edi
leaq 0x4df12(%rip), %rsi     # 0x5611f
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2450
movl -0x440(%rbp), %edx
movq -0x10(%rbp), %rax
movslq -0x424(%rbp), %rcx
movl %edx, 0x1c(%rax,%rcx,4)
movq -0x430(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x4e0, %rsp            # imm = 0x4E0
popq %rbp
retq
nopw %cs:(%rax,%rax)