// File: /workspace/github_cpp_makefile_star2_O1/auton1[P]motiflocation/motif.cpp
// Function: motif::returnMotifLocations(char const*, char const*, int)
vector<int> motif::returnMotifLocations(const char* inputseq, const char* wild, int allowed_mutations)
{
	const char *cp = inputseq;
	const char *mp = wild;
	bool match;
	int max_gap_size;
	vector<int> positions;
	int pos = 0;
	int max_gap_size_plus_one;
	char *buffer;
	size_t sizeof_char = sizeof( char ); 
	char null_char = (char)NULL;
	int mutations = 0;

	while (*inputseq)
	{
		if (basematch(*inputseq, *wild))	// Compare degenerate bases
		{
			wild++;		// Move to next character
			inputseq++;
			//pos++;
		}
		else if ((*wild > '0') && (*wild <= '9'))	// This bit allows for gaps in the motif.
		{
			max_gap_size = (*wild - '0') + max_length;
			max_gap_size_plus_one = max_gap_size+1;
			while ((*wild) && (*wild > '0') && (*wild <= '9'))		// Remove all prefixed numbers
				wild++;
			buffer = new char[max_gap_size_plus_one];
			strncpy(buffer, inputseq, sizeof_char * max_gap_size_plus_one);
			buffer[max_gap_size] = null_char;
			match = IsMotifInSequence(buffer, wild, allowed_mutations - mutations);
			delete [] buffer;
			if (match)
				positions.push_back(pos);	// The call to the recursion returned true, so we should save the position.
			else
			{
				wild = mp;	// We do not have a match,
				cp++;		// so reset the wild string, and goto the next char on the inputsequence.
				inputseq = cp;
				pos++;
				mutations = 0;
			}
		}
		else if (mutations < allowed_mutations)
		{
			wild++;		// Move to next character
			inputseq++;
			mutations++;
		}
		else 
		{
			wild = mp;	// We do not have a match,
			cp++;		// so reset the wild string, and goto the next char on the inputsequence.
			inputseq = cp;
			pos++;
			mutations = 0;
		}
		if ((bool)!*wild)
		{
			positions.push_back(pos);
			wild = mp;	
			cp++;		
			inputseq = cp;
			pos++;
			mutations = 0;
		}
	}

	return positions;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, 0x14(%rsp)
movq %rcx, 0x18(%rsp)
movq %rsi, 0x20(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, 0x8(%rsp)
movq $0x0, 0x10(%rdi)
movl $0x0, (%rsp)
movb (%rdx), %al
testb %al, %al
je 0x5cb5
movq %rdx, %r13
movl $0x0, 0x4(%rsp)
movq 0x18(%rsp), %r14
movq %rdx, %r15
movsbl (%r14), %edx
movsbl %al, %esi
movq 0x20(%rsp), %rdi
callq 0x5cf2
testb %al, %al
je 0x5b90
incq %r14
incq %r13
jmp 0x5c5b
movb (%r14), %al
leal -0x31(%rax), %ecx
cmpb $0x8, %cl
ja 0x5c2d
addb $-0x30, %al
movzbl %al, %ebx
movq 0x20(%rsp), %rax
addl 0x70(%rax), %ebx
decq %r14
movb 0x1(%r14), %al
incq %r14
addb $-0x31, %al
cmpb $0x9, %al
jb 0x5baf
leal 0x1(%rbx), %eax
movslq %eax, %r12
movq %r12, %rdi
callq 0x3030
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x3120
movslq %ebx, %rax
movb $0x0, (%rbp,%rax)
movl 0x14(%rsp), %ecx
subl 0x4(%rsp), %ecx
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x59dc
movl %eax, %r12d
movq %rbp, %rdi
callq 0x32f0
testb %r12b, %r12b
je 0x5c45
movq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5cab
movl (%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5c5b
movl 0x4(%rsp), %eax
cmpl %eax, 0x14(%rsp)
jle 0x5c45
incq %r14
incq %r13
incl %eax
movl %eax, 0x4(%rsp)
jmp 0x5c5b
incl (%rsp)
incq %r15
movl $0x0, 0x4(%rsp)
movq 0x18(%rsp), %r14
movq %r15, %r13
cmpb $0x0, (%r14)
jne 0x5c9d
movq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5c7f
movl (%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5c87
movq %rsp, %rdx
callq 0x5e06
incl (%rsp)
incq %r15
movl $0x0, 0x4(%rsp)
movq 0x18(%rsp), %r14
movq %r15, %r13
movb (%r13), %al
testb %al, %al
jne 0x5b70
jmp 0x5cb5
movq %rsp, %rdx
callq 0x5e06
jmp 0x5c5b
movq 0x8(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x5cea
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x3270
movq %r14, %rdi
callq 0x34d0