// File: /workspace/github_c_makefile_star2_O0/uobikiemukot[P]yaft/./ctrlseq/csi.h
// Function: set_attr
void set_attr(struct terminal_t *term, struct parm_t *parm)
{
	/* SGR: Set Graphic Rendition
	 * 	ESC [ Pm m
	 * 	Pm:
	 *		0: reset all attribute
	 *
	 *		1: brighten foreground color (only work for color index 0-7)
	 *		4: underline
	 *		5: brighten background color (only work for color index 0-7)
	 *		7: reverse (swap foreground/background color)
	 *
	 *		21: reset brighten foreground color
	 *		24: reset underline
	 *		25: reset brighten background color
	 *		27: reset reverse
	 *
	 *		30-37: select foreground color (color index 0-7)
	 *		38: special foreground color selection: implemented in select_color_value()
	 *
	 *		40-47: select background color (color index 0-7)
	 *		48: special foreground color selection: implemented in select_color_value()
	 */
	int i, num;

	if (parm->argc <= 0) {
		term->attribute     = ATTR_RESET;
		term->color_pair.fg = DEFAULT_FG;
		term->color_pair.bg = DEFAULT_BG;
		return;
	}

	for (i = 0; i < parm->argc; i++) {
		num = dec2num(parm->argv[i]);
		//logging(DEBUG, "argc:%d num:%d\n", parm->argc, num);

		if (num == 0) {                        /* reset all attribute and color */
			term->attribute = ATTR_RESET;
			term->color_pair.fg = DEFAULT_FG;
			term->color_pair.bg = DEFAULT_BG;
		} else if (1 <= num && num <= 7) {     /* set attribute */
			term->attribute |= attr_mask[num];
		} else if (21 <= num && num <= 27) {   /* reset attribute */
			term->attribute &= ~attr_mask[num - 20];
		} else if (30 <= num && num <= 37) {   /* set foreground */
			term->color_pair.fg = (num - 30);
		} else if (num == 38) {                /* special foreground color selection */
			/* select foreground color from 256 color index */
			if ((i + 2) < parm->argc && dec2num(parm->argv[i + 1]) == 5) {
				term->color_pair.fg = dec2num(parm->argv[i + 2]);
				i += 2;
			/* select foreground color from specified rgb color */
			} else if ((i + 4) < parm->argc && dec2num(parm->argv[i + 1]) == 2) {
				term->color_pair.fg = rgb2index(dec2num(parm->argv[i + 2]),
					dec2num(parm->argv[i + 3]), dec2num(parm->argv[i + 4]));
				i += 4;
			}
		} else if (num == 39) {                /* reset foreground */
			term->color_pair.fg = DEFAULT_FG;
		} else if (40 <= num && num <= 47) {   /* set background */
			term->color_pair.bg = (num - 40);
		} else if (num == 48) {                /* special background  color selection */
			/* select background color from 256 color index */
			if ((i + 2) < parm->argc && dec2num(parm->argv[i + 1]) == 5) {
				term->color_pair.bg = dec2num(parm->argv[i + 2]);
				i += 2;
			/* select background color from specified rgb color */
			} else if ((i + 4) < parm->argc && dec2num(parm->argv[i + 1]) == 2) {
				term->color_pair.bg = rgb2index(dec2num(parm->argv[i + 2]),
					dec2num(parm->argv[i + 3]), dec2num(parm->argv[i + 4]));
				i += 4;
			}
		} else if (num == 49) {                /* reset background */
			term->color_pair.bg = DEFAULT_BG;
		} else if (90 <= num && num <= 97) {   /* set bright foreground */
			term->color_pair.fg = (num - 90) + BRIGHT_INC;
		} else if (100 <= num && num <= 107) { /* set bright background */
			term->color_pair.bg = (num - 100) + BRIGHT_INC;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jg 0x6719
movq -0x8(%rbp), %rax
movl $0x0, 0x50(%rax)
movq -0x8(%rbp), %rax
movb $0x7, 0x4c(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x4d(%rax)
jmp 0x6ab0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x6ab0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x676a
movq -0x8(%rbp), %rax
movl $0x0, 0x50(%rax)
movq -0x8(%rbp), %rax
movb $0x7, 0x4c(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x4d(%rax)
jmp 0x6aa0
movl $0x1, %eax
cmpl -0x18(%rbp), %eax
jg 0x6798
cmpl $0x7, -0x18(%rbp)
jg 0x6798
movslq -0x18(%rbp), %rcx
leaq 0x4c8b(%rip), %rax      # 0xb410
movzbl (%rax,%rcx), %ecx
movq -0x8(%rbp), %rax
orl 0x50(%rax), %ecx
movl %ecx, 0x50(%rax)
jmp 0x6a9e
movl $0x15, %eax
cmpl -0x18(%rbp), %eax
jg 0x67ce
cmpl $0x1b, -0x18(%rbp)
jg 0x67ce
movl -0x18(%rbp), %eax
subl $0x14, %eax
movslq %eax, %rcx
leaq 0x4c58(%rip), %rax      # 0xb410
movzbl (%rax,%rcx), %ecx
xorl $-0x1, %ecx
movq -0x8(%rbp), %rax
andl 0x50(%rax), %ecx
movl %ecx, 0x50(%rax)
jmp 0x6a9c
movl $0x1e, %eax
cmpl -0x18(%rbp), %eax
jg 0x67f2
cmpl $0x25, -0x18(%rbp)
jg 0x67f2
movl -0x18(%rbp), %eax
subl $0x1e, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x4c(%rax)
jmp 0x6a9a
cmpl $0x26, -0x18(%rbp)
jne 0x68fa
movl -0x14(%rbp), %eax
addl $0x2, %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x6854
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
cmpl $0x5, %eax
jne 0x6854
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x4c(%rax)
movl -0x14(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x14(%rbp)
jmp 0x68f5
movl -0x14(%rbp), %eax
addl $0x4, %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x68f3
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
cmpl $0x2, %eax
jne 0x68f3
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
movb %al, -0x1a(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
movb -0x1a(%rbp), %dl
movb -0x19(%rbp), %cl
movzbl %dl, %edi
movzbl %cl, %esi
movzbl %al, %edx
callq 0x6540
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x4c(%rax)
movl -0x14(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x14(%rbp)
jmp 0x68f5
jmp 0x6a98
cmpl $0x27, -0x18(%rbp)
jne 0x690d
movq -0x8(%rbp), %rax
movb $0x7, 0x4c(%rax)
jmp 0x6a96
movl $0x28, %eax
cmpl -0x18(%rbp), %eax
jg 0x6931
cmpl $0x2f, -0x18(%rbp)
jg 0x6931
movl -0x18(%rbp), %eax
subl $0x28, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x4d(%rax)
jmp 0x6a94
cmpl $0x30, -0x18(%rbp)
jne 0x6a36
movl -0x14(%rbp), %eax
addl $0x2, %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x6993
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
cmpl $0x5, %eax
jne 0x6993
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x4d(%rax)
movl -0x14(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x14(%rbp)
jmp 0x6a34
movl -0x14(%rbp), %eax
addl $0x4, %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x6a32
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
cmpl $0x2, %eax
jne 0x6a32
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
movb %al, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
movb %al, -0x1b(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x31b0
movb -0x1c(%rbp), %dl
movb -0x1b(%rbp), %cl
movzbl %dl, %edi
movzbl %cl, %esi
movzbl %al, %edx
callq 0x6540
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x4d(%rax)
movl -0x14(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x14(%rbp)
jmp 0x6a34
jmp 0x6a92
cmpl $0x31, -0x18(%rbp)
jne 0x6a46
movq -0x8(%rbp), %rax
movb $0x0, 0x4d(%rax)
jmp 0x6a90
movl $0x5a, %eax
cmpl -0x18(%rbp), %eax
jg 0x6a6a
cmpl $0x61, -0x18(%rbp)
jg 0x6a6a
movl -0x18(%rbp), %eax
subl $0x5a, %eax
addl $0x8, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x4c(%rax)
jmp 0x6a8e
movl $0x64, %eax
cmpl -0x18(%rbp), %eax
jg 0x6a8c
cmpl $0x6b, -0x18(%rbp)
jg 0x6a8c
movl -0x18(%rbp), %eax
subl $0x64, %eax
addl $0x8, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x4d(%rax)
jmp 0x6a8e
jmp 0x6a90
jmp 0x6a92
jmp 0x6a94
jmp 0x6a96
jmp 0x6a98
jmp 0x6a9a
jmp 0x6a9c
jmp 0x6a9e
jmp 0x6aa0
jmp 0x6aa2
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x6720
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)