// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movl %r8d, 0x1c(%rsp)
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, 0x30(%rsp)
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rdi)
leaq 0xc(%rsp), %rax
andl $0x0, (%rax)
movq %rdi, 0x20(%rsp)
movups %xmm0, (%rdi)
xorl %ebp, %ebp
movq %rcx, 0x28(%rsp)
movq %rdx, 0x10(%rsp)
movb (%r15), %al
testb %al, %al
je 0x5432
movsbl (%r14), %edx
movsbl %al, %esi
movq 0x30(%rsp), %rdi
callq 0x545c
testb %al, %al
je 0x534b
incq %r14
incq %r15
jmp 0x53fc
movb (%r14), %al
leal -0x31(%rax), %ecx
cmpb $0x8, %cl
ja 0x53d4
addb $-0x30, %al
movzbl %al, %r12d
movq 0x30(%rsp), %rax
addl 0x70(%rax), %r12d
decq %r14
movb 0x1(%r14), %al
incq %r14
addb $-0x31, %al
cmpb $0x9, %al
jb 0x5368
leal 0x1(%r12), %eax
movslq %eax, %r13
movq %r13, %rdi
callq 0x3030
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x3140
movslq %r12d, %rax
movb $0x0, (%rbx,%rax)
movl 0x1c(%rsp), %ecx
subl %ebp, %ecx
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x51d6
movl %eax, %r13d
movq %rbx, %rdi
callq 0x32c0
testb %r13b, %r13b
je 0x53e4
movq 0x20(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x5512
jmp 0x53fc
cmpl %ebp, 0x1c(%rsp)
jle 0x53e4
incq %r14
incq %r15
incl %ebp
jmp 0x53fc
incl 0xc(%rsp)
movq 0x10(%rsp), %r15
incq %r15
xorl %ebp, %ebp
movq 0x28(%rsp), %r14
movq %r15, 0x10(%rsp)
cmpb $0x0, (%r14)
jne 0x5320
movq 0x20(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x5512
incl 0xc(%rsp)
movq 0x10(%rsp), %r15
incq %r15
xorl %ebp, %ebp
movq 0x28(%rsp), %r14
movq %r15, 0x10(%rsp)
jmp 0x5320
movq 0x20(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x20(%rsp), %rdi
callq 0x45ec
movq %rbx, %rdi
callq 0x3470
nop