// File: /workspace/github_c_makefile_star2_O2/s3lase[P]v6shell/sh6.c
// Function: execute
static void
execute(struct tnode *t, int *pin, int *pout)
{
	struct tnode *t1;
	enum tnflags f;
	pid_t cpid;
	int i, pfd[2];
	const char **gav;
	const char *cmd, *p;

	if (t == NULL)
		return;
	switch (t->ntype) {
	case TLIST:
		f = t->nflags & (FFIN | FPIN | FINTR);
		if ((t1 = t->nleft) != NULL)
			t1->nflags |= f;
		execute(t1, NULL, NULL);
		if ((t1 = t->nright) != NULL)
			t1->nflags |= f;
		execute(t1, NULL, NULL);
		return;

	case TPIPE:
		if (pipe(pfd) == -1) {
			err(SH_ERR, FMT1S, ERR_PIPE);
			if (pin != NULL) {
				(void)close(pin[0]);
				(void)close(pin[1]);
			}
			return;
		}
		f = t->nflags;
		if ((t1 = t->nleft) != NULL)
			t1->nflags |= FPOUT | (f & (FFIN|FPIN|FINTR|FPRS));
		execute(t1, pin, pfd);
		if ((t1 = t->nright) != NULL)
			t1->nflags |= FPIN | (f & (FAND|FPOUT|FINTR|FPRS));
		execute(t1, pfd, pout);
		(void)close(pfd[0]);
		(void)close(pfd[1]);
		return;

	case TCOMMAND:
		if (t->nav == NULL || t->nav[0] == NULL) {
			/* should never (but can) be true */
			err(SH_ERR, FMT1S, "execute: Invalid command");
			return;
		}
		cmd = t->nav[0];
		if (EQUAL(cmd, ":")) {
			status = SH_TRUE;
			return;
		}
		if (EQUAL(cmd, "chdir")) {
			ascan(t->nav[1], &trim);
			if (t->nav[1] == NULL)
				err(SH_ERR, FMT2S, cmd, ERR_ARGCOUNT);
			else if (chdir(t->nav[1]) == -1)
				err(SH_ERR, FMT2S, cmd, ERR_BADDIR);
			else
				status = SH_TRUE;
			return;
		}
		if (EQUAL(cmd, "exit")) {
			if (prompt == NULL) {
				(void)lseek(FD0, (off_t)0, SEEK_END);
				EXIT(status);
			}
			return;
		}
		if (EQUAL(cmd, "login") || EQUAL(cmd, "newgrp")) {
			if (prompt != NULL) {
				p = (*cmd == 'l') ? PATH_LOGIN : PATH_NEWGRP;
				vscan(t->nav, &trim);
				(void)sasignal(SIGINT, SIG_DFL);
				(void)sasignal(SIGQUIT, SIG_DFL);
				(void)pexec(p, (char *const *)t->nav);
				(void)sasignal(SIGINT, SIG_IGN);
				(void)sasignal(SIGQUIT, SIG_IGN);
			}
			err(SH_ERR, FMT2S, cmd, ERR_EXEC);
			return;
		}
		if (EQUAL(cmd, "shift")) {
			if (dolc > 1) {
				dolv = &dolv[1];
				dolc--;
				status = SH_TRUE;
				return;
			}
			err(SH_ERR, FMT2S, cmd, ERR_NOARGS);
			return;
		}
		if (EQUAL(cmd, "wait")) {
			pwait(-1);
			return;
		}
		/*FALLTHROUGH*/

	case TSUBSHELL:
		f = t->nflags;
		if ((cpid = ((f & FNOFORK) != 0) ? 0 : fork()) == -1) {
			err(SH_ERR, FMT1S, ERR_FORK);
			return;
		}
		/**** Parent! ****/
		if (cpid != 0) {
			if (pin != NULL && (f & FPIN) != 0) {
				(void)close(pin[0]);
				(void)close(pin[1]);
			}
			if ((f & FPRS) != 0)
				fd_print(FD2, "%u\n", (unsigned)cpid);
			if ((f & FAND) != 0)
				return;
			if ((f & FPOUT) == 0)
				pwait(cpid);
			return;
		}
		/**** Child! ****/
		/*
		 * Redirect (read) input from pipe.
		 */
		if (pin != NULL && (f & FPIN) != 0) {
			if (dup2(pin[0], FD0) == -1)
				err(FC_ERR, FMT1S, strerror(errno));
			(void)close(pin[0]);
			(void)close(pin[1]);
		}
		/*
		 * Redirect (write) output to pipe.
		 */
		if (pout != NULL && (f & FPOUT) != 0) {
			if (dup2(pout[1], FD1) == -1)
				err(FC_ERR, FMT1S, strerror(errno));
			(void)close(pout[0]);
			(void)close(pout[1]);
		}
		/*
		 * Redirect (read) input from file.
		 */
		if (t->nfin != NULL && (f & FPIN) == 0) {
			f |= FFIN;
			ascan(t->nfin, &trim);
			if ((i = open(t->nfin, O_RDONLY)) == -1)
				err(FC_ERR, FMT2S, t->nfin, ERR_OPEN);
			if (dup2(i, FD0) == -1)
				err(FC_ERR, FMT1S, strerror(errno));
			(void)close(i);
		}
		/*
		 * Redirect (write) output to file.
		 */
		if (t->nfout != NULL && (f & FPOUT) == 0) {
			if ((f & FCAT) != 0)
				i = O_WRONLY | O_APPEND | O_CREAT;
			else
				i = O_WRONLY | O_TRUNC | O_CREAT;
			ascan(t->nfout, &trim);
			if ((i = open(t->nfout, i, 0666)) == -1)
				err(FC_ERR, FMT2S, t->nfout, ERR_CREATE);
			if (dup2(i, FD1) == -1)
				err(FC_ERR, FMT1S, strerror(errno));
			(void)close(i);
		}
		/*
		 * Set the action for the SIGINT and SIGQUIT signals, and
		 * redirect input for `&' commands from `/dev/null' if needed.
		 */
		if ((f & FINTR) != 0) {
			(void)sasignal(SIGINT, SIG_IGN);
			(void)sasignal(SIGQUIT, SIG_IGN);
			if (t->nfin == NULL && (f & (FFIN|FPIN|FPRS)) == FPRS) {
				(void)close(FD0);
				if (open("/dev/null", O_RDONLY) != FD0)
					err(FC_ERR,FMT2S,"/dev/null",ERR_OPEN);
			}
		} else {
			if ((sig_child & S_SIGINT) != 0)
				(void)sasignal(SIGINT, SIG_DFL);
			if ((sig_child & S_SIGQUIT) != 0)
				(void)sasignal(SIGQUIT, SIG_DFL);
		}
		/* Set the SIGTERM signal to its default action if needed. */
		if ((sig_child & S_SIGTERM) != 0)
			(void)sasignal(SIGTERM, SIG_DFL);
		if (t->ntype == TSUBSHELL) {
			if ((t1 = t->nsub) != NULL)
				t1->nflags |= (f & (FFIN | FPIN | FINTR));
			execute(t1, NULL, NULL);
			_exit(status);
		}
		glob_flag = false;
		vscan(t->nav, &tglob);
		if (glob_flag) {
			for (i = 0; t->nav[i] != NULL; i++)
				;	/* nothing */
			gav = xmalloc((i + 2) * sizeof(char *));
			gav[0] = "glob6";
			cmd = gav[0];
			(void)memcpy(&gav[1], t->nav, (i + 1) * sizeof(char *));
			(void)err_pexec(cmd, (char *const *)gav);
		} else {
			vscan(t->nav, &trim);
			cmd = t->nav[0];
			(void)err_pexec(cmd, (char *const *)t->nav);
		}
		/*NOTREACHED*/
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x2bb3
movq %rdi, %rbx
movl 0x34(%rdi), %eax
decl %eax
cmpl $0x3, %eax
ja 0x2bb3
movq %rdx, %r14
movq %rsi, %r15
leaq 0x26ad(%rip), %rcx      # 0x5108
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x30(%rbx), %ebp
andl $0x4c, %ebp
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x2a75
orl %ebp, 0x30(%rdi)
xorl %esi, %esi
xorl %edx, %edx
callq 0x2a29
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x2a8a
orl %ebp, 0x30(%rdi)
xorl %esi, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2a29
movq 0x28(%rbx), %r13
testq %r13, %r13
je 0x2b72
movq (%r13), %r12
testq %r12, %r12
je 0x2b72
movzbl (%r12), %eax
cmpl $0x77, %eax
je 0x2cbb
cmpl $0x63, %eax
je 0x2d22
cmpl $0x65, %eax
je 0x2cd6
cmpl $0x6c, %eax
je 0x2bc2
cmpl $0x6e, %eax
je 0x2c1d
cmpl $0x73, %eax
je 0x2be2
cmpl $0x3a, %eax
jne 0x2d39
cmpb $0x0, 0x1(%r12)
jne 0x2d39
jmp 0x3100
movq %rsp, %rdi
callq 0x2190
cmpl $-0x1, %eax
je 0x2b85
movl 0x30(%rbx), %ebp
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x2b35
movl %ebp, %eax
andl $0xcc, %eax
orl 0x30(%rdi), %eax
orl $0x10, %eax
movl %eax, 0x30(%rdi)
movq %rsp, %rdx
movq %r15, %rsi
callq 0x2a29
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x2b58
andl $0xd1, %ebp
orl 0x30(%rdi), %ebp
orl $0x8, %ebp
movl %ebp, 0x30(%rdi)
movq %rsp, %rbx
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2a29
movl (%rbx), %edi
callq 0x2180
movl 0x4(%rbx), %edi
jmp 0x2bae
leaq 0x2897(%rip), %rsi      # 0x5410
leaq 0x263c(%rip), %rdx      # 0x51bc
jmp 0x2d65
leaq 0x2884(%rip), %rsi      # 0x5410
leaq 0x2611(%rip), %rdx      # 0x51a4
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x39b8
testq %r15, %r15
je 0x2bb3
movl (%r15), %edi
callq 0x2180
movl 0x4(%r15), %edi
callq 0x2180
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2638(%rip), %rsi      # 0x5201
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
jne 0x2d39
leaq 0x2618(%rip), %r14      # 0x51f8
jmp 0x2c3b
leaq 0x263d(%rip), %rsi      # 0x5226
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
jne 0x2d39
movl 0x5591(%rip), %eax      # 0x8190
cmpl $0x2, %eax
jl 0x310c
addq $0x8, 0x5578(%rip)      # 0x8188
decl %eax
movl %eax, 0x5578(%rip)      # 0x8190
jmp 0x3100
leaq 0x25ec(%rip), %rsi      # 0x5210
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
jne 0x2d39
leaq 0x25cc(%rip), %r14      # 0x5207
cmpq $0x0, 0x5565(%rip)      # 0x81a8
je 0x2c92
leaq 0xb71(%rip), %rsi       # 0x37bd
movq %r13, %rdi
callq 0x37c3
pushq $0x2
popq %rbp
movl %ebp, %edi
xorl %esi, %esi
callq 0x4188
pushq $0x3
popq %r15
movl %r15d, %edi
xorl %esi, %esi
callq 0x4188
movq 0x28(%rbx), %rsi
movq %r14, %rdi
callq 0x3cb0
pushq $0x1
popq %rbx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x4188
movl %r15d, %edi
movq %rbx, %rsi
callq 0x4188
leaq 0x2773(%rip), %rsi      # 0x540c
leaq 0x2577(%rip), %rcx      # 0x5217
pushq $0x2
popq %rdi
movq %r12, %rdx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39b8
leaq 0x2572(%rip), %rsi      # 0x5234
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
jne 0x2d39
pushq $-0x1
popq %rdi
jmp 0x30cd
leaq 0x2516(%rip), %rsi      # 0x51f3
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
jne 0x2d39
cmpq $0x0, 0x54b7(%rip)      # 0x81a8
jne 0x2bb3
pushq $0x2
popq %rdx
xorl %edi, %edi
xorl %esi, %esi
callq 0x2150
callq 0x20e0
movl %eax, %ebx
callq 0x3c0b
movl 0x549f(%rip), %edi      # 0x81b4
cmpl %eax, %ebx
jne 0x3165
callq 0x2250
leaq 0x24ac(%rip), %rsi      # 0x51d5
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
je 0x30e0
movl 0x30(%rbx), %r12d
testb $0x20, %r12b
jne 0x2d7d
callq 0x22a0
testl %eax, %eax
je 0x2d7d
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x3087
leaq 0x26b2(%rip), %rsi      # 0x5410
leaq 0x24d4(%rip), %rdx      # 0x5239
pushq $0x2
popq %rdi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39b8
testq %r15, %r15
sete %al
testb $0x8, %r12b
sete %cl
orb %al, %cl
jne 0x2dce
movl (%r15), %edi
xorl %esi, %esi
callq 0x2120
cmpl $-0x1, %eax
jne 0x2dbd
callq 0x2070
movl (%rax), %edi
callq 0x2260
leaq 0x2660(%rip), %rsi      # 0x5410
pushq $0x7c
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x39b8
movl (%r15), %edi
callq 0x2180
movl 0x4(%r15), %edi
callq 0x2180
testq %r14, %r14
sete %al
testb $0x10, %r12b
sete %cl
orb %al, %cl
jne 0x2e21
movl 0x4(%r14), %edi
pushq $0x1
popq %rsi
callq 0x2120
cmpl $-0x1, %eax
jne 0x2e10
callq 0x2070
movl (%rax), %edi
callq 0x2260
leaq 0x260d(%rip), %rsi      # 0x5410
pushq $0x7c
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x39b8
movl (%r14), %edi
callq 0x2180
movl 0x4(%r14), %edi
callq 0x2180
movl %r12d, %eax
andl $0x8, %eax
shrl $0x3, %eax
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x2ea6
callq 0x37a8
movq 0x18(%rbx), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x2230
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x2e6d
movq 0x18(%rbx), %rdx
leaq 0x25b0(%rip), %rsi      # 0x540c
leaq 0x22cb(%rip), %rcx      # 0x512e
pushq $0x7c
popq %rdi
xorl %eax, %eax
callq 0x39b8
movl %ebp, %edi
xorl %esi, %esi
callq 0x2120
cmpl $-0x1, %eax
jne 0x2e9b
callq 0x2070
movl (%rax), %edi
callq 0x2260
leaq 0x2582(%rip), %rsi      # 0x5410
pushq $0x7c
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x39b8
orl $0x4, %r12d
movl %ebp, %edi
callq 0x2180
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x2f3a
movl %r12d, %eax
andl $0x10, %eax
jne 0x2f3a
movl %r12d, %ebp
andl $0x2, %ebp
shll $0x8, %ebp
addl $0x241, %ebp            # imm = 0x241
callq 0x37a8
movq 0x20(%rbx), %rdi
movl %ebp, %esi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x2230
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x2f04
movq 0x20(%rbx), %rdx
leaq 0x2519(%rip), %rsi      # 0x540c
leaq 0x235b(%rip), %rcx      # 0x5255
pushq $0x7c
popq %rdi
xorl %eax, %eax
callq 0x39b8
pushq $0x1
popq %rsi
movl %ebp, %edi
callq 0x2120
cmpl $-0x1, %eax
jne 0x2f33
callq 0x2070
movl (%rax), %edi
callq 0x2260
leaq 0x24ea(%rip), %rsi      # 0x5410
pushq $0x7c
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x39b8
movl %ebp, %edi
callq 0x2180
testb $0x40, %r12b
jne 0x2f6a
movl 0x526a(%rip), %eax      # 0x81b0
testb $0x1, %al
je 0x2f5a
pushq $0x2
popq %rdi
xorl %esi, %esi
callq 0x4188
movl 0x5256(%rip), %eax      # 0x81b0
testb $0x2, %al
je 0x2fd4
pushq $0x3
popq %rdi
xorl %esi, %esi
callq 0x4188
jmp 0x2fd4
pushq $0x2
popq %rdi
pushq $0x1
popq %r14
movq %r14, %rsi
callq 0x4188
pushq $0x3
popq %rdi
movq %r14, %rsi
callq 0x4188
movl %r12d, %eax
andl $0x8c, %eax
cmpl $0x80, %eax
jne 0x2fd4
cmpq $0x0, 0x18(%rbx)
jne 0x2fd4
xorl %edi, %edi
callq 0x2180
leaq 0x22bb(%rip), %rdi      # 0x5263
xorl %esi, %esi
xorl %eax, %eax
callq 0x2230
testl %eax, %eax
je 0x2fd4
leaq 0x2450(%rip), %rsi      # 0x540c
leaq 0x22a0(%rip), %rdx      # 0x5263
leaq 0x2164(%rip), %rcx      # 0x512e
pushq $0x7c
popq %rdi
xorl %eax, %eax
callq 0x39b8
testb $0x4, 0x51d5(%rip)      # 0x81b0
je 0x2fe7
pushq $0xf
popq %rdi
xorl %esi, %esi
callq 0x4188
cmpl $0x4, 0x34(%rbx)
je 0x3145
movb $0x0, 0x7a29(%rip)      # 0xaa21
movq 0x28(%rbx), %rdi
leaq 0x93f(%rip), %rsi       # 0x3942
callq 0x37c3
movq 0x28(%rbx), %rdi
cmpb $0x1, 0x7a0e(%rip)      # 0xaa21
jne 0x3061
xorl %r14d, %r14d
cmpq $0x0, (%rdi,%r14)
leaq 0x8(%r14), %r14
jne 0x3018
leaq 0x8(%r14), %rdi
movabsq $0x7fffffff8, %r13      # imm = 0x7FFFFFFF8
andq %r13, %rdi
callq 0x356a
movq %rax, %r15
leaq 0x222a(%rip), %r12      # 0x526d
movq %r12, (%rax)
leaq 0x8(%rax), %rdi
movq 0x28(%rbx), %rsi
andq %r13, %r14
movq %r14, %rdx
callq 0x21f0
movq %r12, %rdi
movq %r15, %rsi
jmp 0x3074
leaq 0x755(%rip), %rsi       # 0x37bd
callq 0x37c3
movq 0x28(%rbx), %rsi
movq (%rsi), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3f94
testq %r15, %r15
sete %al
testb $0x8, %r12b
sete %cl
orb %al, %cl
jne 0x30a9
movl (%r15), %edi
callq 0x2180
movl 0x4(%r15), %edi
callq 0x2180
testb %r12b, %r12b
jns 0x30c1
leaq 0x219c(%rip), %rsi      # 0x5251
pushq $0x2
popq %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x3b68
testb $0x11, %r12b
jne 0x2bb3
movl %ebp, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x37f7
movq 0x8(%r13), %rdi
callq 0x37a8
movq 0x28(%rbx), %rax
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x311f
callq 0x2100
cmpl $-0x1, %eax
je 0x3132
andl $0x0, 0x50ad(%rip)      # 0x81b4
jmp 0x2bb3
leaq 0x22f9(%rip), %rsi      # 0x540c
leaq 0x2112(%rip), %rcx      # 0x522c
jmp 0x2ca0
leaq 0x22e6(%rip), %rsi      # 0x540c
leaq 0x20ae(%rip), %rcx      # 0x51db
jmp 0x2ca0
leaq 0x22d3(%rip), %rsi      # 0x540c
leaq 0x20a5(%rip), %rcx      # 0x51e5
jmp 0x2ca0
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x3156
andl $0x4c, %r12d
orl %r12d, 0x30(%rdi)
xorl %esi, %esi
xorl %edx, %edx
callq 0x2a29
movl 0x504f(%rip), %edi      # 0x81b4
callq 0x2080