// File: /workspace/github_c_makefile_star2_O3/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 0x17094
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x1e6f9
testq %rax, %rax
je 0x1e805
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17094
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movl (%r15), %eax
addl $-0x17, %eax
cmpl $0x6, %eax
ja 0x1ea29
leaq 0x18915(%rip), %rcx     # 0x3713c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %rbp, (%rsp)
jmpq *%rax
movq %r15, %rdi
callq 0x22953
movq %rax, %r12
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq -0x8(%rax,%rcx,8), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2d71e
xorl %edi, %edi
callq 0x1fe30
cmpq $0x0, 0x78(%r15)
je 0x1e88e
xorl %ebx, %ebx
movq 0x88(%r15), %rax
movq (%rax,%rbx,8), %rdi
movq %r14, %rsi
callq 0x1ed37
movq 0x88(%r12), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
cmpq 0x78(%r15), %rbx
jb 0x1e866
callq 0x1fe76
jmp 0x1ed07
movq %r15, %r12
testq %rbp, %rbp
je 0x1ed07
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2da24
movq %r15, %r12
testl %eax, %eax
je 0x1ed07
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2d8fa
movq %rax, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1e7c0
movq %rbp, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x2d71e
movq %r15, %r12
jmp 0x1ed07
movq 0x8(%r15), %rdi
callq 0x22b29
movq %rax, %rdx
leaq 0x8(%r14), %r12
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq -0x8(%rax,%rcx,8), %rdi
movq %r15, %rsi
movq %rdx, 0x20(%rsp)
callq 0x2d71e
cmpl $0x1b, (%r13)
jne 0x1e96d
leaq 0x50b8(%rip), %rdi      # 0x239d8
leaq 0x5715(%rip), %rsi      # 0x2403c
callq 0x2d678
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2ceff
cmpq $0x0, 0x48(%r13)
je 0x1e96d
xorl %ebx, %ebx
movq 0x30(%r15), %rax
movq (%rax,%rbx,8), %rsi
movq 0x40(%r13), %rax
movq (%rax,%rbx,8), %rdx
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq -0x8(%rax,%rcx,8), %rdi
callq 0x2d71e
incq %rbx
cmpq 0x48(%r13), %rbx
jb 0x1e943
movq %r12, 0x18(%rsp)
cmpq $0x0, 0x38(%r15)
movq (%rsp), %rbx
je 0x1e9b0
xorl %ebp, %ebp
leaq 0x10(%rsp), %r12
movq 0x30(%r15), %rax
movq (%rax,%rbp,8), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1e7c0
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2ceff
incq %rbp
cmpq 0x38(%r15), %rbp
jb 0x1e984
movq 0x68(%r15), %rax
movq 0x88(%r15), %r12
movq (%rax), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1e7c0
movq 0x8(%r15), %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x22c4f
movq %rax, %r12
cmpl $0x1b, (%r13)
movq %rbx, %rbp
jne 0x1e9fa
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x2cf36
movq %rax, %rdi
callq 0x2d6e7
movq 0x8(%rsp), %rax
movq %rax, 0x40(%r12)
movq 0x10(%rsp), %rax
movq %rax, 0x48(%r12)
leaq 0x437bb(%rip), %rax     # 0x621d0
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movl 0x4(%rcx), %ecx
movq %r12, (%rax,%rcx,8)
jmp 0x1ed07
cmpq $0x0, 0x70(%r15)
movq %r15, %r12
je 0x1ed07
movq %r15, %rdi
callq 0x22953
movq %rax, %r12
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq -0x8(%rax,%rcx,8), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2d71e
cmpq $0x0, 0x70(%r15)
je 0x1ed07
xorl %ebx, %ebx
movq 0x68(%r15), %rax
movq (%rax,%rbx,8), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1e7c0
movq 0x68(%r12), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
cmpq 0x70(%r15), %rbx
jb 0x1ea66
jmp 0x1ed07
movq %r15, %rdi
callq 0x22953
movq %rax, %r12
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq -0x8(%rax,%rcx,8), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2d71e
cmpq $0x0, 0x78(%r15)
je 0x1ed07
xorl %ebx, %ebx
movq 0x88(%r12), %rax
movq (%rax,%rbx,8), %rax
cmpq $0x0, 0x28(%rax)
je 0x1eaf1
movq 0x88(%r15), %rax
movq (%rax,%rbx,8), %rax
movq 0x28(%rax), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1e7c0
movq %rax, %rcx
jmp 0x1eaf3
xorl %ecx, %ecx
movq 0x8(%r15), %rdi
movq 0x88(%r15), %rax
movq (%rax,%rbx,8), %rax
movq 0x18(%rax), %rsi
movq %r12, %rdx
callq 0x1e18e
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
cmpq 0x78(%r15), %rbx
jb 0x1eabf
jmp 0x1ed07
movq 0x8(%r15), %rdi
callq 0x22b29
movq %rax, %r12
movq 0x80(%r15), %rdi
callq 0x2d180
movq %rax, 0x80(%r12)
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq -0x8(%rax,%rcx,8), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2d71e
cmpq $0x0, 0x20(%r15)
je 0x1ed07
leaq 0x18(%r12), %rax
movq %rax, 0x20(%rsp)
movq %r12, %rax
addq $0x20, %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movq (%rsp), %rbp
movl $0x20, %edi
callq 0x2ce48
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 0x1e7c0
movq %rax, 0x10(%rbx)
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rax
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x1ec18
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1e7c0
movq %rax, 0x18(%rbx)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
callq 0x2ceff
incq %r13
cmpq 0x20(%r15), %r13
jb 0x1ebbe
movq (%rsp), %rbp
jmp 0x1ed07
movq %r15, %rdi
callq 0x231e7
testl %eax, %eax
je 0x1ed32
movq 0x8(%r15), %rdi
callq 0x22b29
movq %rax, %rdx
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq -0x8(%rax,%rcx,8), %rdi
movq %r15, %rsi
movq %rdx, (%rsp)
callq 0x2d71e
cmpq $0x0, 0x48(%r15)
movq %rbp, %r13
je 0x1ecb0
xorl %ebp, %ebp
leaq 0x8(%rsp), %rbx
leaq 0x10(%rsp), %r12
movq 0x40(%r15), %rax
movq (%rax,%rbp,8), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1e7c0
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2ceff
incq %rbp
cmpq 0x48(%r15), %rbp
jb 0x1ec86
movq 0x68(%r15), %rax
movq 0x88(%r15), %rbx
movq (%rax), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1e7c0
movq 0x8(%r15), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x22c4f
movq %rax, %r12
movq 0x8(%rsp), %rax
movq %rax, 0x40(%r12)
movq 0x10(%rsp), %rax
movq %rax, 0x48(%r12)
leaq 0x434da(%rip), %rax     # 0x621d0
movq (%rax), %rax
movq (%rsp), %rcx
movl 0x4(%rcx), %ecx
movq %r12, (%rax,%rcx,8)
movq %r13, %rbp
movq 0x28(%r15), %rdi
testq %rdi, %rdi
je 0x1ed20
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1e7c0
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 0x1ed20