// File: 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:
subq $0xb8, %rsp
movq %rdi, 0x28(%rsp)
movq %rdi, %rax
movq %rax, 0x30(%rsp)
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movq %rcx, 0x98(%rsp)
movl %r8d, 0x94(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x80(%rsp)
movb $0x0, 0x77(%rsp)
callq 0x6490
movl $0x0, 0x70(%rsp)
movq $0x1, 0x58(%rsp)
movb $0x0, 0x57(%rsp)
movl $0x0, 0x50(%rsp)
movq 0xa0(%rsp), %rax
cmpb $0x0, (%rax)
je 0xb647
movq 0x38(%rsp), %rdi
movq 0xa0(%rsp), %rax
movsbl (%rax), %esi
movq 0x98(%rsp), %rax
movsbl (%rax), %edx
callq 0xb680
movb %al, 0x27(%rsp)
jmp 0xb348
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0xb352
jmp 0xb39c
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
movq 0xa0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
jmp 0xb5d4
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
callq 0x64e0
jmp 0xb66a
movq 0x98(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jle 0xb547
movq 0x98(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jg 0xb547
movq 0x38(%rsp), %rcx
movq 0x98(%rsp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
addl 0x70(%rcx), %eax
movl %eax, 0x78(%rsp)
movl 0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
movq 0x98(%rsp), %rcx
xorl %eax, %eax
cmpb $0x0, (%rcx)
movb %al, 0x26(%rsp)
je 0xb427
movq 0x98(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x30, %ecx
movb %al, 0x26(%rsp)
jle 0xb427
movq 0x98(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
setle %al
movb %al, 0x26(%rsp)
movb 0x26(%rsp), %al
testb $0x1, %al
jne 0xb431
jmp 0xb447
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
jmp 0xb3e9
movslq 0x6c(%rsp), %rdi
callq 0x4030
movq %rax, 0x18(%rsp)
jmp 0xb458
movq 0x18(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movq 0x58(%rsp), %rdx
movslq 0x6c(%rsp), %rax
imulq %rax, %rdx
callq 0x41a0
movq 0x38(%rsp), %rdi
movb 0x57(%rsp), %dl
movq 0x60(%rsp), %rax
movslq 0x78(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x60(%rsp), %rsi
movq 0x98(%rsp), %rdx
movl 0x94(%rsp), %ecx
movl 0x50(%rsp), %eax
subl %eax, %ecx
callq 0xaff0
movb %al, 0x17(%rsp)
jmp 0xb4bd
movb 0x17(%rsp), %al
andb $0x1, %al
movb %al, 0x7f(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0xb4e1
movq 0x8(%rsp), %rdi
callq 0x43f0
testb $0x1, 0x7f(%rsp)
je 0xb4fb
movq 0x28(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xb8c0
jmp 0xb4f9
jmp 0xb542
movq 0x80(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x88(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
movl $0x0, 0x50(%rsp)
jmp 0xb5d2
movl 0x50(%rsp), %eax
cmpl 0x94(%rsp), %eax
jge 0xb589
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
movq 0xa0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0xb5d0
movq 0x80(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x88(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
movl $0x0, 0x50(%rsp)
jmp 0xb5d2
jmp 0xb5d4
movq 0x98(%rsp), %rax
cmpb $0x0, (%rax)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xb5ea
jmp 0xb642
movq 0x28(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xb8c0
jmp 0xb5fb
movq 0x80(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x88(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
movl $0x0, 0x50(%rsp)
jmp 0xb311
movb $0x1, 0x77(%rsp)
testb $0x1, 0x77(%rsp)
jne 0xb65d
movq 0x28(%rsp), %rdi
callq 0x64e0
movq 0x30(%rsp), %rax
addq $0xb8, %rsp
retq
movq 0x48(%rsp), %rdi
callq 0x4600
nopw %cs:(%rax,%rax)
nop