// File: /workspace/github_cpp_makefile_star2_O1/simonrharris[P]SKA/src/sk_align.cpp
// Function: filterAlignment(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, 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::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>&, std::vector<int, std::allocator<int>>&, int, int, bool, float&, float&)
void filterAlignment(std::unordered_map < std::string, std::string > & myKmerMap, std::vector < int > & constantBaseVector, const int numSamples, const int minrequired, const bool variantOnly, float & sitecount, float & variantsitecount){

	std::unordered_map < std::string, std::string >::iterator kmit = myKmerMap.begin();
	std::unordered_map < std::string, std::string >::iterator kmitend = myKmerMap.end();

	for (; kmit!=kmitend; ){
		std::vector < int > baseVector (6, 0);
		for (int i=0; i<numSamples; ++i){//count the number of each base in the samples
			baseVector[base_score[kmit->second[i]]]++;
		}

		int acgtTotal=0;
		int acgtCount=0;
		int constbase=-1;

		for (int i=0; i<4; ++i){//count the total number of ACGTs and the number of different bases at the site
			if (baseVector[i]>0){
				acgtCount++;
				constbase=i;//record the site as the constant base if it is present in at least one smaple. This iwll only be used if the site is constant
			}
			acgtTotal+=baseVector[i];
		}

		if (acgtTotal<minrequired || acgtTotal==0){ //if the total number of samples matching the kmer with a base is below the minimum, exclude the site from the alignment
			myKmerMap.erase(kmit++);
		}
		else if (acgtCount==1 && variantOnly){//if the site is constant and variantonlly has been selected, record the variant base and exclude the site from the alignment
			constantBaseVector[constbase]++;
			myKmerMap.erase(kmit++);
			sitecount++;
		}
		else {
			sitecount++;
			if (acgtCount>1){
				variantsitecount++;
			}
			++kmit;
		}
		
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x10(%rsp)
movl %r8d, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x10(%rdi), %r14
testq %r14, %r14
je 0xca9e
movl %edx, %r15d
movl %edx, %r13d
leaq 0x34ac0(%rip), %rbx     # 0x41440
movl 0x8(%rsp), %eax
xorb $0x1, %al
movl %eax, 0x8(%rsp)
movl $0x18, %edi
callq 0x53b0
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testl %r15d, %r15d
jle 0xc9c6
movq 0x28(%r14), %rax
xorl %ecx, %ecx
movsbq (%rax,%rcx), %rdx
movsbq (%rbx,%rdx), %rdx
incl (%r12,%rdx,4)
incq %rcx
cmpq %rcx, %r13
jne 0xc9b0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl (%r12,%rsi,4), %edi
xorl %r8d, %r8d
testl %edi, %edi
setg %r8b
cmovgl %esi, %eax
addl %r8d, %ecx
addl %edi, %edx
incq %rsi
cmpq $0x4, %rsi
jne 0xc9d1
cmpl 0xc(%rsp), %edx
setl %sil
testl %edx, %edx
sete %dl
orb %sil, %dl
je 0xca13
movq (%r14), %rbp
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0xc86a
jmp 0xca85
cmpl $0x1, %ecx
setne %dl
orb 0x8(%rsp), %dl
jne 0xca53
cltq
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
incl (%rcx,%rax,4)
movq (%r14), %rbp
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0xc86a
movq 0x10(%rsp), %rax
movss (%rax), %xmm0
addss 0x265b7(%rip), %xmm0    # 0x33004
movss %xmm0, (%rax)
jmp 0xca85
movq 0x10(%rsp), %rax
movss (%rax), %xmm0
addss 0x265a0(%rip), %xmm0    # 0x33004
movss %xmm0, (%rax)
cmpl $0x2, %ecx
jb 0xca82
movq 0x60(%rsp), %rax
movss (%rax), %xmm0
addss 0x26586(%rip), %xmm0    # 0x33004
movss %xmm0, (%rax)
movq (%r14), %rbp
movl $0x18, %esi
movq %r12, %rdi
callq 0x53c0
movq %rbp, %r14
testq %rbp, %rbp
jne 0xc98a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x18, %esi
movq %r12, %rdi
callq 0x53c0
movq %rbx, %rdi
callq 0x56a0