// File: /workspace/github_c_makefile_star2_O2/oridb[P]mc/parse/infer.c
// Function: tyfix
static Type *
tyfix(Node *ctx, Type *orig, int noerr)
{
	static Type *tyint, *tyflt;
	static Bitset *intset, *fltset;
	Type *t, *d, *base;
	Tyenv *env;
	vlong val;
	size_t i;
	char buf[1024];

	if (!tyint) {
		tyint = mktype(Zloc, Tyint);
		intset = mkbs();
		traitsfor(tyint, intset);
	}
	if (!tyflt) {
		tyflt = mktype(Zloc, Tyflt64);
		fltset = mkbs();
		traitsfor(tyflt, fltset);
	}

	t = tysearch(tf(orig));
	env = t->env;
	if (env)
		pushenv(env);
	base = orig->seqaux;
	/* Process delayed type mappings. */
	if (orig->type == Tyvar && hthas(delayed, orig)) {
		d = htget(delayed, orig);
		if (t->type == Tyvar) {
			/* tyvar is guaranteed to unify error-free */
			unify(ctx, t, d);
			t = tf(t);
		} else if (tybase(t)->type != d->type && !noerr) {
			fatal(ctx, "type %s not compatible with %s near %s\n",
			    tystr(t), tystr(d), ctxstr(ctx));
		}
	}

	/* Default the type */
	if (t->type == Tyvar && t->trneed) {
		if (bsissubset(t->trneed, intset))
			t = tyint;
		else if (bsissubset(t->trneed, fltset))
			t = tyflt;
	}

	if (!t->fixed) {
		t->fixed = 1;
		switch(t->type) {
		case Tyarray:
			if (t->type == Tyarray && t->asize)
				t->asize = fold(t->asize, 1);
			if (t->asize && getintlit(t->asize, &val) && val < 0)
				fatal(t->asize, "negative array size %lld\n", val);
			typesub(t->asize, noerr);
			break;
		case Tystruct:
			inaggr++;
			for (i = 0; i < t->nmemb; i++)
				typesub(t->sdecls[i], noerr);
			inaggr--;
			break;
		case Tyunion:
			for (i = 0; i < t->nmemb; i++) {
				if (t->udecls[i]->etype) {
					tyresolve(t->udecls[i]->etype);
					t->udecls[i]->etype =
						tyfix(ctx, t->udecls[i]->etype, noerr);
				}
			}
			break;
		case Tyname:
			for (i = 0; i < t->narg; i++)
				t->arg[i] = tyfix(ctx, t->arg[i], noerr);
			break;
		default:
			break;
		}
	}

	for (i = 0; i < t->nsub; i++)
		t->sub[i] = tyfix(ctx, t->sub[i], noerr);

	if (t->type == Tyvar && !noerr)
		fatal(ctx, "underconstrained type %s near %s", tyfmt(buf, 1024, t), ctxstr(ctx));
	if (base) {
		if (base != orig)
			base = tyfix(ctx, base, noerr);
		t->seqaux = base;
	}
	if (env)
		popenv(env);
	return t;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x462c5(%rip)     # 0x5e8b8
jne 0x18624
pushq $0x6
popq %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1fdc2
movq %rax, 0x462af(%rip)     # 0x5e8b8
callq 0x29d3c
movq %rax, 0x462b3(%rip)     # 0x5e8c8
movq 0x4629c(%rip), %rdi     # 0x5e8b8
movq %rax, %rsi
callq 0x1897c
cmpq $0x0, 0x46294(%rip)     # 0x5e8c0
jne 0x1865d
pushq $0x10
popq %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1fdc2
movq %rax, 0x4627e(%rip)     # 0x5e8c0
callq 0x29d3c
movq %rax, 0x46282(%rip)     # 0x5e8d0
movq 0x4626b(%rip), %rdi     # 0x5e8c0
movq %rax, %rsi
callq 0x1897c
movq %r14, %rdi
callq 0x17d99
movq %rax, %rdi
callq 0x1589c
movq %rax, %r15
movq 0x60(%rax), %r12
testq %r12, %r12
je 0x18681
movq %r12, %rdi
callq 0x1d970
movq 0x28(%r14), %r13
cmpl $0x19, (%r14)
jne 0x186ee
movq 0x4610e(%rip), %rdi     # 0x5e7a0
movq %r14, %rsi
callq 0x2a517
testl %eax, %eax
je 0x186ee
movq 0x460fb(%rip), %rdi     # 0x5e7a0
movq %r14, %rsi
callq 0x2a3e8
cmpl $0x19, (%r15)
jne 0x186ce
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x18a60
movq %r15, %rdi
callq 0x17d99
movq %rax, %r15
jmp 0x186ee
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0x1fcd8
testl %ebp, %ebp
jne 0x186ee
movq 0x8(%rsp), %rdx
movl (%rdx), %ecx
cmpl %ecx, (%rax)
jne 0x18941
cmpl $0x19, (%r15)
movq %r12, 0x10(%rsp)
jne 0x1873c
movq 0x80(%r15), %rdi
testq %rdi, %rdi
je 0x1873c
movq 0x461bc(%rip), %rsi     # 0x5e8c8
callq 0x2a145
testl %eax, %eax
je 0x1871e
movq 0x4619c(%rip), %r15     # 0x5e8b8
jmp 0x1873c
movq 0x80(%r15), %rdi
movq 0x461a4(%rip), %rsi     # 0x5e8d0
callq 0x2a145
testl %eax, %eax
je 0x1873c
movq 0x46184(%rip), %r15     # 0x5e8c0
cmpb $0x0, 0x98(%r15)
je 0x187c1
xorl %r12d, %r12d
cmpq 0x70(%r15), %r12
jae 0x1876e
movq 0x68(%r15), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x185d2
movq 0x68(%r15), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
jmp 0x18749
testl %ebp, %ebp
jne 0x1877c
cmpl $0x19, (%r15)
je 0x1890d
testq %r13, %r13
movq 0x10(%rsp), %r12
je 0x1879f
cmpq %r14, %r13
je 0x1879b
movq %rbx, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x185d2
movq %rax, %r13
movq %r13, 0x28(%r15)
testq %r12, %r12
je 0x187ac
movq %r12, %rdi
callq 0x1d9bb
movq %r15, %rax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, 0x98(%r15)
movl (%r15), %eax
addl $-0x15, %eax
cmpl $0x7, %eax
ja 0x18746
leaq 0x19295(%rip), %rcx     # 0x31a74
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x88(%r15), %rdi
testq %rdi, %rdi
je 0x188ff
pushq $0x1
popq %rsi
callq 0x12bd3
movq %rax, 0x88(%r15)
testq %rax, %rax
je 0x188ff
leaq 0x18(%rsp), %r12
movq %rax, %rdi
movq %r12, %rsi
callq 0x12b14
testl %eax, %eax
setne %al
movq (%r12), %rdx
testq %rdx, %rdx
sets %cl
andb %al, %cl
movq 0x88(%r15), %rdi
cmpb $0x1, %cl
jne 0x18901
leaq 0x19771(%rip), %rsi     # 0x31fb9
xorl %eax, %eax
callq 0x120fd
xorl %r12d, %r12d
cmpq 0x78(%r15), %r12
jae 0x18746
movq 0x88(%r15), %rax
movq (%rax,%r12,8), %rax
movq 0x28(%rax), %rdi
testq %rdi, %rdi
je 0x1889d
callq 0x192e3
movq 0x88(%r15), %rax
movq (%rax,%r12,8), %rax
movq 0x28(%rax), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x185d2
movq 0x88(%r15), %rcx
movq (%rcx,%r12,8), %rcx
movq %rax, 0x28(%rcx)
incq %r12
jmp 0x18852
incl 0x46030(%rip)           # 0x5e8d8
xorl %r12d, %r12d
cmpq 0x78(%r15), %r12
jae 0x188c8
movq 0x88(%r15), %rax
movq (%rax,%r12,8), %rdi
movl %ebp, %esi
callq 0x17621
incq %r12
jmp 0x188ab
decl 0x4600a(%rip)           # 0x5e8d8
jmp 0x18746
xorl %r12d, %r12d
cmpq 0x48(%r15), %r12
jae 0x18746
movq 0x40(%r15), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x185d2
movq 0x40(%r15), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
jmp 0x188d6
xorl %edi, %edi
movl %ebp, %esi
callq 0x17621
jmp 0x18746
leaq 0x20(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x20783
movq %rax, %r14
movq %rbx, %rdi
callq 0x17f9e
leaq 0x196a2(%rip), %rsi     # 0x31fd3
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x120fd
movq %r15, %rdi
movq %rdx, %r15
callq 0x21009
movq %rax, %r14
movq %r15, %rdi
callq 0x21009
movq %rax, %r15
movq %rbx, %rdi
callq 0x17f9e
leaq 0x19628(%rip), %rsi     # 0x31f91
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x120fd