// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %r9, 0x18(%rsp)
movl %ecx, %r14d
movl %edx, %r15d
movq %rsi, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movq 0x10(%rdi), %rbp
xorl %eax, %eax
testl %edx, %edx
cmovlel %eax, %r15d
leaq 0x30(%rsp), %r12
xorb $0x1, %r8b
movl %r8d, 0x10(%rsp)
leaq 0x2b444(%rip), %r13     # 0x36450
testq %rbp, %rbp
je 0xb129
andl $0x0, 0x14(%rsp)
movq %r12, %rdi
pushq $0x6
popq %rsi
leaq 0x14(%rsp), %rdx
leaq 0xf(%rsp), %rcx
callq 0xbe22
movq 0x30(%rsp), %rcx
xorl %eax, %eax
cmpq %rax, %r15
je 0xb052
movq 0x28(%rbp), %rdx
movsbq (%rdx,%rax), %rdx
movsbq (%r13,%rdx), %rdx
incl (%rcx,%rdx,4)
incq %rax
jmp 0xb036
xorl %esi, %esi
xorl %eax, %eax
pushq $-0x1
popq %rdx
xorl %edi, %edi
cmpq $0x4, %rsi
je 0xb07d
movl (%rcx,%rsi,4), %r8d
xorl %r9d, %r9d
testl %r8d, %r8d
cmovgl %esi, %edx
setg %r9b
addl %r9d, %eax
addl %r8d, %edi
incq %rsi
jmp 0xb05b
cmpl %r14d, %edi
setl %cl
testl %edi, %edi
sete %sil
orb %cl, %sil
je 0xb0a1
movq (%rbp), %rbx
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0xaec4
jmp 0xb119
cmpl $0x1, %eax
setne %cl
orb 0x10(%rsp), %cl
jne 0xb0e3
movslq %edx, %rax
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
incl (%rcx,%rax,4)
movq (%rbp), %rbx
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0xaec4
movq 0x18(%rsp), %rax
movss (%rax), %xmm0
addss 0x19f27(%rip), %xmm0    # 0x25004
movss %xmm0, (%rax)
jmp 0xb119
movq 0x18(%rsp), %rcx
movss (%rcx), %xmm0
addss 0x19f10(%rip), %xmm0    # 0x25004
movss %xmm0, (%rcx)
cmpl $0x2, %eax
jb 0xb115
movq 0x80(%rsp), %rax
movss (%rax), %xmm0
addss 0x19ef3(%rip), %xmm0    # 0x25004
movss %xmm0, (%rax)
movq (%rbp), %rbx
movq %r12, %rdi
callq 0xc052
movq %rbx, %rbp
jmp 0xb00c
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xc052
movq %rbx, %rdi
callq 0x56c0