// File: /workspace/github_c_makefile_star2_O2/oridb[P]mc/mi/match.c
// Function: addrec
static void
addrec(Frontier *fs, Node *pat, Node *val, Path *path)
{
	size_t i, n;
	Type *ty, *mty;
	Node *memb, *name, *tagid, *p, *v, *lit, *dcl, *asn, *deref;
	Ucon *uc;
	char *s;
	Frontier *next;

	pat = fold(pat, 1);
	switch (exprop(pat)) {
	case Olor:
		next = frontierdup(fs);
		next->next = fs->next;
		next->hasorpat = 1;
		fs->next = next;
		fs->hasorpat = 1;
		addrec(fs, pat->expr.args[0], val, path);
		addrec(next, pat->expr.args[1], val, path);
		break;
	case Ogap:
		lappend(&fs->slot, &fs->nslot, mkslot(path, pat, val));
		break;
	case Ovar:
		dcl = decls[pat->expr.did];
		if (dcl->decl.isconst) {
			ty = decltype(dcl);
			if (ty->type == Tyfunc || ty->type == Tycode || ty->type == Tyvalist)
				fatal(dcl, "bad pattern %s:%s: unmatchable type", declname(dcl), tystr(ty));
			if (!dcl->decl.init)
				fatal(dcl, "bad pattern %s:%s: missing initializer", declname(dcl), tystr(ty));
			addrec(fs, dcl->decl.init, val, mkpath(path, 0));
		} else {
			asn = mkexpr(pat->loc, Oasn, pat, val, NULL);
			asn->expr.type = exprtype(pat);
			lappend(&fs->cap, &fs->ncap, asn);

			lappend(&fs->slot, &fs->nslot, mkslot(path, pat, val));
		}
		break;
	case Olit:
		if (pat->expr.args[0]->lit.littype == Lstr) {
			lit = pat->expr.args[0];
			n = lit->lit.strval.len;
			s = lit->lit.strval.buf;

			ty = mktype(pat->loc, Tyuint64);
			p = mkintlit(lit->loc, n);
			p ->expr.type = ty;
			v = structmemb(val, mkname(pat->loc, "len"), ty);

			addrec(fs, p, v, mkpath(path, 0));

			ty = mktype(pat->loc, Tybyte);
			for (i = 0; i < n; i++) {
				p = mkintlit(lit->loc, s[i]);
				p->expr.type = ty;
				v = arrayelt(val, i);
				addrec(fs, p, v, mkpath(path, 1+i));
			}
		} else {
			lappend(&fs->slot, &fs->nslot, mkslot(path, pat, val));
		}
		break;
	case Oaddr:
		deref = mkexpr(val->loc, Oderef, val, NULL);
		deref->expr.type = exprtype(pat->expr.args[0]);
		addrec(fs, pat->expr.args[0], deref, mkpath(path, 0));
		break;
	case Oucon:
		uc = finducon(tybase(exprtype(pat)), pat->expr.args[0]);
		tagid = mkintlit(pat->loc, uc->id);
		tagid->expr.type = mktype(pat->loc, Tyint32);
		addrec(fs, tagid, utag(val), mkpath(path, 0));
		if (uc->etype)
			addrec(fs, pat->expr.args[1], uvalue(val, uc->etype), mkpath(path, 1));
		break;
	case Otup:
		for (i = 0; i < pat->expr.nargs; i++) {
			addrec(fs, pat->expr.args[i], tupelt(val, i), mkpath(path, i));
		}
		break;
	case Oarr:
		for (i = 0; i < pat->expr.nargs; i++) {
			addrec(fs, pat->expr.args[i], arrayelt(val, i), mkpath(path, i));
		}
		break;
	case Ostruct:
		ty = tybase(exprtype(pat));
		for (i = 0; i < ty->nmemb; i++) {
			mty = decltype(ty->sdecls[i]);
			name = ty->sdecls[i]->decl.name;
			memb = findmemb(pat, name);
			if (!memb) {
				memb = mkexpr(ty->sdecls[i]->loc, Ogap, NULL);
				memb->expr.type = mty;
			}
			addrec(fs, memb, structmemb(val, name, mty), mkpath(path, i));
		}
		break;
	default:
		fatal(pat, "unsupported pattern %s of type %s", opstr[exprop(pat)], tystr(exprtype(pat)));
		break;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
pushq $0x1
popq %rbp
pushq $0x13
popq %r14
leaq 0xc07b(%rip), %r15      # 0x34c44
movq %r12, %rdi
movl %ebp, %esi
callq 0x12bd3
movq %rax, %r12
movq %rax, %rdi
callq 0x1b5e6
leal -0x33(%rax), %ecx
cmpl $0x6, %ecx
ja 0x28c50
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
leaq 0x35d72(%rip), %rax     # 0x5e968
movq (%rax), %rax
movq 0x38(%r12), %rcx
movq (%rax,%rcx,8), %r13
cmpb $0x0, 0x72(%r13)
je 0x290e1
movq %r13, %rdi
callq 0x1bf2d
movq %rax, %rbx
movl (%rax), %eax
cmpl $0x1e, %eax
ja 0x28c2d
movl $0x400a0000, %ecx       # imm = 0x400A0000
btl %eax, %ecx
jb 0x29155
movq 0x30(%r13), %r12
testq %r12, %r12
je 0x291a5
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x291cf
movq %rax, 0x10(%rsp)
jmp 0x28bc9
cmpl $0x12, %eax
je 0x28cf6
cmpl $0x14, %eax
jne 0x29171
movl %r14d, %r13d
movq 0x18(%rsp), %r14
movl (%r14), %edi
movq 0x8(%r14), %rsi
callq 0x28b66
movq %rax, %rbx
movq 0x10(%r14), %rdi
movq 0x18(%r14), %rsi
shlq $0x3, %rsi
callq 0x29d0d
movq %rax, 0x10(%rbx)
movq 0x18(%r14), %rax
movq %rax, 0x18(%rbx)
movq 0x20(%r14), %rdi
movq 0x28(%r14), %rsi
shlq $0x3, %rsi
callq 0x29d0d
movq %rax, 0x20(%rbx)
movq 0x28(%r14), %rax
movq %rax, 0x28(%rbx)
movq 0x40(%r14), %rax
movq %rax, 0x40(%rbx)
movl %ebp, 0x38(%rbx)
movq %rbx, 0x40(%r14)
movl %ebp, 0x38(%r14)
movq 0x50(%r12), %rax
movq (%rax), %rsi
movq %r14, %rdi
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x28b9b
movq 0x50(%r12), %rax
movq 0x8(%rax), %r12
movq %rbx, 0x18(%rsp)
movl %r13d, %r14d
jmp 0x28bc9
movq 0x8(%rsp), %rdx
movq (%rdx), %rdi
xorl %ebx, %ebx
movl %r14d, %esi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1b718
movl %r14d, %r13d
movq %rax, %r14
movq 0x50(%r12), %rax
movq (%rax), %rdi
callq 0x1bf90
movq %r14, 0x8(%rsp)
movq %rax, 0x20(%r14)
movl %r13d, %r14d
movq 0x50(%r12), %rax
movq (%rax), %r12
jmp 0x28e03
movq %r12, %rdi
callq 0x1bf90
movq %rax, %rdi
callq 0x1fcd8
movq 0x50(%r12), %rcx
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x203ff
movq %rax, 0x20(%rsp)
movq 0x8(%rax), %rsi
movq (%r12), %rdi
callq 0x1b6fc
movq %rax, %r13
movq (%r12), %rdi
pushq $0x7
popq %rsi
callq 0x1fdc2
movq %rax, 0x20(%r13)
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
pushq $0x43
popq %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1b718
movq %rax, %r14
movq (%rbx), %rdi
pushq $0x7
popq %rsi
callq 0x1fdc2
movq %rax, 0x20(%r14)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x291cf
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rax, %rcx
callq 0x28b9b
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rbx
testq %rbx, %rbx
je 0x290d2
movq 0x50(%r12), %rax
movq 0x8(%rax), %r12
movq 0x8(%rsp), %rdx
movq (%rdx), %rdi
pushq $0x44
popq %rsi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1b718
movq %rax, 0x8(%rsp)
movq %rbx, 0x20(%rax)
movl %ebp, %ebx
pushq $0x13
popq %r14
movq 0x10(%rsp), %rdi
movl %ebx, %esi
jmp 0x28c41
movq 0x50(%r12), %rax
movq (%rax), %r13
cmpl $0x4, 0x18(%r13)
jne 0x28efe
movq 0x30(%r13), %r15
movq 0x38(%r13), %rax
movq %rax, 0x20(%rsp)
movq (%r12), %rdi
pushq $0xe
popq %rsi
callq 0x1fdc2
movq %rax, %rbx
movq (%r13), %rdi
movq %r15, %rsi
callq 0x1b6fc
movq %rax, %r14
movq %rbx, 0x20(%rax)
movq (%r12), %rdi
leaq 0xbc1c(%rip), %rsi      # 0x34a78
callq 0x1b7fd
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x292cb
movq %rax, %rbx
xorl %ebp, %ebp
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x291cf
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x28b9b
movq (%r12), %rdi
movq %r15, %r12
pushq $0x9
popq %rsi
callq 0x1fdc2
movq %rax, %rbx
cmpq %rbp, %r12
je 0x290d2
movq 0x20(%rsp), %rax
movsbq (%rax,%rbp), %rsi
movq (%r13), %rdi
callq 0x1b6fc
movq %rax, %r14
movq %rbx, 0x20(%rax)
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x292eb
movq %rax, %r15
incq %rbp
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x291cf
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x28b9b
jmp 0x28ea7
movq 0x18(%rsp), %r14
leaq 0x10(%r14), %rbx
addq $0x18, %r14
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rdx
jmp 0x29134
xorl %ebx, %ebx
cmpq 0x40(%r12), %rbx
jae 0x290d2
movq 0x50(%r12), %rax
movq (%rax,%rbx,8), %r14
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x292eb
movq %rax, %r15
movq 0x10(%rsp), %rdi
movl %ebx, %esi
callq 0x291cf
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x28b9b
incq %rbx
jmp 0x28f1f
pushq $0x45
popq %r13
xorl %ebp, %ebp
movq 0x8(%rsp), %r15
cmpq 0x40(%r12), %rbp
jae 0x290d2
movq 0x50(%r12), %rax
movq (%rax,%rbp,8), %rbx
movq (%r15), %rdi
movq %rbp, %rsi
callq 0x1b6fc
movq %rax, %r14
movq (%r15), %rdi
pushq $0xe
popq %rsi
callq 0x1fdc2
movq %rax, 0x20(%r14)
movq (%r15), %rdi
movl %r13d, %esi
movq %r15, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1b718
movq %rax, %r14
movq %r15, %rdi
callq 0x1bf90
movq %rax, %rdi
callq 0x1fcd8
movq 0x68(%rax), %rax
movq (%rax,%rbp,8), %rax
movq %rax, 0x20(%r14)
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x291cf
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %rax, %rcx
callq 0x28b9b
incq %rbp
jmp 0x28f72
movq %r12, %rdi
callq 0x1bf90
movq %rax, %rdi
callq 0x1fcd8
movq %rax, %r14
xorl %ebp, %ebp
movq %rax, 0x20(%rsp)
cmpq 0x78(%r14), %rbp
jae 0x290d2
movq 0x88(%r14), %rax
movq (%rax,%rbp,8), %rdi
callq 0x1bf2d
movq %rax, %rbx
movq 0x88(%r14), %rax
movq (%rax,%rbp,8), %rax
movq 0x20(%rax), %r15
xorl %r13d, %r13d
cmpq 0x40(%r12), %r13
jae 0x2906d
movq 0x50(%r12), %rax
movq (%rax,%r13,8), %r14
movq 0x48(%r14), %rdi
movq %r15, %rsi
callq 0x1c100
incq %r13
testl %eax, %eax
je 0x29048
jmp 0x29093
movq 0x20(%rsp), %rax
movq 0x88(%rax), %rax
movq (%rax,%rbp,8), %rax
movq (%rax), %rdi
pushq $0x34
popq %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x1b718
movq %rax, %r14
movq %rbx, 0x20(%rax)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x292cb
movq %rax, %rbx
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x291cf
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x28b9b
incq %rbp
movq 0x20(%rsp), %r14
jmp 0x29019
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rdi
pushq $0x1d
popq %rsi
movq %r12, %rdx
movq 0x8(%rsp), %r15
movq %r15, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1b718
movq %rax, %rbx
movq %r12, %rdi
callq 0x1bf90
movq %rax, 0x20(%rbx)
movq 0x18(%rsp), %r14
leaq 0x20(%r14), %rdi
leaq 0x28(%r14), %rsi
movq %rbx, %rdx
callq 0x29b2d
leaq 0x10(%r14), %rbx
addq $0x18, %r14
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x29281
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x29b2d
movq %r13, %rdi
callq 0x1befe
movq %rax, %r14
movq %rbx, %rdi
callq 0x21009
leaq 0xbd46(%rip), %rsi      # 0x34eb5
jmp 0x291bf
movq %r12, %rdi
callq 0x1b5e6
movl %eax, %eax
leaq 0x3421e(%rip), %rcx     # 0x5d3a0
movq (%rcx,%rax,8), %rbx
movq %r12, %rdi
callq 0x1bf90
movq %rax, %rdi
callq 0x21009
leaq 0xbd63(%rip), %rsi      # 0x34f00
movq %r12, %rdi
movq %rbx, %rdx
jmp 0x291c5
movq %r13, %rdi
callq 0x1befe
movq %rax, %r14
movq %rbx, %rdi
callq 0x21009
leaq 0xbd1a(%rip), %rsi      # 0x34ed9
movq %r13, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x120fd