// File: /workspace/github_c_makefile_star2_O3/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 0x23b8f
movl %r8d, %ebp
movq %rdx, %r14
testl %r8d, %r8d
je 0x23ad7
movq %r12, %rdi
callq 0x17094
movq %rax, %r12
movq %r15, %rdi
callq 0x17094
movq %rax, %r15
movq %r12, %rdi
callq 0x21019
testq %rax, %rax
je 0x23abf
movq %rax, %rdi
callq 0x17094
movq %rax, %r12
movq %r15, %rdi
callq 0x21019
testq %rax, %rax
je 0x23ad7
movq %rax, %rdi
callq 0x17094
movq %rax, %r15
movl (%r12), %eax
xorl %r13d, %r13d
cmpl (%r15), %eax
jne 0x23b99
movq 0x48(%r12), %rax
cmpq 0x48(%r15), %rax
jne 0x23b99
movq 0x70(%r12), %rax
cmpq 0x70(%r15), %rax
jne 0x23b99
movq 0x78(%r12), %rax
cmpq 0x78(%r15), %rax
jne 0x23b99
movl 0x4(%r12), %eax
movl 0x4(%r15), %ecx
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
movq 0x3e6d2(%rip), %rdi     # 0x62200
callq 0x2da24
movl $0x1, %r13d
testl %eax, %eax
jne 0x23b99
movl 0x4(%r12), %esi
movl 0x4(%r15), %eax
cmpl %eax, %esi
je 0x23b99
movq (%r14), %rcx
shlq $0x6, %rcx
cmpq %rsi, %rcx
jbe 0x23bab
movq 0x8(%r14), %rdx
movl %esi, %edi
shrl $0x6, %edi
movq (%rdx,%rdi,8), %rdx
btq %rsi, %rdx
movq (%rbx), %rdx
jae 0x23bae
movq %rdx, %rdi
shlq $0x6, %rdi
cmpq %rax, %rdi
jbe 0x23bae
movq 0x8(%rbx), %rdi
movl %eax, %r8d
shrl $0x6, %r8d
movq (%rdi,%r8,8), %rdi
btq %rax, %rdi
jb 0x23b99
jmp 0x23bae
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 (%rbx), %rdx
shlq $0x6, %rdx
cmpq %rsi, %rdx
jbe 0x23be2
movq 0x8(%rbx), %rdx
movl %esi, %edi
shrl $0x6, %edi
movq (%rdx,%rdi,8), %rdx
btq %rsi, %rdx
jae 0x23be2
cmpq %rax, %rcx
jbe 0x23be2
movq 0x8(%r14), %rcx
movl %eax, %edx
shrl $0x6, %edx
movq (%rcx,%rdx,8), %rcx
btq %rax, %rcx
jb 0x23b99
movq %r14, %rdi
callq 0x2d369
movl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x2d369
movl (%r12), %eax
addl $-0x15, %eax
cmpl $0x8, %eax
ja 0x23f05
leaq 0x14077(%rip), %rcx     # 0x37c84
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x88(%r12), %rdi
callq 0x1d3b3
movq %rax, %r13
movq 0x88(%r15), %rdi
callq 0x1d3b3
cmpq %rax, %r13
je 0x23f05
jmp 0x23f61
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x1e523
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
jmp 0x23e1e
cmpq $0x0, 0x78(%r12)
je 0x23f05
xorl %r13d, %r13d
xorl %ecx, %ecx
movq %rcx, 0x8(%rsp)
movq 0x88(%r12), %rax
movq (%rax,%rcx,8), %rdi
callq 0x1e2ed
movq %rax, 0x18(%rsp)
movq 0x88(%r15), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1e2ed
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x4230
movl %eax, 0x14(%rsp)
movq 0x88(%r12), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1e31c
movq %rax, 0x18(%rsp)
movq 0x88(%r15), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1e31c
movq 0x18(%rsp), %rdi
movq %rax, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x23a5b
testl %eax, %eax
je 0x23f64
cmpl $0x0, 0x14(%rsp)
movq 0x8(%rsp), %rcx
jne 0x23f64
incq %rcx
cmpq 0x78(%r12), %rcx
jb 0x23c71
jmp 0x23f05
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x1e523
xorl %ecx, %ecx
testl %eax, %eax
setne %dl
cmpq $0x0, 0x48(%r12)
je 0x23eff
testl %eax, %eax
sete %al
xorl %r13d, %r13d
xorl %ecx, %ecx
testb $0x1, %al
jne 0x23f64
movq 0x40(%r12), %rax
movq (%rax,%rcx,8), %rdi
movq 0x40(%r15), %rax
movq (%rax,%rcx,8), %rsi
movq %r14, %rdx
movq %rcx, 0x8(%rsp)
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x23a5b
testl %eax, %eax
je 0x23f64
movq 0x8(%rsp), %rcx
incq %rcx
xorl %eax, %eax
cmpq 0x48(%r12), %rcx
jb 0x23d54
jmp 0x23f05
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x1e523
xorl %ecx, %ecx
testl %eax, %eax
setne %dl
cmpq $0x0, 0x38(%r12)
je 0x23eff
testl %eax, %eax
sete %al
xorl %r13d, %r13d
xorl %ecx, %ecx
testb $0x1, %al
jne 0x23f64
movq 0x30(%r12), %rax
movq (%rax,%rcx,8), %rdi
movq 0x30(%r15), %rax
movq (%rax,%rcx,8), %rsi
movq %r14, %rdx
movq %rcx, 0x8(%rsp)
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x23a5b
testl %eax, %eax
je 0x23f64
movq 0x8(%rsp), %rcx
incq %rcx
xorl %eax, %eax
cmpq 0x38(%r12), %rcx
jb 0x23dcf
jmp 0x23f05
movl $0x1, %ecx
cmpq $0x0, 0x78(%r12)
je 0x23f01
testl %ecx, %ecx
sete %al
xorl %r13d, %r13d
xorl %ecx, %ecx
movq %rcx, 0x8(%rsp)
movl %eax, 0x18(%rsp)
movq 0x88(%r12), %rax
movq (%rax,%rcx,8), %rax
movq 0x18(%rax), %rdi
movq 0x88(%r15), %rax
movq (%rax,%rcx,8), %rax
movq 0x18(%rax), %rsi
callq 0x1e523
movl %eax, 0x14(%rsp)
movq 0x88(%r12), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x28(%rax), %rdi
movq 0x88(%r15), %rax
movq (%rax,%rcx,8), %rax
movq 0x28(%rax), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x23a5b
testl %eax, %eax
je 0x23f64
cmpl $0x0, 0x14(%rsp)
movl 0x18(%rsp), %eax
je 0x23f64
testb $0x1, %al
movq 0x8(%rsp), %rcx
jne 0x23f64
incq %rcx
xorl %eax, %eax
cmpq 0x78(%r12), %rcx
jb 0x23e34
jmp 0x23f05
movl 0x4(%r12), %eax
cmpl 0x4(%r15), %eax
je 0x23f05
jmp 0x23f61
cmpq %r15, %r12
je 0x23f05
movq 0x88(%r12), %rdi
movq 0x88(%r15), %rsi
callq 0x2db3b
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
jmp 0x23f01
movb %dl, %cl
testl %ecx, %ecx
je 0x23f61
movq %rbx, 0x8(%rsp)
cmpq $0x0, 0x70(%r12)
je 0x23f46
xorl %r13d, %r13d
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 0x8(%rsp), %rcx
movl %ebp, %r8d
callq 0x23a5b
testl %eax, %eax
je 0x23f5a
incq %rbx
cmpq 0x70(%r12), %rbx
jb 0x23f17
movl 0x4(%r12), %edi
movl 0x4(%r15), %esi
callq 0x23f82
movl $0x1, %r13d
movq 0x8(%rsp), %rbx
jmp 0x23f64
xorl %r13d, %r13d
movl 0x4(%r12), %esi
movq %r14, %rdi
callq 0x2d3d4
movl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x2d3d4
jmp 0x23b99