// File: /workspace/github_c_makefile_star2_O2/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 $0x798, %rsp            # imm = 0x798
movq %rsi, -0x80(%rsp)
testw %cx, %cx
je 0xd917
movabsq $0x4142ffff3c304822, %rax # imm = 0x4142FFFF3C304822
movq %rax, (%rdx)
addq $0x8, %rdx
movq -0x80(%rsp), %rax
addl $-0x2, %eax
movl %eax, -0x74(%rsp)
movl $0x8, %eax
testq %rdi, %rdi
je 0xde38
movl 0xa924(%rip), %r8d      # 0x1825c
xorl %r9d, %r9d
cmpq %r9, %r8
je 0xd94b
andq $0x0, -0x70(%rsp,%r9,8)
incq %r9
jmp 0xd93b
movq %rdi, %r9
movq (%r9), %r9
testq %r9, %r9
je 0xd968
movq 0x8(%r9), %r10
movslq (%r9), %r11
movq %r10, -0x70(%rsp,%r11,8)
addq $0x10, %r9
jmp 0xd94e
movq %r8, %r10
leaq -0x70(%rsp), %r11
xorl %ebx, %ebx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
cmpq %r8, %rbx
je 0xd9c5
movq -0x70(%rsp,%rbx,8), %r9
cmpq %r13, %r9
je 0xd9b9
xorl %ebp, %ebp
xorl %r12d, %r12d
cmpq %rbp, %r10
je 0xd9ae
cmpq %r9, (%r11,%rbp,8)
jne 0xd9a9
testq %rbp, %rbp
je 0xd9a6
cmpq -0x8(%r11,%rbp,8), %r9
je 0xd9a9
incl %r12d
incq %rbp
jmp 0xd98f
cmpl %r14d, %r12d
cmovgl %r12d, %r14d
cmovgq %r9, %r13
incq %rbx
addq $0x8, %r11
decq %r10
jmp 0xd97b
movslq %eax, %r8
movq %r8, 0x28(%rdi)
movq 0x10(%rdi), %r9
testq %r9, %r9
je 0xda42
movq (%r9), %r8
movl $0x4, %ebp
movabsq $0x100000000, %rbx      # imm = 0x100000000
movl $0x2, %r14d
testq %r9, %r9
je 0xda09
movl (%r8), %r11d
movq (%r9), %r10
cmpl (%r10), %r11d
jg 0xda00
movq %r8, %r10
movq 0x8(%r9), %r9
movq %r10, %r8
jmp 0xd9ed
testw %cx, %cx
je 0xda3d
movw $0x7c20, (%rdx)         # imm = 0x7C20
movb 0xb(%r8), %r9b
movb %r9b, 0x2(%rdx)
movb 0xa(%r8), %r9b
movb %r9b, 0x3(%rdx)
movb 0x9(%r8), %r9b
movb %r9b, 0x4(%rdx)
movb 0x8(%r8), %r8b
movb %r8b, 0x5(%rdx)
movw $0x130, 0x6(%rdx)       # imm = 0x130
addq $0x8, %rdx
addl $0x8, %eax
jmp 0xda57
movl $0x4, %ebp
movabsq $0x100000000, %rbx      # imm = 0x100000000
movl $0x2, %r14d
testw %cx, %cx
je 0xda66
movl $0x41521914, (%rdx)     # imm = 0x41521914
addq $0x4, %rdx
addl $0x4, %eax
xorl %r10d, %r10d
movl 0xa7e9(%rip), %r8d      # 0x1825c
cmpl %r8d, %r10d
je 0xddb6
movslq %r10d, %r15
movq -0x70(%rsp,%r15,8), %r9
cmpq %r13, %r9
je 0xdb84
leal -0x2(%r8), %r11d
cmpl %r11d, %r10d
jge 0xdaa8
cmpq -0x68(%rsp,%r15,8), %r9
jne 0xdaa8
cmpq -0x60(%rsp,%r15,8), %r9
je 0xdb8c
testl %r10d, %r10d
je 0xdac8
testw %cx, %cx
je 0xdac3
movw $0x20c, (%rdx)          # imm = 0x20C
movb $0x0, 0x2(%rdx)
movb %r10b, 0x3(%rdx)
addq $0x4, %rdx
movl %ebp, %r8d
jmp 0xdad9
testw %cx, %cx
je 0xdad6
movw $0x24a, (%rdx)          # imm = 0x24A
addq $0x2, %rdx
movl %r14d, %r8d
addl %r8d, %eax
testw %cx, %cx
je 0xdafa
movw $0x67, (%rdx)
leal 0x2(%rax), %r8d
movq -0x70(%rsp,%r15,8), %r9
testq %r9, %r9
je 0xdb32
addq $0x2, %rdx
jmp 0xdb08
movq -0x70(%rsp,%r15,8), %r9
testq %r9, %r9
je 0xdb81
leal 0x2(%rax), %r8d
cmpq %rdi, %r9
je 0xdb48
testw %cx, %cx
je 0xdb81
movl 0x28(%r9), %ebx
subl %r8d, %ebx
movb %bh, (%rdx)
movabsq $0x100000000, %rbx      # imm = 0x100000000
movq -0x70(%rsp,%r15,8), %rsi
movl 0x28(%rsi), %esi
subl %r8d, %esi
jmp 0xdb79
movq -0x80(%rsp), %rsi
subl %r8d, %esi
rolw $0x8, %si
movw %si, 0x2(%rdx)
addq $0x4, %rdx
jmp 0xdb81
cmpq $0x0, 0x10(%rdi)
je 0xdb0d
testw %cx, %cx
je 0xdb81
movl 0x28(%r9), %ebx
subl %r8d, %ebx
addl $0x6, %ebx
movb %bh, (%rdx)
movabsq $0x100000000, %rbx      # imm = 0x100000000
movq -0x70(%rsp,%r15,8), %rsi
movl 0x28(%rsi), %esi
subl %r8d, %esi
addb $0x6, %sil
movb %sil, 0x1(%rdx)
addq $0x2, %rdx
addl $0x4, %eax
incl %r10d
jmp 0xda6c
testl %r10d, %r10d
je 0xdbbc
testw %cx, %cx
je 0xdbb4
movw $0x20c, (%rdx)          # imm = 0x20C
movb $0x0, 0x2(%rdx)
movb %r10b, 0x3(%rdx)
movw $0x86d, 0x4(%rdx)       # imm = 0x86D
addq $0x6, %rdx
movl 0xa6a8(%rip), %r8d      # 0x1825c
addl $0x6, %eax
movl %eax, %r11d
jmp 0xdbc2
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
leaq -0x68(%rsp), %rsi
leaq (%rsi,%r15,8), %r14
shlq $0x20, %r15
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
addq %rsi, %r15
movl %r10d, %r9d
subl %r8d, %r9d
decl %r8d
xorl %ebp, %ebp
leal (%r9,%rbp), %r12d
cmpl $-0x1, %r12d
je 0xdc8a
movq (%r14,%rbp,8), %rsi
addq %rbx, %r15
leaq 0x1(%rbp), %r12
cmpq -0x8(%r14,%rbp,8), %rsi
movq %r12, %rbp
je 0xdbe7
leal -0x1(%r10), %r14d
addq %r12, %r14
addl %r12d, %r9d
je 0xdc8f
testw %cx, %cx
je 0xdc38
movw $0x20c, (%rdx)          # imm = 0x20C
movb $0x0, 0x2(%rdx)
addl %r12d, %r10d
decb %r10b
movb %r10b, 0x3(%rdx)
movw $0x6f, 0x4(%rdx)
addq $0x6, %rdx
leal 0x6(%rax), %r8d
movq %r15, %rsi
sarq $0x1d, %rsi
movq -0x70(%rsp,%rsi), %r9
testq %r9, %r9
je 0xdd28
sarq $0x20, %r15
cmpq %rdi, %r9
je 0xdd3e
testw %cx, %cx
je 0xdd72
movl 0x28(%r9), %ebx
subl %r8d, %ebx
movb %bh, (%rdx)
movabsq $0x100000000, %rbx      # imm = 0x100000000
movq -0x70(%rsp,%r15,8), %rsi
movl 0x28(%rsi), %esi
subl %r8d, %esi
jmp 0xdd6a
movl %r8d, %r10d
jmp 0xdc92
movl %r14d, %r10d
testw %cx, %cx
movl $0x4, %ebp
movl $0x2, %r14d
je 0xdcab
movw $0xfa4e, (%rdx)         # imm = 0xFA4E
addq $0x2, %rdx
leal 0x2(%rax), %r9d
movslq %r8d, %r8
movq -0x70(%rsp,%r8,8), %rbx
testq %rbx, %rbx
je 0xdcdb
cmpq %rdi, %rbx
je 0xdcf1
testw %cx, %cx
je 0xdd19
movl 0x28(%rbx), %ebx
subl %r9d, %ebx
movb %bh, (%rdx)
movq -0x70(%rsp,%r8,8), %rsi
movl 0x28(%rsi), %esi
subl %r9d, %esi
jmp 0xdd11
testw %cx, %cx
je 0xdd19
movq -0x80(%rsp), %rsi
subl %r9d, %esi
rolw $0x8, %si
movw %si, (%rdx)
jmp 0xdd15
cmpq $0x0, 0x10(%rdi)
je 0xdcc1
testw %cx, %cx
je 0xdd19
movl %ebp, %esi
subl %eax, %esi
movl 0x28(%rbx), %ebx
addl %esi, %ebx
movb %bh, (%rdx)
movq -0x70(%rsp,%r8,8), %r8
addl 0x28(%r8), %esi
movb %sil, 0x1(%rdx)
addq $0x2, %rdx
movl %ebp, %r8d
movabsq $0x100000000, %rbx      # imm = 0x100000000
jmp 0xdd86
testw %cx, %cx
je 0xdd72
movq -0x80(%rsp), %rsi
subl %r8d, %esi
rolw $0x8, %si
movw %si, (%rdx)
jmp 0xdd6e
cmpq $0x0, 0x10(%rdi)
je 0xdc5e
testw %cx, %cx
je 0xdd72
movl 0x28(%r9), %ebx
subl %eax, %ebx
movb %bh, (%rdx)
movabsq $0x100000000, %rbx      # imm = 0x100000000
movq -0x70(%rsp,%r15,8), %rsi
movl 0x28(%rsi), %esi
subl %eax, %esi
movb %sil, 0x1(%rdx)
addq $0x2, %rdx
movl $0x8, %r8d
movl %r14d, %r10d
movl $0x4, %ebp
movl $0x2, %r14d
addl %r8d, %eax
testw %cx, %cx
je 0xdb84
cmpl $-0x1, %r11d
je 0xdb84
movl %eax, %esi
subl %r11d, %esi
movl %eax, %r8d
notl %r8d
addl %r11d, %r8d
movslq %r8d, %r8
movb %sil, (%rdx,%r8)
jmp 0xdb84
testq %r13, %r13
je 0xdde3
cmpq %rdi, %r13
je 0xde02
testw %cx, %cx
je 0xde2c
movw $0xfa4e, (%rdx)         # imm = 0xFA4E
movl 0x28(%r13), %ebx
leal 0x2(%rax), %esi
subl %esi, %ebx
movb %bh, 0x2(%rdx)
movl 0x28(%r13), %r8d
subl %esi, %r8d
movb %r8b, 0x3(%rdx)
jmp 0xde28
cmpq $0x0, 0x18(%rdi)
je 0xde2f
testw %cx, %cx
je 0xde2c
movw $0xfa4e, (%rdx)         # imm = 0xFA4E
movl -0x74(%rsp), %ebx
subl %eax, %ebx
movb %bh, 0x2(%rdx)
movb %bl, 0x3(%rdx)
jmp 0xde28
cmpq $0x0, 0x10(%rdi)
je 0xddc0
testw %cx, %cx
je 0xde2c
movw $0xfa4e, (%rdx)         # imm = 0xFA4E
movl %ebp, %esi
subl %eax, %esi
movl 0x28(%r13), %ebx
addl %esi, %ebx
movb %bh, 0x2(%rdx)
addl 0x28(%r13), %esi
movb %sil, 0x3(%rdx)
addq $0x4, %rdx
addl $0x4, %eax
movq 0x18(%rdi), %rdi
jmp 0xd928
addq $0x798, %rsp            # imm = 0x798
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq