// File: /workspace/github_c_makefile_star2_O2/rakitzis[P]rc/walk.c
// Function: walk
extern bool walk(Node *n, bool parent) {
top:	sigchk();
	if (n == NULL) {
		if (!parent)
			exit(0);
		set(TRUE);
		return TRUE;
	}
	switch (n->type) {
	case nArgs: case nBackq: case nConcat: case nCount:
	case nFlat: case nLappend: case nRedir: case nVar:
	case nVarsub: case nWord:
		exec(glob(glom(n)), parent);	/* simple command */
		break;
	case nBody:
		walk(n->u[0].p, TRUE);
		WALK(n->u[1].p, parent);
		/* WALK doesn't fall through */
	case nNowait: {
		int pid;
		if ((pid = rc_fork()) == 0) {
#if defined(RC_JOB) && defined(SIGTTOU) && defined(SIGTTIN) && defined(SIGTSTP)
			setsigdefaults(FALSE);
			rc_signal(SIGTTOU, SIG_IGN);	/* Berkeleyized version: put it in a new pgroup. */
			rc_signal(SIGTTIN, SIG_IGN);
			rc_signal(SIGTSTP, SIG_IGN);
			setpgid(0, getpid());
#else
			setsigdefaults(TRUE);		/* ignore SIGINT, SIGQUIT, SIGTERM */
#endif
			mvfd(rc_open("/dev/null", rFrom), 0);
			walk(n->u[0].p, FALSE);
			exit(getstatus());
		}
		if (interactive)
			fprint(2, "%d\n", pid);
		varassign("apid", word(nprint("%d", pid), NULL), FALSE);
		redirq = NULL; /* kill pre-redir queue */
		break;
	}
	case nAndalso: {
		bool oldcond = cond;
		cond = TRUE;
		if (walk(n->u[0].p, TRUE)) {
			cond = oldcond;
			WALK(n->u[1].p, parent);
		} else
			cond = oldcond;
		break;
	}
	case nOrelse: {
		bool oldcond = cond;
		cond = TRUE;
		if (!walk(n->u[0].p, TRUE)) {
			cond = oldcond;
			WALK(n->u[1].p, parent);
		} else
			cond = oldcond;
		break;
	}
	case nBang:
		set(!walk(n->u[0].p, TRUE));
		break;
	case nIf: {
		bool oldcond = cond;
		Node *true_cmd = n->u[1].p, *false_cmd = NULL;
		if (true_cmd != NULL && true_cmd->type == nElse) {
			false_cmd = true_cmd->u[1].p;
			true_cmd = true_cmd->u[0].p;
		}
		cond = TRUE;
		if (!walk(n->u[0].p, TRUE))
			true_cmd = false_cmd; /* run the else clause */
		cond = oldcond;
		WALK(true_cmd, parent);
	}
	case nWhile: {
		Jbwrap break_jb;
		Edata  break_data;
		Estack break_stack;
		bool testtrue;
		const bool oldcond = cond;
		cond = TRUE;
		if (!walk(n->u[0].p, TRUE)) { /* prevent spurious breaks inside test */
			cond = oldcond;
			break;
		}
		cond = oldcond;
		if (sigsetjmp(break_jb.j, 1))
			break;
		break_data.jb = &break_jb;
		except(eBreak, break_data, &break_stack);

		cond = oldcond;
		do {
			Edata  iter_data;
			Estack iter_stack;
			iter_data.b = newblock();
			except(eArena, iter_data, &iter_stack);
			loop_body(n->u[1].p);
			cond = TRUE;
			testtrue = walk(n->u[0].p, TRUE);
			cond = oldcond;
			unexcept(eArena);
		} while (testtrue);
		cond = oldcond;
		unexcept(eBreak);
		break;
	}
	case nForin: {
		List *l, *var = glom(n->u[0].p);
		Jbwrap break_jb;
		Edata  break_data;
		Estack break_stack;
		if (sigsetjmp(break_jb.j, 1))
			break;
		break_data.jb = &break_jb;
		except(eBreak, break_data, &break_stack);

		for (l = listcpy(glob(glom(n->u[1].p)), nalloc); l != NULL; l = l->n) {
			Edata  iter_data;
			Estack iter_stack;
			assign(var, word(l->w, NULL), FALSE);
			iter_data.b = newblock();
			except(eArena, iter_data, &iter_stack);
			loop_body(n->u[2].p);
			unexcept(eArena);
		}
		unexcept(eBreak);
		break;
	}
	case nSubshell:
		if (dofork(TRUE)) {
			setsigdefaults(FALSE);
			walk(n->u[0].p, FALSE);
			rc_exit(getstatus());
		}
		break;
	case nAssign:
		if (n->u[0].p == NULL)
			rc_error("null variable name");
		assign(glom(n->u[0].p), glob(glom(n->u[1].p)), FALSE);
		break;
	case nPipe:
		dopipe(n);
		break;
	case nNewfn: {
		List *l = glom(n->u[0].p);
		if (l == NULL)
			rc_error("null function name");
		while (l != NULL) {
			if (dashex)
				prettyprint_fn(2, l->w, n->u[1].p);
			fnassign(l->w, n->u[1].p);
			l = l->n;
		}
		set(TRUE);
		break;
	}
	case nRmfn: {
		List *l = glom(n->u[0].p);
		while (l != NULL) {
			if (dashex)
				fprint(2, "fn %S\n", l->w);
			fnrm(l->w);
			l = l->n;
		}
		set(TRUE);
		break;
	}
	case nDup:
		redirq = NULL;
		break; /* Null command */
	case nMatch: {
		List *a = glob(glom(n->u[0].p)), *b = glom(n->u[1].p);
		if (dashex)
			fprint(2, (a != NULL && a->n != NULL) ? "~ (%L) %L\n" : "~ %L %L\n", a, " ", b, " ");
		set(lmatch(a, b));
		break;
	}
	case nSwitch: {
		List *v = glom(n->u[0].p);
		while (1) {
			do {
				n = n->u[1].p;
				if (n == NULL)
					return istrue();
			} while (n->u[0].p == NULL || n->u[0].p->type != nCase);
			if (lmatch(v, glom(n->u[0].p->u[0].p))) {
				for (n = n->u[1].p; n != NULL && (n->u[0].p == NULL || n->u[0].p->type != nCase); n = n->u[1].p)
					walk(n->u[0].p, TRUE);
				break;
			}
		}
		break;
	}
	case nPre: {
		List *v;
		if (n->u[0].p->type == nRedir || n->u[0].p->type == nDup) {
			if (redirq == NULL && !dofork(parent)) /* subshell on first preredir */
				break;
			setsigdefaults(FALSE);
			qredir(n->u[0].p);
			if (!haspreredir(n->u[1].p))
				doredirs(); /* no more preredirs, empty queue */
			walk(n->u[1].p, FALSE);
			rc_exit(getstatus());
			/* NOTREACHED */
		} else if (n->u[0].p->type == nAssign) {
			if (isallpre(n->u[1].p)) {
				walk(n->u[0].p, TRUE);
				WALK(n->u[1].p, parent);
			} else {
				Estack e;
				Edata var;
				v = glom(n->u[0].p->u[0].p);
				assign(v, glob(glom(n->u[0].p->u[1].p)), TRUE);
				var.name = v->w;
				except(eVarstack, var, &e);
				walk(n->u[1].p, parent);
				varrm(v->w, TRUE);
				unexcept(eVarstack);
			}
		} else
			panic("unexpected node in preredir section of walk");
		break;
	}
	case nBrace:
		if (n->u[1].p == NULL) {
			WALK(n->u[0].p, parent);
		} else if (dofork(parent)) {
			setsigdefaults(FALSE);
			walk(n->u[1].p, TRUE); /* Do redirections */
			redirq = NULL;   /* Reset redirection queue */
			walk(n->u[0].p, FALSE); /* Do commands */
			rc_exit(getstatus());
			/* NOTREACHED */
		}
		break;
	case nEpilog:
		qredir(n->u[0].p);
		if (n->u[1].p != NULL) {
			WALK(n->u[1].p, parent); /* Do more redirections. */
		} else {
			doredirs();	/* Okay, we hit the bottom. */
		}
		break;
	case nNmpipe:
		rc_error("named pipes cannot be executed as commands");
		/* NOTREACHED */
	default:
		panic("unknown node in walk");
		/* NOTREACHED */
	}
	return istrue();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x6cdb(%rip), %r15      # 0x13648
pushq $0x1
popq %r14
xorl %r12d, %r12d
callq 0xb266
testq %rbx, %rbx
je 0xcb0d
movl (%rbx), %eax
cmpq $0x20, %rax
ja 0xccda
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl 0xe63a(%rip), %r13d     # 0x1afd8
movl $0x1, 0xe630(%rip)      # 0x1afd8
movq 0x8(%rbx), %rdi
movl %r14d, %esi
callq 0xc950
movl %r13d, 0xe61d(%rip)     # 0x1afd8
testl %eax, %eax
jne 0xca66
jmp 0xd098
movq 0x8(%rbx), %rdi
movl (%rdi), %eax
cmpl $0x1, %eax
jne 0xcb8f
leaq 0x10(%rbx), %r13
movq %r13, %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0xca82
movl (%rcx), %eax
cmpl $0x13, %eax
jne 0xca6f
addq $0x10, %rcx
movq %rcx, %rax
jmp 0xc9de
cmpq $0x0, 0x10(%rbx)
jne 0xd003
movq 0x8(%rbx), %rbx
jmp 0xc974
movq 0x8(%rbx), %rdi
callq 0x68cd
movq 0x10(%rbx), %rax
movq %rax, %rbx
testq %rax, %rax
jne 0xc974
jmp 0xcff9
movq 0x8(%rbx), %rdi
movl %r14d, %esi
callq 0xc950
jmp 0xca66
movl 0xe597(%rip), %r13d     # 0x1afd8
movl $0x1, 0xe58d(%rip)      # 0x1afd8
movq 0x8(%rbx), %rdi
movl %r14d, %esi
callq 0xc950
movl %r13d, 0xe57a(%rip)     # 0x1afd8
testl %eax, %eax
jne 0xd098
movq 0x10(%rbx), %rbx
jmp 0xc974
cmpl $0x1, %eax
je 0xca82
cmpl $0xc, %eax
je 0xca82
cmpl $0x14, %eax
jne 0xcb25
movl %r14d, %esi
callq 0xc950
movq (%r13), %rbx
jmp 0xc974
movq 0x10(%rbx), %rax
testq %rax, %rax
movl %ebp, 0xc(%rsp)
je 0xcab2
cmpl $0xa, (%rax)
jne 0xcab7
movq 0x8(%rax), %rdx
movq 0x10(%rax), %r12
movq %rdx, %rax
jmp 0xcab7
movq %r12, %rax
jmp 0xcab7
movq %rax, %r13
movl 0xe518(%rip), %ebp      # 0x1afd8
movl $0x1, 0xe50e(%rip)      # 0x1afd8
movq 0x8(%rbx), %rdi
movl %r14d, %esi
callq 0xc950
testl %eax, %eax
cmovneq %r13, %r12
movl %ebp, 0xe4f6(%rip)      # 0x1afd8
movq %r12, %rbx
movl 0xc(%rsp), %ebp
jmp 0xc971
movq %rbx, %rdi
callq 0x6914
movq %rax, %rdi
callq 0x5e5f
movq %rax, %rdi
movl %ebp, %esi
callq 0x46d8
jmp 0xd098
testl %ebp, %ebp
je 0xd0af
movl %r14d, %edi
callq 0xb43a
movl %r14d, %eax
jmp 0xd09d
movq 0x8(%rdi), %rdi
callq 0x6914
movq %rax, %r14
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rdi
callq 0x6914
movq %rax, %rdi
callq 0x5e5f
pushq $0x1
popq %r15
movq %r14, %rdi
movq %rax, %rsi
movl %r15d, %edx
callq 0x679b
movq (%r14), %rsi
pushq $0x3
popq %r12
leaq 0x40(%rsp), %rdx
movl %r12d, %edi
callq 0x43bc
movq 0x10(%rbx), %rdi
movl %ebp, %esi
callq 0xc950
movq (%r14), %rdi
movl %r15d, %esi
callq 0xc2ae
movl %r12d, %edi
callq 0x43f0
jmp 0xd098
cmpl $0x14, %eax
je 0xcb9d
cmpl $0xc, %eax
jne 0xd03a
leaq 0xcf24(%rip), %rax      # 0x19ac8
cmpq $0x0, (%rax)
jne 0xcbb9
movl %ebp, %edi
callq 0xd16f
testl %eax, %eax
je 0xd098
xorl %edi, %edi
callq 0x4c71
movq 0x8(%rbx), %rdi
callq 0x68cd
addq $0x10, %rbx
movq %rbx, %rax
movq (%rax), %rax
testq %rax, %rax
je 0xd048
cmpl $0x13, (%rax)
jne 0xd048
movq 0x8(%rax), %rcx
movl (%rcx), %ecx
cmpl $0xc, %ecx
je 0xd04d
cmpl $0x14, %ecx
je 0xd04d
addq $0x10, %rax
jmp 0xcbd0
movq 0x8(%rbx), %rdi
callq 0x6914
leaq 0xcfdd(%rip), %r14      # 0x19bf0
leaq 0x6ac9(%rip), %rbx      # 0x136e3
xorl %r15d, %r15d
pushq $0x2
popq %rbp
movq %rax, %r12
testq %r12, %r12
je 0xccc6
cmpl $0x0, (%r14)
je 0xcc43
movq (%r12), %rdx
movl %r15d, %eax
movl %ebp, %edi
movq %rbx, %rsi
callq 0xa8f6
movq (%r12), %rdi
callq 0x4ba4
movq 0x10(%r12), %r12
jmp 0xcc23
pushq $0x1
popq %rdi
callq 0xd16f
testl %eax, %eax
je 0xd098
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x4c71
jmp 0xd032
movq 0x8(%rbx), %rdi
callq 0x6914
movq %rax, %r14
testq %rax, %rax
jne 0xcc8e
leaq 0x6a47(%rip), %rdi      # 0x136d0
callq 0x45b7
movq %r14, %r15
leaq 0xcf58(%rip), %r14      # 0x19bf0
pushq $0x2
popq %rbp
testq %r15, %r15
je 0xccc6
cmpl $0x0, (%r14)
je 0xccb4
movq (%r15), %rsi
movq 0x10(%rbx), %rdx
movl %ebp, %edi
callq 0x4f96
movq (%r15), %rdi
movq 0x10(%rbx), %rsi
callq 0x4a7a
movq 0x10(%r15), %r15
jmp 0xcc9b
pushq $0x1
popq %rdi
jmp 0xd093
leaq 0x6a55(%rip), %rdi      # 0x1372a
callq 0x45b7
leaq 0x6a74(%rip), %rdi      # 0x13755
jmp 0xd041
movq 0x8(%rbx), %rax
movq %rax, %rdi
testq %rax, %rax
jne 0xcd02
leaq 0x19f3(%rip), %rdi      # 0xe6ec
callq 0x45b7
movq 0x8(%rbx), %rdi
callq 0x6914
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x6914
movq %rax, %rdi
callq 0x5e5f
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x679b
jmp 0xd098
callq 0xc5b0
testl %eax, %eax
je 0xd0b6
movl %eax, %ebx
leaq 0xce91(%rip), %rax      # 0x19bd4
cmpl $0x0, (%rax)
je 0xcd5b
leaq 0x697d(%rip), %rsi      # 0x136cc
xorl %eax, %eax
pushq $0x2
popq %rdi
movl %ebx, %edx
callq 0xa8f6
leaq 0x1a33(%rip), %rdi      # 0xe795
xorl %ebp, %ebp
movl %ebp, %eax
movl %ebx, %esi
callq 0xaaee
movl %ebp, %esi
movq %rax, %rdi
callq 0x6400
leaq 0x1a29(%rip), %rdi      # 0xe7a7
movq %rax, %rsi
movl %ebp, %edx
callq 0xbfac
leaq 0xcd39(%rip), %rax      # 0x19ac8
andq $0x0, (%rax)
jmp 0xd098
movq %rbx, %rdi
callq 0xd204
jmp 0xd098
movq 0x8(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0xc950
xorl %edi, %edi
testl %eax, %eax
sete %al
movb %al, %dil
jmp 0xd093
movq 0x8(%rbx), %rdi
callq 0x6914
movq %rax, %r14
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x3370
testl %eax, %eax
jne 0xd098
pushq $0x1
popq %rdi
leaq 0x40(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x43bc
movq 0x10(%rbx), %rdi
callq 0x6914
movq %rax, %rdi
callq 0x5e5f
leaq -0x34e3(%rip), %rsi     # 0x9928
movq %rax, %rdi
callq 0x9185
xorl %ebp, %ebp
pushq $0x4
popq %r15
leaq 0x10(%rsp), %r12
movq %rax, %r13
testq %r13, %r13
je 0xcf20
movq (%r13), %rdi
movl %ebp, %esi
callq 0x6400
movq %r14, %rdi
movq %rax, %rsi
movl %ebp, %edx
callq 0x679b
callq 0x9a61
movl %r15d, %edi
movq %rax, %rsi
movq %r12, %rdx
callq 0x43bc
movq 0x18(%rbx), %rdi
callq 0xd120
movl %r15d, %edi
callq 0x43f0
movq 0x10(%r13), %r13
jmp 0xce21
movl 0xe165(%rip), %r13d     # 0x1afd8
movl $0x1, 0xe15b(%rip)      # 0x1afd8
movq 0x8(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0xc950
movl %r13d, 0xe148(%rip)     # 0x1afd8
testl %eax, %eax
je 0xd098
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x3370
testl %eax, %eax
jne 0xd098
pushq $0x1
popq %rbp
leaq 0x40(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movl %ebp, %edi
callq 0x43bc
movl %r13d, 0xe110(%rip)     # 0x1afd8
pushq $0x4
popq %r14
leaq 0x10(%rsp), %r15
callq 0x9a61
movl %r14d, %edi
movq %rax, %rsi
movq %r15, %rdx
callq 0x43bc
movq 0x10(%rbx), %rdi
callq 0xd120
movl $0x1, 0xe0e1(%rip)      # 0x1afd8
movq 0x8(%rbx), %rdi
movl %ebp, %esi
callq 0xc950
movl %eax, %r12d
movl %r13d, 0xe0cc(%rip)     # 0x1afd8
movl %r14d, %edi
callq 0x43f0
testl %r12d, %r12d
jne 0xced1
movl %r13d, 0xe0b8(%rip)     # 0x1afd8
pushq $0x1
popq %rdi
jmp 0xcb85
movq 0x8(%rbx), %rdi
callq 0x6914
movq %rax, %rdi
callq 0x5e5f
movq %rax, %r15
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x6914
movq %rax, %rbx
leaq 0xcc9e(%rip), %rax      # 0x19bf0
cmpl $0x0, (%rax)
je 0xd086
testq %r15, %r15
je 0xd065
cmpq $0x0, 0x10(%r14)
leaq 0x6785(%rip), %rax      # 0x136f5
leaq 0x6773(%rip), %rcx      # 0x136ea
cmoveq %rax, %rcx
movq %rcx, %rsi
jmp 0xd06c
movq 0x8(%rbx), %rdi
callq 0x6914
movq %rax, %r14
movq 0x10(%rbx), %r15
testq %r15, %r15
je 0xd098
movq 0x8(%r15), %rax
movq %r15, %rbx
testq %rax, %rax
je 0xcf8f
cmpl $0x18, (%rax)
movq %r15, %rbx
jne 0xcf8f
movq 0x8(%rax), %rdi
callq 0x6914
movq %r14, %rdi
movq %rax, %rsi
callq 0x5dc0
movq %r15, %rbx
testl %eax, %eax
je 0xcf8f
pushq $0x1
popq %rbx
movq %r15, %r14
movq 0x10(%r14), %r14
testq %r14, %r14
je 0xd098
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0xcff0
cmpl $0x18, (%rdi)
je 0xd098
movl %ebx, %esi
callq 0xc950
jmp 0xcfd1
callq 0xb038
jmp 0xd098
movl %ebp, %edi
callq 0xd16f
testl %eax, %eax
je 0xd098
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x4c71
movq 0x10(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0xc950
leaq 0xca9a(%rip), %rax      # 0x19ac8
andq $0x0, (%rax)
movq 0x8(%rbx), %rdi
movl %ebp, %esi
jmp 0xd052
leaq 0x66bd(%rip), %rdi      # 0x136fe
callq 0xbeea
jmp 0xd098
callq 0xb038
movq (%rbx), %rdi
xorl %esi, %esi
callq 0xc950
callq 0xb3ff
movl %eax, %edi
callq 0x4d65
jmp 0xd098
leaq 0x6689(%rip), %rsi      # 0x136f5
leaq 0x654e(%rip), %rcx      # 0x135c1
xorl %eax, %eax
pushq $0x2
popq %rdi
movq %r14, %rdx
movq %rbx, %r8
movq %rcx, %r9
callq 0xa8f6
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5dc0
movl %eax, %edi
callq 0xb43a
callq 0xb3d8
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
callq 0x3330
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x4c71
pushq $0x16
popq %rdi
pushq $0x1
popq %r14
movq %r14, %rsi
callq 0xb30f
pushq $0x15
popq %rdi
movq %r14, %rsi
callq 0xb30f
pushq $0x14
popq %rdi
movq %r14, %rsi
callq 0xb30f
callq 0x30d0
movl %ebp, %edi
movl %eax, %esi
callq 0x3320
leaq 0x1d6c(%rip), %rdi      # 0xee65
movl %ebp, %esi
callq 0x9afc
movl %eax, %edi
movl %ebp, %esi
callq 0xbf88
movq 0x8(%rbx), %rdi
movl %ebp, %esi
callq 0xc950
callq 0xb3ff
movl %eax, %edi
callq 0x3330