// File: /workspace/github_cpp_makefile_star2_O2/simonrharris[P]SKA/src/sk_refalign.cpp
// Function: printVariantSites(std::basic_ofstream<char, std::char_traits<char>>&, int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
void printVariantSites(std::ofstream & myOutfile, const int totalbases, const std::vector < std::string > & sampleNames, const std::vector < std::string > & mySequences){
	std::vector < int > sitestoprint;
	sitestoprint.reserve(10000);
	std::vector < int > constantBases (4, 0);
	for (int i=0; i<totalbases; ++i){

		std::vector < int > baseVector (6, 0);

		for (int j=0; j<sampleNames.size(); ++j){
			char base=toupper(mySequences[j][i]);
			baseVector[base_score[base]]++;
		}

		int acgtCount=0;
		int constbase=-1;

		for (int i=0; i<4; ++i){
			if (baseVector[i]>0){
				acgtCount++;
				constbase=i;
			}
		}

		if (acgtCount==1){
			constantBases[constbase]++;
		}
		else if (acgtCount>1) {
			sitestoprint.push_back(i);
		}
		
	}

	std::cout << "Printing alignment of " << sitestoprint.size() << " variant sites" << std::endl;

	for (int i=0; i<sampleNames.size(); ++i){
		std::string mySequence (sitestoprint.size(), '-');
		for (int j=0; j<sitestoprint.size(); ++j){
			mySequence[j]=mySequences[i][sitestoprint[j]];
		}
		myOutfile << ">" << sampleNames[i] << std::endl << mySequence << std::endl;
	}

	std::cout << "Constant sites (a c g t):" << std::endl;
	std::cout << constantBases[0] << " " << constantBases[1]  << " " << constantBases[2]  << " " << constantBases[3]  << std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, %rbx
movq %rdx, 0x10(%rsp)
movl %esi, 0x18(%rsp)
movq %rdi, 0x70(%rsp)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movl $0x2710, %esi           # imm = 0x2710
callq 0x133ba
leaq 0x50(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x38(%rsp), %rdi
pushq $0x4
popq %rsi
leaq 0x8(%rsp), %rcx
callq 0xbe22
xorl %eax, %eax
leaq 0x50(%rsp), %r15
leaq 0x204c0(%rip), %r13     # 0x36450
movl %eax, 0x8(%rsp)
cmpl 0x18(%rsp), %eax
jge 0x1605f
andl $0x0, 0x1c(%rsp)
movq %r15, %r14
movq %r15, %rdi
pushq $0x6
popq %rsi
leaq 0x1c(%rsp), %rdx
leaq 0xf(%rsp), %rcx
callq 0xbe22
movq 0x10(%rsp), %rax
movq 0x8(%rax), %r15
subq (%rax), %r15
sarq $0x5, %r15
movq (%rbx), %rbp
movq 0x50(%rsp), %r12
subq $0x1, %r15
jb 0x15fff
movslq 0x8(%rsp), %rax
movq (%rbp), %rcx
movsbl (%rcx,%rax), %edi
callq 0x56f0
movsbq %al, %rax
movsbq (%r13,%rax), %rax
incl (%r12,%rax,4)
addq $0x20, %rbp
jmp 0x15fd3
xorl %edx, %edx
movq 0x50(%rsp), %rsi
xorl %ecx, %ecx
pushq $-0x1
popq %rax
movq %r14, %r15
cmpq $0x4, %rdx
je 0x16028
xorl %edi, %edi
cmpl $0x0, (%rsi,%rdx,4)
setg %dil
cmovgl %edx, %eax
addl %edi, %ecx
incq %rdx
jmp 0x1600e
testl %ecx, %ecx
je 0x1604c
cmpl $0x1, %ecx
jne 0x1603d
cltq
movq 0x38(%rsp), %rcx
incl (%rcx,%rax,4)
jmp 0x1604c
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xbe78
movq %r15, %rdi
callq 0xc052
movl 0x8(%rsp), %eax
incl %eax
jmp 0x15f90
movq 0x1ff52(%rip), %rdi     # 0x35fb8
leaq 0xf623(%rip), %rsi      # 0x25690
callq 0x53f0
movq 0x28(%rsp), %rsi
subq 0x20(%rsp), %rsi
sarq $0x2, %rsi
movq %rax, %rdi
callq 0x5280
leaq 0x10309(%rip), %rsi     # 0x26398
movq %rax, %rdi
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
leaq 0x60(%rsp), %r14
xorl %ebp, %ebp
leaq 0x50(%rsp), %r15
leaq 0xffe5(%rip), %r12      # 0x26097
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x5, %rax
cmpq %rbp, %rax
jbe 0x1616e
movq 0x28(%rsp), %rsi
subq 0x20(%rsp), %rsi
sarq $0x2, %rsi
movq %r14, 0x50(%rsp)
movq %r15, %rdi
pushq $0x2d
popq %rdx
callq 0x5470
movq %rbp, %r13
shlq $0x5, %r13
xorl %eax, %eax
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %rax, %rdx
jbe 0x16123
movq (%rbx), %rdx
movslq (%rcx,%rax,4), %rcx
movq (%rdx,%r13), %rdx
movb (%rdx,%rcx), %cl
movq 0x50(%rsp), %rdx
movb %cl, (%rdx,%rax)
incq %rax
jmp 0x160f2
movq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x53f0
movq 0x10(%rsp), %rcx
addq (%rcx), %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
movq %r15, %rsi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq %r15, %rdi
callq 0x5778
incq %rbp
jmp 0x160b2
movq 0x1fe43(%rip), %rdi     # 0x35fb8
leaq 0x1022b(%rip), %rsi     # 0x263a7
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq 0x38(%rsp), %rax
movl (%rax), %esi
movq 0x1fe21(%rip), %rdi     # 0x35fb8
callq 0x56a0
leaq 0x101ba(%rip), %rsi     # 0x2635d
movq %rax, %rdi
callq 0x53f0
movq 0x38(%rsp), %rcx
movl 0x4(%rcx), %esi
movq %rax, %rdi
callq 0x56a0
leaq 0x1019b(%rip), %rsi     # 0x2635d
movq %rax, %rdi
callq 0x53f0
movq 0x38(%rsp), %rcx
movl 0x8(%rcx), %esi
movq %rax, %rdi
callq 0x56a0
leaq 0x1017c(%rip), %rsi     # 0x2635d
movq %rax, %rdi
callq 0x53f0
movq 0x38(%rsp), %rcx
movl 0xc(%rcx), %esi
movq %rax, %rdi
callq 0x56a0
movq %rax, %rdi
callq 0x51c0
leaq 0x38(%rsp), %rdi
callq 0xc052
leaq 0x20(%rsp), %rdi
callq 0xc052
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x16226
movq %rax, %rbx
jmp 0x1625a
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xc052
jmp 0x16250
jmp 0x1623e
jmp 0x1623e
movq %rax, %rbx
jmp 0x16250
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x5778
leaq 0x38(%rsp), %rdi
callq 0xc052
leaq 0x20(%rsp), %rdi
callq 0xc052
movq %rbx, %rdi
callq 0x56c0