// File: /workspace/github_c_makefile_star2_O1/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, %rbp
movq %rsi, %r14
movq %rdi, %r15
movq %rdx, 0x10(%rsp)
cmpb $0x0, 0x29(%r15)
jne 0x2c104
movb $0x1, 0x29(%r15)
cmpb $0x0, 0x28(%r15)
jne 0x2c113
movq 0x10(%r15), %rdx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2d3ff
movq 0x48(%r15), %rax
testq %rax, %rax
je 0x2c0b8
xorl %ebx, %ebx
decq %rax
cmpq %rax, %rbx
jne 0x2bf4e
movq 0x50(%r15), %rax
testq %rax, %rax
je 0x2bf4e
movq 0x10(%rax), %r12
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x2bf62
movq 0x4(%r15), %rdi
callq 0x1e053
movq %rax, %r12
movl $0x0, 0xc(%rsp)
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rax
cmpb $0x0, 0x28(%rax)
je 0x2bf85
cmpq $0x0, 0x60(%rax)
je 0x2bf85
movq 0x4(%rax), %rdi
callq 0x1e053
movq %rax, %r13
jmp 0x2bf89
movq 0x10(%rax), %r13
movq 0x4(%r15), %rdi
movq 0x18(%r15), %rdx
movq 0x30(%r15), %rax
movq (%rax,%rbx,8), %rcx
movl $0x17, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1d832
movq %rax, %rbp
movq 0x4(%r15), %rdi
movl $0x2, %esi
callq 0x22d38
movq %rax, 0x20(%rbp)
movq 0x4(%r15), %rdi
movl $0x3e, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x1d832
movq %rax, %rbp
movq 0x4(%r15), %rdi
movl $0x1, %esi
callq 0x22d38
movq %rax, 0x20(%rbp)
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %rsi, %rbp
callq 0x2d3ff
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rax
cmpb $0x0, 0x28(%rax)
je 0x2c080
cmpq $0x0, 0x60(%rax)
je 0x2c080
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2d3ff
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rax
movq 0x58(%rax), %rdx
movq 0x60(%rax), %rcx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2d566
movq 0x4(%r15), %rdi
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rax
movq 0x10(%rax), %rdx
movl $0x30, %esi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1d832
movq %rax, %r13
movq 0x4(%r15), %rdi
movl $0x1, %esi
callq 0x22d38
movq %rax, 0x20(%r13)
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2d3ff
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2bedc
cmpb $0x0, 0xc(%rsp)
jne 0x2c0a8
movq %r14, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2d3ff
incq %rbx
movq 0x48(%r15), %rax
cmpq %rax, %rbx
jb 0x2bf31
movq 0x50(%r15), %rax
testq %rax, %rax
je 0x2c104
movq 0x10(%rax), %rdx
movq 0x4(%r15), %rdi
movl $0x30, %esi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1d832
movq %rax, %r12
movq 0x4(%r15), %rdi
movl $0x1, %esi
callq 0x22d38
movq %rax, 0x20(%r12)
movq %r14, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2d3ff
movq 0x50(%r15), %r15
jmp 0x2bef8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4(%r15), %rdi
movq 0x10(%r15), %rdx
movl $0x30, %esi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1d832
movq %rax, %r12
movq 0x4(%r15), %rdi
movl $0x1, %esi
callq 0x22d38
movq %rax, 0x20(%r12)
movq %r14, %rdi
movq %rbp, %rsi
movq %r12, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d3ff