// File: /workspace/github_c_makefile_star2_O0/oridb[P]mc/mi/match.c
// Function: gendtree
Dtree *
gendtree(Node *m, Node *val, Node **lbl, size_t nlbl)
{
	Dtree *root;
	Node **pat;
	size_t npat;
	size_t i, j;
	Frontier **frontier, *cur, *last;
	size_t nfrontier;
	FILE *csv;
	char *dbgloc, *dbgfn, *dbgln;


	ndtree = 0;
	dtree = NULL;

	pat = m->matchstmt.matches;
	npat = m->matchstmt.nmatches;

	frontier = NULL;
	nfrontier = 0;
	for (i = 0; i < npat; i++) {
		genfrontier(i, val, pat[i]->match.pat, lbl[i], &frontier, &nfrontier);
	}

	/* to determine if two different sets of captures come from a or-pattern, which is NOT allowed. */
	last = NULL;
	for (i = 0; i < nfrontier; i++) {
		cur = frontier[i];
		if (last && last->i == cur->i) {
			if (last->ncap != cur->ncap)
				fatal(pat[cur->i], "number of wildcard variables in the or-patterns are not equal (%d != %d)", last->ncap, cur->ncap);
			for (j = 0; j < cur->ncap; j++) {
				if (!capcompatible(last->cap[j], cur->cap[j]))
					fatal(pat[cur->i], "wildcard variables have different types in the or-patterns");
			}
		}
		/*
		 * If the match arm does not have or-pattern, we can
		 * insert the assignements of the captures at the
		 * beginning of the associated block.  Otherwise,
		 * the captures can bind different locations with
		 * the same identifier in thehe or-patterns, and
		 * thus the assignments must be carried out before
		 * jumping into the block.  For this reason, in the
		 * case of having or-pattern, we store the
		 * information of captures in the dtree MATCH node
		 * and delegate the insertion of the captures
		 * assignments to the ir generation of dtree
		 */
		if (cur->hasorpat) {
			cur->final->cap = cur->cap;
			cur->final->ncap = cur->ncap;
		} else {
			addcapture(pat[cur->i]->match.block, cur->cap, cur->ncap);
		}
		last = cur;
	}
	root = compile(frontier, nfrontier);

	for (i = 0; i < nfrontier; i++)
		if (frontier[i]->final->refcnt == 0)
			fatal(pat[frontier[i]->i], "pattern matched by earlier case");

	if (debugopt['M'] || getenv("M")) {
		dbgloc = strdup(getenv("M"));
		if (strchr(dbgloc, '@')) {
			dbgfn = strtok(dbgloc, "@");
			dbgln = strtok(NULL, "@")+1; /* offset by 1 to skip the charactor 'L' */
			if (!strcmp(fname(m->loc), dbgfn) && lnum(m->loc) == strtol(dbgln, 0, 0))
				dtreedump(stdout, root);
		}
		else
			dtreedump(stdout, root);

	}
	if (!verifymatch(root)) {
		fatal(m, "nonexhaustive pattern set in match statement");
	}
	if (getenv("MATCH_STATS")) {
		csv = fopen("match.csv", "a");
		assert(csv != NULL);
		fprintf(csv, "%s@L%d, %ld, %zd, %zd\n", fname(m->loc), lnum(m->loc), refsum(root), ndtree, dtheight(root));
		fclose(csv);

		/* clear 'emitted' so it can be reused by genmatchcode. */
		clearemit(root);
	}

	return root;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, 0x39382(%rip) # 0x7dd88
movq $0x0, 0x3937f(%rip) # 0x7dd90
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x44a8c
movq -0x40(%rbp), %rax
movl %eax, %edi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x18(%rax), %rdx
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq -0x50(%rbp), %r8
leaq -0x68(%rbp), %r9
callq 0x44e90
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x44a41
movq $0x0, -0x60(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x68(%rbp), %rax
jae 0x44bfa
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x44b85
movq -0x60(%rbp), %rax
movl (%rax), %eax
movq -0x58(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x44b85
movq -0x60(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
cmpq 0x28(%rcx), %rax
je 0x44b16
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x60(%rbp), %rax
movq 0x28(%rax), %rdx
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rcx
leaq 0x108af(%rip), %rsi     # 0x553be
movb $0x0, %al
callq 0x1dfe0
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jae 0x44b83
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x44f30
cmpl $0x0, %eax
jne 0x44b73
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1089b(%rip), %rsi     # 0x55407
movb $0x0, %al
callq 0x1dfe0
jmp 0x44b75
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x44b1e
jmp 0x44b85
movq -0x58(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x44bb9
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movq %rcx, 0x58(%rax)
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movq %rcx, 0x60(%rax)
jmp 0x44be1
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rdi
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rdx
callq 0x44fd0
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x44a9c
movq -0x50(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x451d0
movq %rax, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x68(%rbp), %rax
jae 0x44c69
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x30(%rax), %rax
cmpq $0x0, 0x68(%rax)
jne 0x44c59
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x107f0(%rip), %rsi     # 0x55442
movb $0x0, %al
callq 0x1dfe0
jmp 0x44c5b
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x44c13
leaq 0x38090(%rip), %rax     # 0x7cd00
movsbl 0x4d(%rax), %eax
cmpl $0x0, %eax
jne 0x44c8f
leaq 0x107e2(%rip), %rdi     # 0x55462
callq 0x6030
cmpq $0x0, %rax
je 0x44d6b
leaq 0x107cc(%rip), %rdi     # 0x55462
callq 0x6030
movq %rax, %rdi
callq 0x6330
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movl $0x40, %esi
callq 0x6110
cmpq $0x0, %rax
je 0x44d56
movq -0x78(%rbp), %rdi
leaq 0x1079a(%rip), %rsi     # 0x55464
callq 0x62e0
movq %rax, -0x80(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x10786(%rip), %rsi     # 0x55464
callq 0x62e0
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x2f090
movq %rax, %rdi
movq -0x80(%rbp), %rsi
callq 0x6220
cmpl $0x0, %eax
jne 0x44d54
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x2f0b0
cltq
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x6250
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jne 0x44d54
movq 0x1a288(%rip), %rax     # 0x5efd0
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x44890
jmp 0x44d69
movq 0x1a273(%rip), %rax     # 0x5efd0
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x44890
jmp 0x44d6b
movq -0x28(%rbp), %rdi
callq 0x459a0
cmpl $0x0, %eax
jne 0x44d8b
movq -0x8(%rbp), %rdi
leaq 0x106e2(%rip), %rsi     # 0x55466
movb $0x0, %al
callq 0x1dfe0
leaq 0x10701(%rip), %rdi     # 0x55493
callq 0x6030
cmpq $0x0, %rax
je 0x44e7d
leaq 0x106f7(%rip), %rdi     # 0x5549f
leaq 0xc713(%rip), %rsi      # 0x514c2
callq 0x62d0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x44dc1
jmp 0x44de0
leaq 0x106e1(%rip), %rdi     # 0x554a9
leaq 0x106e6(%rip), %rsi     # 0x554b5
movl $0x3ed, %edx            # imm = 0x3ED
leaq 0x106e2(%rip), %rcx     # 0x554bd
callq 0x6160
movq -0x70(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x2f090
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x2f0b0
movl %eax, -0xa4(%rbp)
movq -0x28(%rbp), %rdi
callq 0x45a40
movq %rax, -0xa0(%rbp)
movq 0x38f61(%rip), %rax     # 0x7dd88
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rdi
callq 0x45b30
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rdx
movl -0xa4(%rbp), %ecx
movq -0xa0(%rbp), %r8
movq -0x98(%rbp), %r9
leaq 0x1068e(%rip), %rsi     # 0x554ee
movq %rax, (%rsp)
movb $0x0, %al
callq 0x6230
movq -0x70(%rbp), %rdi
callq 0x60f0
movq -0x28(%rbp), %rdi
callq 0x45c00
movq -0x28(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)