// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rdi, %r14
movl $0x400, %edi            # imm = 0x400
callq 0x45c0
testq %rax, %rax
je 0x12a84
movq %rax, %rbx
movq 0x7cab(%rip), %r12      # 0x19f90
movq (%r12), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4560
movq %r13, %rdi
callq 0xee6f
testq %r14, %r14
je 0x12318
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41d0
movq %rax, %rbp
movq %rax, %r15
jmp 0x1231f
movq $-0x1, %r15
cmpq $-0x1, %r15
jne 0x12330
movl $0x0, (%rbx)
xorl %ebp, %ebp
xorl %r15d, %r15d
movq (%r12), %rax
testq %rax, %rax
movq %r13, (%rsp)
je 0x12344
movswl 0x2(%rax), %r14d
jmp 0x1234a
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x1, %edi
callq 0x4140
leaq 0x4(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movslq %r14d, %rax
movq %rax, 0x10(%rsp)
movq %rbp, %r13
movl $0x20, (%rbx,%r15,4)
movq (%r12), %rdi
movl 0x8149(%rip), %esi      # 0x1a4c8
shrl $0x5, %esi
andl $0x700, %esi            # imm = 0x700
addl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x4120
movzwl 0x11efb(%rip), %r14d    # 0x24298
movq 0x10(%rsp), %rdx
subq %rdx, %r14
movq (%r12), %rdi
movzwl 0x97d8(%rip), %esi      # 0x1bb88
decl %esi
callq 0x4070
cmpq %r14, %rbp
jbe 0x123fd
cmpl $-0x1, %eax
je 0x123e5
movq (%r12), %rdi
movzwl 0x11ecc(%rip), %edx     # 0x24298
subq 0x10(%rsp), %rdx
movq %r13, %rax
subq %rdx, %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
callq 0x4370
movq (%r12), %rdi
movzwl 0x9798(%rip), %esi      # 0x1bb88
decl %esi
movzwl 0x11e9f(%rip), %edx     # 0x24298
decl %edx
jmp 0x12437
cmpl $-0x1, %eax
je 0x12412
movq (%r12), %rdi
leal 0x1(%r15), %edx
movq %rbx, %rsi
callq 0x4370
movq (%r12), %r14
movzwl 0x976b(%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 0x8082(%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 0x124e5
movq %r13, %rbp
cmpl $-0x1, %eax
je 0x1236a
movl 0xc(%rsp), %eax
cmpl $0x149, %eax            # imm = 0x149
jg 0x12519
leal -0x102(%rax), %ecx
movq %r13, %rbp
cmpl $0x5, %ecx
ja 0x1236a
leaq 0x2e8e(%rip), %rdx      # 0x15330
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movb 0x8027(%rip), %cl       # 0x1a4d8
cmpb $-0x1, %cl
je 0x125ef
movb 0x8040(%rip), %dl       # 0x1a500
cmpb $-0x1, %dl
je 0x12810
cmpl $0x103, %eax            # imm = 0x103
jne 0x12863
subb $0x1, %dl
movzbl %cl, %ecx
movzbl %dl, %eax
cmovbl %ecx, %eax
jmp 0x12873
movl 0xc(%rsp), %edi
leal -0x1(%rdi), %eax
cmpl $0x1a, %eax
ja 0x12576
leaq 0x2dc8(%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 0x1236a
cmpl $0x14a, %eax            # imm = 0x14A
je 0x125ba
movq %r15, %rbp
cmpl $0x168, %eax            # imm = 0x168
je 0x1236a
movq %r13, %rbp
cmpl $0x19a, %eax            # imm = 0x19A
jne 0x1236a
callq 0x13c6c
movq 0x7a84(%rip), %rax      # 0x19fd0
movzwl (%rax), %eax
movw %ax, 0x9632(%rip)       # 0x1bb88
movq (%rsp), %rdi
callq 0xee6f
movq %r13, %rbp
jmp 0x1236a
cmpq %r15, %r13
adcq $0x0, %r13
movq %r13, %rbp
jmp 0x1236a
cmpl $0x7f, %edi
je 0x1261f
cmpl $0x157, %edi            # imm = 0x157
je 0x12a21
cmpl $0x7f, %edi
ja 0x12822
callq 0x48a0
cmpb $0x5e, (%rax)
movq %r13, %rbp
je 0x1236a
movq %r13, %rbp
cmpq $0xff, %r13
jb 0x12832
jmp 0x1236a
movq %r13, %rbp
cmpq %r13, %r15
jbe 0x1236a
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 0x1236a
xorl %r14d, %r14d
jmp 0x12887
movq (%rsp), %rdi
callq 0xee6f
movq %r13, %rbp
movq %r13, %r15
jmp 0x1236a
movq %r15, %rbp
jmp 0x1236a
cmpq %r13, %r15
jbe 0x1291c
incq %r13
movl $0x0, %ebp
testq %r13, %r13
je 0x1236a
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 0x1236a
leaq 0xc(%rsp), %rdi
callq 0x14032
cmpl $-0x1, %eax
je 0x12a1e
movl 0xc(%rsp), %eax
cmpl $0x65, %eax
jg 0x12930
movq %r13, %rbp
cmpl $0x62, %eax
je 0x129db
cmpl $0x64, %eax
jne 0x1236a
movq (%rsp), %rdi
callq 0xee6f
movq %r13, %rbp
movq %rbp, %r14
cmpq %r15, %rbp
jae 0x126b1
leaq 0x1(%r14), %rbp
movl 0x4(%rbx,%r14,4), %edi
callq 0x45b0
testl %eax, %eax
je 0x12697
cmpq %r15, %r14
jae 0x126c7
movl 0x4(%rbx,%r14,4), %edi
incq %r14
callq 0x45b0
testl %eax, %eax
jne 0x126b1
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 0x1236a
movq (%rsp), %rdi
callq 0xee6f
leaq (%rbx,%r13,4), %rsi
subq %r13, %r15
leaq (,%r15,4), %rdx
movq %rbx, %rdi
callq 0x46d0
xorl %ebp, %ebp
jmp 0x1236a
movq %r13, %rbp
cmpq %r13, %r15
jne 0x1236a
cmpl $0x0, 0x9466(%rip)      # 0x1bb8c
movq %r13, %rbp
je 0x1236a
movq 0x1193a(%rip), %rax     # 0x24070
movslq 0x1193b(%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
cmpq %rcx, %r13
jae 0x1236a
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 0x118d4(%rip), %rax     # 0x24070
movslq 0x118d5(%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
movq %rbp, %r15
jmp 0x1236a
movq (%rsp), %rdi
callq 0xee6f
movq %r13, %rbp
testq %r13, %r13
je 0x128f2
movq %r13, %rbp
movl -0x4(%rbx,%rbp,4), %eax
leal -0x9(%rax), %ecx
cmpl $0x5, %ecx
jae 0x127f3
decq %rbp
jne 0x127dd
jmp 0x128f0
cmpl $0x20, %eax
je 0x127e9
jmp 0x128f2
movq (%rsp), %rdi
callq 0xee6f
xorl %ebp, %ebp
xorl %r15d, %r15d
jmp 0x1236a
cmpl $0x103, %eax            # imm = 0x103
movzbl %cl, %eax
movl $0x0, %ecx
cmovnel %ecx, %eax
jmp 0x12873
movq %r13, %rbp
cmpq $0xfe, %r13
ja 0x1236a
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 0xc(%rsp), %eax
movl %eax, (%rbx,%r13,4)
incq %r15
incq %r13
movq %r13, %rbp
jmp 0x1236a
leal 0x1(%rdx), %eax
cmpb %cl, %dl
movzbl %al, %eax
movl $0x0, %ecx
cmovel %ecx, %eax
movb %al, 0x7c87(%rip)       # 0x1a500
movzbl %al, %eax
leaq 0x923d(%rip), %rcx      # 0x1bac0
movq (%rcx,%rax,8), %r14
movq %r13, %rbp
cmpq $0x0, (%rsp)
je 0x1236a
movq %r13, %rbp
testq %r14, %r14
je 0x1236a
movq (%rsp), %rax
cmpb $0x3e, (%rax)
movq %r13, %rbp
jne 0x1236a
movq (%rsp), %rdi
leaq 0x3d56(%rip), %rsi      # 0x16612
callq 0x44d0
movq %r13, %rbp
testl %eax, %eax
jne 0x1236a
movq (%rsp), %rdi
callq 0xee6f
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41d0
movq %rax, %rbp
movq %rax, %r15
jmp 0x1236a
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x12984
movabsq $0x100003e00, %rcx      # imm = 0x100003E00
movl -0x4(%rbx,%rbp,4), %eax
cmpq $0x20, %rax
ja 0x12915
btq %rax, %rcx
jb 0x12984
decq %rbp
jne 0x12905
jmp 0x12982
movq %r15, %rax
orq %r13, %rax
movq %r13, %rbp
jne 0x1236a
jmp 0x12a1e
cmpl $0x66, %eax
je 0x129a4
movq %r13, %rbp
cmpl $0x107, %eax            # imm = 0x107
jne 0x1236a
movq (%rsp), %rdi
callq 0xee6f
movq %r13, %rbp
testq %r13, %r13
je 0x1296b
movq %r13, %rbp
movl -0x4(%rbx,%rbp,4), %edi
callq 0x45b0
testl %eax, %eax
jne 0x1296b
decq %rbp
jne 0x12957
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x12984
movl -0x4(%rbx,%rbp,4), %edi
callq 0x45b0
testl %eax, %eax
je 0x12984
decq %rbp
jne 0x12970
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 0x1236a
movq %r13, %rbp
cmpq %r15, %r13
jae 0x129bd
leaq 0x1(%rbp), %r13
movl 0x4(%rbx,%rbp,4), %edi
callq 0x45b0
testl %eax, %eax
je 0x129a4
cmpq %r15, %rbp
jae 0x1236a
movl 0x4(%rbx,%rbp,4), %edi
incq %rbp
callq 0x45b0
testl %eax, %eax
jne 0x129bd
jmp 0x1236a
testq %r13, %r13
je 0x129fa
movl -0x4(%rbx,%r13,4), %edi
callq 0x45b0
testl %eax, %eax
jne 0x129f7
decq %r13
jne 0x129e0
xorl %ebp, %ebp
jmp 0x129fa
movq %r13, %rbp
testq %rbp, %rbp
je 0x1236a
movl -0x4(%rbx,%rbp,4), %edi
callq 0x45b0
testl %eax, %eax
je 0x1236a
decq %rbp
jne 0x12a03
jmp 0x1270c
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x4140
movq (%r12), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x4560
leaq 0x38ef(%rip), %rdi      # 0x1632c
callq 0xee6f
movl $0x0, (%rbx,%r15,4)
leaq 0x7cff(%rip), %rdi      # 0x1a750
movl $0xff, %edx
movq %rbx, %rsi
callq 0x47c0
cmpq $0xff, %rax
jb 0x12a6d
movb $0x0, 0x7de2(%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 0xff2e