// File: /workspace/github_c_makefile_star2_O1/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 0xb397
cmpl $0x2, %edx
jne 0xb5d0
leaq 0x309e(%rip), %rax      # 0xe433
jmp 0xb39e
leaq 0x3086(%rip), %rax      # 0xe424
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rax
movq $0x0, (%rax)
movq %rax, 0x8(%rax)
leaq 0x362e(%rip), %rdi      # 0xe9e8
callq 0x5560
testq %rax, %rax
leaq 0x3624(%rip), %rdi      # 0xe9ed
cmovneq %rax, %rdi
callq 0x61cd
leaq 0x48(%rsp), %rbx
movq %rax, 0x30(%rsp)
movq %rax, (%rbx)
leaq 0x50(%rsp), %r12
xorl %r15d, %r15d
leaq 0x2c2b(%rip), %r14      # 0xe019
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5790
movq %rax, 0x50(%rsp,%r15)
testq %rax, %rax
je 0xb41f
leaq 0x8(%r15), %rcx
cmpb $0x0, (%rax)
cmovneq %rcx, %r15
leaq (%rsp,%r15), %r12
addq $0x50, %r12
cmpq $0x7f8, %r15            # imm = 0x7F8
jl 0xb3ee
movq $0x0, (%r12)
leaq 0x850(%rsp), %r13
leaq 0x2f4b(%rip), %rbp      # 0xe381
xorl %ebx, %ebx
movq 0x50(%rsp,%rbx,8), %r14
testq %r14, %r14
je 0xb53f
movq %r14, %rdi
callq 0x5370
testq %rax, %rax
je 0xb52f
movq %rax, %r15
movq %rbx, 0x40(%rsp)
movq %rax, %rdi
callq 0x53f0
testq %rax, %rax
je 0xb522
movq %rax, %rbx
movzbl 0x12(%rbx), %eax
orl $0x2, %eax
cmpl $0xa, %eax
jne 0xb50e
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 0xb50e
movq %r13, %rdi
movl $0x1, %esi
callq 0x57a0
testl %eax, %eax
jne 0xb50e
movl $0x1, %edi
movl $0x98, %esi
callq 0x61a8
movq %rax, %r12
leaq 0x20(%rax), %rdi
movl $0x33, %edx
movq %rbx, %rsi
callq 0xd500
movq $0x0, (%r12)
movq 0x28(%rsp), %rax
movq %rax, 0x8(%r12)
movq %r12, (%rax)
movq %r12, 0x28(%rsp)
movq %r15, %rdi
callq 0x53f0
movq %rax, %rbx
testq %rax, %rax
jne 0xb473
movq %r15, %rdi
callq 0x5730
movq 0x40(%rsp), %rbx
incq %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0xb438
movq 0x30(%rsp), %rdi
callq 0x61c8
movq $0x0, (%rsp)
leaq -0x2e7a(%rip), %r9      # 0x86de
leaq 0x20(%rsp), %r14
movq 0x38(%rsp), %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x74d7
testq %rax, %rax
je 0xb617
movq %rax, %rbx
cmpb $0x0, 0x20(%rax)
je 0xb5c1
movq %rbx, %r15
addq $0x20, %r15
movl 0x14(%rsp), %eax
cmpl $0x2, %eax
je 0xb5a8
cmpl $0x1, %eax
jne 0xb5e3
movq %r15, %rdi
callq 0x87a4
jmp 0xb5c1
movq %r15, %rdi
callq 0x87e5
leaq 0x3378(%rip), %rdi      # 0xe92f
movq %r15, %rsi
xorl %eax, %eax
callq 0x5880
cmpw $0x0, 0x90(%rbx)
je 0xb617
movq %rbx, %rdi
jmp 0xb612
leaq 0x33f5(%rip), %rsi      # 0xe9cc
movl $0x1, %edi
xorl %eax, %eax
callq 0x54c0
leaq 0x3411(%rip), %rsi      # 0xe9fb
movl $0x1, %edi
xorl %eax, %eax
callq 0x54c0
movq (%rdi), %rax
testq %rax, %rax
movq %rax, %rcx
cmoveq %r14, %rcx
movq 0x8(%rdi), %rdx
movq %rdx, 0x8(%rcx)
movq 0x8(%rdi), %rcx
movq %rax, (%rcx)
callq 0x61c8
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
jne 0xb5f6
addq $0x1858, %rsp           # imm = 0x1858
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq