// File: /workspace/github_cpp_makefile_star2_O3/ridgelab[P]Kmer-SSR/src/FindSSRs.cpp
// Function: consume(void*)
static
void* consume(void* consumer_args_vptr)
{
	// cast void pointer to correct pointer type
	ConsumerArguments* consumer_args = (ConsumerArguments*) consumer_args_vptr;

	// Extract the arguments out of the struct
	TaskQueue* tasks = consumer_args->tasks_ptr;
	ProgressMeter* progress_bar = consumer_args->progress_bar_ptr;
	OutputFile* ofd = consumer_args->ofd_ptr;
	AtomicityChecker* atomicity_checker = consumer_args->atomicity_checker_ptr;
	Arguments* args = consumer_args->arguments_ptr;

	// create a container for ssrs
	SSRcontainer* ssrs = new SSRcontainer();
	Task* task = nullptr;

	// while we have work to do
	while (true)
	{
		// get a task to perform
		task = tasks->get();
	
		// if the task is NULL, it's a signal that we're all done here
		if (task == nullptr)
		{
			break; // stop working because there isn't any work left to do
		}

		// add the ssrs to the container and *attempt* to write all ssrs in the container to file
		ssrs->add(task->getID(), findSSRs(task, args, atomicity_checker));
		ssrs->writeToFile(ofd, false, true); // false means it won't block if it can't write, true means clear the SSRcontainer (if it wrote)

		// update the progress bar with the work done
		progress_bar->updateProgress(task->size(), true);

		delete task;
	}

	// if we haven't printed out all the ssrs yet, do it
	if (!ssrs->empty())
	{
		ssrs->writeToFile(ofd, true, false); // true means it will block until it can write, false don't means clear the SSRcontainer (because we're about to delete it anyway)
	}

	// delete the arguments pointer and the SSRcontainer
	delete consumer_args;
	delete ssrs;

	return nullptr;
	//pthread_exit(NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq (%rdi), %r12
movq 0x8(%rdi), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rdi), %rax
movq %rax, (%rsp)
movq 0x18(%rdi), %rbp
movq %rdi, 0x8(%rsp)
movq 0x20(%rdi), %r14
movl $0x8, %edi
callq 0x32f0
movq %rax, %rbx
movq %rax, %rdi
callq 0x4380
movq %r12, %rdi
callq 0x98a4
testq %rax, %rax
je 0x7d56
movq %rax, %r13
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x938e
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x835a
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x45b8
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x7d01
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3300
movq %rbx, %rdi
movq (%rsp), %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x4886
movq %r13, %rdi
callq 0x93d4
movq 0x10(%rsp), %rdi
movl %eax, %esi
movl $0x1, %edx
callq 0xd664
movq %r13, %rdi
callq 0x90fc
movl $0x48, %esi
movq %r13, %rdi
callq 0x3300
movq %r12, %rdi
callq 0x98a4
movq %rax, %r13
testq %rax, %rax
jne 0x7cbe
movq %rbx, %rdi
callq 0x449a
testb %al, %al
jne 0x7d75
movq %rbx, %rdi
movq (%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x4886
movl $0x28, %esi
movq 0x8(%rsp), %rdi
callq 0x3300
movq %rbx, %rdi
callq 0x43b8
movl $0x8, %esi
movq %rbx, %rdi
callq 0x3300
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movl $0x8, %esi
movq %rbx, %rdi
jmp 0x7dd1
movq %rax, %r14
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x7dd6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3300
movq %r14, %rdi
callq 0x3540