// File: /workspace/github_c_makefile_star2_O1/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 $0xf8, %rsp
movl %esi, %ebp
movq %rdi, %rbx
callq 0xbae1
testq %rbx, %rbx
je 0xd685
leaq 0x720d(%rip), %r13      # 0x145f8
movl $0x1, %r14d
xorl %r15d, %r15d
movl (%rbx), %eax
cmpq $0x20, %rax
ja 0xd899
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl 0xdbc7(%rip), %r12d     # 0x1afd8
movl $0x1, 0xdbbd(%rip)      # 0x1afd8
movq 0x8(%rbx), %rdi
movl %r14d, %esi
callq 0xd3c0
movl %r12d, 0xdbaa(%rip)     # 0x1afd8
testl %eax, %eax
je 0xd436
movq 0x10(%rbx), %rbx
testl %eax, %eax
jne 0xd609
jmp 0xdb91
movq 0x8(%rbx), %rdi
movl (%rdi), %eax
cmpl $0x1, %eax
je 0xd5b6
cmpl $0x14, %eax
je 0xd460
cmpl $0xc, %eax
jne 0xd5d4
leaq 0xc661(%rip), %rax      # 0x19ac8
cmpq $0x0, (%rax)
jne 0xd47c
movl %ebp, %edi
callq 0xdc76
testl %eax, %eax
je 0xd5e0
movl %r15d, %edi
callq 0x4eba
movq 0x8(%rbx), %rdi
callq 0x6c1b
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0xd4b7
cmpl $0x13, (%rax)
jne 0xd4b7
movq 0x8(%rax), %rcx
movl (%rcx), %ecx
cmpl $0xc, %ecx
je 0xd4bc
cmpl $0x14, %ecx
je 0xd4bc
movq 0x10(%rax), %rcx
movq %rcx, %rax
testq %rcx, %rcx
jne 0xd496
callq 0xb8a8
movq 0x10(%rbx), %rdi
movl %r15d, %esi
callq 0xd3c0
callq 0xbc85
movl %eax, %edi
callq 0x4fb5
jmp 0xd5e0
cmpq $0x0, 0x10(%rbx)
jne 0xdaf5
movq 0x8(%rbx), %rbx
jmp 0xd609
movq 0x8(%rbx), %rdi
callq 0x6c1b
movq 0x10(%rbx), %rax
movq %rax, %rbx
testq %rax, %rax
jne 0xd609
jmp 0xdb42
movq 0x8(%rbx), %rdi
movl %r14d, %esi
callq 0xd3c0
movq 0x10(%rbx), %rbx
jmp 0xd609
movl 0xdab1(%rip), %r12d     # 0x1afd8
movl $0x1, 0xdaa7(%rip)      # 0x1afd8
movq 0x8(%rbx), %rdi
movl %r14d, %esi
callq 0xd3c0
movl %r12d, 0xda94(%rip)     # 0x1afd8
testl %eax, %eax
jne 0xd54c
movq 0x10(%rbx), %rbx
testl %eax, %eax
je 0xd609
jmp 0xdb91
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0xd574
cmpl $0xa, (%rax)
jne 0xd579
movq 0x8(%rax), %rdx
movq 0x10(%rax), %r15
movq %rdx, %rax
jmp 0xd579
movq %r15, %rax
jmp 0xd579
movq %rax, %r12
movl 0xda55(%rip), %r14d     # 0x1afd8
movl $0x1, 0xda4b(%rip)      # 0x1afd8
movq 0x8(%rbx), %rdi
movl $0x1, %esi
callq 0xd3c0
testl %eax, %eax
cmovneq %r12, %r15
movl %r14d, 0xda30(%rip)     # 0x1afd8
movl $0x1, %r14d
movq %r15, %rbx
xorl %r15d, %r15d
jmp 0xd609
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0xd5f3
movl (%rcx), %eax
cmpl $0x13, %eax
jne 0xd5e4
movq 0x10(%rcx), %rax
movq %rax, %rcx
testq %rax, %rax
jne 0xd5bf
jmp 0xd5f3
leaq 0x70d3(%rip), %rdi      # 0x146ae
callq 0xc83e
movb $0x1, %al
jmp 0xd601
cmpl $0x14, %eax
ja 0xd619
movl $0x101002, %ecx         # imm = 0x101002
btl %eax, %ecx
jae 0xd619
movl %r14d, %esi
callq 0xd3c0
movq 0x10(%rbx), %rbx
xorl %eax, %eax
testb %al, %al
jne 0xdb91
callq 0xbae1
testq %rbx, %rbx
jne 0xd3f4
jmp 0xd685
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x6c67
movq %rax, %r12
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rdi
callq 0x6c67
movq %rax, %rdi
callq 0x60fc
movq %r12, %rdi
movq %rax, %rsi
movl %r14d, %edx
callq 0x6ae8
movq (%r12), %rsi
movl $0x3, %edi
leaq 0x30(%rsp), %rdx
callq 0x459c
movq 0x10(%rbx), %rdi
movl %ebp, %esi
callq 0xd3c0
movq (%r12), %rdi
movl %r14d, %esi
callq 0xcc64
movl $0x3, %edi
callq 0x45d0
jmp 0xd5e0
testl %ebp, %ebp
je 0xdba8
movl $0x1, %ebx
movl %ebx, %edi
callq 0xbcdc
movl %ebx, %eax
jmp 0xdb96
movq %rbx, %rdi
callq 0x6c67
movq %rax, %rdi
callq 0x60fc
movq %rax, %rdi
movl %ebp, %esi
callq 0x48fc
jmp 0xdb91
movq 0x8(%rbx), %rdi
callq 0x6c67
testq %rax, %rax
je 0xdb55
leaq 0xc518(%rip), %r14      # 0x19bf0
leaq 0x6fb4(%rip), %rbx      # 0x14693
xorl %r15d, %r15d
movl $0x2, %ebp
movq %rax, %r12
cmpl $0x0, (%r14)
je 0xd701
movq (%r12), %rdx
movl %r15d, %eax
movl %ebp, %edi
movq %rbx, %rsi
callq 0xb06f
movq (%r12), %rdi
callq 0x4e03
movq 0x10(%r12), %rax
movq %rax, %r12
testq %rax, %rax
jne 0xd6ea
jmp 0xdb55
movl 0xd8b5(%rip), %r13d     # 0x1afd8
movl $0x1, 0xd8ab(%rip)      # 0x1afd8
movq 0x8(%rbx), %rdi
movl $0x1, %esi
callq 0xd3c0
movl %r13d, 0xd896(%rip)     # 0x1afd8
testl %eax, %eax
je 0xdb91
leaq 0x30(%rsp), %rdi
movl $0x1, %esi
callq 0x3370
testl %eax, %eax
jne 0xdb91
movl $0x1, %ebp
leaq 0x30(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movl %ebp, %edi
callq 0x459c
movl %r13d, 0xd85a(%rip)     # 0x1afd8
movl $0x4, %r14d
movq %rsp, %r15
callq 0xa09f
movl %r14d, %edi
movq %rax, %rsi
movq %r15, %rdx
callq 0x459c
movq 0x10(%rbx), %rdi
callq 0xdc21
movl $0x1, 0xd82b(%rip)      # 0x1afd8
movq 0x8(%rbx), %rdi
movl %ebp, %esi
callq 0xd3c0
movl %eax, %r12d
movl %r13d, 0xd816(%rip)     # 0x1afd8
movl %r14d, %edi
callq 0x45d0
testl %r12d, %r12d
jne 0xd787
movl %r13d, 0xd802(%rip)     # 0x1afd8
jmp 0xd969
callq 0xcfb8
testl %eax, %eax
je 0xdbaf
movl %eax, %ebx
leaq 0xc3e3(%rip), %rax      # 0x19bd4
cmpl $0x0, (%rax)
je 0xd80b
leaq 0x6e7f(%rip), %rsi      # 0x1467c
xorl %eax, %eax
movl $0x2, %edi
movl %ebx, %edx
callq 0xb06f
leaq 0x1f93(%rip), %rdi      # 0xf7a5
xorl %ebp, %ebp
movl %ebp, %eax
movl %ebx, %esi
callq 0xb274
movl %ebp, %esi
movq %rax, %rdi
callq 0x6714
leaq 0x1f8d(%rip), %rdi      # 0xf7bb
movq %rax, %rsi
movl %ebp, %edx
callq 0xc918
leaq 0xc289(%rip), %rax      # 0x19ac8
movq $0x0, (%rax)
jmp 0xdb91
cmpq $0x0, 0x8(%rbx)
jne 0xd85e
leaq 0x1ea3(%rip), %rdi      # 0xf6fc
callq 0x47be
movq 0x8(%rbx), %rdi
callq 0x6c67
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x6c67
movq %rax, %rdi
callq 0x60fc
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x6ae8
jmp 0xdb91
leaq 0x6e46(%rip), %rdi      # 0x146da
callq 0x47be
leaq 0x6e65(%rip), %rdi      # 0x14705
callq 0xc83e
jmp 0xdb91
movq %rbx, %rdi
callq 0xdd10
jmp 0xdb91
movq 0x8(%rbx), %rdi
callq 0x6c67
movq %rax, %r14
leaq 0x30(%rsp), %rdi
movl $0x1, %esi
callq 0x3370
testl %eax, %eax
jne 0xdb91
leaq 0x30(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movl $0x1, %edi
callq 0x459c
movq 0x10(%rbx), %rdi
callq 0x6c67
movq %rax, %rdi
callq 0x60fc
leaq -0x39de(%rip), %rsi     # 0x9f28
movq %rax, %rdi
callq 0x9740
testq %rax, %rax
je 0xd969
xorl %ebp, %ebp
movl $0x4, %r15d
movq %rsp, %r12
movq %rax, %r13
movq (%r13), %rdi
movl %ebp, %esi
callq 0x6714
movq %r14, %rdi
movq %rax, %rsi
movl %ebp, %edx
callq 0x6ae8
callq 0xa09f
movl %r15d, %edi
movq %rax, %rsi
movq %r12, %rdx
callq 0x459c
movq 0x18(%rbx), %rdi
callq 0xdc21
movl %r15d, %edi
callq 0x45d0
movq 0x10(%r13), %rax
movq %rax, %r13
testq %rax, %rax
jne 0xd921
movl $0x1, %edi
callq 0x45d0
jmp 0xdb91
movq 0x8(%rbx), %rdi
movl $0x1, %esi
callq 0xd3c0
xorl %edi, %edi
testl %eax, %eax
sete %al
movb %al, %dil
jmp 0xdb8c
movq 0x8(%rbx), %rdi
callq 0x6c67
testq %rax, %rax
je 0xdb49
leaq 0xc242(%rip), %r14      # 0x19bf0
movl $0x2, %ebp
movq %rax, %r15
cmpl $0x0, (%r14)
je 0xd9ca
movq (%r15), %rsi
movq 0x10(%rbx), %rdx
movl %ebp, %edi
callq 0x51fa
movq (%r15), %rdi
movq 0x10(%rbx), %rsi
callq 0x4ccc
movq 0x10(%r15), %rax
movq %rax, %r15
testq %rax, %rax
jne 0xd9b6
jmp 0xdb55
movl $0x1, %edi
callq 0xdc76
testl %eax, %eax
je 0xdb91
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x4eba
jmp 0xdb29
movq 0x8(%rbx), %rdi
callq 0x6c67
movq %rax, %rdi
callq 0x60fc
movq %rax, %r15
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x6c67
movq %rax, %rbx
leaq 0xc1bf(%rip), %rax      # 0x19bf0
cmpl $0x0, (%rax)
je 0xdb7f
testq %r15, %r15
je 0xdb5c
cmpq $0x0, 0x10(%r14)
leaq 0x6c56(%rip), %rax      # 0x146a5
leaq 0x6c44(%rip), %rcx      # 0x1469a
cmoveq %rax, %rcx
movq %rcx, %rsi
jmp 0xdb63
movq 0x8(%rbx), %rdi
callq 0x6c67
movq %rax, %r14
movq %rbx, %rcx
movq 0x10(%rcx), %rbx
testq %rbx, %rbx
sete %bpl
je 0xdae1
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0xda8c
cmpl $0x18, (%rax)
je 0xda92
movq 0x10(%rbx), %rbx
jmp 0xda75
movq 0x8(%rax), %rdi
callq 0x6c67
movq %r14, %rdi
movq %rax, %rsi
callq 0x6058
movq %rbx, %rcx
testl %eax, %eax
je 0xda71
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0xdadf
movl $0x1, %ebx
movq %rax, %r14
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0xdacc
cmpl $0x18, (%rdi)
je 0xdadf
movl %ebx, %esi
callq 0xd3c0
movq 0x10(%r14), %rax
movq %rax, %r14
testq %rax, %rax
jne 0xdabe
jmp 0xdae6
callq 0xbc54
testb $0x1, %bpl
je 0xdb91
jmp 0xdb96
movl %ebp, %edi
callq 0xdc76
testl %eax, %eax
je 0xdb91
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x4eba
movq 0x10(%rbx), %rdi
movl $0x1, %esi
callq 0xd3c0
leaq 0xbfa6(%rip), %rax      # 0x19ac8
movq $0x0, (%rax)
movq 0x8(%rbx), %rdi
movl %ebp, %esi
callq 0xd3c0
callq 0xbc85
movl %eax, %edi
callq 0x4fb5
jmp 0xdb91
callq 0xb8a8
jmp 0xdb91
leaq 0x6b30(%rip), %rdi      # 0x14680
callq 0x47be
movl $0x1, %edi
jmp 0xdb8c
leaq 0x6b42(%rip), %rsi      # 0x146a5
leaq 0x6a07(%rip), %rcx      # 0x14571
xorl %eax, %eax
movl $0x2, %edi
movq %r14, %rdx
movq %rbx, %r8
movq %rcx, %r9
callq 0xb06f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6058
movl %eax, %edi
callq 0xbcdc
callq 0xbc54
addq $0xf8, %rsp
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 0x4eba
movl $0x1, %r14d
movl $0x16, %edi
movq %r14, %rsi
callq 0xbb91
movl $0x15, %edi
movq %r14, %rsi
callq 0xbb91
movl $0x14, %edi
movq %r14, %rsi
callq 0xbb91
callq 0x30d0
movl %ebp, %edi
movl %eax, %esi
callq 0x3320
leaq 0x221b(%rip), %rdi      # 0xfe15
movl %ebp, %esi
callq 0xa148
movl %eax, %edi
movl %ebp, %esi
callq 0xc8f5
movq 0x8(%rbx), %rdi
movl %ebp, %esi
callq 0xd3c0
callq 0xbc85
movl %eax, %edi
callq 0x3330