// File: /workspace/github_c_makefile_star2_O2/theovosse[P]llgen/regexp.c
// Function: PrintDFA
void PrintDFA(RegExp dfa) {
	RegExp state;
	Transition tr, tr2;
	ESet transitions;
	int mCount = charSetSize, count;
	RegExp mState = NULL;
	ESet elt;
	int i, tCount;
	Boolean cSet[256];

	printf("int PMatch(char *str)\n{\n    int pos = 0, lLen = -1;\n\n");
	for (state = dfa; state != NULL; state = state->next) {
		tCount = charSetSize;
		for (i = 0; i != charSetSize; i++) cSet[i] = false;
		for (tr = state->transitions; tr != NULL; tr = tr->next) {
			cSet[tr->transitionChar] = true;
			mCount--;
			tCount--;
		}
		/* mCount is nr. of fails, mState == NULL, the fail state */
		for (tr = state->transitions; tr != NULL; tr = tr->next) {
			if (tr->destination != mState) /* not the most efficient check, but ok */ {
				for (count = 0, tr2 = tr; tr2 != NULL; tr2 = tr2->next)
					if (tr2->destination == tr->destination) count++;
				if (count > mCount) {
					mCount = count;
					mState = tr->destination;
				}
			}
		}
		/* mCount is max. nr. of transitions to the same state, mState is that state */
		printf("  l%ld:\n", state->state.number);
		if (state->info != NULL) {
			Answer first;
			printf("    lLen = pos;\n");
			for (elt = state->info, first = elt->element; elt != NULL; elt = elt->next) {
				if (singleAnswer) {
					if (first->number > ((Answer) elt->element)->number) {
						first = elt->element;
					}
				} else {
					printf("    Accept(%d, \"%s\");\n", ((Answer) elt->element)->number, (const char*) ((Answer) elt->element)->info);
				}
			}
			if (singleAnswer) {
				printf("    Accept(\"%s\");\n", (const char*) first->info);
			}
		}
		if (state->transitions == NULL) {
			printf("    goto fail;\n");
		} else {
			printf("    if (*str == '\\0') goto fail;\n");
			printf("    pos++;\n    switch (*str++)\n    {\n");
			transitions = NULL;
			for (tr = state->transitions; tr != NULL; tr = tr->next) {
				if (tr->destination != mState && !SetMember(tr->destination, transitions)) {
					transitions = AddElement(tr->destination, transitions);
					for (tr2 = tr; tr2 != NULL; tr2 = tr2->next) {
						if (tr2->destination == tr->destination) {
							printf("        case ");
							if (tr2->transitionChar < ' ' || tr2->transitionChar > '~') {
								printf("\\%03x:\n", tr2->transitionChar);
							} else {
								printf("'%c':\n", tr2->transitionChar);
							}
						}
					}
					printf("            goto l%ld;\n", tr->destination->state.number);
				}
			}
			if (mState == NULL) {
				printf("        default:\n            goto fail;\n");
			} else {
				if (tCount != 0) {
					for (i = 0; i != charSetSize; i++) {
						if (!cSet[i]) {
							printf("        case ");
							if (i < ' ' || i > '~') {
								printf("\\%03x:\n", i);
							} else {
								printf("'%c':\n", i);
							}
						}
					}
					printf("            goto fail;\n");
				}
				printf("        default:\n            goto l%ld;\n", mState->state.number);
			}
			RemoveSet(transitions);
			printf("    }\n");
		}
	}
	printf("  fail:\n    return (lLen);\n}\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdi, %r13
movl 0xb0ab(%rip), %ebp      # 0x1825c
leaq 0x4f7c(%rip), %rdi      # 0x12134
callq 0x3090
xorl %ebx, %ebx
testq %r13, %r13
je 0xd43a
movl 0xb08e(%rip), %ecx      # 0x1825c
xorl %eax, %eax
cmpq %rax, %rcx
je 0xd1e0
andw $0x0, 0x10(%rsp,%rax,2)
incq %rax
jmp 0xd1d0
movq %rcx, 0x8(%rsp)
xorl %r12d, %r12d
movq %r13, %rax
movq (%rax), %rax
testq %rax, %rax
je 0xd205
movslq (%rax), %rcx
orw $-0x1, 0x10(%rsp,%rcx,2)
addq $0x10, %rax
incl %r12d
jmp 0xd1eb
subl %r12d, %ebp
movq %r13, %rax
movq (%rax), %rax
testq %rax, %rax
je 0xd247
movq 0x8(%rax), %rcx
cmpq %rbx, %rcx
je 0xd241
xorl %edx, %edx
movq %rax, %rsi
testq %rsi, %rsi
je 0xd238
xorl %edi, %edi
cmpq %rcx, 0x8(%rsi)
movq 0x10(%rsi), %rsi
sete %dil
addl %edi, %edx
jmp 0xd221
cmpl %ebp, %edx
cmovgl %edx, %ebp
cmovgq %rcx, %rbx
addq $0x10, %rax
jmp 0xd20b
movq 0x28(%r13), %rsi
leaq 0x4ca5(%rip), %rdi      # 0x11ef7
xorl %eax, %eax
callq 0x30f0
cmpq $0x0, 0x10(%r13)
je 0xd2c6
leaq 0x4f1f(%rip), %rdi      # 0x12186
callq 0x3090
movq 0x10(%r13), %r15
movq (%r15), %r14
movzwl 0xda5e(%rip), %eax      # 0x1acd8
testq %r15, %r15
je 0xd2af
testw %ax, %ax
je 0xd292
movl (%r14), %eax
movq (%r15), %rcx
cmpl (%rcx), %eax
cmovgq %rcx, %r14
jmp 0xd2a9
movq (%r15), %rax
movl (%rax), %esi
movq 0x8(%rax), %rdx
leaq 0x4c5e(%rip), %rdi      # 0x11f00
xorl %eax, %eax
callq 0x30f0
movq 0x8(%r15), %r15
jmp 0xd273
testw %ax, %ax
je 0xd2c6
movq 0x8(%r14), %rsi
leaq 0x4c58(%rip), %rdi      # 0x11f17
xorl %eax, %eax
callq 0x30f0
cmpq $0x0, (%r13)
leaq 0x4f23(%rip), %rdi      # 0x121f5
je 0xd42c
leaq 0x4eb7(%rip), %rdi      # 0x12196
callq 0x3090
leaq 0x4ecc(%rip), %rdi      # 0x121b7
callq 0x3090
movq %r13, (%rsp)
xorl %r15d, %r15d
movq (%r13), %r13
testq %r13, %r13
je 0xd390
movq 0x8(%r13), %r14
cmpq %rbx, %r14
je 0xd387
movq %r14, %rdi
movq %r15, %rsi
callq 0xbf94
testw %ax, %ax
jne 0xd387
movq %r14, %rdi
movq %r15, %rsi
callq 0xbec0
movq %rax, %r15
movq %r13, %r14
testq %r14, %r14
je 0xd371
movq 0x8(%r14), %rax
cmpq 0x8(%r13), %rax
jne 0xd36b
leaq 0x4be6(%rip), %rdi      # 0x11f2a
xorl %eax, %eax
callq 0x30f0
movl (%r14), %esi
leal -0x7f(%rsi), %eax
leaq 0x4be0(%rip), %rdi      # 0x11f38
cmpl $-0x5f, %eax
jb 0xd364
leaq 0x4bdc(%rip), %rdi      # 0x11f40
xorl %eax, %eax
callq 0x30f0
movq 0x10(%r14), %r14
jmp 0xd32e
movq 0x8(%r13), %rax
movq 0x28(%rax), %rsi
leaq 0x4bd8(%rip), %rdi      # 0x11f58
xorl %eax, %eax
callq 0x30f0
addq $0x10, %r13
jmp 0xd2f7
testq %rbx, %rbx
je 0xd3ed
cmpl %r12d, 0x8(%rsp)
movq (%rsp), %r13
je 0xd40b
xorl %r14d, %r14d
movl 0xaeb3(%rip), %eax      # 0x1825c
cmpq %rax, %r14
je 0xd3ff
cmpw $0x0, 0x10(%rsp,%r14,2)
jne 0xd3e8
leaq 0x4b6c(%rip), %rdi      # 0x11f2a
xorl %eax, %eax
callq 0x30f0
leal -0x7f(%r14), %eax
cmpl $-0x5f, %eax
leaq 0x4b6d(%rip), %rdi      # 0x11f40
leaq 0x4b5e(%rip), %rax      # 0x11f38
cmovbq %rax, %rdi
movl %r14d, %esi
xorl %eax, %eax
callq 0x30f0
incq %r14
jmp 0xd3a3
leaq 0x4de8(%rip), %rdi      # 0x121dc
callq 0x3090
movq (%rsp), %r13
jmp 0xd41d
leaq 0x4de7(%rip), %rdi      # 0x121ed
callq 0x3090
movq 0x28(%rbx), %rsi
leaq 0x4b31(%rip), %rdi      # 0x11f47
xorl %eax, %eax
callq 0x30f0
movq %r15, %rdi
callq 0xbf31
leaq 0x4dd8(%rip), %rdi      # 0x12204
callq 0x3090
movq 0x18(%r13), %r13
jmp 0xd1bf
leaq 0x4d28(%rip), %rdi      # 0x12169
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3090