// File: /workspace/github_c_makefile_star2_O2/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
andl $0x0, 0xc(%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 0xdfc8
movq %rdi, %r13
cmpb $0x0, (%rdi)
je 0xdfc8
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, %ebp
testb $0x1, %bpl
jne 0xde10
movl %ebp, 0x10(%rsp)
movq %r13, 0x20(%rsp)
pushq $0x1
popq %rbp
xorl %r13d, %r13d
movslq %ebp, %rax
movq %r12, 0x20(%rsp,%rax,8)
movq %r15, 0x28(%rsp,%rax,8)
leal 0x2(%rax), %ecx
movl %ecx, 0xc(%rsp)
movq %rsi, 0x30(%rsp,%rax,8)
movl 0x10(%rsp), %ebp
testb $0x8, %bpl
je 0xdd6a
callq 0x4890
callq 0x48c0
movl %eax, %r14d
testl %eax, %eax
jle 0xdea1
pushq $0x1
popq %r15
movl %ebx, %r12d
leaq 0x78(%rsp), %rbx
movl $0x90, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4380
movq %r15, -0x8(%rbx)
leaq 0x15330(%rip), %rdx     # 0x230d0
pushq $0x1
popq %rdi
leaq 0x70(%rsp), %rsi
callq 0x4170
leaq 0x1a0(%rsp), %rbx
movl $0x98, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4380
leaq 0x1539d(%rip), %rdx     # 0x23168
pushq $0x14
popq %rdi
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 0x15405(%rip), %rdx     # 0x23200
pushq $0x1c
popq %rdi
leaq 0x108(%rsp), %rsi
callq 0x4170
jmp 0xdeb1
movq %rsi, 0x18(%rsp)
movl %ebx, 0x14(%rsp)
movq %r13, %rdi
callq 0x5d70
movq %rax, %rbx
incq %rbx
movq %rbx, %rdi
callq 0x45c0
testq %rax, %rax
je 0xdfdd
movq %rax, %r14
movl %ebp, 0x10(%rsp)
pushq $0x1
popq %rbp
movq %rax, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x6016
movq %r14, 0x20(%rsp)
movq %r14, %rax
movq %r14, %r13
movl 0x14(%rsp), %ebx
pushq $-0x1
popq %r14
movzbl (%rax), %ecx
cmpl $0x9, %ecx
je 0xde79
cmpl $0x20, %ecx
je 0xde79
testl %ecx, %ecx
jne 0xde9c
jmp 0xdfb0
movb $0x0, (%rax)
cmpb $0x0, 0x1(%rax)
je 0xdfb0
incq %rax
movslq %ebp, %rcx
incl %ebp
movq %rax, 0x20(%rsp,%rcx,8)
cmpl $0xa, %ebp
je 0xdfc0
incq %rax
jmp 0xde63
jne 0xdeb1
testb $0x2, %bl
jne 0xdffe
callq 0xe139
testb $0x2, %bl
je 0xdec2
movl %r14d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4700
cmpl $-0x1, %r14d
je 0xdfed
testl %r14d, %r14d
je 0xe01b
movl $0xffff, 0x70(%rsp)     # imm = 0xFFFF
testb $0x2, %bl
jne 0xdf08
leaq 0x70(%rsp), %rbx
movl %r14d, %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4700
cmpl $-0x1, %eax
je 0xdee7
movl 0x70(%rsp), %eax
testb $0x7f, %al
jne 0xdf08
movzbl %ah, %eax
movl %eax, 0x70(%rsp)
leaq 0x151c1(%rip), %rsi     # 0x230d0
pushq $0x1
popq %rdi
xorl %edx, %edx
callq 0x4170
leaq 0x15248(%rip), %rsi     # 0x23168
pushq $0x14
popq %rdi
xorl %edx, %edx
callq 0x4170
leaq 0x152cf(%rip), %rsi     # 0x23200
pushq $0x1c
popq %rdi
xorl %edx, %edx
callq 0x4170
movl 0x70(%rsp), %r14d
testb $0x10, %bpl
jne 0xdf58
movl %ebp, %eax
shrb $0x5, %al
testl %r14d, %r14d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xdf99
leaq 0x60ae(%rip), %rbx      # 0x1400d
movq %rbx, %rdi
callq 0x5d70
pushq $0x1
popq %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x4210
leaq 0xc(%rsp), %r15
movl %eax, (%r15)
pushq $0x1
popq %rbx
xorl %edi, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x4460
testq %rax, %rax
jle 0xdf99
cmpl $0xa, 0xc(%rsp)
jne 0xdf80
testb $0x8, %bpl
je 0xdfc0
movq 0xafea(%rip), %rax      # 0x18f90
movq (%rax), %rdi
callq 0x4440
jmp 0xdfc0
cmpl $-0x1, %ebp
setne %al
cmpl $0x7, %ebp
setl %cl
testb %cl, %al
jne 0xdfe3
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
pushq $-0x1
popq %r14
jmp 0xdfc8
movq 0x18(%rsp), %rsi
jmp 0xdd42
leaq 0x62b6(%rip), %rdi      # 0x142aa
callq 0x4740
jmp 0xded5
callq 0x48c0
testl %eax, %eax
jg 0xe09e
jne 0xe0a5
callq 0xe139
callq 0x43f0
movl %ebp, %eax
testb $0x4, %bpl
jne 0xe064
btl $0x8, %eax
jae 0xe091
pushq $0x1
popq %rdi
callq 0x4160
testl %eax, %eax
jne 0xe091
xorl %edi, %edi
callq 0x4720
pushq $0x1
popq %rbx
movq %rax, %rdi
movl %ebx, %esi
movl $0x80, %edx
xorl %eax, %eax
callq 0x46b0
movl %eax, %ebp
movl %eax, %edi
movl %ebx, %esi
callq 0x42f0
movl %ebp, %edi
callq 0x43c0
jmp 0xe091
testb $0x40, %al
je 0xe075
movl 0xb44e(%rip), %edi      # 0x194bc
xorl %esi, %esi
callq 0x42f0
movl 0xb441(%rip), %edi      # 0x194bc
pushq $0x1
popq %rsi
callq 0x42f0
movl 0xb433(%rip), %edi      # 0x194bc
pushq $0x2
popq %rsi
callq 0x42f0
leaq 0x20(%rsp), %rsi
movq (%rsi), %rdi
callq 0x4780
xorl %edi, %edi
callq 0x4110
leaq 0x61fe(%rip), %rdi      # 0x142aa
callq 0x4740
pushq $0x1
popq %rdi
callq 0x4110