// File: /workspace/github_c_makefile_star2_O1/rakitzis[P]rc/exec.c
// Function: exec
extern void exec(List *s, bool parent) {
	char **av, **ev = NULL;
	int stat;
	pid_t pid;
	builtin_t *b;
	char *path = NULL;
	bool didfork, returning, saw_exec, saw_builtin;
	struct termios t;
	av = list2array(s, dashex);
	saw_builtin = saw_exec = FALSE;
	do {
		if (*av == NULL	|| isabsolute(*av))
			b = NULL;
		else if (!saw_builtin && fnlookup(*av) != NULL)
			b = funcall;
		else
			b = isbuiltin(*av);

		/*
		   a builtin applies only to the immediately following
		   command, e.g., builtin exec echo hi
		*/
		saw_builtin = FALSE;

		if (b == b_exec) {
			av++;
			saw_exec = TRUE;
			parent = FALSE;
		} else if (b == b_builtin) {
			av++;
			saw_builtin = TRUE;
		}
	} while (b == b_exec || b == b_builtin);
	if (*av == NULL && saw_exec) { /* do redirs and return on a null exec */
		doredirs();
		return;
	}
	/* force an exit on exec with any rc_error, but not for null commands as above */
	if (saw_exec)
		rc_pid = -1;
	if (b == NULL) {
		path = which(*av, TRUE);
		if (path == NULL && *av != NULL) { /* perform null commands for redirections */
			set(FALSE);
			redirq = NULL;
			if (parent)
				return;
			rc_exit(1);
		}
		ev = makeenv(); /* environment only needs to be built for execve() */
	}
	/*
	   If parent & the redirq is nonnull, builtin or not it has to fork.
	   If the fifoq is nonnull, then it must be emptied at the end so we
	   must fork no matter what.
	 */
	if ((parent && (b == NULL || redirq != NULL)) || outstanding_cmdarg()) {
		if (interactive)
			tcgetattr(0, &t);
		pid = rc_fork();
		didfork = TRUE;
	} else {
		pid = 0;
		didfork = FALSE;
	}
	returning = (!didfork && parent);
	switch (pid) {
	case -1:
		uerror("fork");
		rc_error(NULL);
		/* NOTREACHED */
	case 0:
		if (!returning)
			setsigdefaults(FALSE);
		pop_cmdarg(FALSE);
		doredirs();

		/* null commands performed for redirections */
		if (*av == NULL || b != NULL) {
			if (b != NULL)
				(*b)(av);
			if (returning)
				return;
			rc_exit(getstatus());
		}
		rc_execve(path, av, ev);

#ifdef DEFAULTINTERP
		if (errno == ENOEXEC) {
			*av = path;
			*--av = DEFAULTINTERP;
			execve(*av, (char * const *) av, (char * const *) ev);
		}
#endif

		uerror(*av);
		rc_exit(1);
		/* NOTREACHED */
	default:
		redirq = NULL;
		rc_wait4(pid, &stat, TRUE);
		if (interactive && WIFSIGNALED(stat))
			tcsetattr(0, TCSANOW, &t);
		setstatus(-1, stat);
		/*
		   There is a very good reason for having this weird
		   nl_on_intr variable: when rc and its child both
		   process a SIGINT, (i.e., the child has a SIGINT
		   catcher installed) then you don't want rc to print
		   a newline when the child finally exits. Here's an
		   example: ed, <type ^C>, <type "q">. rc does not
		   and should not print a newline before the next
		   prompt, even though there's a SIGINT in its signal
		   vector.
		*/
		if (WIFEXITED(stat))
			nl_on_intr = FALSE;
		sigchk();
		nl_on_intr = TRUE;
		pop_cmdarg(TRUE);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %esi, 0xc(%rsp)
leaq 0x152db(%rip), %rax     # 0x19bf0
movl (%rax), %esi
callq 0x5210
movq %rax, %rbx
xorl %r15d, %r15d
leaq -0x1382(%rip), %r12     # 0x35a7
leaq -0x1388(%rip), %r13     # 0x35a8
xorl %ebp, %ebp
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x4943
callq 0xc8c8
testl %eax, %eax
je 0x4980
xorl %r14d, %r14d
cmpq %r12, %r14
je 0x495a
xorl %ebp, %ebp
cmpq %r13, %r14
sete %bpl
leaq (%rbx,%rbp,8), %rbx
jmp 0x496e
addq $0x8, %rbx
movl $0x1, %r15d
movl $0x0, 0xc(%rsp)
xorl %ebp, %ebp
cmpq %r12, %r14
sete %al
cmpq %r13, %r14
sete %cl
orb %al, %cl
jne 0x4932
jmp 0x49a7
testl %ebp, %ebp
je 0x4991
movq (%rbx), %rdi
callq 0x349c
movq %rax, %r14
jmp 0x4946
movq (%rbx), %rdi
callq 0x5099
leaq -0x14b2(%rip), %r14     # 0x34ee
testq %rax, %rax
jne 0x4946
jmp 0x4984
movq (%rbx), %rdi
testq %rdi, %rdi
sete %al
testl %r15d, %r15d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x49d0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb8a8
testl %r15d, %r15d
je 0x49e2
leaq 0x151e4(%rip), %rax     # 0x19bc0
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
testq %r14, %r14
movl 0xc(%rsp), %ebp
je 0x49f9
movq $0x0, 0x10(%rsp)
xorl %r15d, %r15d
jmp 0x4a19
movl $0x1, %esi
callq 0xdfb5
movq %rax, %r15
testq %rax, %rax
je 0x4bb7
callq 0x7a42
movq %rax, 0x10(%rsp)
testl %ebp, %ebp
je 0x4a2f
testq %r14, %r14
je 0x4a38
leaq 0x1509f(%rip), %rax     # 0x19ac8
cmpq $0x0, (%rax)
jne 0x4a38
callq 0x4830
testl %eax, %eax
je 0x4a5d
leaq 0x15195(%rip), %rax     # 0x19bd4
cmpl $0x0, (%rax)
je 0x4a50
leaq 0x1c(%rsp), %rsi
xorl %edi, %edi
callq 0x32c0
xorl %r12d, %r12d
callq 0xcfb8
movl %eax, %r13d
jmp 0x4a63
movb $0x1, %r12b
xorl %r13d, %r13d
testl %ebp, %ebp
setne %bpl
testl %r13d, %r13d
je 0x4a8b
cmpl $-0x1, %r13d
jne 0x4b1a
leaq 0xa987(%rip), %rdi      # 0xf406
callq 0xc7ed
xorl %edi, %edi
callq 0x47be
andb %r12b, %bpl
jne 0x4a97
xorl %edi, %edi
callq 0x4eba
xorl %edi, %edi
callq 0x4845
callq 0xb8a8
testq %r14, %r14
jne 0x4aae
cmpq $0x0, (%rbx)
jne 0x4ace
testq %r14, %r14
je 0x4ab9
movq %rbx, %rdi
callq *%r14
testb %bpl, %bpl
jne 0x4ba8
callq 0xbc85
movl %eax, %edi
callq 0x4fb5
movq %r15, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %r14
movq %r14, %rdx
callq 0x31e0
callq 0x3040
cmpl $0x8, (%rax)
jne 0x4b08
movq %r15, (%rbx)
leaq 0xa916(%rip), %rdi      # 0xf40b
movq %rdi, -0x8(%rbx)
addq $-0x8, %rbx
movq %rbx, %rsi
movq %r14, %rdx
callq 0x31e0
movq (%rbx), %rdi
callq 0xc7ed
movl $0x1, %edi
callq 0x4fb5
leaq 0x14fa7(%rip), %rax     # 0x19ac8
movq $0x0, (%rax)
leaq 0x8(%rsp), %rsi
movl %r13d, %edi
movl $0x1, %edx
callq 0xd068
leaq 0x15093(%rip), %rax     # 0x19bd4
cmpl $0x0, (%rax)
je 0x4b6a
movl 0x8(%rsp), %eax
andl $0x7f, %eax
shll $0x18, %eax
addl $0x1000000, %eax        # imm = 0x1000000
cmpl $0x2000000, %eax        # imm = 0x2000000
jl 0x4b6a
leaq 0x1c(%rsp), %rdx
xorl %edi, %edi
xorl %esi, %esi
callq 0x32f0
movl 0x8(%rsp), %esi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xbcfe
testb $0x7f, 0x8(%rsp)
jne 0x4b8c
leaq 0x1476a(%rip), %rax     # 0x192f0
movl $0x0, (%rax)
callq 0xbae1
leaq 0x14758(%rip), %rax     # 0x192f0
movl $0x1, (%rax)
movl $0x1, %edi
callq 0x4845
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, (%rbx)
je 0x4a0f
xorl %edi, %edi
callq 0xbcdc
leaq 0x14ef9(%rip), %rax     # 0x19ac8
movq $0x0, (%rax)
testl %ebp, %ebp
jne 0x4ba8
movl $0x1, %edi
callq 0x4fb5
jmp 0x4a0f
nopl (%rax)