// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movl %esi, 0x4(%rsp)
leaq 0x154ff(%rip), %rax     # 0x19bf0
movl (%rax), %esi
callq 0x4fac
movq %rax, %rbx
xorl %r15d, %r15d
leaq -0x116b(%rip), %r12     # 0x359a
leaq -0x1173(%rip), %r13     # 0x3599
xorl %ebp, %ebp
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x471f
callq 0xbf5d
testl %eax, %eax
je 0x473c
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpq %r12, %r14
sete %bpl
leaq (%rbx,%rbp,8), %rbx
xorl %eax, %eax
testb %al, %al
jne 0x470e
cmpq %r12, %r14
je 0x470e
jmp 0x4781
testl %ebp, %ebp
je 0x476b
movq (%rbx), %rdi
callq 0x349c
movq %rax, %r14
cmpq %r13, %rax
jne 0x4722
addq $0x8, %rbx
movl $0x0, 0x4(%rsp)
movb $0x1, %al
movq %r13, %r14
pushq $0x1
popq %rcx
movl %ecx, %r15d
xorl %ebp, %ebp
jmp 0x4731
movq (%rbx), %rdi
callq 0x4e40
leaq -0x128e(%rip), %r14     # 0x34ec
testq %rax, %rax
jne 0x4722
jmp 0x4740
movq (%rbx), %rdi
testq %rdi, %rdi
sete %al
testl %r15d, %r15d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x47aa
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb038
testl %r15d, %r15d
je 0x47b9
leaq 0x1540a(%rip), %rax     # 0x19bc0
orl $-0x1, (%rax)
testq %r14, %r14
movl 0x4(%rsp), %ebp
je 0x47ca
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0x47e6
pushq $0x1
popq %rsi
callq 0xd48d
movq %rax, %r15
testq %rax, %rax
je 0x4971
callq 0x7629
movq %rax, %r12
testl %ebp, %ebp
je 0x47fc
testq %r14, %r14
je 0x4805
leaq 0x152d2(%rip), %rax     # 0x19ac8
cmpq $0x0, (%rax)
jne 0x4805
callq 0x4617
testl %eax, %eax
je 0x484c
leaq 0x153c8(%rip), %rax     # 0x19bd4
cmpl $0x0, (%rax)
je 0x481d
leaq 0xc(%rsp), %rsi
xorl %edi, %edi
callq 0x32c0
callq 0xc5b0
movl %eax, %r13d
testl %eax, %eax
je 0x4858
cmpl $-0x1, %r13d
jne 0x48dd
leaq 0x9bc0(%rip), %rdi      # 0xe3fa
callq 0xbe9d
xorl %edi, %edi
callq 0x45b7
pushq $-0x1
popq %r13
jmp 0x4858
movl %ebp, %eax
movb $0x1, %bpl
xorl %r13d, %r13d
testl %eax, %eax
jne 0x4861
xorl %ebp, %ebp
xorl %edi, %edi
callq 0x4c71
xorl %edi, %edi
callq 0x462c
callq 0xb038
testq %r14, %r14
jne 0x4878
cmpq $0x0, (%rbx)
jne 0x4898
testq %r14, %r14
je 0x4883
movq %rbx, %rdi
callq *%r14
testb %bpl, %bpl
jne 0x4962
callq 0xb3ff
movl %eax, %edi
callq 0x4d65
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x31e0
callq 0x3040
cmpl $0x8, (%rax)
jne 0x48cd
movq %r15, (%rbx)
leaq 0x9b45(%rip), %rdi      # 0xe3ff
movq %rdi, -0x8(%rbx)
addq $-0x8, %rbx
movq %rbx, %rsi
movq %r12, %rdx
callq 0x31e0
movq (%rbx), %rdi
callq 0xbe9d
pushq $0x1
popq %rdi
callq 0x4d65
leaq 0x151e4(%rip), %rax     # 0x19ac8
andq $0x0, (%rax)
leaq 0x8(%rsp), %rbx
pushq $0x1
popq %rdx
movl %r13d, %edi
movq %rbx, %rsi
callq 0xc644
leaq 0x152d2(%rip), %rax     # 0x19bd4
cmpl $0x0, (%rax)
movl (%rbx), %esi
je 0x492f
movl %esi, %eax
andl $0x7f, %eax
shll $0x18, %eax
addl $0x1000000, %eax        # imm = 0x1000000
cmpl $0x2000000, %eax        # imm = 0x2000000
jl 0x492f
leaq 0xc(%rsp), %rdx
xorl %edi, %edi
xorl %esi, %esi
callq 0x32f0
movl 0x8(%rsp), %esi
pushq $-0x1
popq %rdi
callq 0xb44d
testb $0x7f, 0x8(%rsp)
jne 0x4948
leaq 0x149ab(%rip), %rax     # 0x192f0
andl $0x0, (%rax)
callq 0xb266
leaq 0x1499c(%rip), %rax     # 0x192f0
movl $0x1, (%rax)
pushq $0x1
popq %rdi
callq 0x462c
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, (%rbx)
je 0x47de
xorl %edi, %edi
callq 0xb43a
leaq 0x1513f(%rip), %rax     # 0x19ac8
andq $0x0, (%rax)
testl %ebp, %ebp
jne 0x4962
pushq $0x1
popq %rdi
callq 0x4d65
jmp 0x47de
nop