// File: /workspace/github_c_makefile_star2_O0/uobikiemukot[P]yaft/./ctrlseq/osc.h
// Function: set_palette
void set_palette(struct terminal_t *term, void *arg)
{
	/*
	OSC Ps ; Pt ST
	ref: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
	ref: http://ttssh2.sourceforge.jp/manual/ja/about/ctrlseq.html#OSC

	only recognize change color palette:
		Ps: 4
		Pt: c ; spec
			c: color index (from 0 to 255)
			spec:
				rgb:r/g/b
				rgb:rr/gg/bb
				rgb:rrr/ggg/bbb
				rgb:rrrr/gggg/bbbb
				#rgb
				#rrggbb
				#rrrgggbbb
				#rrrrggggbbbb
					this rgb format is "RGB Device String Specification"
					see http://xjman.dsl.gr.jp/X11R6/X11/CH06.html
		Pt: c ; ?
			response rgb color
				OSC 4 ; c ; rgb:rr/gg/bb ST

	TODO: this function only works in 32bpp mode
	*/
	struct parm_t *pt = (struct parm_t *) arg;
	int i, argc = pt->argc, index;
	int32_t color;
	uint8_t rgb[3];
	char **argv = pt->argv;
	char buf[BUFSIZE];

	if (argc != 3)
		return;

	index = dec2num(argv[1]);
	if (index < 0 || index >= COLORS)
		return;

	if (strncmp(argv[2], "rgb:", 4) == 0) {
		if ((color = parse_color1(argv[2] + 4)) != -1) { /* skip "rgb:" */
			term->virtual_palette[index] = (uint32_t) color;
			term->palette_modified = true;
		}
	} else if (strncmp(argv[2], "#", 1) == 0) {
		if ((color = parse_color2(argv[2] + 1)) != -1) { /* skip "#" */
			term->virtual_palette[index] = (uint32_t) color;
			term->palette_modified = true;
		}
	} else if (strncmp(argv[2], "?", 1) == 0) {
		for (i = 0; i < 3; i++)
			rgb[i] = bit_mask[8] & (term->virtual_palette[index] >> (8 * (2 - i)));

		snprintf(buf, BUFSIZE, "\033]4;%d;rgb:%.2X/%.2X/%.2X\033\\",
			index, rgb[0], rgb[1], rgb[2]);
		ewrite(term->fd, buf, strlen(buf));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x460, %rsp            # imm = 0x460
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
cmpl $0x3, -0x20(%rbp)
je 0x73db
jmp 0x7588
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x31b0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x73fa
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jl 0x73ff
jmp 0x7588
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x4e9d3(%rip), %rsi     # 0x55de1
movl $0x4, %edx
callq 0x2080
cmpl $0x0, %eax
jne 0x7458
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
addq $0x4, %rdi
callq 0x6f90
movl %eax, -0x28(%rbp)
cmpl $-0x1, %eax
je 0x7453
movl -0x28(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl %edx, 0x80(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movb $0x1, 0x480(%rax)
jmp 0x7588
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x4e97f(%rip), %rsi     # 0x55de6
movl $0x1, %edx
callq 0x2080
cmpl $0x0, %eax
jne 0x74b1
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
addq $0x1, %rdi
callq 0x7150
movl %eax, -0x28(%rbp)
cmpl $-0x1, %eax
je 0x74ac
movl -0x28(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl %edx, 0x80(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movb $0x1, 0x480(%rax)
jmp 0x7586
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x4e928(%rip), %rsi     # 0x55de8
movl $0x1, %edx
callq 0x2080
cmpl $0x0, %eax
jne 0x7584
movl $0x0, -0x1c(%rbp)
cmpl $0x3, -0x1c(%rbp)
jge 0x751b
movl 0x3f5a(%rip), %eax      # 0xb440
movq -0x8(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movl 0x80(%rcx,%rdx,4), %edx
movl $0x2, %ecx
subl -0x1c(%rbp), %ecx
shll $0x3, %ecx
shrl %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movb %al, %cl
movslq -0x1c(%rbp), %rax
movb %cl, -0x2b(%rbp,%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x74da
leaq -0x440(%rbp), %rdi
movl -0x24(%rbp), %ecx
movzbl -0x2b(%rbp), %r8d
movzbl -0x2a(%rbp), %r9d
movzbl -0x29(%rbp), %eax
movl $0x400, %esi            # imm = 0x400
leaq 0x4e8ab(%rip), %rdx     # 0x55dea
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2110
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44c(%rbp)
leaq -0x440(%rbp), %rax
movq %rax, -0x448(%rbp)
leaq -0x440(%rbp), %rdi
callq 0x20d0
movl -0x44c(%rbp), %edi
movq -0x448(%rbp), %rsi
movq %rax, %rdx
callq 0x2930
jmp 0x7586
jmp 0x7588
addq $0x460, %rsp            # imm = 0x460
popq %rbp
retq
nopw %cs:(%rax,%rax)