// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1890, %rsp           # imm = 0x1890
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1874(%rbp)
movl -0x1874(%rbp), %eax
movl %eax, -0x1878(%rbp)
subl $0x1, %eax
je 0xf27b
jmp 0xf26e
movl -0x1878(%rbp), %eax
subl $0x2, %eax
je 0xf28b
jmp 0xf29b
leaq 0x52f7(%rip), %rax      # 0x14579
movq %rax, -0x838(%rbp)
jmp 0xf2b4
leaq 0x52f6(%rip), %rax      # 0x14588
movq %rax, -0x838(%rbp)
jmp 0xf2b4
movl -0x1874(%rbp), %edx
movl $0x1, %edi
leaq 0x57fb(%rip), %rsi      # 0x14aa8
movb $0x0, %al
callq 0x54b0
jmp 0xf2b6
movq $0x0, -0x1868(%rbp)
leaq -0x1868(%rbp), %rax
movq %rax, -0x1860(%rbp)
leaq 0x57ee(%rip), %rdi      # 0x14ac4
callq 0x5550
movq %rax, -0x828(%rbp)
cmpq $0x0, %rax
jne 0xf2f6
leaq 0x57da(%rip), %rax      # 0x14ac9
movq %rax, -0x828(%rbp)
movq -0x828(%rbp), %rdi
callq 0x64d0
movq %rax, -0x828(%rbp)
movq %rax, -0x830(%rbp)
leaq -0x820(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x820(%rbp), %rdx
addq $0x7f8, %rdx            # imm = 0x7F8
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x1879(%rbp)
jae 0xf361
leaq -0x830(%rbp), %rdi
leaq 0x4cd1(%rip), %rsi      # 0x14019
callq 0x5780
movq -0x20(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
setne %al
movb %al, -0x1879(%rbp)
movb -0x1879(%rbp), %al
testb $0x1, %al
jne 0xf36d
jmp 0xf38a
movq -0x20(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xf388
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
jmp 0xf31b
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x1870(%rbp)
xorl %eax, %eax
cmpl $0x100, -0x1870(%rbp)   # imm = 0x100
movb %al, -0x187a(%rbp)
jge 0xf3cc
movslq -0x1870(%rbp), %rax
cmpq $0x0, -0x820(%rbp,%rax,8)
setne %al
movb %al, -0x187a(%rbp)
movb -0x187a(%rbp), %al
testb $0x1, %al
jne 0xf3db
jmp 0xf55b
movslq -0x1870(%rbp), %rax
movq -0x820(%rbp,%rax,8), %rdi
callq 0x5360
movq %rax, -0x1848(%rbp)
cmpq $0x0, %rax
jne 0xf401
jmp 0xf547
jmp 0xf403
movq -0x1848(%rbp), %rdi
callq 0x53e0
movq %rax, -0x1850(%rbp)
cmpq $0x0, %rax
je 0xf53b
movq -0x1850(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x8, %eax
je 0xf442
movq -0x1850(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0xa, %eax
je 0xf442
jmp 0xf403
leaq -0x1840(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x5090
leaq -0x1840(%rbp), %rdi
movslq -0x1870(%rbp), %rax
movq -0x820(%rbp,%rax,8), %rcx
movq -0x1850(%rbp), %r8
addq $0x13, %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x5054(%rip), %rdx      # 0x144d6
movb $0x0, %al
callq 0x50b0
movl %eax, -0x186c(%rbp)
cmpl $-0x1, -0x186c(%rbp)
je 0xf4a4
cmpl $0x1000, -0x186c(%rbp)  # imm = 0x1000
jl 0xf4a9
jmp 0xf403
leaq -0x1840(%rbp), %rdi
movl $0x1, %esi
callq 0x5790
cmpl $0x0, %eax
jne 0xf536
movl $0x1, %edi
movl $0x98, %esi
callq 0x6460
movq %rax, -0x1858(%rbp)
movq -0x1858(%rbp), %rdi
addq $0x20, %rdi
movq -0x1850(%rbp), %rsi
addq $0x13, %rsi
movl $0x33, %edx
callq 0x12ce0
movq -0x1858(%rbp), %rax
movq $0x0, (%rax)
movq -0x1860(%rbp), %rcx
movq -0x1858(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x1858(%rbp), %rcx
movq -0x1860(%rbp), %rax
movq %rcx, (%rax)
movq -0x1858(%rbp), %rax
movq %rax, -0x1860(%rbp)
jmp 0xf536
jmp 0xf403
movq -0x1848(%rbp), %rdi
callq 0x5720
movl -0x1870(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1870(%rbp)
jmp 0xf39f
movq -0x828(%rbp), %rdi
callq 0x64b0
movq -0x18(%rbp), %rdi
movq -0x838(%rbp), %rdx
leaq -0x1868(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movl $0x1, %r8d
leaq -0x4e9a(%rip), %r9      # 0xa6f0
movq $0x0, (%rsp)
callq 0x8a30
movq %rax, -0x1858(%rbp)
cmpq $0x0, %rax
je 0xf62c
movq -0x1858(%rbp), %rax
movsbl 0x20(%rax), %eax
cmpl $0x0, %eax
jne 0xf5ba
jmp 0xf62e
movl -0x1874(%rbp), %eax
movl %eax, -0x1880(%rbp)
subl $0x1, %eax
je 0xf5da
jmp 0xf5cd
movl -0x1880(%rbp), %eax
subl $0x2, %eax
je 0xf5ec
jmp 0xf617
movq -0x1858(%rbp), %rdi
addq $0x20, %rdi
callq 0xa850
jmp 0xf62a
movq -0x1858(%rbp), %rdi
addq $0x20, %rdi
callq 0xa8b0
movq -0x1858(%rbp), %rsi
addq $0x20, %rsi
leaq 0x541e(%rip), %rdi      # 0x14a2c
movb $0x0, %al
callq 0x5870
jmp 0xf62a
movl $0x1, %edi
leaq 0x54b4(%rip), %rsi      # 0x14ad7
movb $0x0, %al
callq 0x54b0
jmp 0xf62c
jmp 0xf62e
cmpq $0x0, -0x1858(%rbp)
je 0xf657
movq -0x1858(%rbp), %rax
movswl 0x90(%rax), %eax
cmpl $0x0, %eax
je 0xf657
movq -0x1858(%rbp), %rdi
callq 0x64b0
jmp 0xf659
movq -0x1868(%rbp), %rax
movq %rax, -0x1858(%rbp)
cmpq $0x0, %rax
je 0xf6cf
jmp 0xf66f
movq -0x1858(%rbp), %rax
cmpq $0x0, (%rax)
je 0xf697
movq -0x1858(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x1858(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
jmp 0xf6a9
movq -0x1858(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1860(%rbp)
movq -0x1858(%rbp), %rax
movq (%rax), %rcx
movq -0x1858(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x1858(%rbp), %rdi
callq 0x64b0
jmp 0xf659
addq $0x1890, %rsp           # imm = 0x1890
popq %rbp
retq
nopl (%rax,%rax)