// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movl $0x0, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movl $0xffff, %r14d          # imm = 0xFFFF
testq %rdi, %rdi
je 0xf711
movq %rdi, %r13
cmpb $0x0, (%rdi)
je 0xf711
movl %r8d, %ebx
movq %rcx, %r15
movq %rsi, %r12
testq %rsi, %rsi
sete %al
testq %rdx, %rdx
setne %cl
xorl %esi, %esi
testb %cl, %al
cmoveq %r15, %rsi
cmoveq %rdx, %r15
cmovneq %rdx, %r12
movzwl %bx, %eax
movl %eax, 0xc(%rsp)
testb $0x1, %al
jne 0xf537
movq %r13, 0x20(%rsp)
movl $0x1, %eax
xorl %r13d, %r13d
cltq
movq %r12, 0x20(%rsp,%rax,8)
movq %r15, 0x28(%rsp,%rax,8)
leal 0x2(%rax), %ecx
movl %ecx, 0x10(%rsp)
movq %rsi, 0x30(%rsp,%rax,8)
movl 0xc(%rsp), %ebp
testb $0x8, %bpl
je 0xf489
callq 0x4890
callq 0x48c0
movl %eax, %r14d
testl %eax, %eax
jle 0xf5df
movl %ebx, %r12d
leaq 0x78(%rsp), %rbx
movl $0x90, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4380
movl $0x1, %r15d
movq %r15, -0x8(%rbx)
leaq 0x14c0f(%rip), %rdx     # 0x240d0
leaq 0x70(%rsp), %rsi
movl $0x1, %edi
callq 0x4170
leaq 0x1a0(%rsp), %rbx
movl $0x98, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4380
leaq 0x14c7a(%rip), %rdx     # 0x24168
movl $0x14, %edi
movq %rbx, %rsi
callq 0x4170
leaq 0x110(%rsp), %rbx
movl $0x90, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4380
movq %r15, -0x8(%rbx)
movl %r12d, %ebx
leaq 0x14ce0(%rip), %rdx     # 0x24200
leaq 0x108(%rsp), %rsi
movl $0x1c, %edi
callq 0x4170
jmp 0xf5ef
movq %rsi, 0x18(%rsp)
movl %ebx, 0x14(%rsp)
movq %r13, %rdi
xorl %esi, %esi
callq 0x4490
movq %rax, %rbx
subq %r13, %rbx
incq %rbx
movq %rbx, %rdi
callq 0x45c0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0xf711
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x4860
testq %rbx, %rbx
movq %rbp, %r13
je 0xf590
testq %rax, %rax
jne 0xf590
movb $0x0, -0x1(%r13,%rbx)
movq %r13, 0x20(%rsp)
movl $0x1, %eax
movq %r13, %rcx
movl 0x14(%rsp), %ebx
movzbl (%rcx), %edx
cmpl $0x9, %edx
je 0xf5b7
cmpl $0x20, %edx
je 0xf5b7
testl %edx, %edx
jne 0xf5da
jmp 0xf6f9
movb $0x0, (%rcx)
cmpb $0x0, 0x1(%rcx)
je 0xf6f9
incq %rcx
movslq %eax, %rdx
incl %eax
movq %rcx, 0x20(%rsp,%rdx,8)
cmpl $0xa, %eax
je 0xf709
incq %rcx
jmp 0xf5a1
jne 0xf5ef
testb $0x2, %bl
jne 0xf741
callq 0xf87d
testb $0x2, %bl
je 0xf600
movl %r14d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4700
cmpl $-0x1, %r14d
je 0xf730
testl %r14d, %r14d
je 0xf762
movl $0xffff, 0x70(%rsp)     # imm = 0xFFFF
testb $0x2, %bl
jne 0xf646
leaq 0x70(%rsp), %rbx
movl %r14d, %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4700
cmpl $-0x1, %eax
je 0xf625
movl 0x70(%rsp), %eax
testb $0x7f, %al
jne 0xf646
movzbl %ah, %eax
movl %eax, 0x70(%rsp)
leaq 0x14a83(%rip), %rsi     # 0x240d0
movl $0x1, %edi
xorl %edx, %edx
callq 0x4170
leaq 0x14b08(%rip), %rsi     # 0x24168
movl $0x14, %edi
xorl %edx, %edx
callq 0x4170
leaq 0x14b8d(%rip), %rsi     # 0x24200
movl $0x1c, %edi
xorl %edx, %edx
callq 0x4170
movl 0x70(%rsp), %r14d
testb $0x10, %bpl
jne 0xf69c
movl %ebp, %eax
shrb $0x5, %al
testl %r14d, %r14d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xf6e2
leaq 0x6986(%rip), %rbx      # 0x16029
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4490
subq %rbx, %rax
movl $0x1, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x4210
leaq 0x10(%rsp), %rbx
movl %eax, (%rbx)
movl $0x1, %edx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x4460
testq %rax, %rax
jle 0xf6e2
cmpl $0xa, 0x10(%rsp)
jne 0xf6c7
testb $0x8, %bpl
je 0xf709
movq 0xa8a1(%rip), %rax      # 0x19f90
movq (%rax), %rdi
callq 0x4440
jmp 0xf709
cmpl $-0x1, %eax
setne %cl
cmpl $0x7, %eax
setl %dl
testb %dl, %cl
jne 0xf726
movq %r13, %rdi
callq 0x4090
movl %r14d, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %rsi
jmp 0xf462
leaq 0x6b8f(%rip), %rdi      # 0x162c6
callq 0x4740
jmp 0xf613
callq 0x48c0
testl %eax, %eax
jg 0xf7f1
jne 0xf7f8
callq 0xf87d
callq 0x43f0
movl 0xc(%rsp), %ebp
testb $0x4, %bpl
jne 0xf7b0
btl $0x8, 0xc(%rsp)
jae 0xf7e4
movl $0x1, %edi
callq 0x4160
testl %eax, %eax
jne 0xf7e4
xorl %edi, %edi
callq 0x4720
movq %rax, %rdi
movl $0x1, %esi
movl $0x80, %edx
xorl %eax, %eax
callq 0x46b0
movl %eax, %ebx
movl %eax, %edi
movl $0x1, %esi
callq 0x42f0
movl %ebx, %edi
callq 0x43c0
jmp 0xf7e4
testb $0x40, 0xc(%rsp)
je 0xf7c4
movl 0xacff(%rip), %edi      # 0x1a4bc
xorl %esi, %esi
callq 0x42f0
movl 0xacf2(%rip), %edi      # 0x1a4bc
movl $0x1, %esi
callq 0x42f0
movl 0xace2(%rip), %edi      # 0x1a4bc
movl $0x2, %esi
callq 0x42f0
leaq 0x20(%rsp), %rsi
movq (%rsi), %rdi
callq 0x4780
xorl %edi, %edi
callq 0x4110
callq 0x4c00