// File: /workspace/github_c_makefile_star2_O3/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 0x2bdb
movq %rdi, %rbx
movl 0x34(%rdi), %eax
decl %eax
cmpl $0x3, %eax
ja 0x2bdb
movq %rdx, %r14
movq %rsi, %r15
leaq 0x2681(%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 0x2aaa
orl %ebp, 0x30(%rdi)
xorl %esi, %esi
xorl %edx, %edx
callq 0x2a55
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x2bdb
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 0x2a55
movq 0x28(%rbx), %r13
testq %r13, %r13
je 0x2b98
movq (%r13), %r12
testq %r12, %r12
je 0x2b98
movzbl (%r12), %eax
cmpl $0x6b, %eax
jle 0x2bea
cmpl $0x72, %eax
jg 0x2c53
cmpl $0x6c, %eax
je 0x2c97
cmpl $0x6e, %eax
jne 0x2d8a
leaq 0x26f5(%rip), %rsi      # 0x520d
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
jne 0x2d8a
leaq 0x26d5(%rip), %r14      # 0x5204
jmp 0x2cb5
movq %rsp, %rdi
callq 0x2190
cmpl $-0x1, %eax
je 0x2bab
movl 0x30(%rbx), %ebp
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x2b67
movl %ebp, %eax
andl $0xcc, %eax
orl 0x30(%rdi), %eax
orl $0x10, %eax
movl %eax, 0x30(%rdi)
movq %rsp, %rdx
movq %r15, %rsi
callq 0x2a55
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x2b8a
andl $0xd1, %ebp
orl 0x30(%rdi), %ebp
orl $0x8, %ebp
movl %ebp, 0x30(%rdi)
movq %rsp, %rsi
movq %r14, %rdx
callq 0x2a55
movl (%rsp), %edi
callq 0x2180
movl 0x4(%rsp), %edi
jmp 0x2bd6
leaq 0x286e(%rip), %rsi      # 0x540d
leaq 0x2613(%rip), %rdx      # 0x51b9
jmp 0x2db6
leaq 0x285b(%rip), %rsi      # 0x540d
leaq 0x25e8(%rip), %rdx      # 0x51a1
movl $0x2, %edi
xorl %eax, %eax
callq 0x3ac8
testq %r15, %r15
je 0x2bdb
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
cmpl $0x3a, %eax
je 0x2c86
cmpl $0x63, %eax
je 0x2d73
cmpl $0x65, %eax
jne 0x2d8a
leaq 0x25e4(%rip), %rsi      # 0x51f0
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
jne 0x2d8a
cmpq $0x0, 0x4584(%rip)      # 0x71a8
jne 0x2bdb
xorl %edi, %edi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2150
callq 0x20e0
movl %eax, %ebx
callq 0x3d25
movl 0x456e(%rip), %edi      # 0x71b4
cmpl %eax, %ebx
jne 0x3286
callq 0x2250
cmpl $0x73, %eax
je 0x2d3c
cmpl $0x77, %eax
jne 0x2d8a
leaq 0x25c5(%rip), %rsi      # 0x5231
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
jne 0x2d8a
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
jmp 0x31c2
cmpb $0x0, 0x1(%r12)
jne 0x2d8a
jmp 0x320c
leaq 0x2560(%rip), %rsi      # 0x51fe
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
jne 0x2d8a
leaq 0x2540(%rip), %r14      # 0x51f5
cmpq $0x0, 0x44eb(%rip)      # 0x71a8
je 0x2d29
movq %r12, %rax
movb (%rax), %cl
testb %cl, %cl
je 0x2cda
incq %rax
andb $0x7f, %cl
movb %cl, -0x1(%rax)
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x2ccb
addq $0x8, %r13
movq (%r13), %rax
testq %rax, %rax
jne 0x2cc2
movl $0x2, %edi
xorl %esi, %esi
callq 0x42d8
movl $0x3, %edi
xorl %esi, %esi
callq 0x42d8
movq 0x28(%rbx), %rsi
movq %r14, %rdi
callq 0x3dcc
movl $0x1, %esi
movl $0x2, %edi
callq 0x42d8
movl $0x1, %esi
movl $0x3, %edi
callq 0x42d8
leaq 0x26d9(%rip), %rsi      # 0x5409
leaq 0x24dd(%rip), %rcx      # 0x5214
jmp 0x3249
leaq 0x24e0(%rip), %rsi      # 0x5223
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
jne 0x2d8a
movl 0x443b(%rip), %eax      # 0x7190
cmpl $0x2, %eax
jl 0x322b
addq $0x8, 0x4422(%rip)      # 0x7188
decl %eax
movl %eax, 0x4422(%rip)      # 0x7190
jmp 0x320c
leaq 0x2458(%rip), %rsi      # 0x51d2
movq %r12, %rdi
callq 0x21c0
testl %eax, %eax
je 0x31d5
movl 0x30(%rbx), %r12d
testb $0x20, %r12b
jne 0x2dd0
callq 0x22a0
testl %eax, %eax
je 0x2dd0
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x317a
leaq 0x265e(%rip), %rsi      # 0x540d
leaq 0x2480(%rip), %rdx      # 0x5236
movl $0x2, %edi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3ac8
testq %r15, %r15
sete %al
testb $0x8, %r12b
sete %cl
orb %al, %cl
jne 0x2e23
movl (%r15), %edi
xorl %esi, %esi
callq 0x2120
cmpl $-0x1, %eax
jne 0x2e12
callq 0x2070
movl (%rax), %edi
callq 0x2260
leaq 0x260a(%rip), %rsi      # 0x540d
movl $0x7c, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3ac8
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 0x2e7a
movl 0x4(%r14), %edi
movl $0x1, %esi
callq 0x2120
cmpl $-0x1, %eax
jne 0x2e69
callq 0x2070
movl (%rax), %edi
callq 0x2260
leaq 0x25b3(%rip), %rsi      # 0x540d
movl $0x7c, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3ac8
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 0x2f19
movb (%rdi), %al
testb %al, %al
je 0x2eb0
incq %rdi
andb $0x7f, %al
movb %al, -0x1(%rdi)
movb (%rdi), %al
incq %rdi
testb %al, %al
jne 0x2e9e
movq 0x18(%rbx), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x2230
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x2ede
movq 0x18(%rbx), %rdx
leaq 0x253e(%rip), %rsi      # 0x5409
leaq 0x225c(%rip), %rcx      # 0x512e
movl $0x7c, %edi
xorl %eax, %eax
callq 0x3ac8
movl %ebp, %edi
xorl %esi, %esi
callq 0x2120
cmpl $-0x1, %eax
jne 0x2f0e
callq 0x2070
movl (%rax), %edi
callq 0x2260
leaq 0x250e(%rip), %rsi      # 0x540d
movl $0x7c, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3ac8
orl $0x4, %r12d
movl %ebp, %edi
callq 0x2180
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x2fc7
movl %r12d, %eax
andl $0x10, %eax
jne 0x2fc7
movl %r12d, %esi
andl $0x2, %esi
shll $0x8, %esi
addl $0x241, %esi            # imm = 0x241
movb (%rdi), %al
testb %al, %al
je 0x2f5c
incq %rdi
andb $0x7f, %al
movb %al, -0x1(%rdi)
movb (%rdi), %al
incq %rdi
testb %al, %al
jne 0x2f4a
movq 0x20(%rbx), %rdi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x2230
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x2f8d
movq 0x20(%rbx), %rdx
leaq 0x248f(%rip), %rsi      # 0x5409
leaq 0x22d1(%rip), %rcx      # 0x5252
movl $0x7c, %edi
xorl %eax, %eax
callq 0x3ac8
movl %ebp, %edi
movl $0x1, %esi
callq 0x2120
cmpl $-0x1, %eax
jne 0x2fc0
callq 0x2070
movl (%rax), %edi
callq 0x2260
leaq 0x245c(%rip), %rsi      # 0x540d
movl $0x7c, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3ac8
movl %ebp, %edi
callq 0x2180
testb $0x40, %r12b
jne 0x2ffb
movl 0x41dd(%rip), %eax      # 0x71b0
testb $0x1, %al
je 0x2fe9
movl $0x2, %edi
xorl %esi, %esi
callq 0x42d8
movl 0x41c7(%rip), %eax      # 0x71b0
testb $0x2, %al
je 0x306b
movl $0x3, %edi
xorl %esi, %esi
callq 0x42d8
jmp 0x306b
movl $0x1, %esi
movl $0x2, %edi
callq 0x42d8
movl $0x1, %esi
movl $0x3, %edi
callq 0x42d8
movl %r12d, %eax
andl $0x8c, %eax
cmpl $0x80, %eax
jne 0x306b
cmpq $0x0, 0x18(%rbx)
jne 0x306b
xorl %edi, %edi
callq 0x2180
leaq 0x2223(%rip), %rdi      # 0x5260
xorl %esi, %esi
xorl %eax, %eax
callq 0x2230
testl %eax, %eax
je 0x306b
leaq 0x23b8(%rip), %rsi      # 0x5409
leaq 0x2208(%rip), %rdx      # 0x5260
leaq 0x20cf(%rip), %rcx      # 0x512e
movl $0x7c, %edi
xorl %eax, %eax
callq 0x3ac8
testb $0x4, 0x413e(%rip)      # 0x71b0
je 0x3080
movl $0xf, %edi
xorl %esi, %esi
callq 0x42d8
cmpl $0x4, 0x34(%rbx)
je 0x3266
movq 0x28(%rbx), %rsi
movq (%rsi), %rdx
testq %rdx, %rdx
je 0x3164
xorl %eax, %eax
leaq 0x2290(%rip), %rcx      # 0x5333
movb (%rdx), %dil
testb %dil, %dil
je 0x30d4
movq %rcx, %r8
movb (%r8), %r9b
testb %r9b, %r9b
je 0x30be
incq %r8
cmpb %dil, %r9b
jne 0x30ae
testb %r9b, %r9b
setne %r8b
orb %r8b, %al
movb %dil, (%rdx)
movb 0x1(%rdx), %dil
incq %rdx
jmp 0x30a6
addq $0x8, %rsi
movq (%rsi), %rdx
testq %rdx, %rdx
jne 0x30a3
movq 0x28(%rbx), %rsi
testb $0x1, %al
je 0x3134
xorl %r14d, %r14d
cmpq $0x0, (%rsi,%r14)
leaq 0x8(%r14), %r14
jne 0x30eb
leaq 0x8(%r14), %rdi
movabsq $0x7fffffff8, %r13      # imm = 0x7FFFFFFF8
andq %r13, %rdi
callq 0x36a4
movq %rax, %r15
leaq 0x2154(%rip), %r12      # 0x526a
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 0x3167
movq (%rsi), %rax
testq %rax, %rax
je 0x3164
movb (%rax), %cl
testb %cl, %cl
je 0x3154
incq %rax
andb $0x7f, %cl
movb %cl, -0x1(%rax)
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x3145
addq $0x8, %rsi
movq (%rsi), %rax
testq %rax, %rax
jne 0x313c
movq 0x28(%rbx), %rsi
movq (%rsi), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40c5
testq %r15, %r15
sete %al
testb $0x8, %r12b
sete %cl
orb %al, %cl
jne 0x319c
movl (%r15), %edi
callq 0x2180
movl 0x4(%r15), %edi
callq 0x2180
testb %r12b, %r12b
jns 0x31b6
leaq 0x20a6(%rip), %rsi      # 0x524e
movl $0x2, %edi
movl %ebp, %edx
xorl %eax, %eax
callq 0x3c82
testb $0x11, %r12b
jne 0x2bdb
movl %ebp, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3920
movq 0x8(%r13), %rdi
testq %rdi, %rdi
je 0x321b
movb (%rdi), %al
testb %al, %al
je 0x3202
incq %rdi
andb $0x7f, %al
movb %al, -0x1(%rdi)
movb (%rdi), %al
incq %rdi
testb %al, %al
jne 0x31e7
movq 0x28(%rbx), %rax
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x321b
callq 0x2100
cmpl $-0x1, %eax
je 0x323b
movl $0x0, 0x3f9e(%rip)      # 0x71b4
jmp 0x2bdb
leaq 0x21e7(%rip), %rsi      # 0x5409
leaq 0x1faf(%rip), %rcx      # 0x51d8
jmp 0x3249
leaq 0x21d7(%rip), %rsi      # 0x5409
leaq 0x1ff0(%rip), %rcx      # 0x5229
jmp 0x3249
leaq 0x21c7(%rip), %rsi      # 0x5409
leaq 0x1f99(%rip), %rcx      # 0x51e2
movl $0x2, %edi
movq %r12, %rdx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3ac8
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x3280
andl $0x4c, %r12d
orl %r12d, 0x30(%rdi)
xorl %esi, %esi
xorl %edx, %edx
callq 0x2a55
movl 0x3f2e(%rip), %edi      # 0x71b4
callq 0x2080