// File: /workspace/github_c_makefile_star2_O2/oridb[P]mc/parse/type.c
// Function: tyeq_rec
int
tyeq_rec(Type *a, Type *b, Bitset *avisited, Bitset *bvisited, int search)
{
	Type *x, *y, *t;
	Typair p;
	size_t i;
	int ret;

	if (!a || !b)
		return a == b;
	if (search) {
		a = tysearch(a);
		b = tysearch(b);
		if ((t = boundtype(a)) != NULL)
			a = tysearch(t);
		if ((t = boundtype(b)) != NULL)
			b = tysearch(t);
	}
	if (a->type != b->type)
		return 0;
	if (a->narg != b->narg)
		return 0;
	if (a->nsub != b->nsub)
		return 0;
	if (a->nmemb != b->nmemb)
		return 0;
	p = (Typair){a->tid, b->tid};
	if (hthas(eqcache, &p))
		return 1;

	if (a->tid == b->tid)
		return 1;

	if (bshas(avisited, a->tid) && bshas(bvisited, b->tid))
		return 1;
	if (bshas(bvisited, a->tid) && bshas(avisited, b->tid))
		return 1;

	bsput(avisited, a->tid);
	bsput(bvisited, b->tid);
	ret = 1;

	switch (a->type) {
	case Typaram:
		ret = (a == b);
		ret = ret || streq(a->pname, b->pname);
		//if (ret != streq(a->pname, b->pname))
		//	die("wat");
		break;
	case Tyvar:
		if (a->tid != b->tid)
			ret = 0;
		break;
	case Tyunres:
		if (!nameeq(a->name, b->name))
			ret = 0;
	case Tyunion:
		for (i = 0; i < a->nmemb; i++) {
			if (!nameeq(a->udecls[i]->name, b->udecls[i]->name))
				ret = 0;
			x = a->udecls[i]->etype;
			y = b->udecls[i]->etype;
			if (!tyeq_rec(x, y, avisited, bvisited, search))
				ret = 0;
			if (!ret)
				break;
		}
		break;
	case Tystruct:
		for (i = 0; i < a->nmemb; i++) {
			if (strcmp(declname(a->sdecls[i]), declname(b->sdecls[i])) != 0)
				ret = 0;
			x = decltype(a->sdecls[i]);
			y = decltype(b->sdecls[i]);
			if (!tyeq_rec(x, y, avisited, bvisited, search))
				ret = 0;
			if (!ret)
				break;
		}
		break;
	case Tygeneric:
		if (!nameeq(a->name, b->name))
			ret = 0;
		for (i = 0; i < a->ngparam; i++) {
			ret = ret && tyeq_rec(a->gparam[i], b->gparam[i], avisited, bvisited, search);
			if (!ret)
				break;
		}
		break;
	case Tyname:
		if (!nameeq(a->name, b->name))
			ret = 0;
		for (i = 0; i < a->narg; i++) {
			ret = ret && tyeq_rec(a->arg[i], b->arg[i], avisited, bvisited, search);
			if (!ret)
				break;
		}
		break;
	case Tyarray:
		if (arraysz(a->asize) != arraysz(b->asize))
			ret = 0;
		break;
	default:
		break;
	}
	if (ret) {
		for (i = 0; i < a->nsub; i++) {
			x = a->sub[i];
			y = b->sub[i];
			if (!tyeq_rec(x, y, avisited, bvisited, search)) {
				ret = 0;
				break;
			}
		}
	}
	if (ret)
		equate(a->tid, b->tid);
	bsdel(avisited, a->tid);
	bsdel(bvisited, b->tid);

	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rbx
movq %rsi, %r15
movq %rdi, %r12
testq %rdi, %rdi
setne %al
testq %rsi, %rsi
setne %cl
testb %cl, %al
je 0x21258
movl %r8d, %ebp
movq %rdx, %r14
testl %r8d, %r8d
je 0x2112a
movq %r12, %rdi
callq 0x1589c
movq %rax, %r12
movq %r15, %rdi
callq 0x1589c
movq %rax, %r15
movq %r12, %rdi
callq 0x1e938
testq %rax, %rax
je 0x21112
movq %rax, %rdi
callq 0x1589c
movq %rax, %r12
movq %r15, %rdi
callq 0x1e938
testq %rax, %rax
je 0x2112a
movq %rax, %rdi
callq 0x1589c
movq %rax, %r15
movl (%r12), %eax
xorl %r13d, %r13d
cmpl (%r15), %eax
jne 0x21262
movq 0x48(%r12), %rax
cmpq 0x48(%r15), %rax
jne 0x21262
movq 0x70(%r12), %rax
cmpq 0x70(%r15), %rax
jne 0x21262
movq 0x78(%r12), %rax
cmpq 0x78(%r15), %rax
jne 0x21262
movl 0x4(%r12), %eax
movl 0x4(%r15), %ecx
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
movq 0x3e07f(%rip), %rdi     # 0x5f200
callq 0x2a517
pushq $0x1
popq %r13
testl %eax, %eax
jne 0x21262
movl 0x4(%r12), %esi
movl 0x4(%r15), %eax
cmpl %eax, %esi
je 0x21262
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %rsi, 0x10(%rsp)
callq 0x20633
testl %eax, %eax
je 0x211ce
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x20633
testl %eax, %eax
jne 0x21262
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x20633
testl %eax, %eax
je 0x211f0
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x20633
testl %eax, %eax
jne 0x21262
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x29ed5
movl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x29ed5
movl (%r12), %eax
addl $-0x15, %eax
cmpl $0x8, %eax
ja 0x214dd
pushq $0x1
popq %rdx
leaq 0x12a71(%rip), %rcx     # 0x33c94
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl %edx, %ecx
jmpq *%rax
movq 0x88(%r12), %rdi
callq 0x1b58b
movq %rax, %r13
movq 0x88(%r15), %rdi
callq 0x1b58b
cmpq %rax, %r13
je 0x214dd
jmp 0x2150d
xorl %r13d, %r13d
cmpq %r15, %r12
sete %r13b
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x1c100
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
xorl %edx, %edx
cmpq 0x78(%r12), %rdx
jae 0x214d9
movl %ecx, 0x8(%rsp)
movq 0x88(%r12), %rax
movq (%rax,%rdx,8), %rax
movq 0x18(%rax), %rdi
movq 0x88(%r15), %rax
movq (%rax,%rdx,8), %rax
movq 0x18(%rax), %rsi
movq %rdx, %r13
callq 0x1c100
movl %eax, 0x10(%rsp)
movq 0x88(%r12), %rax
movq (%rax,%r13,8), %rax
movq 0x28(%rax), %rdi
movq 0x88(%r15), %rax
movq %r13, 0x18(%rsp)
movq (%rax,%r13,8), %rax
movq 0x28(%rax), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x210ae
xorl %r13d, %r13d
testl %eax, %eax
je 0x2157c
cmpl $0x0, 0x10(%rsp)
movl 0x8(%rsp), %eax
je 0x2157c
movq 0x18(%rsp), %rdx
incq %rdx
testl %eax, %eax
pushq $0x1
popq %rcx
jne 0x21291
jmp 0x2157c
xorl %ecx, %ecx
cmpq 0x78(%r12), %rcx
jae 0x214dd
movq 0x88(%r12), %rax
movq (%rax,%rcx,8), %rdi
movq %rcx, %r13
callq 0x1befe
movq %rax, 0x8(%rsp)
movq 0x88(%r15), %rax
movq (%rax,%r13,8), %rdi
callq 0x1befe
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x4230
movl %eax, 0x18(%rsp)
movq 0x88(%r12), %rax
movq (%rax,%r13,8), %rdi
callq 0x1bf2d
movq %rax, 0x8(%rsp)
movq 0x88(%r15), %rax
movq %r13, 0x10(%rsp)
movq (%rax,%r13,8), %rdi
callq 0x1bf2d
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x210ae
xorl %r13d, %r13d
testl %eax, %eax
je 0x2157c
movq 0x10(%rsp), %rcx
incq %rcx
cmpl $0x0, 0x18(%rsp)
je 0x21331
jmp 0x2157c
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x1c100
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
xorl %edx, %edx
xorl %r13d, %r13d
cmpq 0x48(%r12), %rdx
jae 0x214d9
testl %ecx, %ecx
je 0x2157c
movq 0x40(%r12), %rax
movq (%rax,%rdx,8), %rdi
movq 0x40(%r15), %rax
movq (%rax,%rdx,8), %rsi
movq %rdx, 0x8(%rsp)
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x210ae
movq 0x8(%rsp), %rdx
incq %rdx
pushq $0x1
popq %rcx
testl %eax, %eax
jne 0x213fa
jmp 0x2157c
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x1c100
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
xorl %edx, %edx
xorl %r13d, %r13d
cmpq 0x38(%r12), %rdx
jae 0x214d9
testl %ecx, %ecx
je 0x2157c
movq 0x30(%r12), %rax
movq (%rax,%rdx,8), %rdi
movq 0x30(%r15), %rax
movq (%rax,%rdx,8), %rsi
movq %rdx, 0x8(%rsp)
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x210ae
movq 0x8(%rsp), %rdx
incq %rdx
pushq $0x1
popq %rcx
testl %eax, %eax
jne 0x21465
jmp 0x2157c
movl 0x4(%r12), %eax
cmpl 0x4(%r15), %eax
je 0x214dd
jmp 0x2150d
cmpq %r15, %r12
je 0x214dd
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x2a626
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
testl %ecx, %ecx
je 0x2150d
xorl %r13d, %r13d
cmpq 0x70(%r12), %r13
jae 0x21512
movq 0x68(%r12), %rax
movq (%rax,%r13,8), %rdi
movq 0x68(%r15), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x210ae
incq %r13
testl %eax, %eax
jne 0x214e0
xorl %r13d, %r13d
jmp 0x2157c
movl 0x4(%r12), %r13d
movl %r13d, 0x10(%rsp)
movl 0x4(%r15), %eax
movl %eax, 0x8(%rsp)
pushq $0x8
popq %rdi
callq 0x29a78
movq %rax, %rbp
movl %r13d, (%rax)
movl 0x8(%rsp), %eax
movl %eax, 0x4(%rbp)
pushq $0x8
popq %rdi
callq 0x29a78
movq %rax, %r13
movl 0x10(%rsp), %eax
movl %eax, (%r13)
movl 0x8(%rsp), %eax
movl %eax, 0x4(%r13)
movq 0x3dca5(%rip), %rdi     # 0x5f200
movq %rbp, %rsi
movq %rbp, %rdx
callq 0x2a22a
movq 0x3dc93(%rip), %rdi     # 0x5f200
movq %r13, %rsi
movq %r13, %rdx
callq 0x2a22a
pushq $0x1
popq %r13
movl 0x4(%r12), %esi
movq %r14, %rdi
callq 0x29f3e
movl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x29f3e
jmp 0x21262