// File: /workspace/github_c_makefile_star2_O2/oridb[P]mc/mi/match.c
// Function: genmatchcode
void
genmatchcode(Dtree *dt, Node ***out, size_t *nout)
{
	Node *jmp, *eq, *fail;
	Node *next;
	int emit;
	size_t i;

	if (dt->emitted)
		return;
	dt->emitted = 1;

	/* the we jump to the accept label when generating the parent */
	if (dt->accept) {
		jmp = mkexpr(dt->loc, Ojmp, dt->lbl, NULL);
		jmp->expr.type = mktype(dt->loc, Tyvoid);
		lappend(out, nout, jmp);
		return;
	}

	lappend(out, nout, dt->lbl);
	for (i = 0; i < dt->nnext; i++) {
		if (i == dt->nnext - 1 && dt->any) {
			fail = dt->any->lbl;
			emit = 0;
		} else {
			fail = genlbl(dt->loc);
			emit = 1;
		}
		if (dt->next[i]->accept && dt->next[i]->ncap > 0) {
			next = genlbl(dt->next[i]->loc);
		} else {
			next = dt->next[i]->lbl;
		}

		eq = mkexpr(dt->loc, Oeq, dt->load, dt->pat[i], NULL);
		eq->expr.type = mktype(dt->loc, Tybool);
		jmp = mkexpr(dt->loc, Ocjmp, eq, next, fail, NULL);
		jmp->expr.type = mktype(dt->loc, Tyvoid);
		lappend(out, nout, jmp);

		if (dt->next[i]->accept && dt->next[i]->ncap > 0) {
			lappend(out, nout, next);
			lcat(out, nout, dt->next[i]->cap, dt->next[i]->ncap);
			jmp = mkexpr(dt->loc, Ojmp, dt->next[i]->lbl, NULL);
			jmp->expr.type = mktype(dt->loc, Tyvoid);
			lappend(out, nout, jmp);
		}

		genmatchcode(dt->next[i], out, nout);
		if (emit)
			lappend(out, nout, fail);
	}
	if (dt->any) {
		jmp = mkexpr(dt->loc, Ojmp, dt->any->lbl, NULL);
		jmp->expr.type = mktype(dt->loc, Tyvoid);
		lappend(out, nout, jmp);
		genmatchcode(dt->any, out, nout);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, %r15
cmpb $0x0, 0x29(%r15)
jne 0x288f7
movb $0x1, 0x29(%r15)
cmpb $0x0, 0x28(%r15)
jne 0x28906
movq 0x10(%r15), %rdx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x29b2d
xorl %ebx, %ebx
movq 0x48(%r15), %rax
cmpq %rax, %rbx
jae 0x288ad
decq %rax
cmpq %rax, %rbx
jne 0x28751
movq 0x50(%r15), %rax
testq %rax, %rax
je 0x28751
movq 0x10(%rax), %r12
movb $0x1, %al
movl %eax, 0x14(%rsp)
jmp 0x28765
movq 0x4(%r15), %rdi
callq 0x1bc4f
movq %rax, %r12
movl $0x0, 0x14(%rsp)
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rax
cmpb $0x0, 0x28(%rax)
je 0x28788
cmpq $0x0, 0x60(%rax)
je 0x28788
movq 0x4(%rax), %rdi
callq 0x1bc4f
movq %rax, %r13
jmp 0x2878c
movq 0x10(%rax), %r13
movq 0x4(%r15), %rdi
movq 0x18(%r15), %rdx
movq 0x30(%r15), %rax
movq (%rax,%rbx,8), %rcx
pushq $0x17
popq %rsi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1b718
movq %rax, %rbp
movq 0x4(%r15), %rdi
pushq $0x2
popq %rsi
callq 0x1fdc2
movq %rax, 0x20(%rbp)
movq 0x4(%r15), %rdi
pushq $0x3e
popq %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x1b718
movq %rax, %rbp
movq 0x4(%r15), %rdi
pushq $0x1
popq %rsi
callq 0x1fdc2
movq %rax, 0x20(%rbp)
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x29b2d
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rdi
cmpb $0x0, 0x28(%rdi)
je 0x28881
cmpq $0x0, 0x60(%rdi)
je 0x28881
movq %r14, %rdi
movq 0x8(%rsp), %rbp
movq %rbp, %rsi
movq %r13, %rdx
callq 0x29b2d
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rax
movq 0x58(%rax), %rdx
movq 0x60(%rax), %rcx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x29c8c
movq 0x4(%r15), %rdi
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rax
movq 0x10(%rax), %rdx
pushq $0x30
popq %rsi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1b718
movq %rax, %r13
movq 0x4(%r15), %rdi
pushq $0x1
popq %rsi
callq 0x1fdc2
movq %rax, 0x20(%r13)
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x29b2d
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
callq 0x286e0
cmpb $0x0, 0x14(%rsp)
jne 0x288a5
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
callq 0x29b2d
incq %rbx
jmp 0x28727
movq 0x50(%r15), %rax
testq %rax, %rax
je 0x288f7
movq 0x10(%rax), %rdx
movq 0x4(%r15), %rdi
pushq $0x30
popq %rsi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1b718
movq %rax, %r12
movq 0x4(%r15), %rdi
pushq $0x1
popq %rsi
callq 0x1fdc2
movq %rax, 0x20(%r12)
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
callq 0x29b2d
movq 0x50(%r15), %r15
jmp 0x286f9
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4(%r15), %rdi
movq 0x10(%r15), %rdx
pushq $0x30
popq %rsi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1b718
movq %rax, %r12
movq 0x4(%r15), %rdi
pushq $0x1
popq %rsi
callq 0x1fdc2
movq %rax, 0x20(%r12)
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x29b2d