// File: ridgelab[P]Kmer-SSR/src/FindSSRs.cpp
// Function: FindSSRs::processSequence(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void FindSSRs::processSequence(const string &header, const string &sequence)
{
	if ( (sequence.size() == 0) || (sequence.size() < this->args->getMinSequenceLength()) || (sequence.size() > this->args->getMaxSequenceLength()) )
	{
		this->progress_bar->updateProgress(sequence.size(), true);
		return;
	}
	
	vector<uint32_t> starts = {0};
	vector<uint32_t> sizes;
	uint32_t ignored_chars_count = 0;

	splitStringOnIgnoredChars(starts, sizes, sequence, ignored_chars_count);

	this->progress_bar->updateProgress(ignored_chars_count, false); // false means don't update the display

	switch (this->args->getNumThreads())
	{
		case 1:
		{
			SSRcontainer* ssrs = new SSRcontainer();
			Task* task = nullptr;

			for (uint32_t i = 0; i < starts.size(); ++i)
			{
				// create the task
				task = new Task(header, sequence.substr(starts[i], sizes[i]), starts[i], sequence.size());
				
				// fulfill the task, add the results to the SSRcontainer so we can write them to file
				ssrs->add(task->getID(), findSSRs(task, this->args, this->atomicity_checker));
				ssrs->writeToFile(this->out_file, true, true); // true means it will block if it can't write (it will always be able to write bcuz it has no competition), the second true means clear the SSRcontainer after writing
				
				// let the user know we've made some progress
				progress_bar->updateProgress(task->size(), true);
			
				// delete the ask now that we've completed it
				delete task;
			}

			delete ssrs;

			break;
		}
		default:
		{
			for (uint32_t i = 0; i < starts.size(); ++i)
			{
				// add a new task to the TaskQueue (so another thread can process it)
				this->tasks->add(new Task(header, sequence.substr(starts[i], sizes[i]), starts[i], sequence.size()));
			}
			
			break;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4260
cmpq $0x0, %rax
je 0x12155
movq -0x18(%rbp), %rdi
callq 0x4260
movq %rax, %rcx
movq -0x110(%rbp), %rax
movq %rcx, -0x118(%rbp)
movq (%rax), %rdi
callq 0x19c70
movl %eax, %ecx
movq -0x118(%rbp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
jb 0x12155
movq -0x18(%rbp), %rdi
callq 0x4260
movq %rax, %rcx
movq -0x110(%rbp), %rax
movq %rcx, -0x120(%rbp)
movq (%rax), %rdi
callq 0x19c90
movl %eax, %ecx
movq -0x120(%rbp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x12188
movq -0x110(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x128(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4260
movq -0x128(%rbp), %rdi
movl %eax, %esi
movl $0x1, %edx
callq 0x207e0
jmp 0x12722
movl $0x0, -0x44(%rbp)
leaq -0x44(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x1, -0x38(%rbp)
leaq -0x45(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0xb3a0
movq -0x130(%rbp), %rcx
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x13550
jmp 0x121c9
leaq -0x45(%rbp), %rdi
callq 0xb540
leaq -0x70(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x135d0
movq -0x110(%rbp), %rdi
movq -0x138(%rbp), %rdx
movl $0x0, -0x74(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x30(%rbp), %rsi
leaq -0x74(%rbp), %r8
callq 0x11e30
jmp 0x1220a
movq -0x110(%rbp), %rax
movq 0x28(%rax), %rdi
movl -0x74(%rbp), %esi
xorl %edx, %edx
callq 0x207e0
jmp 0x12221
movq -0x110(%rbp), %rax
movq (%rax), %rdi
callq 0x19d30
movl %eax, -0x13c(%rbp)
jmp 0x12238
movl -0x13c(%rbp), %eax
subl $0x1, %eax
je 0x12273
jmp 0x12587
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x45(%rbp), %rdi
callq 0xb540
jmp 0x1273d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1272b
movl $0x8, %edi
callq 0x43a0
movq %rax, -0x148(%rbp)
jmp 0x12286
movq -0x148(%rbp), %rdi
callq 0x5ac0
jmp 0x12294
movq -0x148(%rbp), %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movq %rax, -0x150(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x134d0
movq %rax, %rcx
movq -0x150(%rbp), %rax
cmpq %rcx, %rax
jae 0x12554
movl $0x48, %edi
callq 0x43a0
movq %rax, -0x158(%rbp)
jmp 0x122f0
movb $0x1, -0xb1(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x168(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x134b0
movl (%rax), %eax
movq %rax, -0x160(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, %esi
leaq -0x70(%rbp), %rdi
callq 0x134b0
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rdx
movl (%rax), %eax
movl %eax, %ecx
leaq -0xb0(%rbp), %rdi
callq 0x43c0
jmp 0x12358
movl -0x8c(%rbp), %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x134b0
movl (%rax), %eax
movl %eax, -0x174(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4260
movq -0x158(%rbp), %rdi
movq -0x170(%rbp), %rsi
movl -0x174(%rbp), %ecx
movl %eax, %r8d
leaq -0xb0(%rbp), %rdx
callq 0x16070
jmp 0x1239f
movq -0x158(%rbp), %rax
movb $0x0, -0xb1(%rbp)
movq %rax, -0x88(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4788
movq -0x80(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x88(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x16370
jmp 0x123e0
movq -0x110(%rbp), %rax
movq -0x88(%rbp), %rdi
movq (%rax), %rsi
movq 0x30(%rax), %rdx
callq 0x12750
movq %rax, -0x188(%rbp)
jmp 0x12403
movq -0x188(%rbp), %rdx
movq -0x180(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x5e60
jmp 0x1241f
leaq -0xd8(%rbp), %rdi
callq 0x4788
movq -0x110(%rbp), %rax
movq -0x80(%rbp), %rdi
movq 0x20(%rax), %rsi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x61c0
jmp 0x12448
movq -0x110(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x198(%rbp)
movq -0x88(%rbp), %rdi
callq 0x163d0
movl %eax, -0x18c(%rbp)
jmp 0x1246e
movl -0x18c(%rbp), %esi
movq -0x198(%rbp), %rdi
movl $0x1, %edx
callq 0x207e0
jmp 0x12487
movq -0x88(%rbp), %rax
movq %rax, -0x1a0(%rbp)
cmpq $0x0, %rax
je 0x124b8
movq -0x1a0(%rbp), %rdi
callq 0x16110
movq -0x1a0(%rbp), %rdi
movl $0x48, %esi
callq 0x43b0
jmp 0x124ba
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x122b4
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x8, %esi
callq 0x43b0
jmp 0x1272b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x12516
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4788
testb $0x1, -0xb1(%rbp)
jne 0x12521
jmp 0x12532
movq -0x158(%rbp), %rdi
movl $0x48, %esi
callq 0x43b0
jmp 0x1272b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x4788
jmp 0x1272b
movq -0x80(%rbp), %rax
movq %rax, -0x1a8(%rbp)
cmpq $0x0, %rax
je 0x12582
movq -0x1a8(%rbp), %rdi
callq 0x5b10
movq -0x1a8(%rbp), %rdi
movl $0x8, %esi
callq 0x43b0
jmp 0x12710
movl $0x0, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
movq %rax, -0x1b0(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x134d0
movq %rax, %rcx
movq -0x1b0(%rbp), %rax
cmpq %rcx, %rax
jae 0x1270e
movq -0x110(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x1c0(%rbp)
movl $0x48, %edi
callq 0x43a0
movq %rax, -0x1b8(%rbp)
jmp 0x125df
movb $0x1, -0x101(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movl -0xdc(%rbp), %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x134b0
movl (%rax), %eax
movq %rax, -0x1c8(%rbp)
movl -0xdc(%rbp), %eax
movl %eax, %esi
leaq -0x70(%rbp), %rdi
callq 0x134b0
movq -0x1d0(%rbp), %rsi
movq -0x1c8(%rbp), %rdx
movl (%rax), %eax
movl %eax, %ecx
leaq -0x100(%rbp), %rdi
callq 0x43c0
jmp 0x12647
movl -0xdc(%rbp), %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x134b0
movl (%rax), %eax
movl %eax, -0x1dc(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4260
movq -0x1b8(%rbp), %rdi
movq -0x1d8(%rbp), %rsi
movl -0x1dc(%rbp), %ecx
movl %eax, %r8d
leaq -0x100(%rbp), %rdx
callq 0x16070
jmp 0x1268e
movq -0x1b8(%rbp), %rsi
movq -0x1c0(%rbp), %rdi
movb $0x0, -0x101(%rbp)
callq 0x16a90
jmp 0x126aa
leaq -0x100(%rbp), %rdi
callq 0x4788
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x12591
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x126f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x4788
testb $0x1, -0x101(%rbp)
jne 0x126fb
jmp 0x1270c
movq -0x1b8(%rbp), %rdi
movl $0x48, %esi
callq 0x43b0
jmp 0x1272b
jmp 0x12710
leaq -0x70(%rbp), %rdi
callq 0x135f0
leaq -0x30(%rbp), %rdi
callq 0x135f0
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
leaq -0x70(%rbp), %rdi
callq 0x135f0
leaq -0x30(%rbp), %rdi
callq 0x135f0
movq -0x50(%rbp), %rdi
callq 0x46e0
nopw %cs:(%rax,%rax)