// File: /workspace/github_c_makefile_star2_O0/jarun[P]nnn/src/nnn.c
// Function: spawn
static int spawn(char *file, char *arg1, char *arg2, char *arg3, ushort_t flag)
{
	pid_t pid;
	int status = 0, retstatus = 0xFFFF;
	char *argv[EXEC_ARGS_MAX] = {0};
	char *cmd = NULL;

	if (!file || !*file)
		return retstatus;

	/* Swap args if the first arg is NULL and the other 2 aren't */
	if (!arg1 && arg2) {
		arg1 = arg2;
		if (arg3) {
			arg2 = arg3;
			arg3 = NULL;
		} else
			arg2 = NULL;
	}

	if (flag & F_MULTI) {
		cmd = parseargs(file, argv, &status);
		if (!cmd)
			return -1;
	} else
		argv[status++] = file;

	argv[status] = arg1;
	argv[++status] = arg2;
	argv[++status] = arg3;

	if (flag & F_NORMAL)
		exitcurses();

	pid = xfork(flag);
	if (pid == 0) {
		/* Suppress stdout and stderr */
		if (flag & F_NOTRACE) {
			if (flag & F_NOSTDIN)
				dup2(devnullfd, STDIN_FILENO); // NOLINT
			dup2(devnullfd, STDOUT_FILENO); // NOLINT
			dup2(devnullfd, STDERR_FILENO); // NOLINT
		} else if (flag & F_TTY) {
			/* If stdout has been redirected to a non-tty, force output to tty */
			if (!isatty(STDOUT_FILENO)) {
				int fd = open(ctermid(NULL), O_WRONLY, 0200);
				dup2(fd, STDOUT_FILENO);
				close(fd);
			}
		}

		execvp(*argv, argv);
		_exit(EXIT_SUCCESS);
	} else {
		retstatus = join(pid, flag);
		DPRINTF_D(pid);

		if ((flag & F_CONFIRM) || ((flag & F_CHKRTN) && retstatus)) {
			status = write(STDOUT_FILENO, messages[MSG_ENTER], xstrlen(messages[MSG_ENTER]));
			(void)status;
			while ((read(STDIN_FILENO, &status, 1) > 0) && (status != '\n'));
		}

		if (flag & F_NORMAL)
			refresh();

		free(cmd);
	}

	return retstatus;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movw %r8w, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movw %ax, -0x2a(%rbp)
movl $0x0, -0x34(%rbp)
movl $0xffff, -0x38(%rbp)    # imm = 0xFFFF
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x4380
movq $0x0, -0x98(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xde8f
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
jne 0xde9a
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe11f
cmpq $0x0, -0x18(%rbp)
jne 0xded3
cmpq $0x0, -0x20(%rbp)
je 0xded3
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xdec9
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
jmp 0xded1
movq $0x0, -0x20(%rbp)
jmp 0xded3
movzwl -0x2a(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xdf12
movq -0x10(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x34(%rbp), %rdx
callq 0xe1d0
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
jne 0xdf10
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe11f
jmp 0xdf2b
movq -0x10(%rbp), %rcx
movl -0x34(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x34(%rbp)
cltq
movq %rcx, -0x90(%rbp,%rax,8)
movq -0x18(%rbp), %rcx
movslq -0x34(%rbp), %rax
movq %rcx, -0x90(%rbp,%rax,8)
movq -0x20(%rbp), %rcx
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
cltq
movq %rcx, -0x90(%rbp,%rax,8)
movq -0x28(%rbp), %rcx
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
cltq
movq %rcx, -0x90(%rbp,%rax,8)
movzwl -0x2a(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xdf7a
callq 0x4890
movw -0x2a(%rbp), %ax
movzbl %al, %edi
callq 0xe300
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0xe053
movzwl -0x2a(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xdfda
movzwl -0x2a(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0xdfb8
movl 0x12513(%rip), %edi     # 0x204c4
xorl %esi, %esi
callq 0x42f0
movl 0x12506(%rip), %edi     # 0x204c4
movl $0x1, %esi
callq 0x42f0
movl 0x124f6(%rip), %edi     # 0x204c4
movl $0x2, %esi
callq 0x42f0
jmp 0xe039
movzwl -0x2a(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0xe037
movl $0x1, %edi
callq 0x4160
cmpl $0x0, %eax
jne 0xe035
xorl %eax, %eax
movl %eax, %edi
callq 0x4730
movq %rax, %rdi
movl $0x1, %esi
movl $0x80, %edx
movb $0x0, %al
callq 0x46c0
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %edi
movl $0x1, %esi
callq 0x42f0
movl -0x9c(%rbp), %edi
callq 0x43c0
jmp 0xe037
jmp 0xe039
movq -0x90(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x4790
xorl %edi, %edi
callq 0x4110
movl -0x30(%rbp), %edi
movw -0x2a(%rbp), %ax
movzbl %al, %esi
callq 0xe460
movl %eax, -0x38(%rbp)
movzwl -0x2a(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0xe083
movzwl -0x2a(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xe0f2
cmpl $0x0, -0x38(%rbp)
je 0xe0f2
movq 0x11a86(%rip), %rax     # 0x1fb10
movq %rax, -0xa8(%rbp)
movq 0x11a78(%rip), %rdi     # 0x1fb10
callq 0x5cc0
movq -0xa8(%rbp), %rsi
movq %rax, %rdx
movl $0x1, %edi
callq 0x4210
movl %eax, -0x34(%rbp)
xorl %edi, %edi
leaq -0x34(%rbp), %rsi
movl $0x1, %edx
callq 0x4460
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0xa9(%rbp)
jle 0xe0e2
cmpl $0xa, -0x34(%rbp)
setne %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0xe0ee
jmp 0xe0f0
jmp 0xe0b4
jmp 0xe0f2
movzwl -0x2a(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xe10d
movq 0x11e8b(%rip), %rax     # 0x1ff90
movq (%rax), %rdi
callq 0x4440
movq -0x98(%rbp), %rdi
callq 0x4090
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax,%rax)