// File: /workspace/github_c_makefile_star2_O3/odknt[P]st/st.c
// Function: tsetmode
void
tsetmode(int priv, int set, const int *args, int narg)
{
	int alt; const int *lim;

	for (lim = args + narg; args < lim; ++args) {
		if (priv) {
			switch (*args) {
			case 1: /* DECCKM -- Cursor key */
				xsetmode(set, MODE_APPCURSOR);
				break;
			case 5: /* DECSCNM -- Reverse video */
				xsetmode(set, MODE_REVERSE);
				break;
			case 6: /* DECOM -- Origin */
				MODBIT(term.c.state, set, CURSOR_ORIGIN);
				tmoveato(0, 0);
				break;
			case 7: /* DECAWM -- Auto wrap */
				MODBIT(term.mode, set, MODE_WRAP);
				break;
			case 0:  /* Error (IGNORED) */
			case 2:  /* DECANM -- ANSI/VT52 (IGNORED) */
			case 3:  /* DECCOLM -- Column  (IGNORED) */
			case 4:  /* DECSCLM -- Scroll (IGNORED) */
			case 8:  /* DECARM -- Auto repeat (IGNORED) */
			case 18: /* DECPFF -- Printer feed (IGNORED) */
			case 19: /* DECPEX -- Printer extent (IGNORED) */
			case 42: /* DECNRCM -- National characters (IGNORED) */
			case 12: /* att610 -- Start blinking cursor (IGNORED) */
				break;
			case 25: /* DECTCEM -- Text Cursor Enable Mode */
				xsetmode(!set, MODE_HIDE);
				break;
			case 9:    /* X10 mouse compatibility mode */
				xsetpointermotion(0);
				xsetmode(0, MODE_MOUSE);
				xsetmode(set, MODE_MOUSEX10);
				break;
			case 1000: /* 1000: report button press */
				xsetpointermotion(0);
				xsetmode(0, MODE_MOUSE);
				xsetmode(set, MODE_MOUSEBTN);
				break;
			case 1002: /* 1002: report motion on button press */
				xsetpointermotion(0);
				xsetmode(0, MODE_MOUSE);
				xsetmode(set, MODE_MOUSEMOTION);
				break;
			case 1003: /* 1003: enable all mouse motions */
				xsetpointermotion(set);
				xsetmode(0, MODE_MOUSE);
				xsetmode(set, MODE_MOUSEMANY);
				break;
			case 1004: /* 1004: send focus events to tty */
				xsetmode(set, MODE_FOCUS);
				break;
			case 1006: /* 1006: extended reporting mode */
				xsetmode(set, MODE_MOUSESGR);
				break;
			case 1034:
				xsetmode(set, MODE_8BIT);
				break;
			case 1049: /* swap screen & set/restore cursor as xterm */
				if (!allowaltscreen)
					break;
				tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
				/* FALLTHROUGH */
			case 47: /* swap screen */
			case 1047:
				if (!allowaltscreen)
					break;
				alt = IS_SET(MODE_ALTSCREEN);
				if (alt) {
					tclearregion(0, 0, term.col-1,
							term.row-1);
				}
				if (set ^ alt) /* set is always 1 or 0 */
					tswapscreen();
				if (*args != 1049)
					break;
				/* FALLTHROUGH */
			case 1048:
				tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
				break;
			case 2004: /* 2004: bracketed paste mode */
				xsetmode(set, MODE_BRCKTPASTE);
				break;
			/* Not implemented mouse modes. See comments there. */
			case 1001: /* mouse highlight mode; can hang the
				      terminal by design when implemented. */
			case 1005: /* UTF-8 mouse mode; will confuse
				      applications not supporting UTF-8
				      and luit. */
			case 1015: /* urxvt mangled mouse mode; incompatible
				      and can be mistaken for other control
				      codes. */
				break;
			default:
				fprintf(stderr,
					"erresc: unknown private set/reset mode %d\n",
					*args);
				break;
			}
		} else {
			switch (*args) {
			case 0:  /* Error (IGNORED) */
				break;
			case 2:
				xsetmode(set, MODE_KBDLOCK);
				break;
			case 4:  /* IRM -- Insertion-replacement */
				MODBIT(term.mode, set, MODE_INSERT);
				break;
			case 12: /* SRM -- Send/Receive */
				MODBIT(term.mode, !set, MODE_ECHO);
				break;
			case 20: /* LNM -- Linefeed/new line */
				MODBIT(term.mode, set, MODE_CRLF);
				break;
			default:
				fprintf(stderr,
					"erresc: unknown set/reset mode %d\n",
					*args);
				break;
			}
		}
	}
}

// Assembly:
testl %edx, %edx
jle 0xbed7
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movl %edi, %ebp
movslq %edx, %rax
leaq 0x13878(%rip), %rcx     # 0x1f400
leaq (%rcx,%rax,4), %r13
addq $0x20c, %r13            # imm = 0x20C
xorl %r14d, %r14d
testl %esi, %esi
setne %al
sete %r14b
addb %al, %al
movb %al, 0x7(%rsp)
leaq 0x13a60(%rip), %r15     # 0x1f60c
leaq 0x57dd(%rip), %r12      # 0x11390
movl (%r15), %edx
testl %ebp, %ebp
je 0xbc09
cmpl $0x2e, %edx
jle 0xbc2b
cmpl $0x409, %edx            # imm = 0x409
jg 0xbc52
leal -0x3e8(%rdx), %eax
cmpl $0xf, %eax
ja 0xbcf5
leaq 0x576f(%rip), %rcx      # 0x11350
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %edi, %edi
callq 0xd82f
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xd86d
movl %ebx, %edi
movl $0x8, %esi
jmp 0xbe90
movl %edx, %eax
rorl %eax
cmpl $0xa, %eax
ja 0xbeaf
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl %ebx, %edi
movl $0x40, %esi
jmp 0xbe90
cmpl $0x19, %edx
ja 0xbde4
movl %edx, %eax
leaq 0x56ab(%rip), %rcx      # 0x112e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl %ebx, %edi
movl $0x100, %esi            # imm = 0x100
jmp 0xbe90
cmpl $0x417, %edx            # imm = 0x417
jle 0xbcc0
cmpl $0x418, %edx            # imm = 0x418
je 0xbdcb
cmpl $0x419, %edx            # imm = 0x419
je 0xbd55
cmpl $0x7d4, %edx            # imm = 0x7D4
jne 0xbded
movl %ebx, %edi
movl $0x10000, %esi          # imm = 0x10000
jmp 0xbe90
movl 0x11684(%rip), %eax     # 0x1d314
testl %ebx, %ebx
je 0xbcdd
orl $0x8, %eax
jmp 0xbe9a
movl 0x11672(%rip), %eax     # 0x1d314
testl %ebx, %ebx
je 0xbce5
andl $-0x11, %eax
jmp 0xbe9a
movl 0x11660(%rip), %eax     # 0x1d314
testl %ebx, %ebx
je 0xbced
orl $0x2, %eax
jmp 0xbe9a
cmpl $0x40a, %edx            # imm = 0x40A
je 0xbdd8
cmpl $0x417, %edx            # imm = 0x417
je 0xbd6d
jmp 0xbded
andl $-0x9, %eax
jmp 0xbe9a
orl $0x10, %eax
jmp 0xbe9a
andl $-0x3, %eax
jmp 0xbe9a
cmpl $0x2f, %edx
je 0xbd6d
jmp 0xbded
movl %ebx, %edi
movl $0x2000, %esi           # imm = 0x2000
jmp 0xbe90
movl %ebx, %edi
movl $0x200, %esi            # imm = 0x200
jmp 0xbe90
xorl %edi, %edi
callq 0xd82f
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xd86d
movl %ebx, %edi
movl $0x10, %esi
jmp 0xbe90
movl %ebx, %edi
callq 0xd82f
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xd86d
movl %ebx, %edi
movl $0x8000, %esi           # imm = 0x8000
jmp 0xbe90
leaq 0xc83c(%rip), %rax      # 0x18598
cmpl $0x0, (%rax)
je 0xbea0
movl %r14d, %edi
callq 0x9465
leaq 0xc824(%rip), %rax      # 0x18598
cmpl $0x0, (%rax)
je 0xbea0
movl %r14d, %r12d
movl 0x1158d(%rip), %r14d    # 0x1d314
andl $0x4, %r14d
je 0xbda6
movl 0xd6b1(%rip), %edx      # 0x19444
decl %edx
movl 0xd6a5(%rip), %ecx      # 0x19440
decl %ecx
xorl %edi, %edi
xorl %esi, %esi
callq 0x91c0
shrl $0x2, %r14d
cmpl %ebx, %r14d
je 0xbdb4
callq 0x932e
cmpl $0x419, (%r15)          # imm = 0x419
movl %r12d, %r14d
leaq 0x55cb(%rip), %r12      # 0x11390
jne 0xbea0
movl %r14d, %edi
callq 0x9465
jmp 0xbea0
movl %ebx, %edi
movl $0x400, %esi            # imm = 0x400
jmp 0xbe90
cmpl $0x2a, %edx
je 0xbea0
movq 0xc1fc(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x5bf9(%rip), %rsi      # 0x119f7
jmp 0xbec0
xorl %edi, %edi
callq 0xd82f
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xd86d
movl %ebx, %edi
movl $0x4000, %esi           # imm = 0x4000
jmp 0xbe90
movl 0x114ef(%rip), %eax     # 0x1d314
testl %ebx, %ebx
je 0xbe97
orl $0x1, %eax
jmp 0xbe9a
movb 0x114cc(%rip), %al      # 0x1d300
andb $-0x4, %al
addb 0x7(%rsp), %al
movl 0xd604(%rip), %ecx      # 0x19444
testl %ecx, %ecx
movl $0x1, %edx
cmovgl %edx, %ecx
movl 0xd5f0(%rip), %edx      # 0x19440
decl %ecx
decl %edx
testl %ebx, %ebx
movl 0x114b0(%rip), %esi     # 0x1d30c
cmovel %ebx, %esi
movb %al, 0x1149b(%rip)      # 0x1d300
cmovnel 0x114a4(%rip), %edx     # 0x1d310
movl %ecx, 0x11486(%rip)     # 0x1d2f8
cmpl %esi, %edx
cmovgel %esi, %edx
movl %edx, 0x1147f(%rip)     # 0x1d2fc
jmp 0xbea0
movl %r14d, %edi
movl $0x80, %esi
jmp 0xbe90
movl %ebx, %edi
movl $0x20, %esi
callq 0xd86d
jmp 0xbea0
andl $-0x2, %eax
movl %eax, 0x11474(%rip)     # 0x1d314
addq $0x4, %r15
cmpq %r13, %r15
jb 0xbbb3
jmp 0xbec9
movq 0xc13a(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x5b62(%rip), %rsi      # 0x11a22
xorl %eax, %eax
callq 0x69c0
jmp 0xbea0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq