// File: /workspace/github_c_makefile_star2_O2/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
movq %rdi, %rbx
leaq 0x15edd(%rip), %r14     # 0x3317c
testq %rbx, %rbx
je 0x1d43b
movl 0x8(%rbx), %eax
decl %eax
cmpl $0xc, %eax
ja 0x1d43b
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq 0x18(%rbx), %rdi
callq 0x1d290
movq 0x20(%rbx), %rdi
callq 0x1d290
addq $0x28, %rbx
jmp 0x1d333
leaq 0x20(%rbx), %r15
movq 0x20(%rbx), %rax
movq 0x18(%rax), %rdi
callq 0x1d890
movq 0x18(%rbx), %rdi
callq 0x1d290
callq 0x1d8d4
jmp 0x1d320
leaq 0x28(%rbx), %r15
movq 0x28(%rbx), %rax
movq 0x18(%rax), %rdi
callq 0x1d890
movq 0x18(%rbx), %rdi
callq 0x1d290
callq 0x1d8d4
movq 0x20(%rbx), %rdi
callq 0x1d290
movq %r15, %rbx
jmp 0x1d333
cmpl $0x5, 0x18(%rbx)
jne 0x1d43b
addq $0x30, %rbx
movq (%rbx), %rbx
jmp 0x1d29f
movq 0x38(%rbx), %rdi
callq 0x1d890
movq 0x18(%rbx), %rdi
callq 0x1d290
movq 0x20(%rbx), %rdi
callq 0x1d290
movq 0x28(%rbx), %rdi
callq 0x1d290
movq 0x30(%rbx), %rdi
jmp 0x1d44e
movq 0x18(%rbx), %rdi
callq 0x1d290
xorl %r14d, %r14d
cmpq 0x20(%rbx), %r14
jae 0x1d43b
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x1d290
incq %r14
jmp 0x1d374
movq 0x18(%rbx), %rdi
callq 0x1d890
xorl %r14d, %r14d
cmpq 0x20(%rbx), %r14
jae 0x1d453
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x1d290
incq %r14
jmp 0x1d39c
movq 0x48(%rbx), %rdi
callq 0x1d290
xorl %r14d, %r14d
cmpq 0x40(%rbx), %r14
jae 0x1d3dc
movq 0x50(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x1d290
incq %r14
jmp 0x1d3c4
cmpl $0x33, 0x18(%rbx)
jne 0x1d43b
callq 0x1d859
movq 0x50(%rbx), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rdi
testq %rdi, %rdi
je 0x1d3fc
callq 0x1da38
movq 0x50(%rbx), %rcx
movq (%rcx), %rsi
testq %rax, %rax
je 0x1d484
movq %rax, %rdi
callq 0x1dc67
testq %rax, %rax
je 0x1d499
cmpb $0x0, 0x73(%rax)
je 0x1d433
movq 0x20(%rbx), %rdx
movq 0x28(%rbx), %rsi
movq 0x50(%rbx), %rcx
movq %rax, %rdi
callq 0x1cd69
movq 0x18(%rax), %rax
movq %rax, 0x38(%rbx)
popq %rbx
popq %r14
popq %r15
retq
movq 0x20(%rbx), %rdi
callq 0x1d890
movq 0x40(%rbx), %rdi
callq 0x1d290
popq %rbx
popq %r14
popq %r15
jmp 0x1d8d4
leaq 0x4083c(%rip), %rax     # 0x5dca0
movq 0x38(%rax), %rsi
leaq 0x15e0c(%rip), %rdi     # 0x3327b
xorl %eax, %eax
callq 0x1205c
leaq 0x15e18(%rip), %rdi     # 0x33295
xorl %eax, %eax
callq 0x1205c
movq 0x18(%rsi), %rdx
leaq 0x15e94(%rip), %rsi     # 0x33323
movq %rbx, %rdi
xorl %eax, %eax
callq 0x120fd
movq 0x50(%rbx), %rax
movq (%rax), %rdi
callq 0x1c0c8
leaq 0x15e88(%rip), %rdi     # 0x33334
movq %rax, %rsi
jmp 0x1d46f