// File: /workspace/github_c_makefile_star2_O1/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 $0x818, %rsp            # imm = 0x818
movq %rdi, %r14
xorl %ebx, %ebx
testq %rdi, %rdi
je 0xe610
movq %r14, %rax
incl %ebx
movq 0x18(%rax), %rax
testq %rax, %rax
jne 0xe605
movl 0xac45(%rip), %r12d     # 0x1925c
leaq 0x4c0c(%rip), %rdi      # 0x1322a
callq 0x3090
leaq 0x4c32(%rip), %rdi      # 0x1325c
callq 0x3090
testq %r14, %r14
je 0xea11
movq %rbx, (%rsp)
leal 0x1(%rbx), %eax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
xorl %ebp, %ebp
movl 0xac0d(%rip), %edx      # 0x1925c
testq %rdx, %rdx
je 0xe664
shlq $0x3, %rdx
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x3120
movq (%r14), %rax
testq %rax, %rax
je 0xe681
movq 0x8(%rax), %rcx
movslq (%rax), %rdx
movq %rcx, 0x10(%rsp,%rdx,8)
decl %r12d
movq 0x10(%rax), %rax
jmp 0xe667
movq (%r14), %rax
testq %rax, %rax
je 0xe6c0
movq 0x8(%rax), %rcx
cmpq %rbp, %rcx
je 0xe6ba
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 0xe697
cmpl %r12d, %edx
cmovgl %edx, %r12d
cmovgq %rcx, %rbp
movq 0x10(%rax), %rax
jmp 0xe684
testw %r15w, %r15w
je 0xe6d0
movl $0xa, %edi
callq 0x3040
movq 0x28(%r14), %rsi
leaq 0x48b5(%rip), %rdi      # 0x12f90
xorl %eax, %eax
callq 0x30f0
cmpq $0x0, 0x10(%r14)
je 0xe72b
leaq 0x4b97(%rip), %rdi      # 0x13287
callq 0x3090
movq 0x10(%r14), %rax
movq (%rax), %rcx
movl (%rcx), %esi
movq (%rax), %rdx
movq 0x8(%rax), %rax
cmpl (%rdx), %esi
jg 0xe70c
movq %rcx, %rdx
movq %rdx, %rcx
testq %rax, %rax
jne 0xe6fc
movq 0x8(%rdx), %rsi
xorl %r15d, %r15d
leaq 0x4874(%rip), %rdi      # 0x12f96
xorl %eax, %eax
callq 0x30f0
jmp 0xe730
movw $0xffff, %r15w          # imm = 0xFFFF
cmpq $0x0, (%r14)
je 0xe9a6
leaq 0x4b54(%rip), %rdi      # 0x13295
callq 0x3090
leaq 0x4b56(%rip), %rdi      # 0x132a3
callq 0x3090
movl 0xab04(%rip), %eax      # 0x1925c
testl %eax, %eax
je 0xe98c
xorl %r13d, %r13d
movslq %r13d, %r15
movq 0x10(%rsp,%r15,8), %rbx
cmpq %rbp, %rbx
je 0xe806
addl $-0x2, %eax
cmpl %eax, %r13d
jge 0xe78e
cmpq 0x18(%rsp,%r15,8), %rbx
jne 0xe78e
cmpq 0x20(%rsp,%r15,8), %rbx
je 0xe81d
leaq 0x4820(%rip), %rdi      # 0x12fb5
movl %r13d, %esi
xorl %eax, %eax
callq 0x30f0
leal -0x20(%r13), %eax
cmpl $0x5f, %eax
leaq 0x4823(%rip), %rdi      # 0x12fd0
leaq 0x4817(%rip), %rax      # 0x12fcb
cmovbq %rax, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x30f0
testq %rbx, %rbx
je 0xe7d9
cmpq %r14, %rbx
je 0xe7ed
movq 0x28(%rbx), %rsi
leaq 0x4879(%rip), %rdi      # 0x13050
jmp 0xe7ff
leaq 0x4853(%rip), %rdi      # 0x13033
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x30f0
jmp 0xe806
cmpq $0x0, 0x10(%r14)
je 0xe7cc
movq 0x28(%rbx), %rsi
leaq 0x4841(%rip), %rdi      # 0x13040
xorl %eax, %eax
callq 0x30f0
incl %r13d
movl 0xaa4d(%rip), %eax      # 0x1925c
cmpl %eax, %r13d
jne 0xe763
jmp 0xe98c
testl %r13d, %r13d
je 0xe869
leaq 0x478c(%rip), %rdi      # 0x12fb5
movl %r13d, %esi
xorl %eax, %eax
callq 0x30f0
leal -0x20(%r13), %eax
cmpl $0x5f, %eax
leaq 0x478f(%rip), %rdi      # 0x12fd0
leaq 0x4783(%rip), %rax      # 0x12fcb
cmovbq %rax, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x30f0
leaq 0x477b(%rip), %rdi      # 0x12fd8
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x30f0
movl 0xa9ed(%rip), %eax      # 0x1925c
decl %r13d
leaq 0x18(%rsp), %rcx
leaq (%rcx,%r15,8), %rcx
movl $0x1, %edx
subl %eax, %edx
decl %eax
leal (%rdx,%r13), %esi
cmpl $-0x1, %esi
je 0xe8a2
movq (%rcx), %rsi
incl %r13d
leaq 0x8(%rcx), %rdi
cmpq -0x8(%rcx), %rsi
movq %rdi, %rcx
je 0xe884
jmp 0xe8a5
movl %eax, %r13d
movslq %r13d, %r15
cmpl %eax, %r13d
jne 0xe8cc
movq 0x10(%rsp,%r15,8), %rax
testq %rax, %rax
je 0xe91c
cmpq %r14, %rax
je 0xe939
movq 0x28(%rax), %rsi
leaq 0x472e(%rip), %rdi      # 0x12ff5
jmp 0xe963
leaq 0x46e2(%rip), %rdi      # 0x12fb5
movl %r15d, %esi
xorl %eax, %eax
callq 0x30f0
leal -0x20(%r15), %eax
cmpl $0x5f, %eax
leaq 0x46e5(%rip), %rdi      # 0x12fd0
leaq 0x46d9(%rip), %rax      # 0x12fcb
cmovbq %rax, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x30f0
movq 0x10(%rsp,%r15,8), %rax
testq %rax, %rax
je 0xe925
cmpq %r14, %rax
je 0xe951
movq 0x28(%rax), %rsi
leaq 0x4706(%rip), %rdi      # 0x13020
jmp 0xe963
leaq 0x4685(%rip), %rdi      # 0x12fa8
jmp 0xe92c
leaq 0x46d7(%rip), %rdi      # 0x13003
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x30f0
jmp 0xe96a
cmpq $0x0, 0x10(%r14)
je 0xe8bc
movq 0x28(%rax), %rsi
leaq 0x4696(%rip), %rdi      # 0x12fe5
jmp 0xe963
cmpq $0x0, 0x10(%r14)
je 0xe90f
movq 0x28(%rax), %rsi
leaq 0x46ad(%rip), %rdi      # 0x13010
xorl %eax, %eax
callq 0x30f0
movq 0x8(%rsp), %rsi
leal 0x1(%rsi), %ebx
leaq 0x46b5(%rip), %rdi      # 0x1302e
xorl %eax, %eax
callq 0x30f0
movl %ebx, %eax
movq %rax, 0x8(%rsp)
jmp 0xe806
testq %rbp, %rbp
je 0xe9af
cmpq %r14, %rbp
je 0xe9cd
movq 0x28(%rbp), %rsi
xorl %r15d, %r15d
leaq 0x4651(%rip), %rdi      # 0x12ff5
jmp 0xe9e2
cmpq $0x0, 0x18(%r14)
jne 0xe9b6
jmp 0xe9e9
cmpq $0x0, 0x18(%r14)
je 0xe9f8
xorl %r15d, %r15d
leaq 0x45e8(%rip), %rdi      # 0x12fa8
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x30f0
jmp 0xe9e9
cmpq $0x0, 0x10(%r14)
je 0xe996
movq 0x28(%rbp), %rsi
xorl %r15d, %r15d
leaq 0x4603(%rip), %rdi      # 0x12fe5
xorl %eax, %eax
callq 0x30f0
movq 0x18(%r14), %r14
testq %r14, %r14
jne 0xe649
jmp 0xe9fd
xorl %r15d, %r15d
jmp 0xe9e9
testw %r15w, %r15w
movq (%rsp), %rbx
je 0xea11
movl $0xa, %edi
callq 0x3040
leaq 0x4646(%rip), %rdi      # 0x1305e
movl %ebx, %esi
xorl %eax, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30f0