// File: /workspace/github_c_makefile_star2_O2/jarun[P]nnn/src/nnn.c
// Function: run_plugin
static bool run_plugin(char **path, const char *file, char *runfile, char **lastname, char **lastdir)
{
	pid_t p;
	char ctx = 0;
	uchar_t flags = 0;
	bool cmd_as_plugin = FALSE;
	char *nextpath;

	if (!g_state.pluginit) {
		plctrl_init();
		g_state.pluginit = 1;
	}

	setexports(*path);

	/* Check for run-cmd-as-plugin mode */
	if (*file == '!') {
		flags = F_MULTI | F_CONFIRM;
		++file;

		if (*file == '|') { /* Check if output should be paged */
			flags |= F_PAGE;
			++file;
		} else if (*file == '&') { /* Check if GUI flags are to be used */
			flags = F_MULTI | F_NOTRACE | F_NOWAIT;
			++file;
		}

		if (!*file)
			return FALSE;

		if ((flags & F_NOTRACE) || (flags & F_PAGE)) {
			run_cmd_as_plugin(file, flags);
			return TRUE;
		}

		cmd_as_plugin = TRUE;
	}

	if (mkfifo(g_pipepath, 0600) != 0)
		return FALSE;

	exitcurses();

	p = fork();

	if (!p) { // In child
		int wfd = open(g_pipepath, O_WRONLY | O_CLOEXEC);

		if (wfd == -1)
			_exit(EXIT_FAILURE);

		/* Restore sigpipe handler to default */
		sigaction(SIGPIPE, &(struct sigaction){.sa_handler = SIG_DFL}, NULL);

		if (!cmd_as_plugin) {
			char *sel = NULL;
			char std[2] = "-";

			/* Generate absolute path to plugin */
			mkpath(plgpath, file, g_buf);

			if (g_state.picker)
				sel = selpath ? selpath : std;

			if (runfile && runfile[0]) {
				xstrsncpy(*lastname, runfile, NAME_MAX);
				spawn(g_buf, *lastname, *path, sel, 0);
			} else
				spawn(g_buf, NULL, *path, sel, 0);
		} else
			run_cmd_as_plugin(file, flags);

		close(wfd);
		_exit(EXIT_SUCCESS);
	}

	int rfd;

	do
		rfd = open(g_pipepath, O_RDONLY);
	while (rfd == -1 && errno == EINTR);

	nextpath = readpipe(rfd, &ctx, path);
	if (nextpath)
		set_smart_ctx(ctx, nextpath, path, runfile, lastname, lastdir);

	close(rfd);

	/* wait for the child to finish. no zombies allowed */
	waitpid(p, NULL, 0);

	refresh();

	unlink(g_pipepath);

	return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, (%rsp)
movq %rsi, %r13
movq %rdi, %rbx
testb $0x20, 0xa012(%rip)     # 0x19525
jne 0xf5a3
movzbl 0xa220(%rip), %eax      # 0x19740
leaq 0xa1d9(%rip), %rsi      # 0x19700
movb $0x0, -0x1(%rax,%rsi)
leaq 0xb60d(%rip), %r14      # 0x1ab40
pushq $0x40
popq %rbp
movq %r14, %rdi
movq %rbp, %rdx
callq 0x6016
movq %rax, %r15
movb $0x2f, -0x1(%rax,%r14)
leaq (%r14,%rax), %rdi
movq %rbp, %rdx
subq %rax, %rdx
leaq 0x4e67(%rip), %rsi      # 0x143c2
callq 0x6016
movq %rax, %r12
addq %r15, %r12
leaq (%r14,%r12), %r15
decq %r15
callq 0x4220
movl %eax, %edi
callq 0x5d9b
subq %r12, %rbp
movq %r15, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x6016
leaq 0x42a9(%rip), %rdi      # 0x1383a
pushq $0x1
popq %rdx
movq %r14, %rsi
callq 0x4200
orb $0x20, 0x9f82(%rip)     # 0x19525
movq (%rbx), %rdi
callq 0x1185c
movb (%r13), %r15b
cmpb $0x21, %r15b
jne 0xf614
leaq 0x1(%r13), %rdi
movb 0x1(%r13), %al
leaq 0x2(%r13), %rcx
cmpb $0x26, %al
sete %dl
pushq $0x7
popq %rsi
pushq $0x11
popq %r8
cmovel %esi, %r8d
cmpb $0x7c, %al
movl $0x91, %r12d
cmovnel %r8d, %r12d
sete %sil
orb %dl, %sil
movzbl %sil, %edx
testb %dl, %dl
cmovneq %rcx, %rdi
cmpb $0x0, 0x1(%rdx,%r13)
je 0xf631
cmpb $0x7c, %al
setne %al
testb $0x4, %r12b
sete %cl
testb %cl, %al
jne 0xf619
movzbl %r12b, %esi
callq 0x11a0d
jmp 0xf7f2
xorl %r12d, %r12d
jmp 0xf61c
movq %rdi, %r13
leaq 0xb51d(%rip), %rdi      # 0x1ab40
movl $0x180, %esi            # imm = 0x180
callq 0x4510
testl %eax, %eax
je 0xf638
xorl %eax, %eax
jmp 0xf7f4
callq 0x4890
callq 0x48c0
testl %eax, %eax
je 0xf806
movl %eax, %ebp
leaq 0xb4ed(%rip), %r14      # 0x1ab40
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x46b0
movl %eax, %r13d
cmpl $-0x1, %eax
jne 0xf671
callq 0x40c0
cmpl $0x4, (%rax)
je 0xf653
pushq $0x1
popq %rsi
movl %r13d, %edi
callq 0x11a92
cmpq $0x1, %rax
jne 0xf7c4
movb 0xa0c3(%rip), %r14b     # 0x19750
cmpb $0x2d, %r14b
jne 0xf6b4
callq 0x10015
pushq $0x1
popq %rsi
movl %r13d, %edi
callq 0x11a92
cmpq $0x1, %rax
jne 0xf7c4
movb 0xa09c(%rip), %r14b     # 0x19750
cmpb $0x2b, %r14b
jne 0xf6c7
callq 0x11ad3
movl %eax, %r14d
incb %r14b
jmp 0xf6d7
leal -0x35(%r14), %eax
cmpb $-0x5, %al
jb 0xf7c4
addb $-0x30, %r14b
pushq $0x1
popq %rsi
movl %r13d, %edi
callq 0x11a92
cmpq $0x1, %rax
jne 0xf7c4
movzbl 0xa05d(%rip), %eax      # 0x19750
cmpl $0x70, %eax
je 0xf795
cmpl $0x6c, %eax
je 0xf75e
cmpl $0x63, %eax
jne 0xf7c4
movl $0x1000, %esi           # imm = 0x1000
movl %r13d, %edi
callq 0x11a92
testq %rax, %rax
jle 0xf7c4
leaq 0xa029(%rip), %r15      # 0x19750
movb $0x0, (%rax,%r15)
cmpb $0x2f, 0xa01d(%rip)     # 0x19750
jne 0xf7c4
movq %r15, %rdi
callq 0x5d70
decq %rax
movq %rax, %rcx
subq $0x1, %rcx
jb 0xf776
cmpb $0x2f, (%rax,%r15)
jne 0xf776
movb $0x0, (%rax,%r15)
movq %rcx, %rax
jmp 0xf747
callq 0xd3ff
movq (%rbx), %rsi
movl %r13d, %edi
callq 0x6185
movq %rax, %r15
testq %rax, %rax
je 0xf7c4
movsbl %r14b, %edi
movq %r15, %rsi
movq %rbx, %rdx
movq (%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r9
callq 0xfb9d
jmp 0xf7c4
movq 0x9d8c(%rip), %rdi      # 0x19528
callq 0x4090
andq $0x0, 0x9d7f(%rip)      # 0x19528
callq 0x10015
movl $0xffffe7ff, %eax       # imm = 0xFFFFE7FF
andl 0x9d6b(%rip), %eax      # 0x19524
orl $0x800, %eax            # imm = 0x800
movl %eax, 0x9d60(%rip)      # 0x19524
movl %r13d, %edi
callq 0x43c0
movl %ebp, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4700
movq 0x97b2(%rip), %rax      # 0x18f90
movq (%rax), %rdi
callq 0x4440
leaq 0xb353(%rip), %rdi      # 0x1ab40
callq 0x40d0
movb $0x1, %al
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb333(%rip), %rdi      # 0x1ab40
movl $0x80001, %esi          # imm = 0x80001
xorl %eax, %eax
callq 0x46b0
cmpl $-0x1, %eax
jne 0xf826
pushq $0x1
popq %rdi
callq 0x4110
movl %eax, %ebp
leaq 0x20(%rsp), %r14
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x4380
pushq $0xd
popq %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4170
cmpb $0x21, %r15b
jne 0xf85d
movzbl %r12b, %esi
movq %r13, %rdi
callq 0x11a0d
jmp 0xf8db
leaq 0xe(%rsp), %r15
movw $0x2d, (%r15)
movq 0xb231(%rip), %rdi      # 0x1aaa0
leaq 0x9eda(%rip), %rdx      # 0x19750
movq %r13, %rsi
callq 0x6a9f
movq 0x9ca3(%rip), %r14      # 0x19528
testq %r14, %r14
cmoveq %r15, %r14
xorl %esi, %esi
testb $0x10, 0x9c90(%rip)     # 0x19525
cmoveq %rsi, %r14
cmpq $0x0, (%rsp)
je 0xf8c6
movq (%rsp), %rax
cmpb $0x0, (%rax)
jne 0xf8ad
xorl %esi, %esi
jmp 0xf8c6
movq 0x10(%rsp), %r15
movq (%r15), %rdi
movl $0xff, %edx
movq (%rsp), %rsi
callq 0x6016
movq (%r15), %rsi
movq (%rbx), %rdx
leaq 0x9e80(%rip), %rdi      # 0x19750
movq %r14, %rcx
xorl %r8d, %r8d
callq 0xdcb4
movl %ebp, %edi
callq 0x43c0
xorl %edi, %edi
callq 0x4110