// File: /workspace/github_c_makefile_star2_O1/oridb[P]mc/parse/infer.c
// Function: tymatchrank
int
tymatchrank(Type *pat, Type *to)
{
	int match, q;
	size_t i;
	Ucon *puc, *tuc;

	pat = tysearch(pat);
	to = tysearch(to);
	if (pat->type == Typaram) {
		if (!pat->trneed)
			return 0;
		for (i = 0; bsiter(pat->trneed, &i); i++)
			if (!tryconstrain(to, traittab[i], 0))
				return -1;
		return 0;
	} else if (pat->type == Tyvar) {
		return 1;
	} else if (pat->type != to->type) {
		return -1;
	}

	match = 0;
	switch (pat->type) {
	case Tystruct:
		if (pat->nmemb != to->nmemb)
			return -1;
		for (i = 0; i < pat->nmemb; i++) {
			if (!streq(declname(pat->sdecls[i]),declname( to->sdecls[i])))
				return -1;
			q = tymatchrank(decltype(pat->sdecls[i]), decltype(to->sdecls[i]));
			if (q < 0)
				return -1;
			match += q;
		}
		break;
	case Tyunion:
		if (pat->nmemb != to->nmemb)
			return -1;
		for (i = 0; i < pat->nmemb; i++) {
			if (!nameeq(pat->udecls[i], to->udecls[i]))
				return -1;
			puc = pat->udecls[i];
			tuc = to->udecls[i];
			if (puc->etype && tuc->etype) {
				q = tymatchrank(puc->etype, tuc->etype);
				if (q < 0)
					return -1;
				match += q;
			} else if (puc->etype != tuc->etype) {
				return -1;
			}
		}
		break;
	case Tyname:
		if (!nameeq(pat->name, to->name))
			return -1;
		if (pat->narg != to->narg)
			return -1;
		for (i = 0; i < pat->narg; i++) {
			q = tymatchrank(pat->arg[i], to->arg[i]);
			if (q < 0)
				return -1;
			match += q;
		}
		break;
	case Tyarray:
		/* unsized arrays are ok */
		if (pat->asize && to->asize) {
			if (!!litvaleq(pat->asize->expr.args[0], to->asize->expr.args[0]))
				return -1;
		} else if (pat->asize != to->asize) {
			return -1;
		}
		else return tymatchrank(pat->sub[0], to->sub[0]);
		break;
	default:
		if (pat->nsub != to->nsub)
			break;
		if (pat->type == to->type)
			match = 1;
		for (i = 0; i < pat->nsub; i++) {
			q = tymatchrank(pat->sub[i], to->sub[i]);
			if (q < 0)
				return -1;
			match += q;
		}
		break;
	}
	return match;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x172c6
leaq 0x4af1e(%rip), %rax     # 0x621d0
movq (%rax), %rax
movq %rdi, %r12
movl 0x4(%rdi), %ecx
movq (%rax,%rcx,8), %rdi
testq %rdi, %rdi
jne 0x172b5
jmp 0x172c9
xorl %r12d, %r12d
testq %rsi, %rsi
je 0x172e9
leaq 0x4aefb(%rip), %rax     # 0x621d0
movq (%rax), %rax
movq %rsi, %rbx
movl 0x4(%rsi), %ecx
movq (%rax,%rcx,8), %rsi
testq %rsi, %rsi
jne 0x172d8
jmp 0x172eb
xorl %ebx, %ebx
movl (%r12), %eax
movl $0x1, %r14d
cmpl $0x19, %eax
je 0x1761d
cmpl $0x1a, %eax
jne 0x17378
xorl %r14d, %r14d
cmpq $0x0, 0x80(%r12)
je 0x1761d
movq %rsp, %rsi
movq $0x0, (%rsi)
movq 0x80(%r12), %rdi
callq 0x2d753
testl %eax, %eax
je 0x1761d
leaq 0x4aebd(%rip), %r15     # 0x621f8
movq %rsp, %r14
movq (%r15), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1765a
testl %eax, %eax
je 0x17612
incq (%rsp)
movq 0x80(%r12), %rdi
movq %r14, %rsi
callq 0x2d753
testl %eax, %eax
jne 0x1733e
jmp 0x1761a
cmpl (%rbx), %eax
jne 0x17612
addl $-0x15, %eax
cmpl $0x7, %eax
ja 0x175be
leaq 0x1e5fd(%rip), %rcx     # 0x35990
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x88(%r12), %rax
testq %rax, %rax
je 0x1762c
movq 0x88(%rbx), %rcx
testq %rcx, %rcx
je 0x1762c
movq 0x50(%rax), %rax
movq (%rax), %rdi
movq 0x50(%rcx), %rax
movq (%rax), %rsi
callq 0x1e633
xorl %r14d, %r14d
negl %eax
sbbl %r14d, %r14d
jmp 0x1761d
movq 0x78(%r12), %rax
cmpq 0x78(%rbx), %rax
jne 0x17612
movq $0x0, (%rsp)
cmpq $0x0, 0x78(%r12)
je 0x1761a
xorl %r14d, %r14d
xorl %eax, %eax
movq 0x88(%r12), %rcx
movq (%rcx,%rax,8), %rdi
movq 0x88(%rbx), %rcx
movq (%rcx,%rax,8), %rsi
callq 0x1e773
testl %eax, %eax
je 0x17612
movq 0x88(%r12), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x88(%rbx), %rax
movq (%rax,%rcx,8), %rax
movq 0x28(%rdx), %rdi
testq %rdi, %rdi
je 0x17468
movq 0x28(%rax), %rsi
testq %rsi, %rsi
je 0x17468
callq 0x1729e
testl %eax, %eax
js 0x17612
addl %eax, %r14d
jmp 0x17472
cmpq 0x28(%rax), %rdi
jne 0x17612
movq (%rsp), %rax
incq %rax
movq %rax, (%rsp)
cmpq 0x78(%r12), %rax
jb 0x17405
jmp 0x1761d
movq 0x78(%r12), %rax
cmpq 0x78(%rbx), %rax
jne 0x17612
movq $0x0, (%rsp)
cmpq $0x0, 0x78(%r12)
je 0x1761a
xorl %r14d, %r14d
xorl %eax, %eax
movq 0x88(%r12), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x1e53d
movq %rax, %r15
movq 0x88(%rbx), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1e53d
movq %r15, %rdi
movq %rax, %rsi
callq 0x2dfda
testl %eax, %eax
je 0x17612
movq 0x88(%r12), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1e56c
movq %rax, %r15
movq 0x88(%rbx), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1e56c
movq %r15, %rdi
movq %rax, %rsi
callq 0x1729e
testl %eax, %eax
js 0x17612
addl %eax, %r14d
movq (%rsp), %rax
incq %rax
movq %rax, (%rsp)
cmpq 0x78(%r12), %rax
jb 0x174b1
jmp 0x1761d
movq 0x88(%r12), %rdi
movq 0x88(%rbx), %rsi
callq 0x1e773
testl %eax, %eax
je 0x17612
movq 0x48(%r12), %rax
cmpq 0x48(%rbx), %rax
jne 0x17612
movq $0x0, (%rsp)
cmpq $0x0, 0x48(%r12)
je 0x1761a
xorl %r14d, %r14d
xorl %eax, %eax
movq 0x40(%r12), %rcx
movq (%rcx,%rax,8), %rdi
movq 0x40(%rbx), %rcx
movq (%rcx,%rax,8), %rsi
callq 0x1729e
testl %eax, %eax
js 0x17612
addl %eax, %r14d
movq (%rsp), %rax
incq %rax
movq %rax, (%rsp)
cmpq 0x48(%r12), %rax
jb 0x1758d
jmp 0x1761d
movq 0x70(%r12), %rax
cmpq 0x70(%rbx), %rax
jne 0x1761a
movq $0x0, (%rsp)
cmpq $0x0, 0x70(%r12)
je 0x1761d
movl $0x1, %r14d
xorl %eax, %eax
movq 0x68(%r12), %rcx
movq (%rcx,%rax,8), %rdi
movq 0x68(%rbx), %rcx
movq (%rcx,%rax,8), %rsi
callq 0x1729e
testl %eax, %eax
js 0x17612
addl %eax, %r14d
movq (%rsp), %rax
incq %rax
movq %rax, (%rsp)
cmpq 0x70(%r12), %rax
jb 0x175e1
jmp 0x1761d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x1761d
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpq 0x88(%rbx), %rax
jne 0x1761d
movq 0x68(%r12), %rax
movq (%rax), %rdi
movq 0x68(%rbx), %rax
movq (%rax), %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x1729e