// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x17748(%rip), %r14     # 0x3719c
testq %rbx, %rbx
je 0x1fbfa
movl 0x8(%rbx), %eax
decl %eax
cmpl $0xc, %eax
ja 0x1fbfa
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq 0x18(%rbx), %rdi
callq 0x1fa46
jmp 0x1fabb
movq 0x20(%rbx), %rax
movq 0x18(%rax), %rdi
callq 0x20070
movq 0x18(%rbx), %rdi
callq 0x1fa46
callq 0x200b6
movq 0x20(%rbx), %rbx
jmp 0x1fa54
movq 0x28(%rbx), %rax
movq 0x18(%rax), %rdi
callq 0x20070
movq 0x18(%rbx), %rdi
callq 0x1fa46
callq 0x200b6
movq 0x20(%rbx), %rdi
callq 0x1fa46
movq 0x28(%rbx), %rbx
jmp 0x1fa54
cmpl $0x5, 0x18(%rbx)
jne 0x1fbfa
movq 0x30(%rbx), %rbx
jmp 0x1fa54
movq 0x38(%rbx), %rdi
callq 0x20070
movq 0x18(%rbx), %rdi
callq 0x1fa46
movq 0x20(%rbx), %rdi
callq 0x1fa46
movq 0x28(%rbx), %rdi
callq 0x1fa46
movq 0x30(%rbx), %rdi
jmp 0x1fc0f
movq 0x18(%rbx), %rdi
callq 0x1fa46
cmpq $0x0, 0x20(%rbx)
je 0x1fbfa
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x1fa46
incq %r14
cmpq 0x20(%rbx), %r14
jb 0x1fb21
jmp 0x1fbfa
movq 0x18(%rbx), %rdi
callq 0x20070
cmpq $0x0, 0x20(%rbx)
je 0x1fc14
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x1fa46
incq %r14
cmpq 0x20(%rbx), %r14
jb 0x1fb53
jmp 0x1fc14
movq 0x48(%rbx), %rdi
callq 0x1fa46
cmpq $0x0, 0x40(%rbx)
je 0x1fb97
xorl %r14d, %r14d
movq 0x50(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x1fa46
incq %r14
cmpq 0x40(%rbx), %r14
jb 0x1fb81
cmpl $0x33, 0x18(%rbx)
jne 0x1fbfa
callq 0x20037
movq 0x50(%rbx), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rdi
testq %rdi, %rdi
je 0x1fbb7
callq 0x2022f
movq 0x50(%rbx), %rcx
movq (%rcx), %rsi
testq %rax, %rax
je 0x1fc47
movq %rax, %rdi
callq 0x2048b
testq %rax, %rax
je 0x1fc5c
cmpb $0x0, 0x73(%rax)
je 0x1fbf2
movq 0x20(%rbx), %rdx
movq 0x28(%rbx), %rsi
movq 0x50(%rbx), %rcx
movq %rax, %rdi
callq 0x1f4f1
movq 0x18(%rax), %rax
movq %rax, 0x38(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x20(%rbx), %rdi
callq 0x20070
movq 0x40(%rbx), %rdi
callq 0x1fa46
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x200b6
leaq 0x41079(%rip), %rax     # 0x60ca0
movq 0x38(%rax), %rsi
leaq 0x17669(%rip), %rdi     # 0x3729b
xorl %eax, %eax
callq 0x13a00
leaq 0x17675(%rip), %rdi     # 0x372b5
xorl %eax, %eax
callq 0x13a00
movq 0x18(%rsi), %rdx
leaq 0x176f1(%rip), %rsi     # 0x37343
movq %rbx, %rdi
xorl %eax, %eax
callq 0x13aa3
movq 0x50(%rbx), %rax
movq (%rax), %rdi
callq 0x1e73b
leaq 0x176e5(%rip), %rdi     # 0x37354
movq %rax, %rsi
jmp 0x1fc32