// File: /workspace/github_c_makefile_star2_O3/zenlinux[P]cwm/kbfunc.c
// Function: kbfunc_exec
void
kbfunc_exec(struct client_ctx *cc, union arg *arg)
{
#define NPATHS 256
	struct screen_ctx	*sc = cc->sc;
	char			**ap, *paths[NPATHS], *path, *pathcpy, *label;
	char			 tpath[MAXPATHLEN];
	DIR			*dirp;
	struct dirent		*dp;
	struct menu		*mi;
	struct menu_q		 menuq;
	int			 l, i, cmd = arg->i;

	switch (cmd) {
		case CWM_EXEC_PROGRAM:
			label = "exec";
			break;
		case CWM_EXEC_WM:
			label = "wm";
			break;
		default:
			err(1, "kbfunc_exec: invalid cmd %d", cmd);
			/*NOTREACHED*/
	}

	TAILQ_INIT(&menuq);

	if ((path = getenv("PATH")) == NULL)
		path = _PATH_DEFPATH;
	pathcpy = path = xstrdup(path);

	for (ap = paths; ap < &paths[NPATHS - 1] &&
	    (*ap = strsep(&pathcpy, ":")) != NULL;) {
		if (**ap != '\0')
			ap++;
	}
	*ap = NULL;
	for (i = 0; i < NPATHS && paths[i] != NULL; i++) {
		if ((dirp = opendir(paths[i])) == NULL)
			continue;

		while ((dp = readdir(dirp)) != NULL) {
			/* skip everything but regular files and symlinks */
			if (dp->d_type != DT_REG && dp->d_type != DT_LNK)
				continue;
			(void)memset(tpath, '\0', sizeof(tpath));
			l = snprintf(tpath, sizeof(tpath), "%s/%s", paths[i],
			    dp->d_name);
			/* check for truncation etc */
			if (l == -1 || l >= (int)sizeof(tpath))
				continue;
			if (access(tpath, X_OK) == 0) {
				mi = xcalloc(1, sizeof(*mi));
				(void)strlcpy(mi->text,
				    dp->d_name, sizeof(mi->text));
				TAILQ_INSERT_TAIL(&menuq, mi, entry);
			}
		}
		(void)closedir(dirp);
	}
	xfree(path);

	if ((mi = menu_filter(sc, &menuq, label, NULL, 1,
	    search_match_exec, NULL)) != NULL) {
		if (mi->text[0] == '\0')
			goto out;
		switch (cmd) {
			case CWM_EXEC_PROGRAM:
				u_spawn(mi->text);
				break;
			case CWM_EXEC_WM:
				u_exec(mi->text);
				warn("%s", mi->text);
				break;
			default:
				err(1, "kb_func: egad, cmd changed value!");
				break;
		}
	}
out:
	if (mi != NULL && mi->dummy)
		xfree(mi);
	while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
		TAILQ_REMOVE(&menuq, mi, entry);
		xfree(mi);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1858, %rsp           # imm = 0x1858
movq 0x30(%rdi), %rax
movl (%rsi), %edx
cmpl $0x1, %edx
movl %edx, 0x14(%rsp)
movq %rax, 0x38(%rsp)
je 0xb1d0
cmpl $0x2, %edx
jne 0xb409
leaq 0x3255(%rip), %rax      # 0xe423
jmp 0xb1d7
leaq 0x323d(%rip), %rax      # 0xe414
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rax
movq $0x0, (%rax)
movq %rax, 0x8(%rax)
leaq 0x37e5(%rip), %rdi      # 0xe9d8
callq 0x5550
testq %rax, %rax
leaq 0x37db(%rip), %rdi      # 0xe9dd
cmovneq %rax, %rdi
callq 0x61bd
leaq 0x48(%rsp), %rbx
movq %rax, 0x30(%rsp)
movq %rax, (%rbx)
leaq 0x50(%rsp), %r12
xorl %r15d, %r15d
leaq 0x2df2(%rip), %r14      # 0xe019
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5780
movq %rax, 0x50(%rsp,%r15)
testq %rax, %rax
je 0xb258
leaq 0x8(%r15), %rcx
cmpb $0x0, (%rax)
cmovneq %rcx, %r15
leaq (%rsp,%r15), %r12
addq $0x50, %r12
cmpq $0x7f8, %r15            # imm = 0x7F8
jl 0xb227
movq $0x0, (%r12)
leaq 0x850(%rsp), %r13
leaq 0x3102(%rip), %rbp      # 0xe371
xorl %ebx, %ebx
movq 0x50(%rsp,%rbx,8), %r14
testq %r14, %r14
je 0xb378
movq %r14, %rdi
callq 0x5360
testq %rax, %rax
je 0xb368
movq %rax, %r15
movq %rbx, 0x40(%rsp)
movq %rax, %rdi
callq 0x53e0
testq %rax, %rax
je 0xb35b
movq %rax, %rbx
movzbl 0x12(%rbx), %eax
orl $0x2, %eax
cmpl $0xa, %eax
jne 0xb347
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x5090
addq $0x13, %rbx
movl $0x1000, %esi           # imm = 0x1000
movq %r13, %rdi
movq %rbp, %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x50b0
cmpl $-0x1, %eax
sete %cl
cmpl $0x1000, %eax           # imm = 0x1000
setge %al
orb %cl, %al
jne 0xb347
movq %r13, %rdi
movl $0x1, %esi
callq 0x5790
testl %eax, %eax
jne 0xb347
movl $0x1, %edi
movl $0x98, %esi
callq 0x6198
movq %rax, %r12
leaq 0x20(%rax), %rdi
movl $0x33, %edx
movq %rbx, %rsi
callq 0xd220
movq $0x0, (%r12)
movq 0x28(%rsp), %rax
movq %rax, 0x8(%r12)
movq %r12, (%rax)
movq %r12, 0x28(%rsp)
movq %r15, %rdi
callq 0x53e0
movq %rax, %rbx
testq %rax, %rax
jne 0xb2ac
movq %r15, %rdi
callq 0x5720
movq 0x40(%rsp), %rbx
incq %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0xb271
movq 0x30(%rsp), %rdi
callq 0x61b8
movq $0x0, (%rsp)
leaq -0x2e3c(%rip), %r9      # 0x8555
leaq 0x20(%rsp), %r14
movq 0x38(%rsp), %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x7473
testq %rax, %rax
je 0xb44c
movq %rax, %rbx
cmpb $0x0, 0x20(%rax)
je 0xb3fa
movq %rbx, %r15
addq $0x20, %r15
movl 0x14(%rsp), %eax
cmpl $0x2, %eax
je 0xb3e1
cmpl $0x1, %eax
jne 0xb41c
movq %r15, %rdi
callq 0x8618
jmp 0xb3fa
movq %r15, %rdi
callq 0x8659
leaq 0x352f(%rip), %rdi      # 0xe91f
movq %r15, %rsi
xorl %eax, %eax
callq 0x5870
cmpw $0x0, 0x90(%rbx)
je 0xb44c
movq %rbx, %rdi
jmp 0xb447
leaq 0x35ac(%rip), %rsi      # 0xe9bc
movl $0x1, %edi
xorl %eax, %eax
callq 0x54b0
leaq 0x35c8(%rip), %rsi      # 0xe9eb
movl $0x1, %edi
xorl %eax, %eax
callq 0x54b0
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
testq %rax, %rax
movq %rax, %rdx
cmoveq %r14, %rdx
movq %rcx, 0x8(%rdx)
movq %rax, (%rcx)
callq 0x61b8
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
jne 0xb42f
addq $0x1858, %rsp           # imm = 0x1858
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq