// File: /workspace/github_c_makefile_star2_O3/oridb[P]mc/parse/specialize.c
// Function: fixup
static void
fixup(Node *n)
{
	size_t i;
	Node *d;
	Stab *ns;

	if (!n)
		return;
	switch (n->type) {
	case Nuse:	die("Node %s not allowed here\n", nodestr[n->type]);	break;
	case Nexpr:
		fixup(n->expr.idx);
		for (i = 0; i < n->expr.nargs; i++)
			fixup(n->expr.args[i]);
		if (n->expr.op == Ovar) {
			ns = curstab();
			if (n->expr.args[0]->name.ns)
				ns = getns(n->expr.args[0]->name.ns);
			if (!ns)
				fatal(n, "No namespace %s\n", n->expr.args[0]->name.ns);
			d = getdcl(ns, n->expr.args[0]);
			if (!d)
				die("Missing decl %s", namestr(n->expr.args[0]));
			if (d->decl.isgeneric)
				d = specializedcl(d, n->expr.param, n->expr.type, &n->expr.args[0]);
			n->expr.did = d->decl.did;
		}
		break;
	case Nlit:
		switch (n->lit.littype) {
		case Lfunc:	fixup(n->lit.fnval);	break;
		case Lvoid:	break;
		case Lchr:	break;
		case Lint:	break;
		case Lflt:	break;
		case Lstr:	break;
		case Llbl:	break;
		case Lbool:	break;
		}
		break;
	case Nifstmt:
		fixup(n->ifstmt.cond);
		fixup(n->ifstmt.iftrue);
		fixup(n->ifstmt.iffalse);
		break;
	case Nloopstmt:
		pushstab(n->loopstmt.scope);
		fixup(n->loopstmt.init);
		fixup(n->loopstmt.cond);
		fixup(n->loopstmt.step);
		fixup(n->loopstmt.body);
		popstab();
		break;
	case Niterstmt:
		pushstab(n->iterstmt.body->block.scope);
		fixup(n->iterstmt.elt);
		popstab();
		fixup(n->iterstmt.seq);
		fixup(n->iterstmt.body);
		break;
	case Nmatchstmt:
		fixup(n->matchstmt.val);
		for (i = 0; i < n->matchstmt.nmatches; i++)
			fixup(n->matchstmt.matches[i]);
		break;
	case Nmatch:
		/* patterns are evaluated in their block's scope */
		pushstab(n->match.block->block.scope);
		fixup(n->match.pat);
		popstab();
		fixup(n->match.block);
		break;
	case Nblock:
		pushstab(n->block.scope);
		for (i = 0; i < n->block.nstmts; i++)
			fixup(n->block.stmts[i]);
		popstab();
		break;
	case Ndecl:	fixup(n->decl.init);	break;
	case Nfunc:
		pushstab(n->func.scope);
		fixup(n->func.body);
		popstab();
		break;
	case Nnone:
	case Nname: break;
	case Nimpl:	die("trait/impl not implemented");	break;
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
testq %rdi, %rdi
je 0x1f8a3
movq %rdi, %rbx
leaq 0x1799c(%rip), %r14     # 0x371ac
movl 0x8(%rbx), %eax
decl %eax
cmpl $0xc, %eax
ja 0x1f8a3
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq 0x18(%rbx), %rdi
callq 0x1f7f8
movq 0x20(%rbx), %rdi
callq 0x1f7f8
addq $0x28, %rbx
jmp 0x1f897
leaq 0x20(%rbx), %r15
movq 0x20(%rbx), %rax
movq 0x18(%rax), %rdi
callq 0x1fe30
movq 0x18(%rbx), %rdi
callq 0x1f7f8
callq 0x1fe76
jmp 0x1f888
leaq 0x28(%rbx), %r15
movq 0x28(%rbx), %rax
movq 0x18(%rax), %rdi
callq 0x1fe30
movq 0x18(%rbx), %rdi
callq 0x1f7f8
callq 0x1fe76
movq 0x20(%rbx), %rdi
callq 0x1f7f8
movq %r15, %rbx
jmp 0x1f897
cmpl $0x5, 0x18(%rbx)
jne 0x1f8a3
addq $0x30, %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x1f810
popq %rbx
popq %r14
popq %r15
retq
movq 0x38(%rbx), %rdi
callq 0x1fe30
movq 0x18(%rbx), %rdi
callq 0x1f7f8
movq 0x20(%rbx), %rdi
callq 0x1f7f8
movq 0x28(%rbx), %rdi
callq 0x1f7f8
movq 0x30(%rbx), %rdi
jmp 0x1f9d0
movq 0x18(%rbx), %rdi
callq 0x1fe30
cmpq $0x0, 0x20(%rbx)
je 0x1f9d5
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x1f7f8
incq %r14
cmpq 0x20(%rbx), %r14
jb 0x1f8ed
jmp 0x1f9d5
movq 0x18(%rbx), %rdi
callq 0x1f7f8
cmpq $0x0, 0x20(%rbx)
je 0x1f8a3
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x1f7f8
incq %r14
cmpq 0x20(%rbx), %r14
jb 0x1f91b
jmp 0x1f8a3
movq 0x48(%rbx), %rdi
callq 0x1f7f8
cmpq $0x0, 0x40(%rbx)
je 0x1f95f
xorl %r14d, %r14d
movq 0x50(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x1f7f8
incq %r14
cmpq 0x40(%rbx), %r14
jb 0x1f949
cmpl $0x33, 0x18(%rbx)
jne 0x1f8a3
callq 0x1fdf7
movq 0x50(%rbx), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rdi
testq %rdi, %rdi
je 0x1f983
callq 0x1ffef
movq 0x50(%rbx), %rcx
movq (%rcx), %rsi
testq %rax, %rax
je 0x1fa06
movq %rax, %rdi
callq 0x20250
testq %rax, %rax
je 0x1fa1b
cmpb $0x0, 0x73(%rax)
je 0x1f9b6
movq 0x20(%rbx), %rdx
movq 0x28(%rbx), %rsi
movq 0x50(%rbx), %rcx
movq %rax, %rdi
callq 0x1f297
movq 0x18(%rax), %rax
movq %rax, 0x38(%rbx)
jmp 0x1f8a3
movq 0x20(%rbx), %rdi
callq 0x1fe30
movq 0x40(%rbx), %rdi
callq 0x1f7f8
popq %rbx
popq %r14
popq %r15
jmp 0x1fe76
leaq 0x412ba(%rip), %rax     # 0x60ca0
movq 0x38(%rax), %rsi
leaq 0x178ba(%rip), %rdi     # 0x372ab
xorl %eax, %eax
callq 0x13844
leaq 0x178c6(%rip), %rdi     # 0x372c5
xorl %eax, %eax
callq 0x13844
movq 0x18(%rsi), %rdx
leaq 0x17942(%rip), %rsi     # 0x37353
movq %rbx, %rdi
xorl %eax, %eax
callq 0x138e7
movq 0x50(%rbx), %rax
movq (%rax), %rdi
callq 0x1e4eb
leaq 0x17936(%rip), %rdi     # 0x37364
movq %rax, %rsi
jmp 0x1f9f1