// File: /workspace/github_cpp_makefile_star2_O1/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 0xb934
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 0x77da
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3300
movq (%rbx), %rsi
movq %rsp, %rdi
callq 0xb934
leaq 0x6a40(%rip), %rsi      # 0xe22c
movq %rsp, %rdi
callq 0x30f0
testl %eax, %eax
je 0x7848
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 0x784b
xorl %r15d, %r15d
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x7861
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x28(%rbx), %rdi
movl %r15d, %esi
callq 0xd702
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x683c(%rip), %rdx      # 0xe0b6
movq %rdx, %rsi
callq 0x552e
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x6824(%rip), %rdx      # 0xe0b6
leaq 0x60(%rsp), %rdi
movq %rdx, %rsi
callq 0x552e
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x6807(%rip), %rdx      # 0xe0b6
leaq 0x20(%rsp), %rdi
movq %rdx, %rsi
callq 0x552e
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 0x79ec
cmpq $0x0, 0x28(%rsp)
je 0x7988
movq 0x20(%rsp), %rax
cmpb $0x3e, (%rax)
jne 0x799d
movq %rbx, %rdi
movq %rsp, %rsi
movq %r13, %rdx
callq 0x801e
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 0x7966
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x68(%rsp), %rdx
movq %r13, %rdi
xorl %esi, %esi
leaq 0x673f(%rip), %rcx      # 0xe0b6
xorl %r8d, %r8d
callq 0x3470
movl 0x8(%rsp), %esi
addl $0x2, %esi
jmp 0x798d
movl $0x1, %esi
movq 0x28(%rbx), %rdi
xorl %edx, %edx
callq 0xd770
jmp 0x78cb
movq 0x28(%rbx), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0xd770
cmpq $0x0, 0x28(%rsp)
je 0x78cb
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 0x79c1
jmp 0x78cb
movq %rsp, %rsi
leaq 0x60(%rsp), %rdx
movq %rbx, %rdi
callq 0x801e
leaq 0x80(%rsp), %rdi
callq 0x3090
movq (%rbx), %rdi
callq 0xb7ec
cmpl $0x1, %eax
jne 0x7b0d
movq 0x38(%rbx), %rdi
callq 0x9926
movl %eax, %ebp
movq (%rbx), %rdi
callq 0xb7ec
leal (%rax,%rax,2), %eax
cmpl %eax, %ebp
leaq 0x10(%rsp), %r14
jbe 0x7b6a
movl $0x8, %edi
callq 0x32f0
movq %rax, %r14
movq %rax, %rdi
callq 0x4398
leaq 0x40(%rsp), %r15
movq 0x38(%rbx), %rdi
callq 0x9926
movl %eax, %ebp
movq (%rbx), %rdi
callq 0xb7ec
leal (%rax,%rax,2), %eax
cmpl %eax, %ebp
jbe 0x7b31
movq 0x38(%rbx), %rdi
callq 0x99d4
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
callq 0x94d4
movq (%rbx), %rsi
movq 0x30(%rbx), %rdx
movq %r12, %rdi
callq 0x8436
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x45e6
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x7ac5
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x20(%rbx), %rsi
movq %r14, %rdi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x48b4
movq 0x28(%rbx), %r13
movq %r12, %rdi
callq 0x951a
movq %r13, %rdi
movl %eax, %esi
movl $0x1, %edx
callq 0xd770
movq %r12, %rdi
callq 0x921c
movl $0x48, %esi
movq %r12, %rdi
callq 0x3300
jmp 0x7a57
movl $0x1, %ebp
movq (%rbx), %rdi
callq 0xb7ec
cmpl %eax, %ebp
jae 0x7a1a
movq 0x38(%rbx), %rdi
xorl %esi, %esi
callq 0x996e
incl %ebp
jmp 0x7b12
movq %r14, %rdi
callq 0x44bc
testb %al, %al
jne 0x7b50
movq 0x20(%rbx), %rsi
movq %r14, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x48b4
movq %r14, %rdi
callq 0x43dc
movl $0x8, %esi
movq %r14, %rdi
callq 0x3300
leaq 0x10(%rsp), %r14
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x7b86
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x7ba2
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3300
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x7bb8
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 0x7c44
jmp 0x7c51
jmp 0x7c51
movq %rax, %rbx
leaq 0x10(%rsp), %r13
jmp 0x7c75
jmp 0x7c1f
jmp 0x7c17
jmp 0x7c17
jmp 0x7c17
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x7c9a
jmp 0x7ca7
movq %rax, %rbx
jmp 0x7ca7
movq %rax, %rbx
jmp 0x7c91
jmp 0x7c51
jmp 0x7c51
jmp 0x7c51
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x7c54
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3300
jmp 0x7c54
jmp 0x7c51
jmp 0x7c51
jmp 0x7c51
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
leaq 0x10(%rsp), %r13
je 0x7c75
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x7c91
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3300
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x7ca7
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3300
leaq 0x80(%rsp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x3540