// File: /workspace/github_cpp_makefile_star2_O2/ChnMasterOG[P]KmerGO2/kmc_api/kmc_file.cpp
// Function: CKMCFile::GetCountersForRead_kmc2(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<unsigned int, std::allocator<unsigned int>>&)
bool CKMCFile::GetCountersForRead_kmc2(const std::string& read, std::vector<uint32>& counters)
{	
	counters.resize(read.length() - kmer_length + 1);
	std::string transformed_read = read;
	for (char& c : transformed_read)
		c = CKmerAPI::num_codes[(uchar)c];
	
	super_kmers_t super_kmers;
	GetSuperKmers(transformed_read, super_kmers);
	
	uint32 counters_pos = 0;
	if (super_kmers.empty())
	{
		fill_n(counters.begin(), counters.size(), 0);
		return true;
	}

	CKmerAPI kmer(kmer_length);

	uint32 last_end = 0;

	//'N' somewhere in first k-mer
	if (std::get<0>(super_kmers.front()) > 0)
	{
		fill_n(counters.begin(), std::get<0>(super_kmers.front()), 0);
		last_end = std::get<0>(super_kmers.front());
		counters_pos = std::get<0>(super_kmers.front());
	}
	for (auto& super_kmer : super_kmers)
	{
		//'N's between super k-mers
		if (last_end < std::get<0>(super_kmer))
		{
			uint32 gap = std::get<0>(super_kmer) -last_end;
			fill_n(counters.begin() + counters_pos, kmer_length + gap - 1, 0);
			counters_pos += kmer_length + gap - 1;
		}
		last_end = std::get<0>(super_kmer) + std::get<1>(super_kmer);
		
		kmer.from_binary(transformed_read.c_str() + std::get<0>(super_kmer));

		uint32 bin_start_pos = std::get<2>(super_kmer) * single_LUT_size;
		counters[counters_pos++] = count_for_kmer_kmc2(kmer, bin_start_pos);

		for (uint32 i = std::get<0>(super_kmer) +kmer_length; i < std::get<0>(super_kmer) +std::get<1>(super_kmer); ++i)
		{
			kmer.SHL_insert2bits(transformed_read[i]);
			counters[counters_pos++] = count_for_kmer_kmc2(kmer, bin_start_pos);
		}
	}
	//'N's at the end of read
	if (counters_pos < counters.size())
	{
		fill_n(counters.begin() + counters_pos, counters.size() - counters_pos, 0);
		counters_pos = static_cast<uint32>(counters.size());
	}

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq 0x8(%rsi), %rsi
movl 0x78(%rdi), %eax
subq %rax, %rsi
incq %rsi
movq %rdx, 0x10(%rsp)
movq %rdx, %rdi
callq 0x4123ea
leaq 0x58(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x486820
movq (%r12), %rax
movq 0x8(%r12), %rcx
xorl %edx, %edx
movq $0x1b6b940, %rsi        # imm = 0x1B6B940
cmpq %rdx, %rcx
je 0x41167e
movzbl (%rax,%rdx), %edi
movb (%rsi,%rdi), %dil
movb %dil, (%rax,%rdx)
incq %rdx
jmp 0x411668
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x58(%rsp), %rsi
movq %r14, %rdi
callq 0x41209a
movq 0x20(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x4116e2
movl 0x78(%r14), %esi
leaq 0x40(%rsp), %rdi
callq 0x407f72
movq 0x20(%rsp), %r13
movl 0x8(%r13), %esi
testl %esi, %esi
je 0x411707
movq 0x10(%rsp), %rax
movq (%rax), %rdi
leaq 0xc(%rsp), %rdx
andl $0x0, (%rdx)
callq 0x412a67
movq 0x20(%rsp), %r13
movl 0x8(%r13), %ecx
jmp 0x411709
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
subq %rdi, %rsi
sarq $0x2, %rsi
leaq 0x40(%rsp), %rdx
andl $0x0, (%rdx)
callq 0x412a8e
jmp 0x411836
xorl %ecx, %ecx
movq 0x28(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x40(%rsp), %r12
movl %ecx, %r15d
movl %r15d, %edi
cmpq 0x38(%rsp), %r13
je 0x411803
movl 0x8(%r13), %edx
movl %edx, %ebx
subl %ecx, %ebx
jbe 0x411768
shlq $0x2, %rdi
movq 0x10(%rsp), %rax
addq (%rax), %rdi
movl 0x78(%r14), %eax
leal (%rbx,%rax), %esi
decl %esi
andl $0x0, 0xc(%rsp)
leaq 0xc(%rsp), %rdx
callq 0x412a67
movl 0x78(%r14), %eax
addl %ebx, %r15d
addl %eax, %r15d
decl %r15d
movl 0x8(%r13), %edx
movl 0x4(%r13), %eax
movl %eax, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movl %edx, %esi
addq 0x58(%rsp), %rsi
movq %r12, %rdi
callq 0x412722
movl 0x48(%r14), %ebp
imull (%r13), %ebp
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x412042
movl %r15d, %ecx
movq 0x10(%rsp), %rdx
movq (%rdx), %rdx
movl %eax, (%rdx,%rcx,4)
movl 0x8(%r13), %eax
movl 0x78(%r14), %ebx
addl %eax, %ebx
incl %r15d
addl 0x4(%r13), %eax
cmpq %rax, %rbx
jae 0x4117f2
movq 0x58(%rsp), %rax
movzbl (%rax,%rbx), %esi
movq %r12, %rdi
callq 0x4124a2
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x412042
movl %r15d, %ecx
movq 0x10(%rsp), %rdx
movq (%rdx), %rdx
movl %eax, (%rdx,%rcx,4)
incq %rbx
movl 0x8(%r13), %eax
jmp 0x4117b1
movl 0x1c(%rsp), %ecx
addl 0x18(%rsp), %ecx
addq $0xc, %r13
jmp 0x41171b
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rsi
subq %rax, %rsi
sarq $0x2, %rsi
subq %rdi, %rsi
jbe 0x41182c
leaq (%rax,%rdi,4), %rdi
leaq 0xc(%rsp), %rdx
andl $0x0, (%rdx)
callq 0x412a8e
leaq 0x40(%rsp), %rdi
callq 0x40825c
leaq 0x20(%rsp), %rdi
callq 0x412c88
leaq 0x58(%rsp), %rdi
callq 0x484210
movb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x411868
jmp 0x411863
jmp 0x411868
jmp 0x411863
movq %rax, %rbx
jmp 0x411875
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x40825c
leaq 0x20(%rsp), %rdi
callq 0x412c88
leaq 0x58(%rsp), %rdi
callq 0x484210
movq %rbx, %rdi
callq 0x4b8e10
nop