// File: /workspace/github_c_makefile_star2_O0/jarun[P]nnn/src/nnn.c
// Function: nextsel
static int nextsel(int presel)
{
#ifdef BENCH
	return SEL_QUIT;
#endif
	wint_t c = presel;
	int i = 0;
	bool escaped = FALSE;

	if (c == 0 || c == MSGWAIT) {
try_quit:
		i = get_wch(&c);
		//DPRINTF_D(c);
		//DPRINTF_S(keyname(c));

#ifdef KEY_RESIZE
		if (c == KEY_RESIZE)
			handle_key_resize();
#endif

		/* Handle Alt+key */
		if (c == ESC) {
			timeout(0);
			i = get_wch(&c);
			if (i != ERR) {
				if (c == ESC)
					c = CONTROL('L');
				else {
					unget_wch(c);
					c = ';';
				}
				settimeout();
			} else if (escaped) {
				settimeout();
				c = CONTROL('Q');
			} else {
#ifndef NOFIFO
				if (!g_state.fifomode)
					notify_fifo(TRUE); /* Send hovered path to NNN_FIFO */
#endif
				escaped = TRUE;
				settimeout();
				goto try_quit;
			}
		}

		if (i == ERR && presel == MSGWAIT)
			c = (cfg.filtermode || filterset()) ? FILTER : CONTROL('L');
		else if (c == FILTER || c == CONTROL('L'))
			/* Clear previous filter when manually starting */
			clearfilter();
	}

	if (i == ERR) {
		++idle;

		/*
		 * Do not check for directory changes in du mode.
		 * A redraw forces du calculation.
		 * Check for changes every odd second.
		 */
#ifdef LINUX_INOTIFY
		if (!cfg.blkorder && inotify_wd >= 0 && (idle & 1)) {
			struct inotify_event *event;
			char inotify_buf[EVENT_BUF_LEN] = {0};

			i = read(inotify_fd, inotify_buf, EVENT_BUF_LEN);
			if (i > 0) {
				for (char *ptr = inotify_buf;
				     ptr + ((struct inotify_event *)ptr)->len < inotify_buf + i;
				     ptr += sizeof(struct inotify_event) + event->len) {
					event = (struct inotify_event *)ptr;
					DPRINTF_D(event->wd);
					DPRINTF_D(event->mask);
					if (!event->wd)
						break;

					if (event->mask & INOTIFY_MASK) {
						c = handle_event();
						break;
					}
				}
				DPRINTF_S("inotify read done");
			}
		}
#elif defined(BSD_KQUEUE)
		if (!cfg.blkorder && event_fd >= 0 && (idle & 1)) {
			struct kevent event_data[NUM_EVENT_SLOTS] = {0};

			if (kevent(kq, events_to_monitor, NUM_EVENT_SLOTS,
				   event_data, NUM_EVENT_FDS, &gtimeout) > 0)
				c = handle_event();
		}
#elif defined(HAIKU_NM)
		if (!cfg.blkorder && haiku_nm_active && (idle & 1) && haiku_is_update_needed(haiku_hnd))
			c = handle_event();
#endif
	} else
		idle = 0;

	for (i = 0; i < (int)ELEMENTS(bindings); ++i)
		if (c == bindings[i].sym)
			return bindings[i].act;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movl %edi, -0x8(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0xfd5f
cmpl $0x24, -0xc(%rbp)
jne 0xfed5
jmp 0xfd61
movq 0x10228(%rip), %rax     # 0x1ff90
movq (%rax), %rdi
leaq -0xc(%rbp), %rsi
callq 0x48d0
movl %eax, -0x10(%rbp)
cmpl $0x19a, -0xc(%rbp)      # imm = 0x19A
jne 0xfd85
callq 0xebb0
cmpl $0x1b, -0xc(%rbp)
jne 0xfe4f
movq 0x101fa(%rip), %rax     # 0x1ff90
movq (%rax), %rdi
xorl %esi, %esi
callq 0x4580
movq 0x101e9(%rip), %rax     # 0x1ff90
movq (%rax), %rdi
leaq -0xc(%rbp), %rsi
callq 0x48d0
movl %eax, -0x10(%rbp)
cmpl $-0x1, -0x10(%rbp)
je 0xfdf0
cmpl $0x1b, -0xc(%rbp)
jne 0xfdcb
movl $0xc, -0xc(%rbp)
jmp 0xfdda
movl -0xc(%rbp), %edi
callq 0x4550
movl $0x3b, -0xc(%rbp)
movq 0x101af(%rip), %rax     # 0x1ff90
movq (%rax), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x4580
jmp 0xfe4d
testb $0x1, -0x11(%rbp)
je 0xfe13
movq 0x10193(%rip), %rax     # 0x1ff90
movq (%rax), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x4580
movl $0x11, -0xc(%rbp)
jmp 0xfe4b
movl 0x10a0b(%rip), %eax     # 0x20824
shrl $0x5, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xfe2e
movl $0x1, %edi
callq 0xc890
movb $0x1, -0x11(%rbp)
movq 0x10157(%rip), %rax     # 0x1ff90
movq (%rax), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x4580
jmp 0xfd61
jmp 0xfe4d
jmp 0xfe4f
cmpl $-0x1, -0x10(%rbp)
jne 0xfec0
cmpl $0x24, -0x8(%rbp)
jne 0xfec0
movl 0x1066f(%rip), %ecx     # 0x204d0
andl $0x1, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x229(%rbp)
jne 0xfea5
movl 0x10659(%rip), %eax     # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x12008(%rip), %rax     # 0x21e90
imulq $0x2138, %rcx, %rcx     # imm = 0x2138
addq %rcx, %rax
movsbl 0x2101(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x229(%rbp)
movb -0x229(%rbp), %dl
movl $0xc, %eax
movl $0x2f, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0xc(%rbp)
jmp 0xfed3
cmpl $0x2f, -0xc(%rbp)
je 0xfecc
cmpl $0xc, -0xc(%rbp)
jne 0xfed1
callq 0x10600
jmp 0xfed3
jmp 0xfed5
cmpl $-0x1, -0x10(%rbp)
jne 0xffe7
movw 0x1b6e2(%rip), %ax      # 0x2b5c8
addw $0x1, %ax
movw %ax, 0x1b6d7(%rip)      # 0x2b5c8
movl 0x105d9(%rip), %eax     # 0x204d0
shrl $0x4, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xffe5
cmpl $0x0, 0x105bb(%rip)     # 0x204c8
jl 0xffe5
movzwl 0x1b6ae(%rip), %eax     # 0x2b5c8
andl $0x1, %eax
cmpl $0x0, %eax
je 0xffe5
leaq -0x220(%rbp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x4380
movl 0x11d19(%rip), %edi     # 0x21c58
leaq -0x220(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x4460
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jle 0xffe3
leaq -0x220(%rbp), %rax
movq %rax, -0x228(%rbp)
movq -0x228(%rbp), %rax
movq -0x228(%rbp), %rcx
movl 0xc(%rcx), %ecx
addq %rcx, %rax
leaq -0x220(%rbp), %rcx
movslq -0x10(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0xffe1
movq -0x228(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xffa8
jmp 0xffe1
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
andl 0x10833(%rip), %eax     # 0x207e8
cmpl $0x0, %eax
je 0xffc4
callq 0x18ac0
movl %eax, -0xc(%rbp)
jmp 0xffe1
jmp 0xffc6
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
addq $0x10, %rax
addq -0x228(%rbp), %rax
movq %rax, -0x228(%rbp)
jmp 0xff6b
jmp 0xffe3
jmp 0xffe5
jmp 0xfff0
movw $0x0, 0x1b5d8(%rip)     # 0x2b5c8
movl $0x0, -0x10(%rbp)
cmpl $0x58, -0x10(%rbp)
jge 0x10031
movl -0xc(%rbp), %eax
movslq -0x10(%rbp), %rdx
leaq 0x104d5(%rip), %rcx     # 0x204e0
cmpl (%rcx,%rdx,8), %eax
jne 0x10024
movslq -0x10(%rbp), %rcx
leaq 0x104c5(%rip), %rax     # 0x204e0
movl 0x4(%rax,%rcx,8), %eax
movl %eax, -0x4(%rbp)
jmp 0x10038
jmp 0x10026
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xfff7
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
nopw %cs:(%rax,%rax)