// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, 0x58(%rsp)
movq %rdi, %rbx
movq 0x8(%rdx), %r14
testq %r14, %r14
je 0x7f8a
movq %rdx, %r15
movq (%rbx), %rdi
callq 0xb6bc
movl %eax, %eax
movq %r15, 0x30(%rsp)
movq 0x8(%r15), %r12
cmpq %rax, %r14
jb 0x7f8d
movq (%rbx), %rdi
callq 0xb6c0
movl %eax, %eax
cmpq %rax, %r12
jbe 0x7fac
movq 0x30(%rsp), %rax
movq 0x8(%rax), %r12
jmp 0x7f8d
xorl %r12d, %r12d
movq 0x28(%rbx), %rdi
movl %r12d, %esi
movl $0x1, %edx
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd664
xorl %ebp, %ebp
leaq 0x10(%rsp), %rsi
movl %ebp, (%rsi)
leaq 0x38(%rsp), %r15
leaq 0x60(%rsp), %r12
movl $0x1, %edx
movq %r15, %rdi
movq %r12, %rcx
callq 0x8a78
xorps %xmm0, %xmm0
movaps %xmm0, (%r12)
movq $0x0, 0x10(%r12)
leaq 0x54(%rsp), %r8
movl %ebp, (%r8)
leaq 0x60(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movq 0x30(%rsp), %rcx
callq 0x7dde
movq 0x28(%rbx), %rdi
movl 0x54(%rsp), %esi
xorl %edx, %edx
callq 0xd664
movq (%rbx), %rdi
callq 0xb6e4
cmpl $0x1, %eax
jne 0x8182
movl $0x8, %edi
callq 0x32f0
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x4380
movq 0x38(%rsp), %r14
cmpq %r14, 0x40(%rsp)
je 0x8163
movl $0x1, %r12d
xorl %r15d, %r15d
leaq 0x10(%rsp), %r13
movl $0x48, %edi
callq 0x32f0
movq %rax, %rbp
movl (%r14,%r15,4), %edx
movq 0x60(%rsp), %rax
movl (%rax,%r15,4), %ecx
movq %r13, %rdi
movq 0x30(%rsp), %r14
movq %r14, %rsi
callq 0x3320
movq 0x38(%rsp), %rax
movl (%rax,%r15,4), %ecx
movl 0x8(%r14), %r8d
movq %rbp, %rdi
movq 0x58(%rsp), %rsi
movq %r13, %rdx
callq 0x906c
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x80b5
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3300
movq %r13, %rdi
movq %rbp, %rsi
callq 0x938e
movq (%rbx), %rsi
movq 0x30(%rbx), %rdx
movq %rbp, %rdi
callq 0x835a
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x45b8
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x80fb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x20(%rbx), %rsi
movq 0x8(%rsp), %rdi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x4886
movq 0x28(%rbx), %r15
movq %rbp, %rdi
callq 0x93d4
movq %r15, %rdi
movl %eax, %esi
movl $0x1, %edx
callq 0xd664
movq %rbp, %rdi
callq 0x90fc
movl $0x48, %esi
movq %rbp, %rdi
callq 0x3300
movl %r12d, %r15d
movq 0x38(%rsp), %r14
movq 0x40(%rsp), %rax
subq %r14, %rax
sarq $0x2, %rax
incl %r12d
cmpq %r15, %rax
ja 0x8052
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x43b8
movl $0x8, %esi
movq %rbx, %rdi
callq 0x3300
jmp 0x8245
movq 0x38(%rsp), %r14
cmpq %r14, 0x40(%rsp)
je 0x8245
movl $0x1, %r15d
xorl %r12d, %r12d
movq %rbx, %r13
movq 0x38(%rbx), %rbp
movl $0x48, %edi
callq 0x32f0
movq %rax, 0x8(%rsp)
movl (%r14,%r12,4), %edx
movq 0x60(%rsp), %rax
movl (%rax,%r12,4), %ecx
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq 0x30(%rsp), %r14
movq %r14, %rsi
callq 0x3320
movq 0x38(%rsp), %rax
movl (%rax,%r12,4), %ecx
movl 0x8(%r14), %r8d
movb $0x1, %r14b
movq 0x8(%rsp), %r12
movq %r12, %rdi
movq 0x58(%rsp), %rsi
movq %rbx, %rdx
callq 0x906c
xorl %r14d, %r14d
movq %rbp, %rdi
movq %r12, %rsi
callq 0x9834
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
movq %r13, %rbx
je 0x8225
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3300
movl %r15d, %r12d
movq 0x38(%rsp), %r14
movq 0x40(%rsp), %rax
subq %r14, %rax
sarq $0x2, %rax
incl %r15d
cmpq %r12, %rax
ja 0x819b
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x825c
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x3300
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x8273
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x3300
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x8, %esi
jmp 0x8315
jmp 0x8321
jmp 0x8321
movq %rax, %rbx
jmp 0x82bd
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x82bd
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3300
movl $0x48, %esi
movq %rbp, %rdi
jmp 0x831a
jmp 0x8321
jmp 0x8321
movq %rax, %rbx
jmp 0x8310
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x8324
movq 0x20(%rsp), %rsi
incq %rsi
jmp 0x831a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x830b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3300
testb %r14b, %r14b
je 0x8324
movl $0x48, %esi
movq 0x8(%rsp), %rdi
callq 0x3300
jmp 0x8324
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x833b
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x3300
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x8352
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x3300
movq %rbx, %rdi
callq 0x3540