// File: /workspace/github_c_makefile_star2_O1/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 $0x228, %rsp            # imm = 0x228
movl $0x0, (%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0xffff, %r12d          # imm = 0xFFFF
testq %rdi, %rdi
je 0xf947
movq %rdi, %r13
cmpb $0x0, (%rdi)
je 0xf947
movl %r8d, %ebp
movq %rcx, %r14
movq %rsi, %r15
testq %rsi, %rsi
sete %al
testq %rdx, %rdx
setne %cl
xorl %ebx, %ebx
testb %cl, %al
cmoveq %r14, %rbx
cmoveq %rdx, %r14
cmovneq %rdx, %r15
movzwl %bp, %eax
movl %eax, 0x4(%rsp)
testb $0x1, %al
jne 0xf693
movl $0x1, (%rsp)
movq %r13, 0x10(%rsp)
xorl %edi, %edi
movl 0x4(%rsp), %r13d
jmp 0xf75e
movq %r13, %rdi
xorl %esi, %esi
callq 0x4490
movq %rax, %r12
subq %r13, %r12
incq %r12
movq %r12, %rdi
callq 0x45c0
testq %rax, %rax
je 0xf729
movl %ebp, 0x8(%rsp)
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x4860
movq %rbp, %rdi
testq %r12, %r12
je 0xf6dd
testq %rax, %rax
jne 0xf6dd
movb $0x0, -0x1(%rdi,%r12)
movq %rdi, 0x10(%rsp)
movl $0x1, %r12d
movq %rdi, %rax
movl 0x4(%rsp), %r13d
movl 0x8(%rsp), %ebp
movzbl (%rax), %ecx
cmpl $0x9, %ecx
je 0xf707
cmpl $0x20, %ecx
je 0xf707
testl %ecx, %ecx
jne 0xf724
jmp 0xf738
movb $0x0, (%rax)
cmpb $0x0, 0x1(%rax)
je 0xf738
incq %rax
movslq %r12d, %rcx
incl %r12d
movq %rax, 0x10(%rsp,%rcx,8)
cmpl $0xa, %r12d
je 0xf732
incq %rax
jmp 0xf6f4
xorl %edi, %edi
movl 0x4(%rsp), %r13d
jmp 0xf755
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $-0x1, %r12d
setne %al
cmpl $0x7, %r12d
setl %cl
testb %cl, %al
jne 0xf751
callq 0x4090
xorl %edi, %edi
movl %r12d, (%rsp)
testq %rdi, %rdi
je 0xf95c
movq %rdi, 0x8(%rsp)
movslq (%rsp), %rax
movq %r15, 0x10(%rsp,%rax,8)
movq %r14, 0x18(%rsp,%rax,8)
leaq 0x2(%rax), %rcx
movl %ecx, (%rsp)
movq %rbx, 0x20(%rsp,%rax,8)
testb $0x8, %r13b
je 0xf788
callq 0x4890
callq 0x48c0
movl %eax, %r14d
testl %eax, %eax
jle 0xf823
leaq 0x60(%rsp), %r15
movl $0x98, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x4380
movl $0x1, %ebx
movq %rbx, (%r15)
leaq 0x14915(%rip), %rdx     # 0x240d0
movl $0x1, %edi
movq %r15, %rsi
callq 0x4170
leaq 0x190(%rsp), %r15
movl $0x98, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x4380
leaq 0x14982(%rip), %rdx     # 0x24168
movl $0x14, %edi
movq %r15, %rsi
callq 0x4170
leaq 0xf8(%rsp), %r15
movl $0x98, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x4380
movq %rbx, (%r15)
leaq 0x149ec(%rip), %rdx     # 0x24200
movl $0x1c, %edi
movq %r15, %rsi
callq 0x4170
jmp 0xf834
jne 0xf834
testb $0x2, %bpl
jne 0xf964
callq 0xfab5
testb $0x2, %bpl
je 0xf846
movl %r14d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4700
cmpl $-0x1, %r14d
je 0xf989
testl %r14d, %r14d
je 0xf99a
movl $0xffff, 0x60(%rsp)     # imm = 0xFFFF
testb $0x2, %bpl
jne 0xf88d
leaq 0x60(%rsp), %r15
movl %r14d, %edi
movq %r15, %rsi
xorl %edx, %edx
callq 0x4700
cmpl $-0x1, %eax
je 0xf86c
movl 0x60(%rsp), %eax
testb $0x7f, %al
jne 0xf88d
movzbl %ah, %eax
movl %eax, 0x60(%rsp)
leaq 0x1483c(%rip), %rsi     # 0x240d0
movl $0x1, %edi
xorl %edx, %edx
callq 0x4170
leaq 0x148c1(%rip), %rsi     # 0x24168
movl $0x14, %edi
xorl %edx, %edx
callq 0x4170
leaq 0x14946(%rip), %rsi     # 0x24200
movl $0x1c, %edi
xorl %edx, %edx
callq 0x4170
movl 0x60(%rsp), %r12d
testb $0x10, %r13b
jne 0xf8e4
movl %r13d, %eax
shrb $0x5, %al
testl %r12d, %r12d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xf928
leaq 0x6724(%rip), %r14      # 0x1600f
movq %r14, %rdi
xorl %esi, %esi
callq 0x4490
subq %r14, %rax
movl $0x1, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x4210
movq %rsp, %r14
movl %eax, (%r14)
movl $0x1, %edx
xorl %edi, %edi
movq %r14, %rsi
callq 0x4460
testq %rax, %rax
jle 0xf928
cmpl $0xa, (%rsp)
jne 0xf90e
testb $0x8, %r13b
je 0xf93d
movq 0xa65b(%rip), %rax      # 0x19f90
movq (%rax), %rdi
callq 0x4440
movq 0x8(%rsp), %rdi
callq 0x4090
movl %r12d, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0xf947
callq 0x48c0
testl %eax, %eax
jg 0xfa29
jne 0xfa30
callq 0xfab5
callq 0x43f0
xorl %r14d, %r14d
jmp 0xf850
leaq 0x691c(%rip), %rdi      # 0x162ac
callq 0x4740
jmp 0xf850
testb $0x4, %r13b
jne 0xf9e8
btl $0x8, 0x4(%rsp)
jae 0xfa1c
movl $0x1, %edi
callq 0x4160
testl %eax, %eax
jne 0xfa1c
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 0xfa1c
testb $0x40, 0x4(%rsp)
je 0xf9fc
movl 0xaac7(%rip), %edi      # 0x1a4bc
xorl %esi, %esi
callq 0x42f0
movl 0xaaba(%rip), %edi      # 0x1a4bc
movl $0x1, %esi
callq 0x42f0
movl 0xaaaa(%rip), %edi      # 0x1a4bc
movl $0x2, %esi
callq 0x42f0
leaq 0x10(%rsp), %rsi
movq (%rsi), %rdi
callq 0x4780
xorl %edi, %edi
callq 0x4110
callq 0x4c0c