// File: /workspace/github_c_makefile_star2_O3/theovosse[P]llgen/regexp.c
// Function: CompileDFA
int CompileDFA(RegExp dfa, int prevLen, unsigned char *code, Boolean generate) {
	RegExp state;
	Transition tr;
	int mCount = charSetSize, count;
	RegExp mState = NULL;
	ESet elt;
	int i, j;
	RegExp cSet[256];
	int nrBytes = 0;
	int tmpJump;

	/* MOVE.L A0,A1
	   MOVE.W #$FFFF,D0
	   CLR.W D1 */
	if (generate) {
		*code++ = 0x22;
		*code++ = 0x48;
		*code++ = 0x30;
		*code++ = 0x3C;
		*code++ = 0xFF;
		*code++ = 0xFF;
		*code++ = 0x42;
		*code++ = 0x41;
	}
	nrBytes += 8;
	for (state = dfa; state != NULL; state = state->next) {
		for (i = 0; i != charSetSize; i++) cSet[i] = NULL;
		for (tr = state->transitions; tr != NULL; tr = tr->next) {
			cSet[tr->transitionChar] = tr->destination;
		}
		mCount = -1; mState = NULL;
		for (i = 0; i != charSetSize; i++) {
			if (cSet[i] != mState) /* not the most efficient check, but ok */ {
				for (count = 0, j = i; j != charSetSize; j++)
					if (cSet[j] == cSet[i] && (j == i || cSet[j] != cSet[j - 1]))
						count++;
				if (count > mCount) {
					mCount = count;
					mState = cSet[i];
				}
			}
		}
		/* mCount is max. nr. of transitions to the same state, mState is that state */
		state->state.number = nrBytes;
		if (state->info != NULL) {
			Answer first;
			for (elt = state->info, first = elt->element; elt != NULL; elt = elt->next) {
				if (first->number > ((Answer) elt->element)->number) {
					first = elt->element;
				}
			}
			/* MOVEA.L #first->info,A0 */
			if (generate) {
				*code++ = 0x20;
				*code++ = 0x7C;
				*code++ = ((long int) first->info) >> 24;
				*code++ = (((long int) first->info) >> 16) & 0xFF;
				*code++ = (((long int) first->info) >> 8) & 0xFF;
				*code++ = ((long int) first->info) & 0xFF;
			}
			nrBytes += 6;
			/* MOVE.W D1,D0 */
			if (generate) {
				*code++ = 0x30;
				*code++ = 0x01;
			}
			nrBytes += 2;
		}
		/* MOVE.B (A1)+,D2
		   ADDQ.W #1,D1 */
		if (generate) {
			*code++ = 0x14;
			*code++ = 0x19;
			*code++ = 0x52;
			*code++ = 0x41;
		}
		nrBytes += 4;
		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) {
						tmpJump = -1;
					} else {
						/* CMP.B  #i,D2 */
						if (generate) {
							*code++ = 0x0C;
							*code++ = 0x02;
							*code++ = 0x00;
							*code++ = i & 0xFF;
						}
						nrBytes += 4;
						/* BLT    tempLabel */
						if (generate) {
							*code++ = 0x6D;
							*code++ = 0x08;
						}
						nrBytes += 2;
						tmpJump = nrBytes; /* wijzig code[tmpJump - nrBytes - 1] */
					}
					do {
						i++;
					}
					while (i != charSetSize && cSet[i] == cSet[i - 1]);
					i--;
					if (i == charSetSize - 1) {
						/* JMP */
						if (generate) {
							*code++ = 0x4E;
							*code++ = 0xFA;
						}
						nrBytes += 2;
						if (cSet[i] == NULL) {
							/* JMP    FAIL */
							if (generate) {
								*code++ = ((prevLen - nrBytes) >> 8) & 0xFF;
								*code++ = (prevLen - nrBytes) & 0xFF;
							}
							nrBytes += 2;
						} else if (cSet[i] == state && state->info != NULL) {
							/* JMP @cSet[i]->state.number + 6 */
							if (generate) {
								*code++ = ((cSet[i]->state.number + 6 - nrBytes) >> 8) & 0xFF;
								*code++ = (cSet[i]->state.number + 6 - nrBytes) & 0xFF;
							}
							nrBytes += 2;
						} else {
							/* JMP @cSet[i]->state.number */
							if (generate) {
								*code++ = ((cSet[i]->state.number - nrBytes) >> 8) & 0xFF;
								*code++ = (cSet[i]->state.number - nrBytes) & 0xFF;
							}
							nrBytes += 2;
						}
					} else {
						/* CMP.B  #$i,D2 */
						if (generate) {
							*code++ = 0x0C;
							*code++ = 0x02;
							*code++ = 0x00;
							*code++ = i & 0xFF;
						}
						nrBytes += 4;
						/* BLE */
						if (generate) {
							*code++ = 0x6F;
							*code++ = 0x00;
						}
						nrBytes += 2;
						if (cSet[i] == NULL) {
							/* BLE    FAIL */
							if (generate) {
								*code++ = ((prevLen - nrBytes) >> 8) & 0xFF;
								*code++ = (prevLen - nrBytes) & 0xFF;
							}
							nrBytes += 2;
						} else if (cSet[i] == state && state->info != NULL) {
							/* BLE    @cSet[i]->state.number + 6 */
							if (generate) {
								*code++ = ((cSet[i]->state.number + 6 - nrBytes) >> 8) & 0xFF;
								*code++ = (cSet[i]->state.number + 6 - nrBytes) & 0xFF;
							}
							nrBytes += 2;
						} else {
							/* BLE    @cSet[i]->state.number */
							if (generate) {
								*code++ = ((cSet[i]->state.number - nrBytes) >> 8) & 0xFF;
								*code++ = (cSet[i]->state.number - nrBytes) & 0xFF;
							}
							nrBytes += 2;
						}
					}
					/* tempLabel */
					if (generate && tmpJump != -1) {
						code[tmpJump - nrBytes - 1] = nrBytes - tmpJump;
					}
				} else {
					if (i == 0) {
						/* TST.B  D2 */
						if (generate) {
							*code++ = 0x4A;
							*code++ = 0x02;
						}
						nrBytes += 2;
					} else {
						/* CMP.B  #i,D2 */
						if (generate) {
							*code++ = 0x0C;
							*code++ = 0x02;
							*code++ = 0x00;
							*code++ = i & 0xFF;
						}
						nrBytes += 4;
					}
					/* BEQ */
					if (generate) {
						*code++ = 0x67;
						*code++ = 0x00;
					}
					nrBytes += 2;
					if (cSet[i] == NULL) {
						/* BEQ    FAIL */
						if (generate) {
							*code++ = ((prevLen - nrBytes) >> 8) & 0xFF;
							*code++ = (prevLen - nrBytes) & 0xFF;
						}
						nrBytes += 2;
					} else if (cSet[i] == state && state->info != NULL) {
						/* BEQ    @cSet[i]->state.number + 6 */
						if (generate) {
							*code++ = ((cSet[i]->state.number + 6 - nrBytes) >> 8) & 0xFF;
							*code++ = (cSet[i]->state.number + 6 - nrBytes) & 0xFF;
						}
						nrBytes += 2;
					} else {
						/* BEQ    @cSet[i]->state.number */
						if (generate) {
							*code++ = ((cSet[i]->state.number - nrBytes) >> 8) & 0xFF;
							*code++ = (cSet[i]->state.number - nrBytes) & 0xFF;
						}
						nrBytes += 2;
					}
				}
			}
			i++;
		}
		if (mState == NULL) {
			if (state->next != NULL) {
				/* JMP    FAIL */
				if (generate) {
					*code++ = 0x4E;
					*code++ = 0xFA;
					*code++ = ((prevLen - (nrBytes + 2)) >> 8) & 0xFF;
					*code++ = (prevLen - (nrBytes + 2)) & 0xFF;
				}
				nrBytes += 4;
			}
		} else {
			if (mState == state && state->info != NULL) {
				/* JMP    @mState->state.number + 6 */
				if (generate) {
					*code++ = 0x4E;
					*code++ = 0xFA;
					*code++ = ((mState->state.number + 6 - (nrBytes + 2)) >> 8) & 0xFF;
					*code++ = (mState->state.number + 6 - (nrBytes + 2)) & 0xFF;
				}
				nrBytes += 4;
			} else {
				/* JMP    @mState->state.number */
				if (generate) {
					*code++ = 0x4E;
					*code++ = 0xFA;
					*code++ = ((mState->state.number - (nrBytes + 2)) >> 8) & 0xFF;
					*code++ = (mState->state.number - (nrBytes + 2)) & 0xFF;
				}
				nrBytes += 4;
			}
		}
	}
	/* RTS
	 */
 /* if (generate) {
		RenumberDFA(dfa);
	} */
	return (nrBytes);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x818, %rsp            # imm = 0x818
movl %ecx, %r13d
movq %rdx, %rbp
movl %esi, %r11d
movq %rdi, %r15
testw %r13w, %r13w
je 0xe759
movabsq $0x4142ffff3c304822, %rax # imm = 0x4142FFFF3C304822
movq %rax, (%rbp)
addq $0x8, %rbp
testq %r15, %r15
je 0xeca6
leal -0x2(%r11), %eax
movl %eax, 0xc(%rsp)
movl $0x8, %r12d
movabsq $0x100000000, %rbx      # imm = 0x100000000
movq %r11, (%rsp)
movl 0xaad7(%rip), %r14d     # 0x1925c
testq %r14, %r14
je 0xe7a2
leaq (,%r14,8), %rdx
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x3120
movq (%rsp), %r11
movq (%r15), %rax
testq %rax, %rax
je 0xe7bc
movq 0x8(%rax), %rcx
movslq (%rax), %rdx
movq %rcx, 0x10(%rsp,%rdx,8)
movq 0x10(%rax), %rax
jmp 0xe7a5
testq %r14, %r14
je 0xe81b
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %r14, %rdx
leaq 0x10(%rsp), %rsi
xorl %edi, %edi
xorl %eax, %eax
movq 0x10(%rsp,%rdi,8), %r8
cmpq %rax, %r8
je 0xe80a
xorl %r10d, %r10d
xorl %r9d, %r9d
cmpq %r8, (%rsi,%r10,8)
jne 0xe7f7
testq %r10, %r10
je 0xe7f4
cmpq -0x8(%rsi,%r10,8), %r8
je 0xe7f7
incl %r9d
incq %r10
cmpq %r10, %rdx
jne 0xe7e2
cmpl %ecx, %r9d
cmovgl %r9d, %ecx
cmovgq %r8, %rax
incq %rdi
addq $0x8, %rsi
decq %rdx
cmpq %r14, %rdi
jne 0xe7d2
jmp 0xe81d
xorl %eax, %eax
movslq %r12d, %rcx
movq %rcx, 0x28(%r15)
movq 0x10(%r15), %rdx
testq %rdx, %rdx
je 0xe87e
movq (%rdx), %rcx
movl (%rcx), %esi
movq (%rdx), %rdi
movl (%rdi), %r8d
cmpl %r8d, %esi
cmovgel %r8d, %esi
movq 0x8(%rdx), %rdx
cmovgq %rdi, %rcx
testq %rdx, %rdx
jne 0xe832
testw %r13w, %r13w
je 0xe87a
movw $0x7c20, (%rbp)         # imm = 0x7C20
movb 0xb(%rcx), %dl
movb %dl, 0x2(%rbp)
movb 0xa(%rcx), %dl
movb %dl, 0x3(%rbp)
movb 0x9(%rcx), %dl
movb %dl, 0x4(%rbp)
movb 0x8(%rcx), %cl
movb %cl, 0x5(%rbp)
movw $0x130, 0x6(%rbp)       # imm = 0x130
addq $0x8, %rbp
addl $0x8, %r12d
testw %r13w, %r13w
je 0xe88f
movl $0x41521914, (%rbp)     # imm = 0x41521914
addq $0x4, %rbp
addl $0x4, %r12d
movl 0xa9c3(%rip), %edi      # 0x1925c
testl %edi, %edi
je 0xec1a
xorl %ecx, %ecx
movslq %ecx, %rsi
movq 0x10(%rsp,%rsi,8), %rdx
cmpq %rax, %rdx
je 0xe9b1
leal -0x2(%rdi), %r8d
cmpl %r8d, %ecx
jge 0xe8cf
cmpq 0x18(%rsp,%rsi,8), %rdx
jne 0xe8cf
cmpq 0x20(%rsp,%rsi,8), %rdx
je 0xe9c6
testl %ecx, %ecx
je 0xe8f1
movl $0x4, %edx
testw %r13w, %r13w
je 0xe906
movw $0x20c, (%rbp)          # imm = 0x20C
movb $0x0, 0x2(%rbp)
movb %cl, 0x3(%rbp)
addq $0x4, %rbp
jmp 0xe906
movl $0x2, %edx
testw %r13w, %r13w
je 0xe906
movw $0x24a, (%rbp)          # imm = 0x24A
addq $0x2, %rbp
addl %edx, %r12d
testw %r13w, %r13w
je 0xe92a
movw $0x67, (%rbp)
leal 0x2(%r12), %edx
movq 0x10(%rsp,%rsi,8), %rdi
testq %rdi, %rdi
je 0xe962
addq $0x2, %rbp
jmp 0xe939
movq 0x10(%rsp,%rsi,8), %rdi
testq %rdi, %rdi
je 0xe9ad
leal 0x2(%r12), %edx
cmpq %r15, %rdi
je 0xe975
testw %r13w, %r13w
je 0xe9ad
movl 0x28(%rdi), %ebx
subl %edx, %ebx
movb %bh, (%rbp)
movabsq $0x100000000, %rbx      # imm = 0x100000000
movq 0x10(%rsp,%rsi,8), %rsi
movl 0x28(%rsi), %esi
subl %edx, %esi
jmp 0xe9a5
movl %r11d, %esi
subl %edx, %esi
rolw $0x8, %si
movw %si, 0x2(%rbp)
addq $0x4, %rbp
jmp 0xe9ad
cmpq $0x0, 0x10(%r15)
je 0xe93e
testw %r13w, %r13w
je 0xe9ad
movl 0x28(%rdi), %ebx
subl %edx, %ebx
addl $0x6, %ebx
movb %bh, (%rbp)
movabsq $0x100000000, %rbx      # imm = 0x100000000
movq 0x10(%rsp,%rsi,8), %rsi
movl 0x28(%rsi), %esi
subl %edx, %esi
addb $0x6, %sil
movb %sil, 0x1(%rbp)
addq $0x2, %rbp
addl $0x4, %r12d
incl %ecx
movl 0xa8a3(%rip), %edi      # 0x1925c
cmpl %edi, %ecx
jne 0xe8a3
jmp 0xec1a
testl %ecx, %ecx
je 0xe9f8
testw %r13w, %r13w
je 0xe9ed
movw $0x20c, (%rbp)          # imm = 0x20C
movb $0x0, 0x2(%rbp)
movb %cl, 0x3(%rbp)
movw $0x86d, 0x4(%rbp)       # imm = 0x86D
addq $0x6, %rbp
movl 0xa86f(%rip), %edi      # 0x1925c
addl $0x6, %r12d
movl %r12d, 0x8(%rsp)
jmp 0xea00
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movq %rsi, %r8
shlq $0x20, %r8
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
addq %rdx, %r8
leaq 0x18(%rsp), %rdx
leaq (%rdx,%rsi,8), %r10
movl %ecx, %r9d
subl %edi, %r9d
decl %edi
xorl %r14d, %r14d
leal (%r9,%r14), %r11d
cmpl $-0x1, %r11d
je 0xea94
movq (%r10,%r14,8), %rdx
addq %rbx, %r8
leaq 0x1(%r14), %r11
cmpq -0x8(%r10,%r14,8), %rdx
movq %r11, %r14
je 0xea28
addq %r11, %rsi
decq %rsi
addl %r11d, %r9d
je 0xea98
testw %r13w, %r13w
je 0xeb54
movw $0x20c, (%rbp)          # imm = 0x20C
movb $0x0, 0x2(%rbp)
addl %r11d, %ecx
decb %cl
movb %cl, 0x3(%rbp)
movw $0x6f, 0x4(%rbp)
leal 0x6(%r12), %ecx
sarq $0x1d, %r8
movq 0x10(%rsp,%r8), %rdi
testq %rdi, %rdi
je 0xeb93
addq $0x6, %rbp
jmp 0xeb6b
movl %edi, %ecx
jmp 0xea9a
movl %esi, %ecx
movslq %edi, %rdi
testw %r13w, %r13w
movq (%rsp), %r11
je 0xeac2
movw $0xfa4e, (%rbp)         # imm = 0xFA4E
leal 0x2(%r12), %esi
movq 0x10(%rsp,%rdi,8), %r8
testq %r8, %r8
je 0xeb00
addq $0x2, %rbp
jmp 0xead1
movq 0x10(%rsp,%rdi,8), %r8
testq %r8, %r8
je 0xeb11
leal 0x2(%r12), %esi
leaq (%rsp,%rdi,8), %r9
addq $0x10, %r9
cmpq %r15, %r8
je 0xeb1b
movl $0x4, %edi
testw %r13w, %r13w
je 0xebdb
movl 0x28(%r8), %edx
subl %esi, %edx
movb %dh, (%rbp)
movq (%r9), %rdx
movl 0x28(%rdx), %edx
subl %esi, %edx
jmp 0xeb48
movl %r11d, %edx
subl %esi, %edx
rolw $0x8, %dx
movw %dx, 0x2(%rbp)
addq $0x4, %rbp
movl $0x4, %edi
jmp 0xebdb
cmpq $0x0, 0x10(%r15)
je 0xeade
movl $0x4, %edi
testw %r13w, %r13w
je 0xebdb
movl 0x28(%r8), %edx
subl %esi, %edx
addl $0x6, %edx
movb %dh, (%rbp)
movq (%r9), %rdx
movl 0x28(%rdx), %edx
subl %esi, %edx
addb $0x6, %dl
movb %dl, 0x1(%rbp)
addq $0x2, %rbp
jmp 0xebdb
sarq $0x1d, %r8
movq 0x10(%rsp,%r8), %rdi
testq %rdi, %rdi
je 0xec0d
leal 0x6(%r12), %ecx
addq %rsp, %r8
addq $0x10, %r8
movq (%rsp), %r11
cmpq %r15, %rdi
je 0xebaa
testw %r13w, %r13w
je 0xebd4
movl 0x28(%rdi), %edx
subl %ecx, %edx
movb %dh, (%rbp)
movq (%r8), %rdx
movl 0x28(%rdx), %edx
subl %ecx, %edx
jmp 0xebcd
movq (%rsp), %r11
movl %r11d, %edx
subl %ecx, %edx
rolw $0x8, %dx
movw %dx, 0x6(%rbp)
addq $0x8, %rbp
jmp 0xebd4
cmpq $0x0, 0x10(%r15)
je 0xeb7b
testw %r13w, %r13w
je 0xebd4
movl 0x28(%rdi), %edx
subl %ecx, %edx
addl $0x6, %edx
movb %dh, (%rbp)
movq (%r8), %rdx
movl 0x28(%rdx), %edx
subl %ecx, %edx
addb $0x6, %dl
movb %dl, 0x1(%rbp)
addq $0x2, %rbp
movl $0x8, %edi
movl %esi, %ecx
addl %edi, %r12d
testw %r13w, %r13w
je 0xe9b1
movl 0x8(%rsp), %edi
cmpl $-0x1, %edi
je 0xe9b1
movl %r12d, %edx
subl %edi, %edx
movl %r12d, %esi
notl %esi
addl %edi, %esi
movslq %esi, %rsi
movb %dl, (%rbp,%rsi)
jmp 0xe9b1
movl $0x8, %edi
movl %esi, %ecx
movq (%rsp), %r11
jmp 0xebdb
testq %rax, %rax
je 0xec44
cmpq %r15, %rax
je 0xec7b
testw %r13w, %r13w
je 0xec68
movw $0xfa4e, (%rbp)         # imm = 0xFA4E
movl 0x28(%rax), %ecx
leal 0x2(%r12), %edx
subl %edx, %ecx
movb %ch, 0x2(%rbp)
movl 0x28(%rax), %eax
subl %edx, %eax
jmp 0xec61
cmpq $0x0, 0x18(%r15)
je 0xec6c
testw %r13w, %r13w
je 0xec68
movw $0xfa4e, (%rbp)         # imm = 0xFA4E
movl 0xc(%rsp), %eax
subl %r12d, %eax
movb %ah, 0x2(%rbp)
movb %al, 0x3(%rbp)
addq $0x4, %rbp
addl $0x4, %r12d
movq 0x18(%r15), %r15
testq %r15, %r15
jne 0xe77e
jmp 0xecac
cmpq $0x0, 0x10(%r15)
je 0xec24
testw %r13w, %r13w
je 0xec68
movw $0xfa4e, (%rbp)         # imm = 0xFA4E
movl $0x4, %ecx
subl %r12d, %ecx
movl 0x28(%rax), %edx
addl %ecx, %edx
movb %dh, 0x2(%rbp)
addl 0x28(%rax), %ecx
movb %cl, 0x3(%rbp)
jmp 0xec64
movl $0x8, %r12d
movl %r12d, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq