// File: /workspace/github_c_makefile_star2_O3/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 $0xc8, %rsp
movq %r8, 0x10(%rsp)
movq %rcx, %r12
movq %rdx, 0x18(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
movb $0x0, 0xf(%rsp)
testb $0x20, 0x95ef(%rip)     # 0x1a525
jne 0x11033
movq %rbx, 0x28(%rsp)
movq %r12, %rbx
movzbl 0x97f5(%rip), %eax      # 0x1a740
leaq 0x97ae(%rip), %rsi      # 0x1a700
movb $0x0, -0x1(%rax,%rsi)
leaq 0xabe2(%rip), %rbp      # 0x1bb40
movl $0x40, %r14d
movl $0x40, %ecx
movq %rbp, %rdi
xorl %edx, %edx
callq 0x4860
movq %rax, %r15
testq %rax, %rax
jne 0x10f89
movb $0x0, 0xabfd(%rip)      # 0x1bb7f
leaq 0xabf7(%rip), %r15      # 0x1bb80
movq %r15, %r12
subq %rbp, %r12
movb $0x2f, -0x1(%r15)
subq %r12, %r14
leaq 0x5440(%rip), %rsi      # 0x163de
movq %r15, %rdi
xorl %edx, %edx
movq %r14, %rcx
callq 0x4860
movq %rax, %r14
testq %rax, %rax
jne 0x10fc7
leaq 0xabc6(%rip), %r14      # 0x1bb80
cmpq $0x40, %r12
je 0x10fc7
movb $0x0, 0xabb8(%rip)      # 0x1bb7f
subq %r15, %r14
addq %r12, %r14
leaq (%r14,%rbp), %r15
decq %r15
callq 0x4220
movl %eax, %edi
callq 0x5f73
subq $0x40, %r14
sete %bpl
negq %r14
movq %r15, %rdi
movq %rax, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x4860
testq %rax, %rax
setne %al
orb %bpl, %al
jne 0x1100c
movb $0x0, -0x1(%r15,%r14)
leaq 0x4843(%rip), %rdi      # 0x15856
leaq 0xab26(%rip), %rsi      # 0x1bb40
movl $0x1, %edx
callq 0x4200
orb $0x20, 0x94fa(%rip)     # 0x1a525
movq %rbx, %r12
movq 0x28(%rsp), %rbx
movq (%rbx), %rdi
callq 0x13652
movb (%r13), %r15b
cmpb $0x21, %r15b
jne 0x110a8
leaq 0x1(%r13), %rdi
movb 0x1(%r13), %al
leaq 0x2(%r13), %rcx
cmpb $0x26, %al
sete %dl
movl $0x7, %esi
movl $0x11, %r8d
cmovel %esi, %r8d
cmpb $0x7c, %al
movl $0x91, %r14d
cmovnel %r8d, %r14d
sete %sil
orb %dl, %sil
movzbl %sil, %edx
testb %dl, %dl
cmovneq %rcx, %rdi
cmpb $0x0, 0x1(%rdx,%r13)
je 0x110c5
cmpb $0x7c, %al
setne %al
testb $0x4, %r14b
sete %cl
testb %cl, %al
jne 0x110ad
movzbl %r14b, %esi
callq 0x1382c
jmp 0x1116c
xorl %r14d, %r14d
jmp 0x110b0
movq %rdi, %r13
leaq 0xaa89(%rip), %rdi      # 0x1bb40
movl $0x180, %esi            # imm = 0x180
callq 0x4510
testl %eax, %eax
je 0x110cc
xorl %eax, %eax
jmp 0x1116e
callq 0x4890
callq 0x48c0
testl %eax, %eax
je 0x11180
movl %eax, %ebp
leaq 0xaa59(%rip), %r15      # 0x1bb40
movq %r15, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x46b0
movl %eax, %r14d
cmpl $-0x1, %eax
jne 0x1110c
callq 0x40c0
cmpl $0x4, (%rax)
je 0x110e7
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
jmp 0x1110f
movl %r14d, %edi
leaq 0xf(%rsp), %rsi
movq %rbx, %rdx
callq 0x138c8
testq %rax, %rax
je 0x1113e
movsbl 0xf(%rsp), %edi
movq %rax, %rsi
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
movq %r12, %r8
movq 0x10(%rsp), %r9
callq 0x116a6
movl %r14d, %edi
callq 0x43c0
movl %ebp, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4700
movq 0x8e38(%rip), %rax      # 0x19f90
movq (%rax), %rdi
callq 0x4440
leaq 0xa9d9(%rip), %rdi      # 0x1bb40
callq 0x40d0
movb $0x1, %al
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, 0x10(%rsp)
leaq 0xa9b4(%rip), %rdi      # 0x1bb40
movl $0x80001, %esi          # imm = 0x80001
xorl %eax, %eax
callq 0x46b0
cmpl $-0x1, %eax
jne 0x111a7
movl $0x1, %edi
callq 0x4110
movl %eax, %ebp
leaq 0x30(%rsp), %r12
movl $0x98, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x4380
movl $0xd, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x4170
cmpb $0x21, %r15b
jne 0x111e3
movzbl %r14b, %esi
movq %r13, %rdi
callq 0x1382c
jmp 0x1127b
leaq 0x26(%rsp), %r15
movw $0x2d, (%r15)
movq 0xa8ab(%rip), %rdi      # 0x1baa0
leaq 0x9554(%rip), %rdx      # 0x1a750
movq %r13, %rsi
callq 0x6d5c
movq 0x931d(%rip), %r14      # 0x1a528
testq %r14, %r14
cmoveq %r15, %r14
xorl %esi, %esi
testb $0x10, 0x930a(%rip)     # 0x1a525
cmoveq %rsi, %r14
cmpq $0x0, 0x18(%rsp)
je 0x11266
movq 0x18(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x11235
xorl %esi, %esi
jmp 0x11266
movq 0x10(%rsp), %rax
movq (%rax), %r15
movl $0xff, %ecx
movq %r15, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x4860
testq %rax, %rax
jne 0x1125e
movb $0x0, 0xfe(%r15)
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movq (%rbx), %rdx
leaq 0x94e0(%rip), %rdi      # 0x1a750
movq %r14, %rcx
xorl %r8d, %r8d
callq 0xf3d1
movl %ebp, %edi
callq 0x43c0
xorl %edi, %edi
callq 0x4110