// File: /workspace/github_c_makefile_star2_O3/jarun[P]nnn/src/nnn.c
// Function: xreadline
static char *xreadline(const char *prefill, const char *prompt)
{
	size_t len, pos, lpos;
	int x, r;
	const int WCHAR_T_WIDTH = sizeof(wchar_t);
	wint_t ch[1];
	wchar_t * const buf = malloc(sizeof(wchar_t) * READLINE_MAX);

	if (!buf)
		errexit();

	cleartimeout();
	printmsg(prompt);

	if (prefill) {
		DPRINTF_S(prefill);
		len = pos = mbstowcs(buf, prefill, READLINE_MAX);
	} else
		len = (size_t)-1;

	if (len == (size_t)-1) {
		buf[0] = '\0';
		len = pos = 0;
	}

	x = getcurx(stdscr);
	curs_set(TRUE);

	while (1) {
		buf[len] = ' ';
		attron(COLOR_PAIR(cfg.curctx + 1));
		if (pos > (size_t)(xcols - x)) {
			mvaddnwstr(xlines - 1, x, buf + (pos - (xcols - x) + 1), xcols - x);
			move(xlines - 1, xcols - 1);
		} else {
			mvaddnwstr(xlines - 1, x, buf, len + 1);
			move(xlines - 1, x + wcswidth(buf, pos));
		}
		attroff(COLOR_PAIR(cfg.curctx + 1));

		r = get_wch(ch);
		if (r == ERR)
			continue;

		if (r == OK) {
			switch (*ch) {
			case KEY_ENTER: // fallthrough
			case '\n': // fallthrough
			case '\r':
				goto END;
			case CONTROL('D'):
				if (pos < len)
					++pos;
				else if (!(pos || len)) { /* Exit on ^D at empty prompt */
					len = 0;
					goto END;
				} else
					continue;
				// fallthrough
			case DEL: // fallthrough
			case '\b': /* rhel25 sends '\b' for backspace */
				if (pos > 0) {
					memmove(buf + pos - 1, buf + pos,
						(len - pos) * WCHAR_T_WIDTH);
					--len, --pos;
				}
				continue;
			case '\t':
				if ((len == pos) && ndents && (pos < (READLINE_MAX - xstrlen(pdents[cur].name)))) {
					buf[pos] = '\0';
					lpos = mbstowcs(NULL, pdents[cur].name, MB_CUR_MAX);
					pos += mbstowcs(buf + wcslen(buf), pdents[cur].name, lpos);
					len = pos;
				}
				continue;
			case CONTROL('F'):
				if (pos < len)
					++pos;
				continue;
			case CONTROL('B'):
				if (pos > 0)
					--pos;
				continue;
			case CONTROL('W'):
				printmsg(prompt);
				lpos = pos;
				while (pos > 0 && ISSPACE(buf[pos-1]))
					--pos;
				while (pos > 0 && !ISSPACE(buf[pos-1]))
					--pos;
				memmove(buf + pos, buf + lpos, (len - lpos) * WCHAR_T_WIDTH);
				len -= lpos - pos;
				continue;
			case CONTROL('K'):
				printmsg(prompt);
				len = pos;
				continue;
			case CONTROL('L'):
				printmsg(prompt);
				len = pos = 0;
				continue;
			case CONTROL('A'):
				pos = 0;
				continue;
			case CONTROL('E'):
				pos = len;
				continue;
			case CONTROL('U'):
				printmsg(prompt);
				memmove(buf, buf + pos, (len - pos) * WCHAR_T_WIDTH);
				len -= pos;
				pos = 0;
				continue;
			case ESC: /* Exit prompt on Esc, but just filter out Alt+key */
				if (handle_alt_key(ch) != ERR) {
					switch (*ch) {
					case 'd':
						printmsg(prompt);
						lpos = pos;
						while (pos < len && !iswalnum(buf[pos + 1]))
							++pos;
						while (pos < len && iswalnum(buf[++pos]));
						memmove(buf + lpos, buf + pos, (len - pos) * WCHAR_T_WIDTH);
						len -= pos - lpos;
						pos = lpos;
						continue;
					case KEY_BACKSPACE:
						printmsg(prompt);
						lpos = pos;
						while (pos > 0 && !iswalnum(buf[pos - 1]))
							--pos;
						while (pos > 0 && iswalnum(buf[pos - 1]))
							--pos;
						memmove(buf + pos, buf + lpos, (len - lpos) * WCHAR_T_WIDTH);
						len -= lpos - pos;
						continue;
					case 'f':
						while (pos < len && !iswalnum(buf[pos + 1]))
							++pos;
						while (pos < len && iswalnum(buf[++pos]));
						continue;
					case 'b':
						while (pos > 0 && !iswalnum(buf[pos - 1]))
							--pos;
						while (pos > 0 && iswalnum(buf[pos - 1]))
							--pos;
						continue;
					}
					continue;
				}

				len = 0;
				goto END;
			}

			/* Filter out all other control chars */
			if (*ch < ASCII_MAX && keyname(*ch)[0] == '^')
				continue;

			if (pos < READLINE_MAX - 1) {
				memmove(buf + pos + 1, buf + pos,
					(len - pos) * WCHAR_T_WIDTH);
				buf[pos] = *ch;
				++len, ++pos;
				continue;
			}
		} else {
			switch (*ch) {
#ifdef KEY_RESIZE
			case KEY_RESIZE:
				clearoldprompt();
				xlines = LINES;
				printmsg(prompt);
				break;
#endif
			case KEY_LEFT:
				if (pos > 0)
					--pos;
				break;
			case KEY_RIGHT:
				if (pos < len)
					++pos;
				break;
			case KEY_BACKSPACE:
				if (pos > 0) {
					memmove(buf + pos - 1, buf + pos,
						(len - pos) * WCHAR_T_WIDTH);
					--len, --pos;
				}
				break;
			case KEY_DC:
				if (pos < len) {
					memmove(buf + pos, buf + pos + 1,
						(len - pos - 1) * WCHAR_T_WIDTH);
					--len;
				}
				break;
			case KEY_END:
				pos = len;
				break;
			case KEY_HOME:
				pos = 0;
				break;
			case KEY_UP: // fallthrough
			case KEY_DOWN:
			{
				char *cmd = getcmdfromhist(*ch == KEY_UP);

				if (prompt && cmd && (xstrcmp(prompt, PROMPT) == 0)) {
					printmsg(prompt);
					len = pos = mbstowcs(buf, cmd, READLINE_MAX); // fallthrough
				}
			}
			default:
				break;
			}
		}
	}

END:
	curs_set(FALSE);
	settimeout();
	printmsg("");

	buf[len] = '\0';

	pos = wcstombs(g_buf, buf, READLINE_MAX - 1);
	if (pos >= READLINE_MAX - 1)
		g_buf[READLINE_MAX - 1] = '\0';

	free(buf);
	return g_buf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movq %rdi, %r14
movl $0x400, %edi            # imm = 0x400
callq 0x45c0
testq %rax, %rax
je 0x12744
movq %rax, %rbx
movq 0x7fec(%rip), %r12      # 0x19f90
movq (%r12), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4560
movq %r15, %rdi
callq 0xec60
testq %r14, %r14
je 0x11fd8
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41d0
movq %rax, %rbp
cmpq $-0x1, %rax
jne 0x11fe0
movl $0x0, (%rbx)
xorl %ebp, %ebp
movq (%r12), %rax
testq %rax, %rax
movq %r15, (%rsp)
je 0x11ff4
movswl 0x2(%rax), %r14d
jmp 0x11ffa
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x1, %edi
callq 0x4140
leaq 0x4(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %r14, 0x20(%rsp)
movslq %r14d, %rax
movq %rax, 0x18(%rsp)
movq %rbp, %r15
movq %rbp, %r13
movl $0x20, (%rbx,%r15,4)
movq (%r12), %rdi
movl 0x8496(%rip), %esi      # 0x1a4c8
shrl $0x5, %esi
andl $0x700, %esi            # imm = 0x700
addl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x4120
movzwl 0x12248(%rip), %r14d    # 0x24298
movq 0x18(%rsp), %rdx
subq %rdx, %r14
movq (%r12), %rdi
movzwl 0x9b25(%rip), %esi      # 0x1bb88
decl %esi
callq 0x4070
cmpq %r14, %rbp
jbe 0x120b0
cmpl $-0x1, %eax
je 0x12098
movq (%r12), %rdi
movzwl 0x12219(%rip), %edx     # 0x24298
subq 0x18(%rsp), %rdx
movq %r13, %rax
subq %rdx, %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
callq 0x4370
movq (%r12), %rdi
movzwl 0x9ae5(%rip), %esi      # 0x1bb88
decl %esi
movzwl 0x121ec(%rip), %edx     # 0x24298
decl %edx
jmp 0x120ea
cmpl $-0x1, %eax
je 0x120c5
movq (%r12), %rdi
leal 0x1(%r15), %edx
movq %rbx, %rsi
callq 0x4370
movq (%r12), %r14
movzwl 0x9ab8(%rip), %ebp      # 0x1bb88
decl %ebp
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4190
movq 0x20(%rsp), %rcx
leal (%rax,%rcx), %edx
movq %r14, %rdi
movl %ebp, %esi
callq 0x4070
movq (%r12), %rdi
movl 0x83cf(%rip), %esi      # 0x1a4c8
shrl $0x5, %esi
andl $0x700, %esi            # imm = 0x700
addl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x4730
movq (%r12), %rdi
leaq 0xc(%rsp), %rsi
callq 0x48d0
testl %eax, %eax
je 0x1219b
movq %r13, %rbp
cmpl $-0x1, %eax
je 0x1201d
movl 0xc(%rsp), %eax
cmpl $0x149, %eax            # imm = 0x149
jg 0x121d1
leal -0x102(%rax), %ecx
movq %r13, %rbp
cmpl $0x5, %ecx
ja 0x1201d
leaq 0x31db(%rip), %rdx      # 0x15330
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movb 0x8374(%rip), %cl       # 0x1a4d8
movq %r13, %rbp
cmpb $-0x1, %cl
je 0x1201d
movb 0x838a(%rip), %dl       # 0x1a500
cmpb $-0x1, %dl
je 0x124a4
cmpl $0x103, %eax            # imm = 0x103
jne 0x124f3
subb $0x1, %dl
movzbl %cl, %ecx
movzbl %dl, %eax
cmovbl %ecx, %eax
jmp 0x12503
movl 0xc(%rsp), %r14d
leal -0x1(%r14), %eax
cmpl $0x1a, %eax
ja 0x1222e
leaq 0x3110(%rip), %rcx      # 0x152c4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
xorl %ebp, %ebp
jmpq *%rax
subq $0x1, %r13
movl $0x0, %ebp
cmovaeq %r13, %rbp
jmp 0x1201d
cmpl $0x14a, %eax            # imm = 0x14A
je 0x12288
movq %r15, %rbp
cmpl $0x168, %eax            # imm = 0x168
je 0x1201d
movq %r13, %rbp
cmpl $0x19a, %eax            # imm = 0x19A
jne 0x1201d
callq 0x13adc
movq 0x7dcc(%rip), %rax      # 0x19fd0
movzwl (%rax), %eax
movw %ax, 0x997a(%rip)       # 0x1bb88
movq (%rsp), %rdi
callq 0xec60
movq %r13, %rbp
jmp 0x1201d
cmpq %r15, %r13
adcq $0x0, %r13
movq %r13, %rbp
jmp 0x1201d
cmpl $0x7f, %r14d
je 0x12279
cmpl $0x157, %r14d           # imm = 0x157
je 0x126e1
cmpl $0x7f, %r14d
ja 0x124b6
movl %r14d, %edi
callq 0x48a0
cmpb $0x5e, (%rax)
movq %r13, %rbp
je 0x1201d
movq %r13, %rbp
cmpq $0xfe, %r13
ja 0x1201d
movl 0xc(%rsp), %r14d
jmp 0x124c6
movl $0x0, %ebp
testq %r13, %r13
jne 0x122e5
jmp 0x1201d
movq %r13, %rbp
cmpq %r13, %r15
jbe 0x1201d
leaq (%rbx,%r13,4), %rdi
leaq (%rbx,%r13,4), %rsi
addq $0x4, %rsi
movq %r13, %rdx
notq %rdx
addq %r15, %rdx
shlq $0x2, %rdx
callq 0x46d0
decq %r15
movq %r13, %rbp
jmp 0x1201d
movq (%rsp), %rdi
callq 0xec60
movq %r13, %rbp
movq %r13, %r15
jmp 0x1201d
movq %r15, %rbp
jmp 0x1201d
cmpq %r13, %r15
jbe 0x12580
incq %r13
leaq (%rbx,%r13,4), %rsi
leaq (%rbx,%r13,4), %rdi
addq $-0x4, %rdi
movq %r15, %rdx
subq %r13, %rdx
shlq $0x2, %rdx
callq 0x46d0
decq %r15
decq %r13
movq %r13, %rbp
jmp 0x1201d
leaq 0xc(%rsp), %rdi
callq 0x13ea9
cmpl $-0x1, %eax
je 0x126de
movl 0xc(%rsp), %eax
cmpl $0x65, %eax
jg 0x12594
cmpl $0x62, %eax
je 0x1263f
movq %r13, %rbp
cmpl $0x64, %eax
jne 0x1201d
movq (%rsp), %rdi
callq 0xec60
movq %r13, %rbp
movq %rbp, %r14
cmpq %r15, %rbp
jae 0x1236d
leaq 0x1(%r14), %rbp
movq 0x10(%rsp), %rax
movl (%rax,%r14,4), %edi
callq 0x45b0
testl %eax, %eax
je 0x1234f
cmpq %r15, %r14
jae 0x12387
movq 0x10(%rsp), %rax
movl (%rax,%r14,4), %edi
incq %r14
callq 0x45b0
testl %eax, %eax
jne 0x1236d
leaq (%rbx,%r13,4), %rdi
leaq (%rbx,%r14,4), %rsi
movq %r15, %rdx
subq %r14, %rdx
shlq $0x2, %rdx
callq 0x46d0
addq %r13, %r15
subq %r14, %r15
movq %r13, %rbp
jmp 0x1201d
movq (%rsp), %rdi
callq 0xec60
leaq (%rbx,%r13,4), %rsi
subq %r13, %r15
leaq (,%r15,4), %rdx
movq %rbx, %rdi
callq 0x46d0
xorl %ebp, %ebp
jmp 0x1201d
movq %r13, %rbp
cmpq %r13, %r15
jne 0x1201d
cmpl $0x0, 0x97a6(%rip)      # 0x1bb8c
movq %r13, %rbp
je 0x1201d
movq 0x11c7a(%rip), %rax     # 0x24070
movslq 0x11c7b(%rip), %rcx     # 0x24078
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4490
movq %r14, %rcx
subq %rax, %rcx
addq $0x100, %rcx            # imm = 0x100
movq %r13, %rbp
movq %r13, %r15
cmpq %rcx, %r13
jae 0x1201d
jmp 0x12688
movq (%rsp), %rdi
callq 0xec60
testq %r13, %r13
je 0x1261d
movq %r13, %rax
movl -0x4(%rbx,%rax,4), %ecx
leal -0x9(%rcx), %edx
cmpl $0x5, %edx
jae 0x1245f
decq %rax
jne 0x12449
jmp 0x1261d
cmpl $0x20, %ecx
je 0x12455
movl -0x4(%rbx,%rax,4), %ecx
cmpq $0x20, %rcx
ja 0x12482
movabsq $0x100003e00, %rdx      # imm = 0x100003E00
btq %rcx, %rdx
jb 0x12665
movl $0x0, %ebp
decq %rax
jne 0x12464
jmp 0x1261f
movq (%rsp), %rdi
callq 0xec60
xorl %ebp, %ebp
xorl %r15d, %r15d
jmp 0x1201d
cmpl $0x103, %eax            # imm = 0x103
movzbl %cl, %eax
movl $0x0, %ecx
cmovnel %ecx, %eax
jmp 0x12503
movq %r13, %rbp
cmpq $0xfe, %r13
ja 0x1201d
leaq (%rbx,%r13,4), %rsi
leaq (%rbx,%r13,4), %rdi
addq $0x4, %rdi
movq %r15, %rdx
subq %r13, %rdx
shlq $0x2, %rdx
callq 0x46d0
movl %r14d, (%rbx,%r13,4)
incq %r15
incq %r13
movq %r13, %rbp
jmp 0x1201d
leal 0x1(%rdx), %eax
cmpb %cl, %dl
movzbl %al, %eax
movl $0x0, %ecx
cmovel %ecx, %eax
movb %al, 0x7ff7(%rip)       # 0x1a500
movq %r13, %rbp
cmpq $0x0, (%rsp)
je 0x1201d
movzbl %al, %eax
leaq 0x959f(%rip), %rcx      # 0x1bac0
movq (%rcx,%rax,8), %r14
movq %r13, %rbp
testq %r14, %r14
je 0x1201d
movq (%rsp), %rax
cmpb $0x3e, (%rax)
movq %r13, %rbp
jne 0x1201d
movq (%rsp), %rdi
leaq 0x40e0(%rip), %rsi      # 0x1662c
callq 0x44d0
movq %r13, %rbp
testl %eax, %eax
jne 0x1201d
movq (%rsp), %rdi
callq 0xec60
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41d0
movq %rax, %rbp
movq %rax, %r15
jmp 0x1201d
movq %r15, %rax
orq %r13, %rax
movq %r13, %rbp
jne 0x1201d
jmp 0x126de
cmpl $0x66, %eax
je 0x125cc
movq %r13, %rbp
cmpl $0x107, %eax            # imm = 0x107
jne 0x1201d
movq (%rsp), %rdi
callq 0xec60
testq %r13, %r13
je 0x1261d
movq %r13, %rbp
movl -0x4(%rbx,%rbp,4), %edi
callq 0x45b0
testl %eax, %eax
jne 0x1260b
decq %rbp
jne 0x125b8
jmp 0x1261d
movq %r13, %rbp
cmpq %r15, %r13
jae 0x125e9
leaq 0x1(%rbp), %r13
movq 0x10(%rsp), %rax
movl (%rax,%rbp,4), %edi
callq 0x45b0
testl %eax, %eax
je 0x125cc
cmpq %r15, %rbp
jae 0x1201d
movq 0x10(%rsp), %rax
movl (%rax,%rbp,4), %edi
incq %rbp
callq 0x45b0
testl %eax, %eax
jne 0x125e9
jmp 0x1201d
movl -0x4(%rbx,%rbp,4), %edi
callq 0x45b0
testl %eax, %eax
je 0x1261f
decq %rbp
jne 0x1260b
xorl %ebp, %ebp
leaq (%rbx,%rbp,4), %rdi
leaq (%rbx,%r13,4), %rsi
subq %r13, %r15
leaq (,%r15,4), %rdx
callq 0x46d0
addq %rbp, %r15
jmp 0x1201d
movl $0x0, %ebp
testq %r13, %r13
je 0x1201d
movl -0x4(%rbx,%r13,4), %edi
callq 0x45b0
testl %eax, %eax
jne 0x1266a
decq %r13
jne 0x1264d
jmp 0x123cc
movq %rax, %rbp
jmp 0x1261f
movq %r13, %rbp
movl -0x4(%rbx,%rbp,4), %edi
callq 0x45b0
testl %eax, %eax
je 0x1201d
decq %rbp
jne 0x1266d
jmp 0x123cc
movl $0x0, (%rbx,%r13,4)
callq 0x42b0
xorl %edi, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x41d0
movq %rax, %r14
movq %rbx, %rdi
callq 0x4330
leaq (%rbx,%rax,4), %rdi
movq 0x119b8(%rip), %rax     # 0x24070
movslq 0x119b9(%rip), %rcx     # 0x24078
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rsi
movq %r14, %rdx
callq 0x41d0
movq %rax, %rbp
addq %r13, %rbp
jmp 0x1201a
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x4140
movq (%r12), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x4560
leaq 0x3c49(%rip), %rdi      # 0x16346
callq 0xec60
movl $0x0, (%rbx,%r15,4)
leaq 0x803f(%rip), %rdi      # 0x1a750
movl $0xff, %edx
movq %rbx, %rsi
callq 0x47c0
cmpq $0xff, %rax
jb 0x1272d
movb $0x0, 0x8122(%rip)      # 0x1a84f
movq %rbx, %rdi
callq 0x4090
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xe6d, %edi            # imm = 0xE6D
callq 0xfcfe