// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movb %r8b, %al
movq 0x10(%rbp), %r8
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq %r9, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0xff80
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0xf7c0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xf790
testb $0x1, %al
jne 0x18f89
jmp 0x191d9
movl $0x0, -0x54(%rbp)
leaq -0x55(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x1a8f0
movq -0xa0(%rbp), %rcx
leaq -0x50(%rbp), %rdi
movl $0x6, %esi
leaq -0x54(%rbp), %rdx
callq 0x1a910
jmp 0x18fbb
leaq -0x55(%rbp), %rdi
callq 0x1a990
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1905f
leaq -0x30(%rbp), %rdi
callq 0xf880
movq %rax, %rdi
addq $0x20, %rdi
movslq -0x68(%rbp), %rsi
callq 0x69e0
movq %rax, -0xa8(%rbp)
jmp 0x18ff9
movq -0xa8(%rbp), %rax
movsbq (%rax), %rcx
leaq 0x60585(%rip), %rax     # 0x79590
movsbq (%rax,%rcx), %rsi
leaq -0x50(%rbp), %rdi
callq 0x1a9b0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x18fcb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x55(%rbp), %rdi
callq 0x1a990
jmp 0x191e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x1aa00
jmp 0x191e2
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl $0xffffffff, -0x74(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x78(%rbp)
cmpl $0x4, -0x78(%rbp)
jge 0x190c2
movslq -0x78(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x1a9b0
cmpl $0x0, (%rax)
jle 0x190a2
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x74(%rbp)
movslq -0x78(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x1a9b0
movl (%rax), %eax
addl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x1907b
movl -0x6c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jl 0x190d0
cmpl $0x0, -0x6c(%rbp)
jne 0x19116
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x10070
movq -0xb8(%rbp), %rdi
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rsi
callq 0x10030
movq %rax, -0xb0(%rbp)
jmp 0x19103
movq -0xb0(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x191cb
cmpl $0x1, -0x70(%rbp)
jne 0x19192
testb $0x1, -0x19(%rbp)
je 0x19192
movq -0x10(%rbp), %rdi
movslq -0x74(%rbp), %rsi
callq 0x1a9b0
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x10070
movq -0xc8(%rbp), %rdi
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rsi
callq 0x10030
movq %rax, -0xc0(%rbp)
jmp 0x1916e
movq -0xc0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movss 0x3fe7c(%rip), %xmm0    # 0x59004
addss (%rax), %xmm0
movss %xmm0, (%rax)
jmp 0x191c9
movq -0x28(%rbp), %rax
movss 0x3fe66(%rip), %xmm0    # 0x59004
addss (%rax), %xmm0
movss %xmm0, (%rax)
cmpl $0x1, -0x70(%rbp)
jle 0x191c0
movq 0x10(%rbp), %rax
movss 0x3fe4c(%rip), %xmm0    # 0x59004
addss (%rax), %xmm0
movss %xmm0, (%rax)
leaq -0x30(%rbp), %rdi
callq 0x1a9d0
jmp 0x191cb
leaq -0x50(%rbp), %rdi
callq 0x1aa00
jmp 0x18f73
addq $0xd0, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x6900
nopl (%rax,%rax)