// File: simonrharris[P]SKA/src/kmers.cpp
// Function: applyFileKmerArrayMapFilters(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::array<int, 8ul>, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::array<int, 8ul>>>>&, int const&)
void applyFileKmerArrayMapFilters(std::unordered_map < std::string, std::array < int, 8 > > & kmerMap, const int & userfilecutoff){

	std::cout << "Filtering kmers for file coverage" << std::endl;

	int filebasecoverage;
	int maxfilebasecoverage;
	float filecovcutoff;

	std::unordered_map < std::string, std::array < int, 8 > >::iterator it = kmerMap.begin();
	std::unordered_map < std::string, std::array < int, 8 > >::iterator endIter = kmerMap.end();
	for (; it!=endIter; ){

		//calculate the total file kmer coverage and remove the kmer if it is below the minimum cutoff
		filebasecoverage=0;
		maxfilebasecoverage=0;
		for (std::array < int, 8 >::iterator it2=it->second.begin(); it2!=it->second.begin()+4; ++it2){
			filebasecoverage+=*it2;
			if (*it2>maxfilebasecoverage){
				maxfilebasecoverage=*it2;
			}
		}

		if (filebasecoverage<userfilecutoff){
			kmerMap.erase(it++);
		}
		else {
			int j=4;
			for (int i=0; i<4; ++i, ++j){
				it->second[j]+=it->second[i];
				it->second[i]=0;
			}
			++it;
		}

	}
	std::cout << kmerMap.size() << " unique kmers in map after filtering" << std::endl;
	//return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x6b0e1(%rip), %rdi     # 0x78fa8
leaq 0x4b6d8(%rip), %rsi     # 0x595a6
callq 0x6520
movq %rax, %rdi
movq 0x6b0b3(%rip), %rsi     # 0x78f90
callq 0x6570
movq -0x8(%rbp), %rdi
callq 0xfac0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0xf990
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xeee0
testb $0x1, %al
jne 0xdf12
jmp 0xe061
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xf9c0
movq %rax, %rdi
addq $0x20, %rdi
callq 0xfaf0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xf9c0
movq %rax, %rdi
addq $0x20, %rdi
callq 0xfaf0
movq %rax, %rcx
movq -0x58(%rbp), %rax
addq $0x10, %rcx
cmpq %rcx, %rax
je 0xdf96
movq -0x38(%rbp), %rax
movl (%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x38(%rbp), %rax
movl (%rax), %eax
cmpl -0x18(%rbp), %eax
jle 0xdf86
movq -0x38(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
jmp 0xdf88
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
jmp 0xdf39
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xdfce
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0xfb50
movq -0x60(%rbp), %rdi
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rsi
callq 0xfb10
movq %rax, -0x48(%rbp)
jmp 0xe05c
movl $0x4, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
cmpl $0x4, -0x50(%rbp)
jge 0xe053
leaq -0x28(%rbp), %rdi
callq 0xf9c0
movq %rax, %rdi
addq $0x20, %rdi
movslq -0x50(%rbp), %rsi
callq 0xf9f0
movl (%rax), %eax
movl %eax, -0x64(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xf9c0
movq %rax, %rdi
addq $0x20, %rdi
movslq -0x4c(%rbp), %rsi
callq 0xf9f0
movl -0x64(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
leaq -0x28(%rbp), %rdi
callq 0xf9c0
movq %rax, %rdi
addq $0x20, %rdi
movslq -0x50(%rbp), %rsi
callq 0xf9f0
movl $0x0, (%rax)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xdfdc
leaq -0x28(%rbp), %rdi
callq 0xfb80
jmp 0xdefc
movq -0x8(%rbp), %rdi
callq 0xfbb0
movq %rax, %rsi
movq 0x6af34(%rip), %rdi     # 0x78fa8
callq 0x6120
movq %rax, %rdi
leaq 0x4b545(%rip), %rsi     # 0x595c8
callq 0x6520
movq %rax, %rdi
movq 0x6aefe(%rip), %rsi     # 0x78f90
callq 0x6570
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)