// File: /workspace/github_c_makefile_star2_O0/mrdotx[P]st/st.c
// Function: trt_kbdselect
int trt_kbdselect(KeySym ksym, char *buf, int len) {
	static TCursor cu;
	static Rune target[64];
	static int type = 1, ptarget, in_use;
	static int sens, quant;
	static char selectsearch_mode;
	int i, bound, *xy;


	if ( selectsearch_mode & 2 ) {
		if ( ksym == XK_Return ) {
			selectsearch_mode ^= 2;
			set_notifmode(selectsearch_mode, -2);
			if ( ksym == XK_Escape )    ptarget = 0;
			return 0;
		}
		else if ( ksym == XK_BackSpace ) {
			if ( !ptarget )     return 0;
			term.line[term.bot][ptarget--].u = ' ';
		}
		else if ( len < 1 ) {
			return 0;
		}
		else if ( ptarget == term.col  || ksym == XK_Escape ) {
			return 0;
		}
		else {
			utf8decode(buf, &target[ptarget++], len);
			term.line[term.bot][ptarget].u = target[ptarget - 1];
		}

		if ( ksym != XK_BackSpace )
			search(selectsearch_mode, &target[0], ptarget, sens, type, &cu);

		term.dirty[term.bot] = 1;
		drawregion(0, term.bot, term.col, term.bot + 1);
		return 0;
	}

	switch ( ksym ) {
	case -1 :
		in_use = 1;
		cu.x = term.c.x, cu.y = term.c.y;
		set_notifmode(0, ksym);
		return MODE_KBDSELECT;
	case XK_s :
		if ( selectsearch_mode & 1 )
			selclear();
		else
			selstart(term.c.x, term.c.y, 0);
		set_notifmode(selectsearch_mode ^= 1, ksym);
		break;
	case XK_t :
		selextend(term.c.x, term.c.y, type ^= 3, i = 0);  /* 2 fois */
		selextend(term.c.x, term.c.y, type, i = 0);
		break;
	case XK_slash :
	case XK_KP_Divide :
	case XK_question :
		ksym &= XK_question;                /* Divide to slash */
		sens = (ksym == XK_slash) ? -1 : 1;
		ptarget = 0;
		set_notifmode(15, ksym);
		selectsearch_mode ^= 2;
		break;
	case XK_Escape :
		if ( !in_use )  break;
		selclear();
	case XK_Return :
		set_notifmode(4, ksym);
		term.c.x = cu.x, term.c.y = cu.y;
		select_or_drawcursor(selectsearch_mode = 0, type);
		in_use = quant = 0;
		return MODE_KBDSELECT;
	case XK_n :
	case XK_N :
		if ( ptarget )
			search(selectsearch_mode, &target[0], ptarget, (ksym == XK_n) ? -1 : 1, type, &cu);
		break;
	case XK_BackSpace :
		term.c.x = 0;
		select_or_drawcursor(selectsearch_mode, type);
		break;
	case XK_dollar :
		term.c.x = term.col - 1;
		select_or_drawcursor(selectsearch_mode, type);
		break;
	case XK_Home :
		term.c.x = 0, term.c.y = 0;
		select_or_drawcursor(selectsearch_mode, type);
		break;
	case XK_End :
		term.c.x = cu.x, term.c.y = cu.y;
		select_or_drawcursor(selectsearch_mode, type);
		break;
	case XK_Page_Up :
	case XK_Page_Down :
		term.c.y = (ksym == XK_Prior ) ? 0 : cu.y;
		select_or_drawcursor(selectsearch_mode, type);
		break;
	case XK_exclam :
		term.c.x = term.col >> 1;
		select_or_drawcursor(selectsearch_mode, type);
		break;
	case XK_asterisk :
	case XK_KP_Multiply :
		term.c.x = term.col >> 1;
	case XK_underscore :
		term.c.y = cu.y >> 1;
		select_or_drawcursor(selectsearch_mode, type);
		break;
	default :
		if ( ksym >= XK_0 && ksym <= XK_9 ) {               /* 0-9 keyboard */
			quant = (quant * 10) + (ksym ^ XK_0);
			return 0;
		}
		else if ( ksym >= XK_KP_0 && ksym <= XK_KP_9 ) {    /* 0-9 numpad */
			quant = (quant * 10) + (ksym ^ XK_KP_0);
			return 0;
		}
		else if ( ksym == XK_k || ksym == XK_h )
			i = ksym & 1;
		else if ( ksym == XK_l || ksym == XK_j )
			i = ((ksym & 6) | 4) >> 1;
		else if ( (XK_Home & ksym) != XK_Home || (i = (ksym ^ XK_Home) - 1) > 3 )
			break;

		xy = (i & 1) ? &term.c.y : &term.c.x;
		sens = (i & 2) ? 1 : -1;
		bound = (i >> 1 ^ 1) ? 0 : (i ^ 3) ? term.col - 1 : term.bot;

		if ( quant == 0 )
			quant++;

		if ( *xy == bound && ((sens < 0 && bound == 0) || (sens > 0 && bound > 0)) )
			break;

		*xy += quant * sens;
		if ( *xy < 0 || ( bound > 0 && *xy > bound) )
			*xy = bound;

		select_or_drawcursor(selectsearch_mode, type);
	}
	quant = 0;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movsbl 0x17f86(%rip), %eax     # 0x21450
andl $0x2, %eax
cmpl $0x0, %eax
je 0x9690
cmpq $0xff0d, -0x10(%rbp)    # imm = 0xFF0D
jne 0x9523
movsbl 0x17f69(%rip), %eax     # 0x21450
xorl $0x2, %eax
movb %al, 0x17f60(%rip)      # 0x21450
movsbl 0x17f59(%rip), %edi     # 0x21450
movq $-0x2, %rsi
callq 0xa9b0
cmpq $0xff1b, -0x10(%rbp)    # imm = 0xFF1B
jne 0x9517
movl $0x0, 0x17f29(%rip)     # 0x21440
movl $0x0, -0x4(%rbp)
jmp 0x9cf3
cmpq $0xff08, -0x10(%rbp)    # imm = 0xFF08
jne 0x957a
cmpl $0x0, 0x17f0c(%rip)     # 0x21440
jne 0x9542
movl $0x0, -0x4(%rbp)
jmp 0x9cf3
movq 0x14d87(%rip), %rax     # 0x1e2d0
movslq 0x15d68(%rip), %rcx     # 0x1f2b8
movq (%rax,%rcx,8), %rax
movl 0x17ee6(%rip), %ecx     # 0x21440
movl %ecx, %edx
addl $-0x1, %edx
movl %edx, 0x17edb(%rip)     # 0x21440
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x20, (%rax)
jmp 0x961a
cmpl $0x1, -0x1c(%rbp)
jge 0x958c
movl $0x0, -0x4(%rbp)
jmp 0x9cf3
movl 0x17eae(%rip), %eax     # 0x21440
cmpl 0x14d34(%rip), %eax     # 0x1e2cc
je 0x95a4
cmpq $0xff1b, -0x10(%rbp)    # imm = 0xFF1B
jne 0x95b0
movl $0x0, -0x4(%rbp)
jmp 0x9cf3
movq -0x18(%rbp), %rdi
movl 0x17e86(%rip), %eax     # 0x21440
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x17e7b(%rip)     # 0x21440
cltq
leaq 0x17d72(%rip), %rsi     # 0x21340
shlq $0x2, %rax
addq %rax, %rsi
movslq -0x1c(%rbp), %rdx
callq 0xaf00
movl 0x17e5c(%rip), %eax     # 0x21440
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x17d4f(%rip), %rax     # 0x21340
movl (%rax,%rcx,4), %ecx
movq 0x14cd5(%rip), %rax     # 0x1e2d0
movslq 0x15cb6(%rip), %rdx     # 0x1f2b8
movq (%rax,%rdx,8), %rax
movslq 0x17e33(%rip), %rdx     # 0x21440
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
jmp 0x9618
jmp 0x961a
jmp 0x961c
cmpq $0xff08, -0x10(%rbp)    # imm = 0xFF08
je 0x9653
movsbl 0x17e23(%rip), %edi     # 0x21450
movl 0x17e0d(%rip), %edx     # 0x21440
movl 0x17e0f(%rip), %ecx     # 0x21448
movl 0x11f50(%rip), %r8d     # 0x1b590
leaq 0x17cf9(%rip), %rsi     # 0x21340
leaq 0x17cca(%rip), %r9      # 0x21318
callq 0xad60
movq 0x15c2e(%rip), %rax     # 0x1f288
movslq 0x15c57(%rip), %rcx     # 0x1f2b8
movl $0x1, (%rax,%rcx,4)
movl 0x15c4a(%rip), %esi     # 0x1f2b8
movl 0x14c58(%rip), %edx     # 0x1e2cc
movl 0x15c3e(%rip), %ecx     # 0x1f2b8
addl $0x1, %ecx
xorl %edi, %edi
callq 0xa3f0
movl $0x0, -0x4(%rbp)
jmp 0x9cf3
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
subq $-0x1, %rax
je 0x97db
jmp 0x96a4
movq -0x38(%rbp), %rax
subq $0x21, %rax
je 0x9a92
jmp 0x96b4
movq -0x38(%rbp), %rax
subq $0x24, %rax
je 0x99d8
jmp 0x96c4
movq -0x38(%rbp), %rax
subq $0x2a, %rax
je 0x9ab7
jmp 0x96d4
movq -0x38(%rbp), %rax
subq $0x2f, %rax
je 0x98ac
jmp 0x96e4
movq -0x38(%rbp), %rax
subq $0x3f, %rax
je 0x98ac
jmp 0x96f4
movq -0x38(%rbp), %rax
subq $0x4e, %rax
je 0x996d
jmp 0x9704
movq -0x38(%rbp), %rax
subq $0x5f, %rax
je 0x9ac5
jmp 0x9714
movq -0x38(%rbp), %rax
subq $0x6e, %rax
je 0x996d
jmp 0x9724
movq -0x38(%rbp), %rax
subq $0x73, %rax
je 0x9814
jmp 0x9734
movq -0x38(%rbp), %rax
subq $0x74, %rax
je 0x985e
jmp 0x9744
movq -0x38(%rbp), %rax
subq $0xff08, %rax           # imm = 0xFF08
je 0x99b7
jmp 0x9756
movq -0x38(%rbp), %rax
subq $0xff0d, %rax           # imm = 0xFF0D
je 0x9913
jmp 0x9768
movq -0x38(%rbp), %rax
subq $0xff1b, %rax           # imm = 0xFF1B
je 0x9900
jmp 0x977a
movq -0x38(%rbp), %rax
subq $0xff50, %rax           # imm = 0xFF50
je 0x99fe
jmp 0x978c
movq -0x38(%rbp), %rax
addq $-0xff55, %rax          # imm = 0xFFFF00AB
subq $0x2, %rax
jb 0x9a58
jmp 0x97a2
movq -0x38(%rbp), %rax
subq $0xff57, %rax           # imm = 0xFF57
je 0x9a29
jmp 0x97b4
movq -0x38(%rbp), %rax
subq $0xffaa, %rax           # imm = 0xFFAA
je 0x9ab7
jmp 0x97c6
movq -0x38(%rbp), %rax
subq $0xffaf, %rax           # imm = 0xFFAF
je 0x98ac
jmp 0x9aea
movl $0x1, 0x17c5f(%rip)     # 0x21444
movl 0x15ab5(%rip), %eax     # 0x1f2a0
movl %eax, 0x17b37(%rip)     # 0x21328
movl 0x15aad(%rip), %eax     # 0x1f2a4
movl %eax, 0x17b2f(%rip)     # 0x2132c
movq -0x10(%rbp), %rsi
xorl %edi, %edi
callq 0xa9b0
movl $0x40000, -0x4(%rbp)    # imm = 0x40000
jmp 0x9cf3
movsbl 0x17c35(%rip), %eax     # 0x21450
andl $0x1, %eax
cmpl $0x0, %eax
je 0x982a
callq 0x6f40
jmp 0x983d
movl 0x15a70(%rip), %edi     # 0x1f2a0
movl 0x15a6e(%rip), %esi     # 0x1f2a4
xorl %edx, %edx
callq 0x6ea0
movsbl 0x17c0c(%rip), %eax     # 0x21450
xorl $0x1, %eax
movb %al, 0x17c03(%rip)      # 0x21450
movsbl %al, %edi
movq -0x10(%rbp), %rsi
callq 0xa9b0
jmp 0x9ce2
movl 0x15a3c(%rip), %edi     # 0x1f2a0
movl 0x15a3a(%rip), %esi     # 0x1f2a4
movl 0x11d20(%rip), %edx     # 0x1b590
xorl $0x3, %edx
movl %edx, 0x11d17(%rip)     # 0x1b590
movl $0x0, -0x20(%rbp)
xorl %ecx, %ecx
callq 0x71f0
movl 0x15a13(%rip), %edi     # 0x1f2a0
movl 0x15a11(%rip), %esi     # 0x1f2a4
movl 0x11cf7(%rip), %edx     # 0x1b590
movl $0x0, -0x20(%rbp)
xorl %ecx, %ecx
callq 0x71f0
jmp 0x9ce2
movq -0x10(%rbp), %rax
andq $0x3f, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdx
movl $0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq $0x2f, %rdx
cmovel %ecx, %eax
movl %eax, 0x17b75(%rip)     # 0x21448
movl $0x0, 0x17b63(%rip)     # 0x21440
movq -0x10(%rbp), %rsi
movl $0xf, %edi
callq 0xa9b0
movsbl 0x17b5e(%rip), %eax     # 0x21450
xorl $0x2, %eax
movb %al, 0x17b55(%rip)      # 0x21450
jmp 0x9ce2
cmpl $0x0, 0x17b3d(%rip)     # 0x21444
jne 0x990e
jmp 0x9ce2
callq 0x6f40
movq -0x10(%rbp), %rsi
movl $0x4, %edi
callq 0xa9b0
movl 0x17a01(%rip), %eax     # 0x21328
movl %eax, 0x15973(%rip)     # 0x1f2a0
movl 0x179f9(%rip), %eax     # 0x2132c
movl %eax, 0x1596b(%rip)     # 0x1f2a4
movb $0x0, 0x17b10(%rip)     # 0x21450
movl 0x11c4a(%rip), %esi     # 0x1b590
xorl %edi, %edi
callq 0xac80
movl $0x0, 0x17af5(%rip)     # 0x2144c
movl $0x0, 0x17ae3(%rip)     # 0x21444
movl $0x40000, -0x4(%rbp)    # imm = 0x40000
jmp 0x9cf3
cmpl $0x0, 0x17acc(%rip)     # 0x21440
je 0x99b2
movsbl 0x17ad3(%rip), %edi     # 0x21450
movl 0x17abd(%rip), %edx     # 0x21440
movq -0x10(%rbp), %rsi
movl $0x1, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq $0x6e, %rsi
cmovel %eax, %ecx
movl 0x11bf1(%rip), %r8d     # 0x1b590
leaq 0x1799a(%rip), %rsi     # 0x21340
leaq 0x1796b(%rip), %r9      # 0x21318
callq 0xad60
jmp 0x9ce2
movl $0x0, 0x158df(%rip)     # 0x1f2a0
movsbl 0x17a88(%rip), %edi     # 0x21450
movl 0x11bc2(%rip), %esi     # 0x1b590
callq 0xac80
jmp 0x9ce2
movl 0x148ee(%rip), %eax     # 0x1e2cc
subl $0x1, %eax
movl %eax, 0x158b9(%rip)     # 0x1f2a0
movsbl 0x17a62(%rip), %edi     # 0x21450
movl 0x11b9c(%rip), %esi     # 0x1b590
callq 0xac80
jmp 0x9ce2
movl $0x0, 0x15898(%rip)     # 0x1f2a0
movl $0x0, 0x15892(%rip)     # 0x1f2a4
movsbl 0x17a37(%rip), %edi     # 0x21450
movl 0x11b71(%rip), %esi     # 0x1b590
callq 0xac80
jmp 0x9ce2
movl 0x178f9(%rip), %eax     # 0x21328
movl %eax, 0x1586b(%rip)     # 0x1f2a0
movl 0x178f1(%rip), %eax     # 0x2132c
movl %eax, 0x15863(%rip)     # 0x1f2a4
movsbl 0x17a08(%rip), %edi     # 0x21450
movl 0x11b42(%rip), %esi     # 0x1b590
callq 0xac80
jmp 0x9ce2
cmpq $0xff55, -0x10(%rbp)    # imm = 0xFF55
jne 0x9a69
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
jmp 0x9a72
movl 0x178bd(%rip), %eax     # 0x2132c
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, 0x15829(%rip)     # 0x1f2a4
movsbl 0x179ce(%rip), %edi     # 0x21450
movl 0x11b08(%rip), %esi     # 0x1b590
callq 0xac80
jmp 0x9ce2
movl 0x14834(%rip), %eax     # 0x1e2cc
sarl %eax
movl %eax, 0x15800(%rip)     # 0x1f2a0
movsbl 0x179a9(%rip), %edi     # 0x21450
movl 0x11ae3(%rip), %esi     # 0x1b590
callq 0xac80
jmp 0x9ce2
movl 0x1480f(%rip), %eax     # 0x1e2cc
sarl %eax
movl %eax, 0x157db(%rip)     # 0x1f2a0
movl 0x17861(%rip), %eax     # 0x2132c
sarl %eax
movl %eax, 0x157d1(%rip)     # 0x1f2a4
movsbl 0x17976(%rip), %edi     # 0x21450
movl 0x11ab0(%rip), %esi     # 0x1b590
callq 0xac80
jmp 0x9ce2
cmpq $0x30, -0x10(%rbp)
jb 0x9b1e
cmpq $0x39, -0x10(%rbp)
ja 0x9b1e
imull $0xa, 0x1794d(%rip), %eax # 0x2144c
cltq
movq -0x10(%rbp), %rcx
xorq $0x30, %rcx
addq %rcx, %rax
movl %eax, 0x1793a(%rip)     # 0x2144c
movl $0x0, -0x4(%rbp)
jmp 0x9cf3
cmpq $0xffb0, -0x10(%rbp)    # imm = 0xFFB0
jb 0x9b5b
cmpq $0xffb9, -0x10(%rbp)    # imm = 0xFFB9
ja 0x9b5b
imull $0xa, 0x17913(%rip), %eax # 0x2144c
cltq
movq -0x10(%rbp), %rcx
xorq $0xffb0, %rcx           # imm = 0xFFB0
addq %rcx, %rax
movl %eax, 0x178fd(%rip)     # 0x2144c
movl $0x0, -0x4(%rbp)
jmp 0x9cf3
cmpq $0x6b, -0x10(%rbp)
je 0x9b69
cmpq $0x68, -0x10(%rbp)
jne 0x9b76
movq -0x10(%rbp), %rax
andq $0x1, %rax
movl %eax, -0x20(%rbp)
jmp 0x9bc9
cmpq $0x6c, -0x10(%rbp)
je 0x9b84
cmpq $0x6a, -0x10(%rbp)
jne 0x9b98
movq -0x10(%rbp), %rax
andq $0x6, %rax
orq $0x4, %rax
shrq %rax
movl %eax, -0x20(%rbp)
jmp 0x9bc7
movq -0x10(%rbp), %rax
andq $0xff50, %rax           # imm = 0xFF50
cmpq $0xff50, %rax           # imm = 0xFF50
jne 0x9bc0
movq -0x10(%rbp), %rax
xorq $0xff50, %rax           # imm = 0xFF50
subq $0x1, %rax
movl %eax, -0x20(%rbp)
cmpl $0x3, %eax
jle 0x9bc5
jmp 0x9ce2
jmp 0x9bc7
jmp 0x9bc9
jmp 0x9bcb
jmp 0x9bcd
movl -0x20(%rbp), %edx
andl $0x1, %edx
leaq 0x146ee(%rip), %rcx     # 0x1e2c8
addq $0xfc8, %rcx            # imm = 0xFC8
movq %rcx, %rax
addq $0x10, %rax
addq $0x14, %rcx
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x20(%rbp), %edx
andl $0x2, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, 0x17835(%rip)     # 0x21448
movl -0x20(%rbp), %eax
sarl %eax
xorl $0x1, %eax
cmpl $0x0, %eax
je 0x9c27
xorl %eax, %eax
movl %eax, -0x40(%rbp)
jmp 0x9c4f
movl -0x20(%rbp), %eax
xorl $0x3, %eax
cmpl $0x0, %eax
je 0x9c40
movl 0x14694(%rip), %eax     # 0x1e2cc
subl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x9c49
movl 0x15672(%rip), %eax     # 0x1f2b8
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, 0x177f0(%rip)     # 0x2144c
jne 0x9c6d
movl 0x177e8(%rip), %eax     # 0x2144c
addl $0x1, %eax
movl %eax, 0x177df(%rip)     # 0x2144c
movq -0x30(%rbp), %rax
movl (%rax), %eax
cmpl -0x24(%rbp), %eax
jne 0x9c98
cmpl $0x0, 0x177c9(%rip)     # 0x21448
jge 0x9c87
cmpl $0x0, -0x24(%rbp)
je 0x9c96
cmpl $0x0, 0x177ba(%rip)     # 0x21448
jle 0x9c98
cmpl $0x0, -0x24(%rbp)
jle 0x9c98
jmp 0x9ce2
movl 0x177ae(%rip), %ecx     # 0x2144c
imull 0x177a3(%rip), %ecx     # 0x21448
movq -0x30(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
jl 0x9cc7
cmpl $0x0, -0x24(%rbp)
jle 0x9cd0
movq -0x30(%rbp), %rax
movl (%rax), %eax
cmpl -0x24(%rbp), %eax
jle 0x9cd0
movl -0x24(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movsbl 0x17779(%rip), %edi     # 0x21450
movl 0x118b3(%rip), %esi     # 0x1b590
callq 0xac80
movl $0x0, 0x17760(%rip)     # 0x2144c
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)