// File: /workspace/github_cpp_makefile_star2_O3/ridgelab[P]Kmer-SSR/src/FindSSRs.cpp
// Function: FindSSRs::processInput()
void FindSSRs::processInput() // produce
{
	ifstream fasta_file;
	fasta_file.open(this->args->getInFileName().c_str());

	// init (set the data_size of) the progress bar
	uint32_t init_size = this->args->getInFileName() == "/dev/stdin" ? 0 : calculateDataSizeFromFasta(fasta_file);
	this->progress_bar->initialize(init_size);

	string header = "";
	string sequence = "";
	string line = "";
	while (getline(fasta_file, line))
	{
		if (line.size())
		{
			if (line[0] != '>') // line is a sequence
			{
				this->progress_bar->updateProgress(1, false); // +1 for the '\n'

				for (uint32_t i = 0; i < line.size(); ++i) // -1 because we don't want to add the '\n' to the sequence
				{
					//sequence = sequence + (char) toupper(line[i]);
					sequence += (char) toupper(line[i]);
					//if (!isspace(line[i])) // TODO
					//{
					//	sequence += (char) toupper(line[i]);
					//}
					//else
					//{
					//	// update the progress bar based on the space
					//}
				}
			}
			else // line is a header
			{
				this->processSequence(header,sequence);

				header = line.substr(1, string::npos);
				sequence = "";
				
				this->progress_bar->updateProgress(header.size() + 2, false); // +1 for the '\n', +1 for the '>'
			}
		}
		else // empty line
		{
			this->progress_bar->updateProgress(1, false); // +1 for the '\n'
		}
		
	}
	
	this->processSequence(header,sequence); // catch the last sequence

	fasta_file.close(); // close the input file

	// put some NULL tasks in the TaskQueue, signalling the threads they can quit when they encounter one
	switch (this->args->getNumThreads())
	{
		case 1:
			break;
		default:
			for (uint32_t i = 1; i < this->args->getNumThreads(); ++i)
			{
				this->tasks->add(nullptr);
			}
			break;
	}

	// if there are plenty of tasks left (more than 2 tasks, excluding the dummy tasks, per thread)
	if (this->tasks->size() > (this->args->getNumThreads() * 3))
	{
		// the main thread becomes a consumer for a while
		SSRcontainer* ssrs = new SSRcontainer();
		Task* task = nullptr;

		// but only until each thread will have 2 tasks left (excluding the dummy task)
		while (this->tasks->size() > (this->args->getNumThreads() * 3))
		{
			// get a task
			task = this->tasks->get(); // get a task
		
			// fulfill the task, add the results to the SSRcontainer, attempt to write them to file
			ssrs->add(task->getID(), findSSRs(task, this->args, this->atomicity_checker));
			ssrs->writeToFile(this->out_file, false, true); // false means it won't block if it can't write, true means it will clear the SSRcontainer if it wrote
		
			// 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;
		}

		// if we didn't write everything, let's do it now
		if (!ssrs->empty())
		{
			ssrs->writeToFile(this->out_file, true, false); // true means it will block until it can write, false means it won't clear the SSRcontainer when finished (because we're about to delete the thing anyway right after this)
		}

		delete ssrs;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %rdi, %rbx
leaq 0x80(%rsp), %rdi
callq 0x3350
movq (%rbx), %rsi
movq %rsp, %rdi
callq 0xb82c
movq (%rsp), %rsi
leaq 0x80(%rsp), %r14
movq %r14, %rdi
movl $0x8, %edx
callq 0x31d0
leaq 0x10(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x76ee
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3300
movq (%rbx), %rsi
movq %rsp, %rdi
callq 0xb82c
leaq 0x6b2c(%rip), %rsi      # 0xe22c
movq %rsp, %rdi
callq 0x30f0
testl %eax, %eax
je 0x775c
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x33e0
leaq 0x80(%rsp), %rdi
callq 0x3530
movq %rax, %r15
leaq 0x80(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x33e0
movq 0x80(%rsp), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x34f0
jmp 0x775f
xorl %r15d, %r15d
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x7775
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x28(%rbx), %rdi
movl %r15d, %esi
callq 0xd5f6
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x6928(%rip), %rdx      # 0xe0b6
movq %rdx, %rsi
callq 0x54f4
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x6910(%rip), %rdx      # 0xe0b6
leaq 0x60(%rsp), %rdi
movq %rdx, %rsi
callq 0x54f4
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x68f3(%rip), %rdx      # 0xe0b6
leaq 0x20(%rsp), %rdi
movq %rdx, %rsi
callq 0x54f4
leaq 0x20(%rsp), %r15
leaq 0x60(%rsp), %r13
leaq 0x40(%rsp), %rbp
movq 0x80(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32d0
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x3580
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x7900
cmpq $0x0, 0x28(%rsp)
je 0x789c
movq 0x20(%rsp), %rax
cmpb $0x3e, (%rax)
jne 0x78b1
movq %rbx, %rdi
movq %rsp, %rsi
movq %r13, %rdx
callq 0x7f36
movl $0x1, %edx
movq %rbp, %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x3320
movq %rsp, %rdi
movq %rbp, %rsi
callq 0x33a0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x787a
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x68(%rsp), %rdx
movq %r13, %rdi
xorl %esi, %esi
leaq 0x682b(%rip), %rcx      # 0xe0b6
xorl %r8d, %r8d
callq 0x3470
movl 0x8(%rsp), %esi
addl $0x2, %esi
jmp 0x78a1
movl $0x1, %esi
movq 0x28(%rbx), %rdi
xorl %edx, %edx
callq 0xd664
jmp 0x77df
movq 0x28(%rbx), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0xd664
cmpq $0x0, 0x28(%rsp)
je 0x77df
movl $0x1, %r12d
xorl %eax, %eax
movq 0x20(%rsp), %rcx
movsbl (%rcx,%rax), %edi
callq 0x3590
movsbl %al, %esi
movq %r13, %rdi
callq 0x3290
movl %r12d, %eax
incl %r12d
cmpq %rax, 0x28(%rsp)
ja 0x78d5
jmp 0x77df
movq %rsp, %rsi
leaq 0x60(%rsp), %rdx
movq %rbx, %rdi
callq 0x7f36
leaq 0x80(%rsp), %rdi
callq 0x3090
movq (%rbx), %rdi
callq 0xb6e4
cmpl $0x1, %eax
jne 0x7a21
movq 0x38(%rbx), %rdi
callq 0x97ec
movl %eax, %ebp
movq (%rbx), %rdi
callq 0xb6e4
leal (%rax,%rax,2), %eax
cmpl %eax, %ebp
leaq 0x10(%rsp), %r14
jbe 0x7a7e
movl $0x8, %edi
callq 0x32f0
movq %rax, %r14
movq %rax, %rdi
callq 0x4380
leaq 0x40(%rsp), %r15
movq 0x38(%rbx), %rdi
callq 0x97ec
movl %eax, %ebp
movq (%rbx), %rdi
callq 0xb6e4
leal (%rax,%rax,2), %eax
cmpl %eax, %ebp
jbe 0x7a45
movq 0x38(%rbx), %rdi
callq 0x98a4
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
callq 0x938e
movq (%rbx), %rsi
movq 0x30(%rbx), %rdx
movq %r12, %rdi
callq 0x835a
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x45b8
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x79d9
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x20(%rbx), %rsi
movq %r14, %rdi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x4886
movq 0x28(%rbx), %r13
movq %r12, %rdi
callq 0x93d4
movq %r13, %rdi
movl %eax, %esi
movl $0x1, %edx
callq 0xd664
movq %r12, %rdi
callq 0x90fc
movl $0x48, %esi
movq %r12, %rdi
callq 0x3300
jmp 0x796b
movl $0x1, %ebp
movq (%rbx), %rdi
callq 0xb6e4
cmpl %eax, %ebp
jae 0x792e
movq 0x38(%rbx), %rdi
xorl %esi, %esi
callq 0x9834
incl %ebp
jmp 0x7a26
movq %r14, %rdi
callq 0x449a
testb %al, %al
jne 0x7a64
movq 0x20(%rbx), %rsi
movq %r14, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x4886
movq %r14, %rdi
callq 0x43b8
movl $0x8, %esi
movq %r14, %rdi
callq 0x3300
leaq 0x10(%rsp), %r14
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x7a9a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x7ab6
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3300
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x7acc
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3300
leaq 0x80(%rsp), %rdi
callq 0x30c0
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x8, %esi
movq %r14, %rdi
jmp 0x7b58
jmp 0x7b65
jmp 0x7b65
movq %rax, %rbx
leaq 0x10(%rsp), %r13
jmp 0x7b89
jmp 0x7b33
jmp 0x7b2b
jmp 0x7b2b
jmp 0x7b2b
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x7bae
jmp 0x7bbb
movq %rax, %rbx
jmp 0x7bbb
movq %rax, %rbx
jmp 0x7ba5
jmp 0x7b65
jmp 0x7b65
jmp 0x7b65
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x7b68
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3300
jmp 0x7b68
jmp 0x7b65
jmp 0x7b65
jmp 0x7b65
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
leaq 0x10(%rsp), %r13
je 0x7b89
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x7ba5
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3300
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x7bbb
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3300
leaq 0x80(%rsp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x3540