// File: /workspace/github_c_makefile_star2_O1/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 0xb873
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movl %edi, %ebp
movslq %edx, %rax
leaq 0x12eee(%rip), %rcx     # 0x1e410
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 0x130d6(%rip), %r15     # 0x1e61c
leaq 0x4e13(%rip), %r12      # 0x10360
movl (%r15), %edx
testl %ebp, %ebp
je 0xb5a3
cmpl $0x2e, %edx
jle 0xb5c5
cmpl $0x409, %edx            # imm = 0x409
jg 0xb5ec
leal -0x3e8(%rdx), %eax
cmpl $0xf, %eax
ja 0xb68f
leaq 0x4da5(%rip), %rcx      # 0x10320
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %edi, %edi
callq 0xd1fb
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xd239
movl %ebx, %edi
movl $0x8, %esi
jmp 0xb82c
movl %edx, %eax
rorl %eax
cmpl $0xa, %eax
ja 0xb84b
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl %ebx, %edi
movl $0x40, %esi
jmp 0xb82c
cmpl $0x19, %edx
ja 0xb77e
movl %edx, %eax
leaq 0x4ce1(%rip), %rcx      # 0x102b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl %ebx, %edi
movl $0x100, %esi            # imm = 0x100
jmp 0xb82c
cmpl $0x417, %edx            # imm = 0x417
jle 0xb65a
cmpl $0x418, %edx            # imm = 0x418
je 0xb765
cmpl $0x419, %edx            # imm = 0x419
je 0xb6ef
cmpl $0x7d4, %edx            # imm = 0x7D4
jne 0xb787
movl %ebx, %edi
movl $0x10000, %esi          # imm = 0x10000
jmp 0xb82c
movl 0x10cfa(%rip), %eax     # 0x1c324
testl %ebx, %ebx
je 0xb677
orl $0x8, %eax
jmp 0xb836
movl 0x10ce8(%rip), %eax     # 0x1c324
testl %ebx, %ebx
je 0xb67f
andl $-0x11, %eax
jmp 0xb836
movl 0x10cd6(%rip), %eax     # 0x1c324
testl %ebx, %ebx
je 0xb687
orl $0x2, %eax
jmp 0xb836
cmpl $0x40a, %edx            # imm = 0x40A
je 0xb772
cmpl $0x417, %edx            # imm = 0x417
je 0xb707
jmp 0xb787
andl $-0x9, %eax
jmp 0xb836
orl $0x10, %eax
jmp 0xb836
andl $-0x3, %eax
jmp 0xb836
cmpl $0x2f, %edx
je 0xb707
jmp 0xb787
movl %ebx, %edi
movl $0x2000, %esi           # imm = 0x2000
jmp 0xb82c
movl %ebx, %edi
movl $0x200, %esi            # imm = 0x200
jmp 0xb82c
xorl %edi, %edi
callq 0xd1fb
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xd239
movl %ebx, %edi
movl $0x10, %esi
jmp 0xb82c
movl %ebx, %edi
callq 0xd1fb
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xd239
movl %ebx, %edi
movl $0x8000, %esi           # imm = 0x8000
jmp 0xb82c
leaq 0xbeb2(%rip), %rax      # 0x175a8
cmpl $0x0, (%rax)
je 0xb83c
movl %r14d, %edi
callq 0x90e7
leaq 0xbe9a(%rip), %rax      # 0x175a8
cmpl $0x0, (%rax)
je 0xb83c
movl %r14d, %r12d
movl 0x10c03(%rip), %r14d    # 0x1c324
andl $0x4, %r14d
je 0xb740
movl 0xcd27(%rip), %edx      # 0x18454
decl %edx
movl 0xcd1b(%rip), %ecx      # 0x18450
decl %ecx
xorl %edi, %edi
xorl %esi, %esi
callq 0x8f20
shrl $0x2, %r14d
cmpl %ebx, %r14d
je 0xb74e
callq 0x908e
cmpl $0x419, (%r15)          # imm = 0x419
movl %r12d, %r14d
leaq 0x4c01(%rip), %r12      # 0x10360
jne 0xb83c
movl %r14d, %edi
callq 0x90e7
jmp 0xb83c
movl %ebx, %edi
movl $0x400, %esi            # imm = 0x400
jmp 0xb82c
cmpl $0x2a, %edx
je 0xb83c
movq 0xb862(%rip), %rax      # 0x16ff0
movq (%rax), %rdi
leaq 0x5233(%rip), %rsi      # 0x109cb
jmp 0xb85c
xorl %edi, %edi
callq 0xd1fb
xorl %edi, %edi
movl $0xc018, %esi           # imm = 0xC018
callq 0xd239
movl %ebx, %edi
movl $0x4000, %esi           # imm = 0x4000
jmp 0xb82c
movl 0x10b65(%rip), %eax     # 0x1c324
testl %ebx, %ebx
je 0xb833
orl $0x1, %eax
jmp 0xb836
movb 0x10b42(%rip), %al      # 0x1c310
andb $-0x4, %al
addb 0x7(%rsp), %al
andb $-0x2, %al
movl 0xcc78(%rip), %ecx      # 0x18454
testl %ecx, %ecx
movl $0x1, %edx
cmovgl %edx, %ecx
movl 0xcc64(%rip), %edx      # 0x18450
decl %ecx
decl %edx
testl %ebx, %ebx
movl 0x10b24(%rip), %esi     # 0x1c31c
cmovel %ebx, %esi
movb %al, 0x10b0f(%rip)      # 0x1c310
cmovnel 0x10b18(%rip), %edx     # 0x1c320
movl %ecx, 0x10afa(%rip)     # 0x1c308
cmpl %esi, %edx
cmovgel %esi, %edx
movl %edx, 0x10af3(%rip)     # 0x1c30c
jmp 0xb83c
movl %r14d, %edi
movl $0x80, %esi
jmp 0xb82c
movl %ebx, %edi
movl $0x20, %esi
callq 0xd239
jmp 0xb83c
andl $-0x2, %eax
movl %eax, 0x10ae8(%rip)     # 0x1c324
addq $0x4, %r15
cmpq %r13, %r15
jb 0xb54d
jmp 0xb865
movq 0xb79e(%rip), %rax      # 0x16ff0
movq (%rax), %rdi
leaq 0x519a(%rip), %rsi      # 0x109f6
xorl %eax, %eax
callq 0x69e0
jmp 0xb83c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq