// File: /workspace/github_c_makefile_star2_O2/oridb[P]mc/parse/specialize.c
// Function: tyspecialize
Type *
tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed)
{
	Type *t, *ret, *tmp, *var;
	Traitspec *ts;
	size_t i, narg;
	Type **arg;

	t = tysearch(orig);
	tmp = substget(tsmap, t);
	if (tmp)
		return tysearch(tmp);
	arg = NULL;
	narg = 0;
	switch (t->type) {
	case Typaram:
		ret = mktyvar(t->loc);
		ret->trneed = bsdup(t->trneed);
		substput(tsmap, t, ret);
		for (i = 0; i < t->nspec; i++) {
			ts = zalloc(sizeof(Traitspec));
			ts->trait = t->spec[i]->trait;
			ts->ntrait = t->spec[i]->ntrait;
			ts->param = tyspecialize(t->spec[i]->param, tsmap, delayed);
			if (t->spec[i]->aux)
				ts->aux = tyspecialize(t->spec[i]->aux, tsmap, delayed);
			lappend(&ret->spec, &ret->nspec, ts);
		}
		break;
	case Tygeneric:
		var = mktyvar(t->loc);
		substput(tsmap, t, var);
		if (orig->type == Tyunres) {
			substpush(tsmap);
			for (i = 0; i < orig->narg; i++)
				substput(tsmap, t->gparam[i], orig->arg[i]);
		}
		for (i = 0; i < t->ngparam; i++)
			lappend(&arg, &narg, tyspecialize(t->gparam[i], tsmap, delayed));
		ret = mktyname(t->loc, t->name, tyspecialize(t->sub[0], tsmap, delayed));
		if (orig->type == Tyunres)
			substpop(tsmap);
		ret->arg = arg;
		ret->narg = narg;
		tytab[var->tid] = ret;
		break;
	case Tyname:
		if (!hasparams(t))
			return t;
		var = mktyvar(t->loc);
		substput(tsmap, t, var);
		for (i = 0; i < t->narg; i++)
			lappend(&arg, &narg, tyspecialize(t->arg[i], tsmap, delayed));
		ret = mktyname(t->loc, t->name, tyspecialize(t->sub[0], tsmap, delayed));
		ret->arg = arg;
		ret->narg = narg;
		tytab[var->tid] = ret;
		break;
	case Tystruct:
		ret = tydup(t);
		substput(tsmap, t, ret);
		pushstab(NULL);
		for (i = 0; i < t->nmemb; i++)
			ret->sdecls[i] = specializenode(t->sdecls[i], tsmap);
		popstab();
		break;
	case Tyunion:
		ret = tydup(t);
		substput(tsmap, t, ret);
		for (i = 0; i < t->nmemb; i++) {
			tmp = NULL;
			if (ret->udecls[i]->etype)
				tmp = tyspecialize(t->udecls[i]->etype, tsmap, delayed);
			ret->udecls[i] = mkucon(t->loc, t->udecls[i]->name, ret, tmp);
			ret->udecls[i]->utype = ret;
			ret->udecls[i]->id = i;
			ret->udecls[i]->synth = 1;
		}
		break;
	case Tyvar:
		ret = t;
		if (delayed && hthas(delayed, t)) {
			tmp = htget(delayed, t);
			htput(delayed, ret, tyspecialize(tmp, tsmap, delayed));
		}
		break;
	default:
		if (t->nsub > 0) {
			ret = tydup(t);
			substput(tsmap, t, ret);
			for (i = 0; i < t->nsub; i++)
				ret->sub[i] = tyspecialize(t->sub[i], tsmap, delayed);
		} else {
			ret = t;
		}
		break;
	}
	if (t->seqaux)
		ret->seqaux = tyspecialize(t->seqaux, tsmap, delayed);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %r13
callq 0x1589c
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x1c28d
testq %rax, %rax
je 0x1c393
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1589c
andq $0x0, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movl (%r15), %eax
addl $-0x17, %eax
cmpl $0x6, %eax
ja 0x1c56b
leaq 0x16d57(%rip), %rcx     # 0x3310c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %rbp, (%rsp)
jmpq *%rax
movq %r15, %rdi
callq 0x1fe75
movq %rax, %r12
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1c27c
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x1d890
cmpq 0x78(%r15), %rbx
jae 0x1c561
movq 0x88(%r15), %rax
movq (%rax,%rbx,8), %rdi
movq %r14, %rsi
callq 0x1c82b
movq 0x88(%r12), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x1c3e4
movq %r15, %r12
testq %rbp, %rbp
je 0x1c7fb
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2a517
movq %r15, %r12
testl %eax, %eax
je 0x1c7fb
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2a3e8
movq %rax, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1c34e
movq %rbp, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x2a22a
movq %r15, %r12
jmp 0x1c7fb
movq 0x8(%r15), %rdi
callq 0x2003f
movq %r14, %rdi
movq %r15, %rsi
movq %rax, 0x18(%rsp)
movq %rax, %rdx
callq 0x1c27c
cmpl $0x1b, (%r13)
jne 0x1c4b3
movq %r14, %rdi
callq 0x1c2e6
xorl %ebx, %ebx
cmpq 0x48(%r13), %rbx
jae 0x1c4b3
movq 0x30(%r15), %rax
movq (%rax,%rbx,8), %rsi
movq 0x40(%r13), %rax
movq (%rax,%rbx,8), %rdx
movq %r14, %rdi
callq 0x1c27c
incq %rbx
jmp 0x1c490
xorl %ebp, %ebp
leaq 0x8(%rsp), %rbx
leaq 0x10(%rsp), %r12
cmpq 0x38(%r15), %rbp
jae 0x1c4ec
movq 0x30(%r15), %rax
movq (%rax,%rbp,8), %rdi
movq %r14, %rsi
movq (%rsp), %rdx
callq 0x1c34e
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x29b2d
incq %rbp
jmp 0x1c4bf
movq 0x68(%r15), %rax
movq 0x88(%r15), %rbx
movq (%rax), %rdi
movq %r14, %rsi
movq (%rsp), %rbp
movq %rbp, %rdx
callq 0x1c34e
movq 0x8(%r15), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2015b
movq %rax, %r12
cmpl $0x1b, (%r13)
jne 0x1c536
leaq 0x8(%r14), %rsi
movq %r14, %rdi
callq 0x29b64
movq %rax, %rdi
callq 0x2a1f3
movq 0x8(%rsp), %rax
movq %rax, 0x40(%r12)
movq 0x10(%rsp), %rax
movq %rax, 0x48(%r12)
leaq 0x42c7f(%rip), %rax     # 0x5f1d0
movq (%rax), %rax
movq 0x18(%rsp), %rcx
movl 0x4(%rcx), %ecx
jmp 0x1c7f7
callq 0x1d8d4
jmp 0x1c7fb
cmpq $0x0, 0x70(%r15)
movq %r15, %r12
je 0x1c7fb
movq %r15, %rdi
callq 0x1fe75
movq %rax, %r12
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1c27c
xorl %ebx, %ebx
cmpq 0x70(%r15), %rbx
jae 0x1c7fb
movq 0x68(%r15), %rax
movq (%rax,%rbx,8), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1c34e
movq 0x68(%r12), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x1c594
movq %r15, %rdi
callq 0x1fe75
movq %rax, %r12
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1c27c
xorl %ebx, %ebx
cmpq 0x78(%r15), %rbx
jae 0x1c7fb
movq 0x88(%r12), %rax
movq (%rax,%rbx,8), %rax
cmpq $0x0, 0x28(%rax)
je 0x1c616
movq 0x88(%r15), %rax
movq (%rax,%rbx,8), %rax
movq 0x28(%rax), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1c34e
movq %rax, %rcx
jmp 0x1c618
xorl %ecx, %ecx
movq 0x8(%r15), %rdi
movq 0x88(%r15), %rax
movq (%rax,%rbx,8), %rax
movq 0x18(%rax), %rsi
movq %r12, %rdx
callq 0x1be63
movq 0x88(%r12), %rcx
movq %rax, (%rcx,%rbx,8)
movq 0x88(%r12), %rax
movq (%rax,%rbx,8), %rax
movq %r12, 0x20(%rax)
movq 0x88(%r12), %rax
movq (%rax,%rbx,8), %rax
movq %rbx, 0x8(%rax)
movq 0x88(%r12), %rax
movq (%rax,%rbx,8), %rax
movl $0x1, 0x10(%rax)
incq %rbx
jmp 0x1c5da
movq 0x8(%r15), %rdi
callq 0x2003f
movq %rax, %r12
movq 0x80(%r15), %rdi
callq 0x29d7c
movq %rax, 0x80(%r12)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1c27c
leaq 0x18(%r12), %rax
movq %rax, 0x18(%rsp)
movq %r12, %rax
addq $0x20, %rax
movq %rax, 0x20(%rsp)
xorl %r13d, %r13d
movq (%rsp), %rbp
cmpq 0x20(%r15), %r13
jae 0x1c73a
pushq $0x20
popq %rdi
callq 0x29a78
movq %rax, %rbx
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rcx
movq (%rcx), %rcx
movq %rcx, (%rbx)
movq (%rax,%r13,8), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movq 0x10(%rax), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1c34e
movq %rax, 0x10(%rbx)
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rax
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x1c723
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1c34e
movq %rax, 0x18(%rbx)
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x29b2d
incq %r13
jmp 0x1c6c5
movq (%rsp), %rbp
jmp 0x1c7fb
movq %r15, %rdi
callq 0x2065a
testl %eax, %eax
je 0x1c826
movq 0x8(%r15), %rdi
callq 0x2003f
movq %rax, %r13
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1c27c
xorl %ebp, %ebp
leaq 0x8(%rsp), %rbx
leaq 0x10(%rsp), %r12
cmpq 0x48(%r15), %rbp
jae 0x1c7a6
movq 0x40(%r15), %rax
movq (%rax,%rbp,8), %rdi
movq %r14, %rsi
movq (%rsp), %rdx
callq 0x1c34e
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x29b2d
incq %rbp
jmp 0x1c779
movq 0x68(%r15), %rax
movq 0x88(%r15), %rbx
movq (%rax), %rdi
movq %r14, %rsi
movq (%rsp), %rbp
movq %rbp, %rdx
callq 0x1c34e
movq 0x8(%r15), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2015b
movq %rax, %r12
movq 0x8(%rsp), %rax
movq %rax, 0x40(%r12)
movq 0x10(%rsp), %rax
movq %rax, 0x48(%r12)
leaq 0x429e0(%rip), %rax     # 0x5f1d0
movq (%rax), %rax
movl 0x4(%r13), %ecx
movq %r12, (%rax,%rcx,8)
movq 0x28(%r15), %rdi
testq %rdi, %rdi
je 0x1c814
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1c34e
movq %rax, 0x28(%r12)
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %r12
jmp 0x1c814