// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movl %edi, %ebp
xorl %r14d, %r14d
testl %esi, %esi
setne %sil
movslq %edx, %rax
leaq 0x13562(%rip), %rcx     # 0x1e410
leaq 0x20c(%rcx,%rax,4), %r13
leaq 0x1375f(%rip), %r12     # 0x1e61c
sete %r14b
addb %sil, %sil
movb %sil, 0x7(%rsp)
leaq 0x5558(%rip), %r15      # 0x10428
cmpq %r13, %r12
jae 0xb174
movl (%r12), %edx
testl %ebp, %ebp
je 0xaf1d
cmpl $0x19, %edx
jbe 0xaf3c
leal -0x3e8(%rdx), %eax
cmpl $0xf, %eax
ja 0xaf5a
leaq 0x54f0(%rip), %rcx      # 0x103e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %edi, %edi
callq 0xc76f
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xc7ad
movl %ebx, %edi
pushq $0x8
jmp 0xb07b
movl %edx, %eax
rorl %eax
cmpl $0xa, %eax
ja 0xb147
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl %ebx, %edi
pushq $0x40
jmp 0xb07b
movl %edx, %eax
leaq 0x543b(%rip), %rcx      # 0x10380
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl %ebx, %edi
movl $0x100, %esi            # imm = 0x100
jmp 0xb07c
cmpl $0x2a, %edx
je 0xb13e
cmpl $0x2f, %edx
je 0xb0c8
cmpl $0x40a, %edx            # imm = 0x40A
je 0xb129
cmpl $0x417, %edx            # imm = 0x417
je 0xb0c8
cmpl $0x418, %edx            # imm = 0x418
je 0xb11f
cmpl $0x419, %edx            # imm = 0x419
je 0xb0b4
cmpl $0x7d4, %edx            # imm = 0x7D4
jne 0xb15a
movl %ebx, %edi
movl $0x10000, %esi          # imm = 0x10000
jmp 0xb07c
movl 0x1136a(%rip), %eax     # 0x1c324
testl %ebx, %ebx
je 0xafea
orl $0x8, %eax
jmp 0xb138
movl 0x11358(%rip), %eax     # 0x1c324
testl %ebx, %ebx
je 0xaff2
andl $-0x11, %eax
jmp 0xb138
movl 0x11346(%rip), %eax     # 0x1c324
testl %ebx, %ebx
je 0xaffa
orl $0x2, %eax
jmp 0xb138
andl $-0x9, %eax
jmp 0xb138
orl $0x10, %eax
jmp 0xb138
andl $-0x3, %eax
jmp 0xb138
movl 0x1131c(%rip), %eax     # 0x1c324
testl %ebx, %ebx
je 0xb135
orl $0x1, %eax
jmp 0xb138
movl %r14d, %edi
movl $0x80, %esi
jmp 0xb07c
xorl %edi, %edi
callq 0xc76f
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xc7ad
movl %ebx, %edi
movl $0x4000, %esi           # imm = 0x4000
jmp 0xb07c
movl %ebx, %edi
pushq $0x20
jmp 0xb07b
movb 0x112c6(%rip), %al      # 0x1c310
andb $-0x3, %al
orb 0x7(%rsp), %al
movb %al, 0x112ba(%rip)      # 0x1c310
xorl %edi, %edi
xorl %esi, %esi
callq 0xac94
jmp 0xb13e
xorl %edi, %edi
callq 0xc76f
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xc7ad
movl %ebx, %edi
pushq $0x10
popq %rsi
callq 0xc7ad
jmp 0xb13e
movl %ebx, %edi
movl $0x200, %esi            # imm = 0x200
jmp 0xb07c
movl %ebx, %edi
callq 0xc76f
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xc7ad
movl %ebx, %edi
movl $0x8000, %esi           # imm = 0x8000
jmp 0xb07c
movl %ebx, %edi
movl $0x2000, %esi           # imm = 0x2000
jmp 0xb07c
leaq 0xc4ed(%rip), %rax      # 0x175a8
cmpl $0x0, (%rax)
je 0xb13e
movl %r14d, %edi
callq 0x89c9
leaq 0xc4d9(%rip), %rax      # 0x175a8
cmpl $0x0, (%rax)
je 0xb13e
movl %r14d, %r15d
movl 0x11246(%rip), %r14d    # 0x1c324
andl $0x4, %r14d
je 0xb0fd
movl 0xd36a(%rip), %edx      # 0x18454
decl %edx
movl 0xd35e(%rip), %ecx      # 0x18450
decl %ecx
xorl %edi, %edi
xorl %esi, %esi
callq 0x8883
shrl $0x2, %r14d
cmpl %ebx, %r14d
je 0xb10b
callq 0x89a8
cmpl $0x419, (%r12)          # imm = 0x419
movl %r15d, %r14d
leaq 0x530b(%rip), %r15      # 0x10428
jne 0xb13e
movl %r14d, %edi
callq 0x89c9
jmp 0xb13e
movl %ebx, %edi
movl $0x400, %esi            # imm = 0x400
jmp 0xb07c
andl $-0x2, %eax
movl %eax, 0x111e6(%rip)     # 0x1c324
addq $0x4, %r12
jmp 0xaed0
movq 0xbea2(%rip), %rax      # 0x16ff0
movq (%rax), %rdi
leaq 0x589a(%rip), %rsi      # 0x109f2
jmp 0xb16b
movq 0xbe8f(%rip), %rax      # 0x16ff0
movq (%rax), %rdi
leaq 0x585c(%rip), %rsi      # 0x109c7
xorl %eax, %eax
callq 0x69d0
jmp 0xb13e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq