// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movq %rcx, %rbx
movq %rsi, %r15
movq %rdi, %r12
testq %rdi, %rdi
setne %al
testq %rsi, %rsi
setne %cl
testb %cl, %al
je 0x240e5
movl %r8d, %ebp
movq %rdx, %r14
testl %r8d, %r8d
je 0x23f8d
movq %r12, %rdi
callq 0x1727c
movq %rax, %r12
movq %r15, %rdi
callq 0x1727c
movq %rax, %r15
movq %r12, %rdi
callq 0x21297
testq %rax, %rax
je 0x23f75
movq %rax, %rdi
callq 0x1727c
movq %rax, %r12
movq %r15, %rdi
callq 0x21297
testq %rax, %rax
je 0x23f8d
movq %rax, %rdi
callq 0x1727c
movq %rax, %r15
movl (%r12), %eax
xorl %r13d, %r13d
cmpl (%r15), %eax
jne 0x240ef
movq 0x48(%r12), %rax
cmpq 0x48(%r15), %rax
jne 0x240ef
movq 0x70(%r12), %rax
cmpq 0x70(%r15), %rax
jne 0x240ef
movq 0x78(%r12), %rax
cmpq 0x78(%r15), %rax
jne 0x240ef
movl 0x4(%r12), %eax
movl 0x4(%r15), %ecx
leaq 0x10(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
movq 0x3e21c(%rip), %rdi     # 0x62200
callq 0x2decd
movl $0x1, %r13d
testl %eax, %eax
jne 0x240ef
movl 0x4(%r12), %esi
movl 0x4(%r15), %eax
cmpl %eax, %esi
je 0x240ef
movq (%r14), %rcx
shlq $0x6, %rcx
cmpq %rsi, %rcx
jbe 0x2404a
movq 0x8(%r14), %rdx
movl %esi, %edi
shrl $0x6, %edi
movq (%rdx,%rdi,8), %rdx
btq %rsi, %rdx
jae 0x2404a
movq (%rbx), %rdx
shlq $0x6, %rdx
cmpq %rax, %rdx
jbe 0x2404a
movq 0x8(%rbx), %rdx
movl %eax, %edi
shrl $0x6, %edi
movq (%rdx,%rdi,8), %rdx
btq %rax, %rdx
jb 0x240ef
movq (%rbx), %rdx
shlq $0x6, %rdx
cmpq %rsi, %rdx
jbe 0x24081
movq 0x8(%rbx), %rdx
movl %esi, %edi
shrl $0x6, %edi
movq (%rdx,%rdi,8), %rdx
btq %rsi, %rdx
jae 0x24081
cmpq %rax, %rcx
jbe 0x24081
movq 0x8(%r14), %rcx
movl %eax, %edx
shrl $0x6, %edx
movq (%rcx,%rdx,8), %rcx
btq %rax, %rcx
jb 0x240ef
movq %r14, %rdi
callq 0x2d816
movl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x2d816
movl (%r12), %eax
movl $0x1, %ecx
addl $-0x15, %eax
cmpl $0x8, %eax
ja 0x2436d
leaq 0x13c03(%rip), %rcx     # 0x37cb4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl $0x1, %ecx
jmpq *%rax
movq 0x88(%r12), %rdi
callq 0x1d603
movq %rax, %r13
movq 0x88(%r15), %rdi
callq 0x1d603
xorl %ecx, %ecx
cmpq %rax, %r13
jmp 0x24344
xorl %r13d, %r13d
cmpq %r15, %r12
sete %r13b
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x1e773
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
cmpq $0x0, 0x78(%r12)
je 0x2436d
testl %ecx, %ecx
sete %al
xorl %r13d, %r13d
movl %eax, (%rsp)
movq 0x88(%r12), %rax
movq (%rax,%r13,8), %rax
movq 0x18(%rax), %rdi
movq 0x88(%r15), %rax
movq (%rax,%r13,8), %rax
movq 0x18(%rax), %rsi
callq 0x1e773
movl %eax, 0xc(%rsp)
movq 0x88(%r12), %rax
movq (%rax,%r13,8), %rax
movq 0x28(%rax), %rdi
movq 0x88(%r15), %rax
movq (%rax,%r13,8), %rax
movq 0x28(%rax), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x23f11
testl %eax, %eax
je 0x2436b
cmpl $0x0, 0xc(%rsp)
movl (%rsp), %eax
je 0x2436b
testb $0x1, %al
jne 0x2436b
incq %r13
xorl %eax, %eax
cmpq 0x78(%r12), %r13
jb 0x24130
jmp 0x2425a
cmpq $0x0, 0x78(%r12)
je 0x2436d
xorl %r13d, %r13d
movq 0x88(%r12), %rax
movq (%rax,%r13,8), %rdi
callq 0x1e53d
movq %rax, (%rsp)
movq 0x88(%r15), %rax
movq (%rax,%r13,8), %rdi
callq 0x1e53d
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x4230
movl %eax, 0xc(%rsp)
movq 0x88(%r12), %rax
movq (%rax,%r13,8), %rdi
callq 0x1e56c
movq %rax, (%rsp)
movq 0x88(%r15), %rax
movq (%rax,%r13,8), %rdi
callq 0x1e56c
movq (%rsp), %rdi
movq %rax, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x23f11
testl %eax, %eax
je 0x2436b
cmpl $0x0, 0xc(%rsp)
jne 0x2436b
incq %r13
cmpq 0x78(%r12), %r13
jb 0x241ca
movl $0x1, %ecx
jmp 0x2436d
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x1e773
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
cmpq $0x0, 0x48(%r12)
je 0x2436d
xorl %r13d, %r13d
testl %ecx, %ecx
je 0x242b8
movq 0x40(%r12), %rax
movq (%rax,%r13,8), %rdi
movq 0x40(%r15), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x23f11
testl %eax, %eax
setne %al
jmp 0x242ba
xorl %eax, %eax
movzbl %al, %ecx
testb %cl, %cl
je 0x2436d
incq %r13
cmpq 0x48(%r12), %r13
jb 0x2428e
jmp 0x2436d
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x1e773
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
cmpq $0x0, 0x38(%r12)
je 0x2436d
xorl %r13d, %r13d
testl %ecx, %ecx
je 0x24324
movq 0x30(%r12), %rax
movq (%rax,%r13,8), %rdi
movq 0x30(%r15), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x23f11
testl %eax, %eax
setne %al
jmp 0x24326
xorl %eax, %eax
movzbl %al, %ecx
testb %cl, %cl
je 0x2436d
incq %r13
cmpq 0x38(%r12), %r13
jb 0x242fa
jmp 0x2436d
movl 0x4(%r12), %eax
xorl %ecx, %ecx
cmpl 0x4(%r15), %eax
sete %cl
jmp 0x2436d
cmpq %r15, %r12
je 0x2436d
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x2dfda
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
jmp 0x2436d
xorl %ecx, %ecx
testl %ecx, %ecx
je 0x243b8
movl $0x1, %r13d
cmpq $0x0, 0x70(%r12)
je 0x243bf
movq %rbx, (%rsp)
xorl %ebx, %ebx
movq 0x68(%r12), %rax
movq (%rax,%rbx,8), %rdi
movq 0x68(%r15), %rax
movq (%rax,%rbx,8), %rsi
movq %r14, %rdx
movq (%rsp), %rcx
movl %ebp, %r8d
callq 0x23f11
testl %eax, %eax
sete %al
je 0x243c3
incq %rbx
cmpq 0x70(%r12), %rbx
jb 0x24385
jmp 0x243c6
xorl %r13d, %r13d
movb $0x1, %al
jmp 0x243ca
xorl %eax, %eax
jmp 0x243ca
xorl %r13d, %r13d
movq (%rsp), %rbx
testb %al, %al
jne 0x243dc
movl 0x4(%r12), %edi
movl 0x4(%r15), %esi
callq 0x243fa
movl 0x4(%r12), %esi
movq %r14, %rdi
callq 0x2d872
movl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x2d872
jmp 0x240ef