// File: /workspace/github_c_makefile_star2_O2/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 0xad30
cmpl $0x2, %edx
jne 0xaf4b
leaq 0x36f5(%rip), %rax      # 0xe423
jmp 0xad37
leaq 0x36dd(%rip), %rax      # 0xe414
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rax
andq $0x0, (%rax)
movq %rax, 0x8(%rax)
leaq 0x3c88(%rip), %rdi      # 0xe9d8
callq 0x5550
testq %rax, %rax
leaq 0x3c7e(%rip), %rdi      # 0xe9dd
cmovneq %rax, %rdi
callq 0x6055
leaq 0x48(%rsp), %rbx
movq %rax, 0x30(%rsp)
movq %rax, (%rbx)
xorl %r15d, %r15d
leaq 0x329a(%rip), %r14      # 0xe019
cmpq $0x7f7, %r15            # imm = 0x7F7
ja 0xada8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5780
movq %rax, 0x50(%rsp,%r15)
testq %rax, %rax
je 0xada8
cmpb $0x0, (%rax)
je 0xad7f
addq $0x8, %r15
jmp 0xad7f
andq $0x0, 0x50(%rsp,%r15)
leaq 0x850(%rsp), %r13
leaq 0x35b4(%rip), %rbp      # 0xe371
pushq $0x1
popq %r14
xorl %ebx, %ebx
cmpq $0x100, %rbx            # imm = 0x100
je 0xaec5
movq 0x50(%rsp,%rbx,8), %r12
testq %r12, %r12
je 0xaec5
movq %r12, %rdi
callq 0x5360
testq %rax, %rax
je 0xaebd
movq %rax, %r15
movq %rbx, 0x40(%rsp)
movq %r15, %rdi
callq 0x53e0
testq %rax, %rax
je 0xaeb0
movq %rax, %rbx
movzbl 0x12(%rax), %eax
orl $0x2, %eax
cmpl $0xa, %eax
jne 0xadf7
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 %r12, %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 0xadf7
movq %r13, %rdi
movl %r14d, %esi
callq 0x5790
testl %eax, %eax
jne 0xadf7
movl $0x98, %esi
pushq $0x1
popq %rdi
callq 0x6032
movq %rbp, %r13
movl %r14d, %ebp
movq %rax, %r14
leaq 0x20(%rax), %rdi
movq %rbx, %rsi
pushq $0x33
popq %rdx
callq 0xcd50
andq $0x0, (%r14)
movq 0x28(%rsp), %rax
movq %rax, 0x8(%r14)
movq %r14, (%rax)
movq %r14, 0x28(%rsp)
movl %ebp, %r14d
movq %r13, %rbp
leaq 0x850(%rsp), %r13
jmp 0xadf7
movq %r15, %rdi
callq 0x5720
movq 0x40(%rsp), %rbx
incq %rbx
jmp 0xadc3
movq 0x30(%rsp), %rdi
callq 0x6050
andq $0x0, (%rsp)
leaq -0x2c0e(%rip), %r9      # 0x82cd
leaq 0x20(%rsp), %rbx
pushq $0x1
popq %r8
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
callq 0x7294
testq %rax, %rax
je 0xaf75
movq %rax, %r14
cmpb $0x0, 0x20(%rax)
je 0xaf3e
movq %r14, %r15
addq $0x20, %r15
movl 0x14(%rsp), %eax
cmpl $0x2, %eax
je 0xaf25
cmpl $0x1, %eax
jne 0xaf5c
movq %r15, %rdi
callq 0x8384
jmp 0xaf3e
movq %r15, %rdi
callq 0x83c3
leaq 0x39eb(%rip), %rdi      # 0xe91f
movq %r15, %rsi
xorl %eax, %eax
callq 0x5870
cmpw $0x0, 0x90(%r14)
jne 0xaf6d
jmp 0xaf75
leaq 0x3a6a(%rip), %rsi      # 0xe9bc
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x54b0
leaq 0x3a88(%rip), %rsi      # 0xe9eb
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x54b0
movq %r14, %rdi
callq 0x6050
movq 0x20(%rsp), %r14
testq %r14, %r14
je 0xaf99
movq (%r14), %rax
movq 0x8(%r14), %rcx
testq %rax, %rax
movq %rax, %rdx
cmoveq %rbx, %rdx
movq %rcx, 0x8(%rdx)
movq %rax, (%rcx)
jmp 0xaf6d
addq $0x1858, %rsp           # imm = 0x1858
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq