// File: /workspace/github_c_makefile_star2_O1/jarun[P]nnn/src/nnn.c
// Function: get_output
static bool get_output(char *file, char *arg1, char *arg2, int fdout, bool page)
{
	pid_t pid;
	int pipefd[2];
	int index = 0, flags;
	bool ret = FALSE;
	bool have_file = fdout != -1;
	int cmd_in_fd = -1;
	int cmd_out_fd = -1;
	ssize_t len;

	/*
	 * In this case the logic of the function dictates that we should write the output of the command
	 * to `fd` and show it in the pager. But since we didn't open the file descriptor we have no right
	 * to close it, the caller must do it. We don't even know the path to pass to the pager and
	 * it's a real hassle to get it. In general this just invites problems so we are blocking it.
	 */
	if (have_file && page) {
		DPRINTF_S("invalid get_ouptput() call");
		return FALSE;
	}

	/* Setup file descriptors for child command */
	if (!have_file && page) {
		// Case 2
		fdout = create_tmp_file();
		if (fdout == -1)
			return FALSE;

		cmd_in_fd = STDIN_FILENO;
		cmd_out_fd = fdout;
	} else if (have_file) {
		// Case 3
		cmd_in_fd = STDIN_FILENO;
		cmd_out_fd = fdout;
	} else {
		// Case 1
		if (pipe(pipefd) == -1)
			errexit();

		for (index = 0; index < 2; ++index) {
			/* Get previous flags */
			flags = fcntl(pipefd[index], F_GETFL, 0);

			/* Set bit for non-blocking flag */
			flags |= O_NONBLOCK;

			/* Change flags on fd */
			fcntl(pipefd[index], F_SETFL, flags);
		}

		cmd_in_fd = pipefd[0];
		cmd_out_fd = pipefd[1];
	}

	pid = fork();
	if (pid == 0) {
		/* In child */
		close(cmd_in_fd);
		dup2(cmd_out_fd, STDOUT_FILENO);
		dup2(cmd_out_fd, STDERR_FILENO);
		close(cmd_out_fd);

		spawn(file, arg1, arg2, NULL, F_MULTI);
		_exit(EXIT_SUCCESS);
	}

	/* In parent */
	waitpid(pid, NULL, 0);

	/* Do what each case should do */
	if (!have_file && page) {
		// Case 2
		close(fdout);

		spawn(pager, g_tmpfpath, NULL, NULL, F_CLI | F_TTY);

		unlink(g_tmpfpath);
		return TRUE;
	}

	if (have_file)
		// Case 3
		return TRUE;

	// Case 1
	len = read(pipefd[0], g_buf, CMD_LEN_MAX - 1);
	if (len > 0)
		ret = TRUE;

	close(pipefd[0]);
	close(pipefd[1]);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %r12d
cmpl $-0x1, %ecx
setne %al
testb %r12b, %al
je 0x117eb
xorl %r13d, %r13d
jmp 0x1190c
movl %ecx, %ebp
movq %rdx, %r14
movq %rdi, %r15
movq %rsi, 0x10(%rsp)
cmpl $-0x1, %ecx
setne %al
xorb $0x1, %r12b
orb %al, %r12b
je 0x1186c
movq %r14, 0x8(%rsp)
xorl %r13d, %r13d
movl %ebp, %ebx
movl %ebp, %r14d
cmpl $-0x1, %ebp
jne 0x11887
movq %rsp, %rdi
callq 0x43e0
cmpl $-0x1, %eax
je 0x11969
xorl %ebx, %ebx
movl (%rsp,%rbx,4), %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x46c0
orl $0x800, %eax            # imm = 0x800
movl (%rsp,%rbx,4), %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x46c0
incq %rbx
cmpq $0x1, %rbx
je 0x1182c
movl (%rsp), %r13d
movl 0x4(%rsp), %r14d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x11887
callq 0xf5a4
xorl %r13d, %r13d
cmpl $-0x1, %eax
je 0x1190c
movl %eax, %ebx
movq %r14, 0x8(%rsp)
movl %eax, %r14d
callq 0x48c0
testl %eax, %eax
je 0x1191e
movl %eax, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4700
testb %r12b, %r12b
je 0x118da
movb $0x1, %r13b
cmpl $-0x1, %ebp
jne 0x1190c
movl (%rsp), %edi
leaq 0x8e9a(%rip), %rsi      # 0x1a750
movl $0x11ff, %edx           # imm = 0x11FF
callq 0x4460
testq %rax, %rax
setg %r13b
movl (%rsp), %edi
callq 0x43c0
movl 0x4(%rsp), %edi
callq 0x43c0
jmp 0x1190c
movl %ebx, %edi
callq 0x43c0
movq 0x8e08(%rip), %rdi      # 0x1a6f0
leaq 0x8e11(%rip), %rbx      # 0x1a700
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x109, %r8d            # imm = 0x109
callq 0xf5fc
movq %rbx, %rdi
callq 0x40d0
movb $0x1, %r13b
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, %edi
callq 0x43c0
movl %r14d, %edi
movl $0x1, %esi
callq 0x42f0
movl %r14d, %edi
movl $0x2, %esi
callq 0x42f0
movl %r14d, %edi
callq 0x43c0
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0xf5fc
xorl %edi, %edi
callq 0x4110
movl $0x127a, %edi           # imm = 0x127A
callq 0xff2e