// File: /workspace/github_c_makefile_star2_O3/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 0x1f4f5
movq %rdi, %r12
cmpb $0x0, 0x73(%rdi)
je 0x1f514
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %rbp
movq %r12, %rdi
callq 0x1f1a2
movq %rax, %r15
movq %rax, (%r14)
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x1f2e6
callq 0x1ffef
movq %rax, %r14
jmp 0x1f2f4
leaq 0x41f8b(%rip), %rax     # 0x61278
movq 0x90(%rax), %r14
testq %r14, %r14
je 0x1f533
movq %r14, %rdi
movq %r15, %rsi
callq 0x20250
movq %rax, %r13
testq %rax, %rax
jne 0x1f4e3
cmpq $0x0, 0x40(%r12)
je 0x1f347
movq %rbp, 0x30(%rsp)
movq 0x48(%r12), %rdi
movq %rbx, %rsi
callq 0x2da24
testl %eax, %eax
je 0x1f34f
movq 0x48(%r12), %rdi
movq %rbx, %rsi
callq 0x2d8fa
movq %rax, %rbp
jmp 0x1f405
movq %r12, %rbp
jmp 0x1f40e
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, (%rsp)
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq 0x58(%r12), %r14
testq %r14, %r14
je 0x1f54c
movq %r12, 0x18(%rsp)
movq 0x50(%r12), %r15
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%r15,%rbx,8), %rdi
callq 0x1e31c
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x170b6
cmpl %r12d, %eax
jle 0x1f3c0
movl %eax, %r13d
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2d0c7
movq (%r15,%rbx,8), %rbp
movl %r13d, %r12d
jmp 0x1f3d5
jne 0x1f3d5
movq (%r15,%rbx,8), %rdx
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2ceff
incq %rbx
cmpq %rbx, %r14
jne 0x1f38b
testl %r12d, %r12d
movq 0x18(%rsp), %r12
js 0x1f54c
cmpq $0x0, 0x8(%rsp)
movq (%rsp), %rbx
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r15
jne 0x1f58c
testq %rbp, %rbp
je 0x1f550
leaq 0x41dcb(%rip), %rax     # 0x611e0
cmpb $0x0, 0x53(%rax)
je 0x1f44a
movl (%rbp), %r12d
movq 0x20(%rbp), %rdi
callq 0x1e4eb
movq %rax, %r13
movq %r15, %rdi
callq 0x1e4eb
leaq 0x17e56(%rip), %rdi     # 0x37290
movl %r12d, %esi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4140
movq %r14, %rdi
callq 0x1fe30
callq 0x1e744
movq %rax, %r12
movq 0x28(%rbp), %rdx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1f5a8
movq 0x28(%rbp), %rdi
movq %r12, %rsi
callq 0x1f7c6
movq (%rbp), %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1e04f
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 0x1ed37
movq %rax, 0x30(%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0x204de
movq %r13, %rdi
callq 0x1f7f8
leaq 0x41db2(%rip), %rsi     # 0x61278
leaq 0x40(%rsi), %rdi
addq $0x48, %rsi
movq %r13, %rdx
callq 0x2ceff
movq %r12, %rdi
callq 0x1e785
callq 0x1fe76
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17ce4(%rip), %rdi     # 0x371e0
leaq 0x17cf2(%rip), %rsi     # 0x371f5
leaq 0x17cf8(%rip), %rcx     # 0x37202
movl $0x220, %edx            # imm = 0x220
callq 0x4180
leaq 0x17d1c(%rip), %rdi     # 0x37237
leaq 0x17cd3(%rip), %rsi     # 0x371f5
leaq 0x17cd9(%rip), %rcx     # 0x37202
movl $0x221, %edx            # imm = 0x221
callq 0x4180
movq 0x18(%r15), %rdx
movq 0x20(%r15), %rcx
leaq 0x17d0b(%rip), %rsi     # 0x3724d
movq %r15, %rdi
xorl %eax, %eax
callq 0x138e7
movq (%rsp), %rbx
movq 0x30(%rsp), %rdi
callq 0x2398e
movq %rax, %r14
movq 0x20(%r12), %rdi
callq 0x1e4eb
movq %rax, %r15
movq %rbx, %rdi
callq 0x2398e
leaq 0x17cf6(%rip), %rsi     # 0x3726f
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x138e7
movq %rbx, %rdi
callq 0x2398e
leaq 0x17d45(%rip), %rsi     # 0x372e0
movq %r12, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x138e7