// File: ridgelab[P]Kmer-SSR/src/FindSSRs.cpp
// Function: seekSinglePeriodSizeSSRatIndex(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned int, unsigned int, unsigned int)
static
SSR* seekSinglePeriodSizeSSRatIndex(const string &sequence, uint32_t index, uint32_t global_pos, uint32_t period)
{
	//assert((period * 2) <= sequence.size());
	
	string base = sequence.substr(index, period);
	string next = base;
	uint32_t repeats = 0;
	uint32_t pos = index;

	while ( (base == next) && (pos < (sequence.size() - period + 1)) )
	{
		++repeats;
		pos += period;
		next = sequence.substr(pos,  period);
	}

	//// check up to one period before
	//for (uint32_t i = index; (i >= 0) && (i > (index - period)); --i)
	//{
	//	if (sequence[i] == sequence[i + period])
	//	{

	//	}

	//	if (i == 0)
	//	{
	//		break;
	//	}
	//}
	//// check up to one period after

	return new SSR(base, repeats, index + global_pos);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %eax
movl %eax, %edx
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq -0x38(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x43c0
movq -0xc0(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x4170
jmp 0x12e28
movl $0x0, -0x68(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x6c(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x7b90
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xc1(%rbp)
jne 0x12e53
jmp 0x12e86
movl -0x6c(%rbp), %eax
movq %rax, -0xd0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4260
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movl -0x14(%rbp), %edx
subq %rdx, %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
setb %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x12e92
jmp 0x12f04
movl -0x68(%rbp), %eax
incl %eax
movl %eax, -0x68(%rbp)
movl -0x14(%rbp), %ecx
movl -0x6c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x6c(%rbp)
movq -0x8(%rbp), %rsi
movl -0x6c(%rbp), %eax
movl %eax, %edx
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq -0x90(%rbp), %rdi
callq 0x43c0
jmp 0x12ec1
leaq -0x58(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x44b0
leaq -0x90(%rbp), %rdi
callq 0x4788
jmp 0x12e35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x12fd2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x12fc9
movl $0x28, %edi
callq 0x43a0
movq %rax, -0xd8(%rbp)
jmp 0x12f17
movb $0x1, -0xb1(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4170
jmp 0x12f30
movq -0xd8(%rbp), %rdi
movl -0x68(%rbp), %edx
movl -0xc(%rbp), %ecx
movl -0x10(%rbp), %eax
addl %eax, %ecx
leaq -0xb0(%rbp), %rsi
callq 0x56f0
jmp 0x12f50
movb $0x0, -0xb1(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4788
leaq -0x58(%rbp), %rdi
callq 0x4788
leaq -0x38(%rbp), %rdi
callq 0x4788
movq -0xd8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x12fab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4788
testb $0x1, -0xb1(%rbp)
jne 0x12fb6
jmp 0x12fc7
movq -0xd8(%rbp), %rdi
movl $0x28, %esi
callq 0x43b0
jmp 0x12fc9
leaq -0x58(%rbp), %rdi
callq 0x4788
leaq -0x38(%rbp), %rdi
callq 0x4788
movq -0x60(%rbp), %rdi
callq 0x46e0
nopw %cs:(%rax,%rax)