// File: /workspace/github_c_makefile_star2_O3/theovosse[P]llgen/regexp.c
// Function: DisassembleDFA
void DisassembleDFA(RegExp dfa) {
	RegExp state;
	Transition tr, tr2;
	int mCount = charSetSize, count;
	RegExp mState = NULL;
	ESet elt;
	int i, tCount;
	RegExp cSet[256];
	int tempLabel = 1;
	Boolean justPrintedLabel = false;
	int nrStates = 0;

	for (state = dfa; state != NULL; state = state->next) nrStates++;
	tempLabel = nrStates + 1;
	printf(";\tNull-terminated string in A0.\n;\tResult in D0,A0\n");
	printf("\tMOVE.L A0,A1\n\tMOVE.W #$FFFF,D0\n\tCLR.W  D1\n");
	for (state = dfa; state != NULL; state = state->next) {
		tCount = charSetSize;
		for (i = 0; i != charSetSize; i++) cSet[i] = NULL;
		for (tr = state->transitions; tr != NULL; tr = tr->next) {
			cSet[tr->transitionChar] = tr->destination;
			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 */
		if (justPrintedLabel) printf("\n");
		printf("@%ld:", state->state.number);
		justPrintedLabel = true;
		if (state->info != NULL) {
			Answer first;
			printf("\tMOVE.W D1,D0\n");
			for (elt = state->info, first = elt->element; elt != NULL; elt = elt->next) {
				if (first->number > ((Answer) elt->element)->number) {
					first = elt->element;
				}
			}
			printf("\tMOVE.L #$%lx,A0\n", (long) first->info);
			justPrintedLabel = false;
		}
		if (state->transitions == NULL) {
			if (state->next != NULL) {
				printf("\tJMP    @%d\n", nrStates);
				justPrintedLabel = false;
			}
		} else {
			printf("\tADDQ.W #1,D1\n");
			printf("\tMOVE.B (A1)+,D2\n");
		 /* printf("\tTST.B  D2\n\tBEQ    @%d\n", nrStates); */
			justPrintedLabel = false;
			i = 0;
			while (i != charSetSize) {
				if (cSet[i] != mState) {
					if (i < charSetSize - 2 && cSet[i] == cSet[i + 1] && cSet[i] == cSet[i + 2]) {
						if (i != 0) {
							printf("\tCMP.B  #$%02x,D2\t; '", i);
							if (' ' <= i && i <= '~') printf("%c'\n", i);
							else printf("\\%03o'\n", i);
							printf("\tBLT    @%d\n", tempLabel);
							justPrintedLabel = false;
						}
						do {
							i++;
						}
						while (i != charSetSize && cSet[i] == cSet[i - 1]);
						i--;
						if (i == charSetSize - 1) {
							if (cSet[i] == NULL) {
								printf("\tJMP    @%d\n", nrStates);
							} else if (cSet[i] == state && state->info != NULL) {
								printf("\tJMP    @%ld+8\n", cSet[i]->state.number);
							} else {
								printf("\tJMP    @%ld\n", cSet[i]->state.number);
							}
						} else {
							printf("\tCMP.B  #$%02x,D2\t; '", i);
							if (' ' <= i && i <= '~') printf("%c'\n", i);
							else printf("\\%03o'\n", i);
							if (cSet[i] == NULL) {
								printf("\tBLE    @%d\n", nrStates);
							} else if (cSet[i] == state && state->info != NULL) {
								printf("\tBLE    @%ld+8\n", cSet[i]->state.number);
							} else {
								printf("\tBLE    @%ld\n", cSet[i]->state.number);
							}
						}
						printf("@%d:", tempLabel++);
						justPrintedLabel = true;
					} else {
						printf("\tCMP.B  #$%02x,D2\t; '", i);
						if (' ' <= i && i <= '~') printf("%c'\n", i);
						else printf("\\%03o'\n", i);
						if (cSet[i] == NULL) {
							printf("\tBEQ    @%d\n", nrStates);
						} else if (cSet[i] == state && state->info != NULL) {
							printf("\tBEQ    @%ld+8\n", cSet[i]->state.number);
						} else {
							printf("\tBEQ    @%ld\n", cSet[i]->state.number);
						}
						justPrintedLabel = false;
					}
				}
				i++;
			}
			if (mState == NULL) {
				if (state->next != NULL) {
					printf("\tJMP    @%d\n", nrStates);
				}
			} else if (mState == state && state->info != NULL) {
				printf("\tJMP    @%ld+8\n", mState->state.number);
			} else  {
				printf("\tJMP    @%ld\n", mState->state.number);
			}
			justPrintedLabel = false;
		}
	}
	if (justPrintedLabel) printf("\n");
	printf("@%d:\tRTS\n", nrStates);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x828, %rsp            # imm = 0x828
movq %rdi, %rbx
xorl %ebp, %ebp
testq %rdi, %rdi
je 0xe286
movq %rbx, %rax
incl %ebp
movq 0x18(%rax), %rax
testq %rax, %rax
jne 0xe27b
movl 0xafcf(%rip), %r12d     # 0x1925c
leaq 0x4f96(%rip), %rdi      # 0x1322a
callq 0x3090
leaq 0x4fbc(%rip), %rdi      # 0x1325c
callq 0x3090
testq %rbx, %rbx
je 0xe703
leal 0x1(%rbp), %eax
movq %rax, 0x18(%rsp)
xorl %r15d, %r15d
xorl %r9d, %r9d
movq %rbp, 0x8(%rsp)
movl 0xaf95(%rip), %edx      # 0x1925c
testq %rdx, %rdx
je 0xe2e2
shlq $0x3, %rdx
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movq %r9, %r14
callq 0x3120
movq %r14, %r9
movq (%rbx), %rax
movq %rax, %rcx
testq %rax, %rax
je 0xe341
movq 0x8(%rcx), %rdx
movslq (%rcx), %rsi
movq %rdx, 0x20(%rsp,%rsi,8)
decl %r12d
movq 0x10(%rcx), %rcx
testq %rcx, %rcx
jne 0xe2ed
jmp 0xe33c
movq 0x8(%rax), %rcx
cmpq %r9, %rcx
je 0xe338
xorl %edx, %edx
movq %rax, %rsi
xorl %edi, %edi
cmpq %rcx, 0x8(%rsi)
movq 0x10(%rsi), %r8
sete %dil
addl %edi, %edx
movq %r8, %rsi
testq %r8, %r8
jne 0xe315
cmpl %r12d, %edx
cmovgl %edx, %r12d
cmovgq %rcx, %r9
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0xe307
movq %r9, (%rsp)
testw %r15w, %r15w
je 0xe355
movl $0xa, %edi
callq 0x3040
movq 0x28(%rbx), %rsi
leaq 0x4c30(%rip), %rdi      # 0x12f90
xorl %eax, %eax
callq 0x30f0
cmpq $0x0, 0x10(%rbx)
je 0xe3b1
leaq 0x4f12(%rip), %rdi      # 0x13287
callq 0x3090
movq 0x10(%rbx), %rcx
movq (%rcx), %rax
movl (%rax), %edx
movq (%rcx), %rsi
movl (%rsi), %edi
cmpl %edi, %edx
cmovgel %edi, %edx
movq 0x8(%rcx), %rcx
cmovgq %rsi, %rax
testq %rcx, %rcx
jne 0xe383
movq 0x8(%rax), %rsi
xorl %r15d, %r15d
leaq 0x4bee(%rip), %rdi      # 0x12f96
xorl %eax, %eax
callq 0x30f0
jmp 0xe3b6
movw $0xffff, %r15w          # imm = 0xFFFF
cmpq $0x0, (%rbx)
je 0xe67c
leaq 0x4ece(%rip), %rdi      # 0x13295
callq 0x3090
leaq 0x4ed0(%rip), %rdi      # 0x132a3
callq 0x3090
movl 0xae7e(%rip), %eax      # 0x1925c
testl %eax, %eax
je 0xe685
xorl %r13d, %r13d
movq (%rsp), %r9
movq %rbx, 0x10(%rsp)
movslq %r13d, %r14
movq 0x20(%rsp,%r14,8), %r15
cmpq %r9, %r15
je 0xe497
leal -0x2(%rax), %ecx
cmpl %ecx, %r13d
jge 0xe41d
cmpq 0x28(%rsp,%r14,8), %r15
jne 0xe41d
cmpq 0x30(%rsp,%r14,8), %r15
je 0xe4ae
leaq 0x4b91(%rip), %rdi      # 0x12fb5
movl %r13d, %esi
xorl %eax, %eax
callq 0x30f0
leal -0x20(%r13), %eax
cmpl $0x5f, %eax
leaq 0x4b94(%rip), %rdi      # 0x12fd0
leaq 0x4b88(%rip), %rax      # 0x12fcb
cmovbq %rax, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x30f0
testq %r15, %r15
je 0xe468
cmpq %rbx, %r15
je 0xe47a
movq 0x28(%r15), %rsi
leaq 0x4bea(%rip), %rdi      # 0x13050
jmp 0xe48c
leaq 0x4bc4(%rip), %rdi      # 0x13033
movl %ebp, %esi
xorl %eax, %eax
callq 0x30f0
jmp 0xe493
cmpq $0x0, 0x10(%rbx)
je 0xe45b
movq 0x28(%r15), %rsi
leaq 0x4bb4(%rip), %rdi      # 0x13040
xorl %eax, %eax
callq 0x30f0
movq (%rsp), %r9
incl %r13d
movl 0xadbc(%rip), %eax      # 0x1925c
cmpl %eax, %r13d
jne 0xe3f2
jmp 0xe689
testl %r13d, %r13d
je 0xe500
leaq 0x4afb(%rip), %rdi      # 0x12fb5
movl %r13d, %esi
xorl %eax, %eax
callq 0x30f0
leal -0x20(%r13), %eax
cmpl $0x5f, %eax
leaq 0x4afe(%rip), %rdi      # 0x12fd0
leaq 0x4af2(%rip), %rax      # 0x12fcb
cmovbq %rax, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x30f0
leaq 0x4aea(%rip), %rdi      # 0x12fd8
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x30f0
movl 0xad5c(%rip), %eax      # 0x1925c
movq %r14, %rbx
shlq $0x20, %rbx
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rbx
leaq 0x28(%rsp), %rcx
leaq (%rcx,%r14,8), %rdx
movl %r13d, %ecx
subl %eax, %ecx
decl %eax
xorl %esi, %esi
leal (%rcx,%rsi), %edi
cmpl $-0x1, %edi
je 0xe5c1
movabsq $0x100000000, %rdi      # imm = 0x100000000
addq %rdi, %rbx
leaq 0x1(%rsi), %rbp
cmpq %r15, (%rdx,%rsi,8)
movq %rbp, %rsi
je 0xe526
leaq (%r14,%rbp), %r15
decq %r15
addl %ebp, %ecx
je 0xe5c6
leaq 0x4a57(%rip), %rdi      # 0x12fb5
movl %r15d, %esi
xorl %eax, %eax
callq 0x30f0
leal -0x21(%r13,%rbp), %eax
cmpl $0x5f, %eax
leaq 0x4a59(%rip), %rdi      # 0x12fd0
leaq 0x4a4d(%rip), %rax      # 0x12fcb
cmovbq %rax, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x30f0
sarq $0x1d, %rbx
movq 0x20(%rsp,%rbx), %rax
testq %rax, %rax
je 0xe61e
movq 0x10(%rsp), %rcx
cmpq %rcx, %rax
movq 0x8(%rsp), %rbp
je 0xe635
movq 0x28(%rax), %rsi
leaq 0x4a64(%rip), %rdi      # 0x13020
jmp 0xe64b
movl %eax, %r13d
jmp 0xe5c9
movl %r15d, %r13d
cltq
movq 0x20(%rsp,%rax,8), %rax
testq %rax, %rax
movq 0x8(%rsp), %rbp
movq 0x10(%rsp), %rcx
je 0xe5f1
cmpq %rcx, %rax
je 0xe603
movq 0x28(%rax), %rsi
leaq 0x4a06(%rip), %rdi      # 0x12ff5
jmp 0xe615
leaq 0x49b0(%rip), %rdi      # 0x12fa8
movl %ebp, %esi
xorl %eax, %eax
callq 0x30f0
jmp 0xe655
cmpq $0x0, 0x10(%rcx)
je 0xe5e4
movq 0x28(%rax), %rsi
leaq 0x49d0(%rip), %rdi      # 0x12fe5
xorl %eax, %eax
callq 0x30f0
jmp 0xe655
leaq 0x49de(%rip), %rdi      # 0x13003
movq 0x8(%rsp), %rbp
movl %ebp, %esi
xorl %eax, %eax
callq 0x30f0
jmp 0xe652
cmpq $0x0, 0x10(%rcx)
je 0xe5b1
movq 0x28(%rax), %rsi
leaq 0x49c5(%rip), %rdi      # 0x13010
xorl %eax, %eax
callq 0x30f0
movl %r15d, %r13d
movq 0x18(%rsp), %rsi
leal 0x1(%rsi), %ebx
leaq 0x49ca(%rip), %rdi      # 0x1302e
xorl %eax, %eax
callq 0x30f0
movl %ebx, %eax
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rbx
jmp 0xe493
cmpq $0x0, 0x18(%rbx)
jne 0xe6aa
jmp 0xe6db
movq (%rsp), %r9
testq %r9, %r9
je 0xe6a3
cmpq %rbx, %r9
je 0xe6bf
movq 0x28(%r9), %rsi
xorl %r15d, %r15d
leaq 0x4954(%rip), %rdi      # 0x12ff5
jmp 0xe6d4
cmpq $0x0, 0x18(%rbx)
je 0xe6ee
xorl %r15d, %r15d
leaq 0x48f4(%rip), %rdi      # 0x12fa8
movl %ebp, %esi
xorl %eax, %eax
callq 0x30f0
jmp 0xe6db
cmpq $0x0, 0x10(%rbx)
je 0xe693
movq 0x28(%r9), %rsi
xorl %r15d, %r15d
leaq 0x4911(%rip), %rdi      # 0x12fe5
xorl %eax, %eax
callq 0x30f0
movq (%rsp), %r9
movq 0x18(%rbx), %rbx
testq %rbx, %rbx
jne 0xe2c1
jmp 0xe6f3
xorl %r15d, %r15d
jmp 0xe6df
testw %r15w, %r15w
je 0xe703
movl $0xa, %edi
callq 0x3040
leaq 0x4954(%rip), %rdi      # 0x1305e
movl %ebp, %esi
xorl %eax, %eax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30f0