// File: simonrharris[P]SKA/src/kmers.cpp
// Function: printMergedKmerFile(std::unordered_map<std::vector<bool, std::allocator<bool>>, 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>>>>, std::hash<std::vector<bool, std::allocator<bool>>>, std::equal_to<std::vector<bool, std::allocator<bool>>>, std::allocator<std::pair<std::vector<bool, std::allocator<bool>> 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&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, 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&, int)
int printMergedKmerFile(const std::unordered_map < std::vector < bool >, std::vector < std::string > > & mymap, const std::string outputfile, const std::vector < std::string > & mysamples, const int kmersize){

	std::cout << "Writing split kmers to " << outputfile << std::endl;

	std::ofstream kmerout(outputfile); //open output file stream
	if (kmerout.fail()){
		std::cerr << std::endl << "Error: Failed to open " << outputfile << std::endl << std::endl;
		return 1;
	}
	kmerout << "SKA v" << versionNumber << std::endl;
	kmerout << kmersize << std::endl; // print kmer size to output file stream
	for ( std::vector < std::string >::const_iterator it=mysamples.begin(); it!=mysamples.end(); ++it){ //print each sample name to output file stream
		kmerout << *it << " "; 
	}
	kmerout << std::endl;

	for ( std::unordered_map < std::vector < bool >, std::vector < std::string > >::const_iterator it=mymap.begin(); it!=mymap.end(); ++it){
		std::stringstream bitstringstream;
		for (std::vector < bool >::const_iterator it2=it->first.begin(); it2!=it->first.end(); ++it2){
			bitstringstream << *it2;
		}
		std::string bitstring = bitstringstream.str();

		ascii_bitstring(bitstring);
		kmerout << bitstring;
		for (std::vector < std::string >::const_iterator it2=it->second.begin(); it2!=it->second.end(); ++it2){
			kmerout << *it2;
		}
		kmerout << std::endl;
	}
	
	kmerout.close();
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rsi, -0x460(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq 0x6c770(%rip), %rdi     # 0x78fa8
leaq 0x4cbd9(%rip), %rsi     # 0x59418
callq 0x6520
movq -0x460(%rbp), %rsi
movq %rax, %rdi
callq 0x64d0
movq %rax, %rdi
movq 0x6c733(%rip), %rsi     # 0x78f90
callq 0x6570
movq -0x460(%rbp), %rsi
leaq -0x228(%rbp), %rdi
movl $0x10, %edx
callq 0x69b0
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x6030
movb %al, -0x451(%rbp)
jmp 0xc89a
movb -0x451(%rbp), %al
testb $0x1, %al
jne 0xc8a9
jmp 0xc95b
movq 0x6c740(%rip), %rdi     # 0x78ff0
movq 0x6c6d9(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x468(%rbp)
jmp 0xc8c5
movq -0x468(%rbp), %rdi
leaq 0x4cb5d(%rip), %rsi     # 0x59430
callq 0x6520
movq %rax, -0x470(%rbp)
jmp 0xc8e1
movq -0x460(%rbp), %rsi
movq -0x470(%rbp), %rdi
callq 0x64d0
movq %rax, -0x478(%rbp)
jmp 0xc8fd
movq -0x478(%rbp), %rdi
movq 0x6c685(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x480(%rbp)
jmp 0xc919
movq -0x480(%rbp), %rdi
movq 0x6c669(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0xc92e
movl $0x1, -0x4(%rbp)
movl $0x1, -0x238(%rbp)
jmp 0xcd02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0xcd1a
leaq 0x4d418(%rip), %rsi     # 0x59d7a
leaq -0x228(%rbp), %rdi
callq 0x6520
movq %rax, -0x488(%rbp)
jmp 0xc977
movq -0x488(%rbp), %rdi
leaq 0x6ccdb(%rip), %rsi     # 0x79660
callq 0x64d0
movq %rax, -0x490(%rbp)
jmp 0xc993
movq -0x490(%rbp), %rdi
movq 0x6c5ef(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0xc9a8
movl -0x24(%rbp), %esi
leaq -0x228(%rbp), %rdi
callq 0x68d0
movq %rax, -0x498(%rbp)
jmp 0xc9c0
movq -0x498(%rbp), %rdi
movq 0x6c5c2(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0xc9d5
movq -0x20(%rbp), %rdi
callq 0xefe0
movq %rax, -0x240(%rbp)
movq -0x20(%rbp), %rdi
callq 0xf050
movq %rax, -0x248(%rbp)
leaq -0x240(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0xf010
testb $0x1, %al
jne 0xca0e
jmp 0xca57
leaq -0x240(%rbp), %rdi
callq 0xf080
movq %rax, %rsi
leaq -0x228(%rbp), %rdi
callq 0x64d0
movq %rax, -0x4a0(%rbp)
jmp 0xca32
movq -0x4a0(%rbp), %rdi
leaq 0x4d90d(%rip), %rsi     # 0x5a34d
callq 0x6520
jmp 0xca47
jmp 0xca49
leaq -0x240(%rbp), %rdi
callq 0xf0a0
jmp 0xc9e5
movq 0x6c532(%rip), %rsi     # 0x78f90
leaq -0x228(%rbp), %rdi
callq 0x6570
jmp 0xca6c
movq -0x10(%rbp), %rdi
callq 0xf0c0
movq %rax, -0x250(%rbp)
movq -0x10(%rbp), %rdi
callq 0xf120
movq %rax, -0x258(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0xf0f0
testb $0x1, %al
jne 0xcaa8
jmp 0xcce3
leaq -0x3e0(%rbp), %rdi
callq 0x63a0
jmp 0xcab6
leaq -0x250(%rbp), %rdi
callq 0xf150
movq %rax, %rdi
callq 0xf180
movl %edx, -0x3f8(%rbp)
movq %rax, -0x400(%rbp)
movq -0x400(%rbp), %rax
movq %rax, -0x3f0(%rbp)
movl -0x3f8(%rbp), %eax
movl %eax, -0x3e8(%rbp)
leaq -0x250(%rbp), %rdi
callq 0xf150
movq %rax, %rdi
callq 0xf1f0
movl %edx, -0x418(%rbp)
movq %rax, -0x420(%rbp)
movl -0x418(%rbp), %eax
movl %eax, -0x408(%rbp)
movq -0x420(%rbp), %rax
movq %rax, -0x410(%rbp)
leaq -0x3f0(%rbp), %rdi
leaq -0x410(%rbp), %rsi
callq 0xf1c0
movb %al, -0x4a1(%rbp)
jmp 0xcb47
movb -0x4a1(%rbp), %al
testb $0x1, %al
jne 0xcb53
jmp 0xcbbb
leaq -0x3d0(%rbp), %rax
movq %rax, -0x4b0(%rbp)
leaq -0x3f0(%rbp), %rdi
callq 0xf230
movb %al, -0x4a2(%rbp)
jmp 0xcb75
movq -0x4b0(%rbp), %rdi
movb -0x4a2(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
callq 0x6920
jmp 0xcb8f
jmp 0xcb91
leaq -0x3f0(%rbp), %rdi
callq 0xf270
jmp 0xcb9f
jmp 0xcaf1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0xccd5
leaq -0x440(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
callq 0x6510
jmp 0xcbd0
leaq -0x440(%rbp), %rdi
callq 0xbb40
jmp 0xcbde
leaq -0x228(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0x64d0
jmp 0xcbf3
leaq -0x250(%rbp), %rdi
callq 0xf150
movq %rax, %rdi
addq $0x28, %rdi
callq 0xefe0
movq %rax, -0x448(%rbp)
leaq -0x250(%rbp), %rdi
callq 0xf150
movq %rax, %rdi
addq $0x28, %rdi
callq 0xf050
movq %rax, -0x450(%rbp)
leaq -0x448(%rbp), %rdi
leaq -0x450(%rbp), %rsi
callq 0xf010
testb $0x1, %al
jne 0xcc4a
jmp 0xcc97
leaq -0x448(%rbp), %rdi
callq 0xf080
movq %rax, %rsi
leaq -0x228(%rbp), %rdi
callq 0x64d0
jmp 0xcc67
jmp 0xcc69
leaq -0x448(%rbp), %rdi
callq 0xf0a0
jmp 0xcc12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x440(%rbp), %rdi
callq 0x6a08
jmp 0xccd5
movq 0x6c2f2(%rip), %rsi     # 0x78f90
leaq -0x228(%rbp), %rdi
callq 0x6570
jmp 0xccac
leaq -0x440(%rbp), %rdi
callq 0x6a08
leaq -0x3e0(%rbp), %rdi
callq 0x6410
leaq -0x250(%rbp), %rdi
callq 0xf2a0
jmp 0xca7c
leaq -0x3e0(%rbp), %rdi
callq 0x6410
jmp 0xcd1a
leaq -0x228(%rbp), %rdi
callq 0x6740
jmp 0xccf1
movl $0x0, -0x4(%rbp)
movl $0x1, -0x238(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x67d0
movl -0x4(%rbp), %eax
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0x67d0
movq -0x230(%rbp), %rdi
callq 0x6900
nopw %cs:(%rax,%rax)