// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x1a9a3(%rip), %rax     # 0x1fc80
movl (%rax), %esi
callq 0x5fd0
movq %rax, -0x18(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x5311
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x11d90
cmpl $0x0, %eax
je 0x531b
movq $0x0, -0x30(%rbp)
jmp 0x5352
cmpl $0x0, -0x48(%rbp)
jne 0x5340
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x5d30
cmpq $0x0, %rax
je 0x5340
leaq -0x1e0a(%rip), %rax     # 0x3530
movq %rax, -0x30(%rbp)
jmp 0x5350
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3490
movq %rax, -0x30(%rbp)
jmp 0x5352
movl $0x0, -0x48(%rbp)
leaq -0x1d40(%rip), %rax     # 0x3620
cmpq %rax, -0x30(%rbp)
jne 0x5382
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl $0x1, -0x44(%rbp)
movl $0x0, -0xc(%rbp)
jmp 0x53a4
leaq -0x1d59(%rip), %rax     # 0x3630
cmpq %rax, -0x30(%rbp)
jne 0x53a2
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x53a4
jmp 0x53a6
movb $0x1, %al
leaq -0x1d8f(%rip), %rcx     # 0x3620
cmpq %rcx, -0x30(%rbp)
movb %al, -0x85(%rbp)
je 0x53cf
leaq -0x1d92(%rip), %rax     # 0x3630
cmpq %rax, -0x30(%rbp)
sete %al
movb %al, -0x85(%rbp)
movb -0x85(%rbp), %al
testb $0x1, %al
jne 0x52f6
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x53f7
cmpl $0x0, -0x44(%rbp)
je 0x53f7
callq 0x10150
jmp 0x5670
cmpl $0x0, -0x44(%rbp)
je 0x540a
leaq 0x1a84c(%rip), %rax     # 0x1fc50
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
cmpq $0x0, -0x30(%rbp)
jne 0x546a
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x13ee0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x5461
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x5461
xorl %edi, %edi
callq 0x107a0
leaq 0x1a713(%rip), %rax     # 0x1fb58
movq $0x0, (%rax)
cmpl $0x0, -0xc(%rbp)
je 0x5457
jmp 0x5670
movl $0x1, %edi
callq 0x5c00
callq 0x9ff0
movq %rax, -0x20(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x5484
cmpq $0x0, -0x30(%rbp)
je 0x548e
leaq 0x1a6da(%rip), %rax     # 0x1fb58
cmpq $0x0, (%rax)
jne 0x548e
callq 0x5180
cmpl $0x0, %eax
je 0x54b9
leaq 0x1a7cf(%rip), %rax     # 0x1fc64
cmpl $0x0, (%rax)
je 0x54a8
xorl %edi, %edi
leaq -0x84(%rbp), %rsi
callq 0x32b0
callq 0x127b0
movl %eax, -0x28(%rbp)
movl $0x1, -0x3c(%rbp)
jmp 0x54c7
movl $0x0, -0x28(%rbp)
movl $0x0, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x3c(%rbp)
movb %al, -0x86(%rbp)
jne 0x54e2
cmpl $0x0, -0xc(%rbp)
setne %al
movb %al, -0x86(%rbp)
movb -0x86(%rbp), %al
movzbl %al, %eax
andl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x8c(%rbp)
subl $-0x1, %eax
je 0x5510
jmp 0x5501
movl -0x8c(%rbp), %eax
testl %eax, %eax
je 0x5525
jmp 0x55e1
leaq 0xff43(%rip), %rdi      # 0x1545a
callq 0x11c10
xorl %eax, %eax
movl %eax, %edi
callq 0x50d0
cmpl $0x0, -0x40(%rbp)
jne 0x5532
xorl %edi, %edi
callq 0x5ab0
xorl %edi, %edi
callq 0x51b0
callq 0x10150
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x554f
cmpq $0x0, -0x30(%rbp)
je 0x5577
cmpq $0x0, -0x30(%rbp)
je 0x5560
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rdi
callq *%rax
cmpl $0x0, -0x40(%rbp)
je 0x556b
jmp 0x5670
callq 0x10730
movl %eax, %edi
callq 0x5c00
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x31d0
callq 0x3040
cmpl $0x8, (%rax)
jne 0x55cb
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $-0x8, %rcx
movq %rcx, -0x18(%rbp)
leaq 0xfeac(%rip), %rcx      # 0x1545f
movq %rcx, -0x8(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x31d0
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x11c10
movl $0x1, %edi
callq 0x5c00
leaq 0x1a570(%rip), %rax     # 0x1fb58
movq $0x0, (%rax)
movl -0x28(%rbp), %edi
leaq -0x24(%rbp), %rsi
movl $0x1, %edx
callq 0x128c0
leaq 0x1a65d(%rip), %rax     # 0x1fc64
cmpl $0x0, (%rax)
je 0x562f
movl -0x24(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0x562f
xorl %esi, %esi
leaq -0x84(%rbp), %rdx
movl %esi, %edi
callq 0x32e0
movl -0x24(%rbp), %esi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x107d0
movl -0x24(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x5654
leaq 0x19ca2(%rip), %rax     # 0x1f2f0
movl $0x0, (%rax)
callq 0x104a0
leaq 0x19c90(%rip), %rax     # 0x1f2f0
movl $0x1, (%rax)
movl $0x1, %edi
callq 0x51b0
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)