// File: /workspace/github_c_makefile_star2_O1/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 0x1f74f
movq %rdi, %r12
cmpb $0x0, 0x73(%rdi)
je 0x1f76e
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %rbp
movq %r12, %rdi
callq 0x1f3fc
movq %rax, %rbx
movq %rax, (%r14)
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x1f540
callq 0x2022f
movq %rax, %r14
jmp 0x1f54e
leaq 0x41d31(%rip), %rax     # 0x61278
movq 0x90(%rax), %r14
testq %r14, %r14
je 0x1f78d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2048b
movq %rax, %r13
testq %rax, %rax
jne 0x1f73d
cmpq $0x0, 0x40(%r12)
je 0x1f5a1
movq %rbp, 0x28(%rsp)
movq 0x48(%r12), %rdi
movq %r15, %rsi
callq 0x2decd
testl %eax, %eax
je 0x1f5a9
movq 0x48(%r12), %rdi
movq %r15, %rsi
callq 0x2dd9a
movq %rax, %rbp
jmp 0x1f65f
movq %r12, %rbp
jmp 0x1f668
movq %rbx, 0x8(%rsp)
xorl %ebp, %ebp
movq %rbp, 0x18(%rsp)
movq %rbp, (%rsp)
movq 0x58(%r12), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x1f640
movq %r14, 0x20(%rsp)
movq %r15, 0x10(%rsp)
movq 0x50(%r12), %r15
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
xorl %ebp, %ebp
movq (%r15,%r14,8), %rdi
callq 0x1e56c
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x1729e
cmpl %ebx, %eax
jle 0x1f614
movl %eax, %r13d
leaq 0x18(%rsp), %rdi
movq %rsp, %rsi
callq 0x2d5c5
movq (%r15,%r14,8), %rbp
movl %r13d, %ebx
jmp 0x1f627
jne 0x1f627
movq (%r15,%r14,8), %rdx
leaq 0x18(%rsp), %rdi
movq %rsp, %rsi
callq 0x2d3ff
incq %r14
cmpq %r14, 0x30(%rsp)
jne 0x1f5e1
shrl $0x1f, %ebx
movq 0x10(%rsp), %r15
movq 0x20(%rsp), %r14
jmp 0x1f642
movb $0x1, %bl
testb %bl, %bl
je 0x1f64f
xorl %ebp, %ebp
movq 0x8(%rsp), %rbx
jmp 0x1f65f
cmpq $0x0, (%rsp)
movq 0x8(%rsp), %rbx
jne 0x1f7e2
testq %rbp, %rbp
je 0x1f7a6
leaq 0x41b71(%rip), %rax     # 0x611e0
cmpb $0x0, 0x53(%rax)
je 0x1f6a4
movl (%rbp), %r12d
movq 0x20(%rbp), %rdi
callq 0x1e73b
movq %rax, %r13
movq %rbx, %rdi
callq 0x1e73b
leaq 0x17bec(%rip), %rdi     # 0x37280
movl %r12d, %esi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4140
movq %r14, %rdi
callq 0x20070
callq 0x1e994
movq %rax, %r12
movq 0x28(%rbp), %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x1f7fe
movq 0x28(%rbp), %rdi
movq %r12, %rsi
callq 0x1fa14
movq (%rbp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1e29f
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 0x1ef85
movq %rax, 0x30(%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0x2071e
movq %r13, %rdi
callq 0x1fa46
leaq 0x41b58(%rip), %rsi     # 0x61278
leaq 0x40(%rsi), %rdi
addq $0x48, %rsi
movq %r13, %rdx
callq 0x2d3ff
movq %r12, %rdi
callq 0x1e9d5
callq 0x200b6
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17a7a(%rip), %rdi     # 0x371d0
leaq 0x17a88(%rip), %rsi     # 0x371e5
leaq 0x17a8e(%rip), %rcx     # 0x371f2
movl $0x220, %edx            # imm = 0x220
callq 0x4180
leaq 0x17ab2(%rip), %rdi     # 0x37227
leaq 0x17a69(%rip), %rsi     # 0x371e5
leaq 0x17a6f(%rip), %rcx     # 0x371f2
movl $0x221, %edx            # imm = 0x221
callq 0x4180
movq 0x18(%rbx), %rdx
movq 0x20(%rbx), %rcx
leaq 0x17aa1(%rip), %rsi     # 0x3723d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x13aa3
movq 0x28(%rsp), %rdi
callq 0x23e44
movq %rax, %r14
movq 0x20(%r12), %rdi
callq 0x1e73b
movq %r15, %rdi
movq %rax, %r15
callq 0x23e44
leaq 0x17a90(%rip), %rsi     # 0x3725f
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x13aa3
movq %r15, %rdi
callq 0x23e44
leaq 0x17adf(%rip), %rsi     # 0x372d0
movq %r12, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x13aa3