// File: /workspace/github_c_makefile_star2_O2/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, %rcx
movl 0xadea(%rip), %r13d     # 0x1825c
xorl %r14d, %r14d
movq %rdi, %rax
testq %rax, %rax
je 0xd486
movq 0x18(%rax), %rax
incl %r14d
jmp 0xd478
leaq 0x4d7d(%rip), %rdi      # 0x1220a
movq %rcx, %rbx
callq 0x3090
leaq 0x4da0(%rip), %rdi      # 0x1223c
callq 0x3090
movq %rbx, %r8
leal 0x1(%r14), %eax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
movq %r14, 0x10(%rsp)
testq %r8, %r8
je 0xd8bc
movl 0xad97(%rip), %eax      # 0x1825c
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0xd4d7
andq $0x0, 0x20(%rsp,%rcx,8)
incq %rcx
jmp 0xd4c7
movq %r8, %rax
movq (%rax), %rax
testq %rax, %rax
je 0xd4f7
movq 0x8(%rax), %rcx
movslq (%rax), %rdx
movq %rcx, 0x20(%rsp,%rdx,8)
decl %r13d
addq $0x10, %rax
jmp 0xd4da
movq %r8, %rax
movq (%rax), %rax
testq %rax, %rax
je 0xd538
movq 0x8(%rax), %rcx
cmpq %rbx, %rcx
je 0xd532
xorl %edx, %edx
movq %rax, %rsi
testq %rsi, %rsi
je 0xd527
xorl %edi, %edi
cmpq %rcx, 0x8(%rsi)
movq 0x10(%rsi), %rsi
sete %dil
addl %edi, %edx
jmp 0xd510
cmpl %r13d, %edx
cmovgl %edx, %r13d
cmovgq %rcx, %rbx
addq $0x10, %rax
jmp 0xd4fa
testw %bp, %bp
movq %r8, 0x8(%rsp)
je 0xd54f
pushq $0xa
popq %rdi
callq 0x3040
movq 0x8(%rsp), %r8
movq 0x28(%r8), %rsi
leaq 0x4a16(%rip), %rdi      # 0x11f70
xorl %eax, %eax
callq 0x30f0
movq 0x8(%rsp), %r8
cmpq $0x0, 0x10(%r8)
je 0xd5ba
leaq 0x4cf3(%rip), %rdi      # 0x12267
callq 0x3090
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
testq %rax, %rax
je 0xd59f
movl (%rcx), %esi
movq (%rax), %rdx
cmpl (%rdx), %esi
jg 0xd596
movq %rcx, %rdx
movq 0x8(%rax), %rax
movq %rdx, %rcx
jmp 0xd585
movq 0x8(%rcx), %rsi
xorl %ebp, %ebp
leaq 0x49ca(%rip), %rdi      # 0x11f76
xorl %eax, %eax
callq 0x30f0
movq 0x8(%rsp), %r8
jmp 0xd5be
movw $0xffff, %bp            # imm = 0xFFFF
cmpq $0x0, (%r8)
je 0xd86a
leaq 0x4ca6(%rip), %rdi      # 0x12275
callq 0x3090
leaq 0x4ca8(%rip), %rdi      # 0x12283
callq 0x3090
xorl %ebp, %ebp
movl 0xac74(%rip), %eax      # 0x1825c
cmpl %eax, %ebp
je 0xd84c
movslq %ebp, %r12
movq 0x20(%rsp,%r12,8), %r15
cmpq %rbx, %r15
je 0xd693
leal -0x2(%rax), %ecx
cmpl %ecx, %ebp
jge 0xd61a
cmpq 0x28(%rsp,%r12,8), %r15
jne 0xd61a
cmpq 0x30(%rsp,%r12,8), %r15
je 0xd69a
leaq 0x4974(%rip), %rdi      # 0x11f95
movl %ebp, %esi
xorl %eax, %eax
callq 0x30f0
leal -0x20(%rbp), %eax
cmpl $0x5f, %eax
leaq 0x4979(%rip), %rdi      # 0x11fb0
leaq 0x496d(%rip), %rax      # 0x11fab
cmovbq %rax, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x30f0
testq %r15, %r15
je 0xd667
movq 0x8(%rsp), %rax
cmpq %rax, %r15
je 0xd67a
movq 0x28(%r15), %rsi
leaq 0x49cb(%rip), %rdi      # 0x12030
jmp 0xd68c
leaq 0x49a5(%rip), %rdi      # 0x12013
movl %r14d, %esi
xorl %eax, %eax
callq 0x30f0
jmp 0xd693
cmpq $0x0, 0x10(%rax)
je 0xd65a
movq 0x28(%r15), %rsi
leaq 0x4994(%rip), %rdi      # 0x12020
xorl %eax, %eax
callq 0x30f0
incl %ebp
jmp 0xd5e2
testl %ebp, %ebp
je 0xd6e8
leaq 0x48f0(%rip), %rdi      # 0x11f95
movl %ebp, %esi
xorl %eax, %eax
callq 0x30f0
leal -0x20(%rbp), %eax
cmpl $0x5f, %eax
leaq 0x48f5(%rip), %rdi      # 0x11fb0
leaq 0x48e9(%rip), %rax      # 0x11fab
cmovbq %rax, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x30f0
leaq 0x48e2(%rip), %rdi      # 0x11fb8
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x30f0
movl 0xab74(%rip), %eax      # 0x1825c
leaq 0x28(%rsp), %rcx
leaq (%rcx,%r12,8), %rdx
shlq $0x20, %r12
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %r12
movl %ebp, %ecx
subl %eax, %ecx
decl %eax
xorl %esi, %esi
movq 0x8(%rsp), %r8
leal (%rcx,%rsi), %edi
cmpl $-0x1, %edi
je 0xd79d
movabsq $0x100000000, %rdi      # imm = 0x100000000
addq %rdi, %r12
leaq 0x1(%rsi), %r14
cmpq %r15, (%rdx,%rsi,8)
movq %r14, %rsi
je 0xd70f
leal -0x1(%rbp), %r15d
addq %r14, %r15
addl %r14d, %ecx
je 0xd7a1
leaq 0x484d(%rip), %rdi      # 0x11f95
movl %r15d, %esi
xorl %eax, %eax
callq 0x30f0
leal (%r14,%rbp), %eax
addl $-0x21, %eax
cmpl $0x5f, %eax
leaq 0x484d(%rip), %rdi      # 0x11fb0
leaq 0x4841(%rip), %rax      # 0x11fab
cmovbq %rax, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x30f0
sarq $0x1d, %r12
movq 0x20(%rsp,%r12), %rax
testq %rax, %rax
je 0xd7f2
movq 0x8(%rsp), %rcx
cmpq %rcx, %rax
je 0xd807
movq 0x28(%rax), %rsi
leaq 0x4865(%rip), %rdi      # 0x12000
jmp 0xd819
movl %eax, %ebp
jmp 0xd7a4
movl %r15d, %ebp
cltq
movq 0x20(%rsp,%rax,8), %rax
testq %rax, %rax
movq 0x10(%rsp), %rsi
je 0xd7c7
cmpq %r8, %rax
je 0xd7d7
movq 0x28(%rax), %rsi
leaq 0x4810(%rip), %rdi      # 0x11fd5
jmp 0xd7e9
leaq 0x47ba(%rip), %rdi      # 0x11f88
xorl %eax, %eax
callq 0x30f0
jmp 0xd823
cmpq $0x0, 0x10(%r8)
je 0xd7ba
movq 0x28(%rax), %rsi
leaq 0x47dc(%rip), %rdi      # 0x11fc5
xorl %eax, %eax
callq 0x30f0
jmp 0xd823
leaq 0x47ea(%rip), %rdi      # 0x11fe3
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x30f0
jmp 0xd820
cmpq $0x0, 0x10(%rcx)
je 0xd790
movq 0x28(%rax), %rsi
leaq 0x47d7(%rip), %rdi      # 0x11ff0
xorl %eax, %eax
callq 0x30f0
movl %r15d, %ebp
movq 0x18(%rsp), %rsi
leal 0x1(%rsi), %r14d
leaq 0x47db(%rip), %rdi      # 0x1200e
xorl %eax, %eax
callq 0x30f0
movl %r14d, %eax
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %r14
jmp 0xd693
testq %rbx, %rbx
movq 0x8(%rsp), %r8
je 0xd873
cmpq %r8, %rbx
je 0xd88f
movq 0x28(%rbx), %rsi
xorl %ebp, %ebp
leaq 0x476d(%rip), %rdi      # 0x11fd5
jmp 0xd8a3
cmpq $0x0, 0x18(%r8)
jne 0xd87a
jmp 0xd8af
cmpq $0x0, 0x18(%r8)
je 0xd8b8
xorl %ebp, %ebp
leaq 0x4705(%rip), %rdi      # 0x11f88
movl %r14d, %esi
xorl %eax, %eax
callq 0x30f0
jmp 0xd8aa
cmpq $0x0, 0x10(%r8)
je 0xd85b
movq 0x28(%rbx), %rsi
xorl %ebp, %ebp
leaq 0x4722(%rip), %rdi      # 0x11fc5
xorl %eax, %eax
callq 0x30f0
movq 0x8(%rsp), %r8
movq 0x18(%r8), %r8
jmp 0xd4b6
xorl %ebp, %ebp
jmp 0xd8af
testw %bp, %bp
je 0xd8c9
pushq $0xa
popq %rdi
callq 0x3040
leaq 0x476e(%rip), %rdi      # 0x1203e
movl %r14d, %esi
xorl %eax, %eax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30f0