// File: /workspace/github_c_makefile_star2_O2/oridb[P]mc/parse/specialize.c
// Function: specializedcl
Node *
specializedcl(Node *gnode, Type *param, Type *to, Node **name)
{
	Tysubst *tsmap;
	Node *g, *d, *n;
	Stab *st;

	assert(gnode->type == Ndecl);
	assert(gnode->decl.isgeneric);

	n = genericname(gnode, param, to);
	*name = n;
	if (n->name.ns)
		st = getns(n->name.ns);
	else
		st = file.globls;
	if (!st)
		fatal(n, "Can't find symbol table for %s.%s", n->name.ns, n->name.name);
	d = getdcl(st, n);
	if (d)
		return d;
	if (gnode->decl.trait) {
		g = bestimpl(gnode, to);
		if (!g)
			fatal(gnode, "type %s does not implement %s:%s",
				tystr(param), namestr(gnode->decl.name), tystr(to));
	} else {
		g = gnode;
	}
	if (debugopt['S'])
		printf("specializing [%d]%s => %s\n", g->loc.line,
			namestr(g->decl.name), namestr(n));
	/* namespaced names need to be looked up in context. */
	pushstab(st);

	/* specialize */
	tsmap = mksubst();
	fillsubst(tsmap, to, g->decl.type);

	d = mkdecl(g->loc, n, tysubst(g->decl.type, tsmap));
	d->decl.isconst = g->decl.isconst;
	d->decl.isextern = g->decl.isextern;
	d->decl.isglobl = g->decl.isglobl;
	d->decl.init = specializenode(g->decl.init, tsmap);
	putdcl(st, d);

	fixup(d);

	lappend(&file.stmts, &file.nstmts, d);
	substfree(tsmap);
	popstab();
	return d;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpl $0xb, 0x8(%rdi)
jne 0x1cfc4
movq %rdi, %r12
cmpb $0x0, 0x73(%rdi)
je 0x1cfe3
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %rbp
movq %r12, %rdi
callq 0x1cc74
movq %rax, %r15
movq %rax, (%r14)
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x1cdb8
callq 0x1da38
movq %rax, %r14
jmp 0x1cdc6
leaq 0x414b9(%rip), %rax     # 0x5e278
movq 0x90(%rax), %r14
testq %r14, %r14
je 0x1d002
movq %r14, %rdi
movq %r15, %rsi
callq 0x1dc67
movq %rax, %r13
testq %rax, %rax
jne 0x1cfb2
cmpq $0x0, 0x40(%r12)
je 0x1ce19
movq %rbp, 0x30(%rsp)
movq 0x48(%r12), %rdi
movq %rbx, %rsi
callq 0x2a517
testl %eax, %eax
je 0x1ce21
movq 0x48(%r12), %rdi
movq %rbx, %rsi
callq 0x2a3e8
movq %rax, %rbp
jmp 0x1ced4
movq %r12, %rbp
jmp 0x1cedd
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, (%rsp)
leaq 0x18(%rsp), %rax
andq $0x0, (%rax)
leaq 0x8(%rsp), %rax
andq $0x0, (%rax)
movq 0x50(%r12), %r14
movq %r12, 0x10(%rsp)
movq 0x58(%r12), %r15
pushq $-0x1
popq %r12
xorl %ebp, %ebp
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x1ceac
movq (%r14,%rbx,8), %rdi
callq 0x1bf2d
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x158be
cmpl %r12d, %eax
jle 0x1ce92
movl %eax, %r13d
leaq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x29cc7
movq (%r14,%rbx,8), %rbp
movl %r13d, %r12d
jmp 0x1cea7
jne 0x1cea7
movq (%r14,%rbx,8), %rdx
leaq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x29b2d
incq %rbx
jmp 0x1ce58
testl %r12d, %r12d
js 0x1d01b
cmpq $0x0, 0x8(%rsp)
movq (%rsp), %rbx
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r15
movq 0x10(%rsp), %r12
jne 0x1d060
testq %rbp, %rbp
je 0x1d024
leaq 0x412fc(%rip), %rax     # 0x5e1e0
cmpb $0x0, 0x53(%rax)
je 0x1cf19
movl (%rbp), %r12d
movq 0x20(%rbp), %rdi
callq 0x1c0c8
movq %rax, %r13
movq %r15, %rdi
callq 0x1c0c8
leaq 0x16357(%rip), %rdi     # 0x33260
movl %r12d, %esi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4140
movq %r14, %rdi
callq 0x1d890
callq 0x1c2cd
movq %rax, %r12
movq 0x28(%rbp), %rdx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1d07c
movq 0x28(%rbp), %rdi
movq %r12, %rsi
callq 0x1d25e
movq (%rbp), %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1bd5f
movq %rax, %r13
movb 0x72(%rbp), %al
movb %al, 0x72(%r13)
movb 0x74(%rbp), %al
movb %al, 0x74(%r13)
movb 0x71(%rbp), %al
movb %al, 0x71(%r13)
movq 0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x1c82b
movq %rax, 0x30(%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0x1deda
movq %r13, %rdi
callq 0x1d290
leaq 0x412e3(%rip), %rsi     # 0x5e278
leaq 0x40(%rsi), %rdi
addq $0x48, %rsi
movq %r13, %rdx
callq 0x29b2d
movq %r12, %rdi
callq 0x1c319
callq 0x1d8d4
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x161e5(%rip), %rdi     # 0x331b0
leaq 0x161f3(%rip), %rsi     # 0x331c5
leaq 0x161f9(%rip), %rcx     # 0x331d2
movl $0x220, %edx            # imm = 0x220
callq 0x4180
leaq 0x1621d(%rip), %rdi     # 0x33207
leaq 0x161d4(%rip), %rsi     # 0x331c5
leaq 0x161da(%rip), %rcx     # 0x331d2
movl $0x221, %edx            # imm = 0x221
callq 0x4180
movq 0x18(%r15), %rdx
movq 0x20(%r15), %rcx
leaq 0x1620c(%rip), %rsi     # 0x3321d
movq %r15, %rdi
xorl %eax, %eax
callq 0x120fd
movq (%rsp), %rbx
movq 0x10(%rsp), %r12
movq 0x30(%rsp), %rdi
callq 0x21009
movq %rax, %r14
movq 0x20(%r12), %rdi
callq 0x1c0c8
movq %rax, %r15
movq %rbx, %rdi
callq 0x21009
leaq 0x161f2(%rip), %rsi     # 0x3323f
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x120fd
movq %rbx, %rdi
callq 0x21009
leaq 0x16241(%rip), %rsi     # 0x332b0
movq %r12, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x120fd