// File: /workspace/github_cpp_makefile_star2_O1/simonrharris[P]SKA/src/kmers.cpp
// Function: printKmerFile(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>>>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, float)
int printKmerFile(const std::unordered_map < std::string, std::array < int, 8 > > & mymap, const std::string outputfile, const int kmersize, float userminmaf){
	
	std::cout << "Writing split kmers to " << outputfile << std::endl;

	std::ofstream kmerfile(outputfile);
	if (kmerfile.fail()){
		std::cerr << std::endl << "Error: Failed to open " << outputfile << std::endl << std::endl;
		return 1;
	}
	kmerfile << "SKA v" << versionNumber << std::endl;
	kmerfile << kmersize << std::endl;
	std:: string samplename=splitFileName(outputfile);
	kmerfile << samplename.substr(0, samplename.find_last_of(".")) << std::endl;
	kmerfile << '"';
	for (std::unordered_map < std::string, std::array < int, 8 > >::const_iterator it=mymap.begin(); it!=mymap.end(); ++it){
		std::string kmer=it->first;
		char base;
		bool basefound=false;
		int i=0;

		int filebasecoverage=0;
		int maxfilebasecoverage=0;
		char maxbase;
		for (std::array < int, 8 >::const_iterator it2=it->second.begin(); it2!=it->second.begin()+4; ++it2, ++i){
			filebasecoverage+=*it2;
			if (*it2>maxfilebasecoverage){
				maxfilebasecoverage=*it2;
				base=bases[i];
			}
		}

		float covcutoff=(1.0-userminmaf)*filebasecoverage;

		if (ascii_codons(kmer)){return 1;}
		if (maxfilebasecoverage>=covcutoff){	
			kmerfile << base << kmer;
		}
		else {
			kmerfile << "N" << kmer;
		}
	}
	kmerfile.close();
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movss %xmm0, 0x30(%rsp)
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x3840d(%rip), %r15     # 0x40fc0
leaq 0x2a85e(%rip), %rsi     # 0x33418
movl $0x17, %edx
movq %r15, %rdi
callq 0x5420
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r15, %rdi
callq 0x5420
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x5720
movq (%r15), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x78(%rsp,%rax)
je 0x8cda
movq 0x383c2(%rip), %rdi     # 0x40ff0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq 0x383a7(%rip), %rdi     # 0x40ff0
callq 0x5030
movq %rax, %rdi
callq 0x5250
movq %rax, %rbx
leaq 0x2a7d0(%rip), %rsi     # 0x33430
movl $0x16, %edx
movq %rax, %rdi
callq 0x5420
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0x5420
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x5250
jmp 0x8f6f
leaq 0x2b099(%rip), %rsi     # 0x33d7a
leaq 0x58(%rsp), %rdi
movl $0x5, %edx
callq 0x5420
leaq 0x38819(%rip), %rax     # 0x41510
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0x58(%rsp), %rdi
callq 0x5420
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
leaq 0x58(%rsp), %rdi
movl %ebp, %esi
callq 0x5690
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x7e20
leaq 0x2d68a(%rip), %rsi     # 0x36406
leaq 0x38(%rsp), %r14
movl $0x1, %ecx
movq %r14, %rdi
movq $-0x1, %rdx
callq 0x5740
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x53e0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x58(%rsp), %rdi
callq 0x5420
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5250
leaq 0x20(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x8e00
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x53c0
leaq 0x10(%rsp), %rsi
movb $0x22, (%rsi)
leaq 0x58(%rsp), %rdi
movl $0x1, %edx
callq 0x5420
movq 0x10(%rbx), %rbp
testq %rbp, %rbp
movss 0x30(%rsp), %xmm0
je 0x8f2a
cvtss2sd %xmm0, %xmm0
movsd 0x2a432(%rip), %xmm1    # 0x33268
subsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
leaq 0x10(%rsp), %rbx
movq %r13, 0x10(%rsp)
movq 0x8(%rbp), %rsi
movq 0x10(%rbp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x859a
xorl %r15d, %r15d
movl $0x28, %eax
leaq 0x38659(%rip), %rcx     # 0x414c5
xorl %r14d, %r14d
movl (%rbp,%rax), %edx
cmpl %r15d, %edx
jle 0x8e7e
movb (%rcx), %r12b
movl %edx, %r15d
addl %edx, %r14d
addq $0x4, %rax
incq %rcx
cmpq $0x38, %rax
jne 0x8e6f
movq %rbx, %rdi
callq 0x6ab2
testl %eax, %eax
jne 0x8f38
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x30(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %r15d, %xmm1
cvtsd2ss %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jae 0x8ed8
movl $0x1, %edx
leaq 0x58(%rsp), %r14
movq %r14, %rdi
leaq 0x2a576(%rip), %rsi     # 0x33447
callq 0x5420
jmp 0x8ef4
movb %r12b, 0xf(%rsp)
movl $0x1, %edx
leaq 0x58(%rsp), %rdi
leaq 0xf(%rsp), %rsi
callq 0x5420
movq %rax, %r14
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x5420
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x8f1d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x53c0
movq (%rbp), %rbp
testq %rbp, %rbp
jne 0x8e45
xorl %ebx, %ebx
leaq 0x58(%rsp), %rdi
callq 0x5530
jmp 0x8f54
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x8f4f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x53c0
movl $0x1, %ebx
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8f6f
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x53c0
movq 0x3803a(%rip), %rax     # 0x40fb0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x60(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x58(%rsp,%rcx)
callq 0x5330
leaq 0x150(%rsp), %rdi
callq 0x5120
movl %ebx, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8fce
jmp 0x8fd3
jmp 0x8fce
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x8fe5
jmp 0x8ff2
movq %rax, %rbx
jmp 0x8ff2
movq %rax, %rbx
jmp 0x900d
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x8ff2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x53c0
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x900d
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x53c0
leaq 0x58(%rsp), %rdi
callq 0x55a0
movq %rbx, %rdi
callq 0x56a0