// File: /workspace/github_c_makefile_star2_O1/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, 0x477d4(%rip)     # 0x618b8
jne 0x1a117
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x6, %esi
callq 0x22d38
movq %rax, 0x477bc(%rip)     # 0x618b8
callq 0x2d63c
movq %rax, 0x477c0(%rip)     # 0x618c8
movq 0x477a9(%rip), %rdi     # 0x618b8
movq %rax, %rsi
callq 0x1a4ae
cmpq $0x0, 0x477a1(%rip)     # 0x618c0
jne 0x1a152
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x10, %esi
callq 0x22d38
movq %rax, 0x47789(%rip)     # 0x618c0
callq 0x2d63c
movq %rax, 0x4778d(%rip)     # 0x618d0
movq 0x47776(%rip), %rdi     # 0x618c0
movq %rax, %rsi
callq 0x1a4ae
movq %r14, %rdi
callq 0x196c0
testq %rax, %rax
je 0x1a17a
leaq 0x4806a(%rip), %rcx     # 0x621d0
movq (%rcx), %rcx
movq %rax, %r15
movl 0x4(%rax), %eax
movq (%rcx,%rax,8), %rax
testq %rax, %rax
jne 0x1a169
jmp 0x1a17d
xorl %r15d, %r15d
movq 0x60(%r15), %r12
testq %r12, %r12
je 0x1a18e
movq %r12, %rdi
callq 0x20159
movq 0x28(%r14), %r13
cmpl $0x19, (%r14)
jne 0x1a1fb
movq 0x47601(%rip), %rdi     # 0x617a0
movq %r14, %rsi
callq 0x2decd
testl %eax, %eax
je 0x1a1fb
movq 0x475ee(%rip), %rdi     # 0x617a0
movq %r14, %rsi
callq 0x2dd9a
cmpl $0x19, (%r15)
jne 0x1a1db
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1a59b
movq %r15, %rdi
callq 0x196c0
movq %rax, %r15
jmp 0x1a1fb
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0x22c44
testl %ebp, %ebp
jne 0x1a1fb
movq 0x8(%rsp), %rdx
movl (%rdx), %ecx
cmpl %ecx, (%rax)
jne 0x1a45e
cmpl $0x19, (%r15)
movq %r12, 0x10(%rsp)
jne 0x1a249
movq 0x80(%r15), %rdi
testq %rdi, %rdi
je 0x1a249
movq 0x476af(%rip), %rsi     # 0x618c8
callq 0x2dad2
testl %eax, %eax
je 0x1a22b
movq 0x4768f(%rip), %r15     # 0x618b8
jmp 0x1a249
movq 0x80(%r15), %rdi
movq 0x47697(%rip), %rsi     # 0x618d0
callq 0x2dad2
testl %eax, %eax
je 0x1a249
movq 0x47677(%rip), %r15     # 0x618c0
cmpb $0x0, 0x98(%r15)
je 0x1a2d7
cmpq $0x0, 0x70(%r15)
je 0x1a284
xorl %r12d, %r12d
movq 0x68(%r15), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x1a0c3
movq 0x68(%r15), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
cmpq 0x70(%r15), %r12
jb 0x1a261
testl %ebp, %ebp
jne 0x1a292
cmpl $0x19, (%r15)
je 0x1a42a
testq %r13, %r13
movq 0x10(%rsp), %r12
je 0x1a2b5
cmpq %r14, %r13
je 0x1a2b1
movq %rbx, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x1a0c3
movq %rax, %r13
movq %r13, 0x28(%r15)
testq %r12, %r12
je 0x1a2c2
movq %r12, %rdi
callq 0x201a4
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 0x1a257
leaq 0x1b79f(%rip), %rcx     # 0x35a94
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x88(%r15), %rdi
testq %rdi, %rdi
je 0x1a31b
movl $0x1, %esi
callq 0x14703
movq %rax, 0x88(%r15)
movq 0x88(%r15), %rdi
testq %rdi, %rdi
je 0x1a34e
leaq 0x18(%rsp), %r12
movq %r12, %rsi
callq 0x14638
testl %eax, %eax
setne %al
movq (%r12), %rdx
testq %rdx, %rdx
sets %cl
andb %al, %cl
cmpb $0x1, %cl
je 0x1a499
movq 0x88(%r15), %rdi
movl %ebp, %esi
callq 0x19164
jmp 0x1a257
cmpq $0x0, 0x78(%r15)
je 0x1a257
xorl %r12d, %r12d
movq 0x88(%r15), %rax
movq (%rax,%r12,8), %rax
movq 0x28(%rax), %rdi
testq %rdi, %rdi
je 0x1a3b0
callq 0x1ae68
movq 0x88(%r15), %rax
movq (%rax,%r12,8), %rax
movq 0x28(%rax), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x1a0c3
movq 0x88(%r15), %rcx
movq (%rcx,%r12,8), %rcx
movq %rax, 0x28(%rcx)
incq %r12
cmpq 0x78(%r15), %r12
jb 0x1a36f
jmp 0x1a257
incl 0x47514(%rip)           # 0x618d8
cmpq $0x0, 0x78(%r15)
je 0x1a3e9
xorl %r12d, %r12d
movq 0x88(%r15), %rax
movq (%rax,%r12,8), %rdi
movl %ebp, %esi
callq 0x19164
incq %r12
cmpq 0x78(%r15), %r12
jb 0x1a3ce
decl 0x474e9(%rip)           # 0x618d8
jmp 0x1a257
cmpq $0x0, 0x48(%r15)
je 0x1a257
xorl %r12d, %r12d
movq 0x40(%r15), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x1a0c3
movq 0x40(%r15), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
cmpq 0x48(%r15), %r12
jb 0x1a402
jmp 0x1a257
leaq 0x20(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x237ca
movq %rax, %r14
movq %rbx, %rdi
callq 0x19a6f
leaq 0x1bba5(%rip), %rsi     # 0x35ff3
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x13aa3
movq %r15, %rdi
movq %rdx, %r15
callq 0x23e44
movq %rax, %r14
movq %r15, %rdi
callq 0x23e44
movq %rax, %r15
movq %rbx, %rdi
callq 0x19a6f
leaq 0x1bb2b(%rip), %rsi     # 0x35fb1
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x13aa3
movq 0x88(%r15), %rdi
leaq 0x1bb32(%rip), %rsi     # 0x35fd9
xorl %eax, %eax
callq 0x13aa3