// File: /workspace/github_cpp_makefile_star2_O2/ChnMasterOG[P]KmerGO2/kmc_api/kmc_file.cpp
// Function: CKMCFile::GetCountersForRead_kmc2_both_strands(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_both_strands(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), rev_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));
		rev_kmer.from_binary_rev(transformed_read.c_str() + std::get<0>(super_kmer));

		uint32 bin_start_pos = std::get<2>(super_kmer) * single_LUT_size;
		if(kmer < rev_kmer)
			counters[counters_pos++] = count_for_kmer_kmc2(kmer, bin_start_pos);
		else
			counters[counters_pos++] = count_for_kmer_kmc2(rev_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]);
			rev_kmer.SHR_insert2bits(3 - transformed_read[i]);
			if(kmer < rev_kmer)
				counters[counters_pos++] = count_for_kmer_kmc2(kmer, bin_start_pos);
			else
				counters[counters_pos++] = count_for_kmer_kmc2(rev_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 $0x98, %rsp
movq %rsi, %r15
movq 0x8(%rsi), %rsi
movq %rdi, 0x10(%rsp)
movl 0x78(%rdi), %eax
subq %rax, %rsi
incq %rsi
movq %rdx, 0x8(%rsp)
movq %rdx, %rdi
callq 0x4123ea
leaq 0x60(%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 0x411365
movzbl (%rax,%rdx), %edi
movb (%rsi,%rdi), %dil
movb %dil, (%rax,%rdx)
incq %rdx
jmp 0x41134f
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x60(%rsp), %rsi
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
callq 0x41209a
movq 0x20(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x4113dd
movl 0x78(%rbp), %esi
leaq 0x40(%rsp), %rdi
callq 0x407f72
movl 0x78(%rbp), %esi
leaq 0x80(%rsp), %rdi
callq 0x407f72
movq 0x20(%rsp), %r13
movl 0x8(%r13), %esi
testl %esi, %esi
je 0x411402
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x4(%rsp), %rdx
andl $0x0, (%rdx)
callq 0x412a67
movq 0x20(%rsp), %r13
movl 0x8(%r13), %ecx
jmp 0x411404
movq 0x8(%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 0x4115a8
xorl %ecx, %ecx
movq 0x28(%rsp), %rax
movq %rax, 0x58(%rsp)
movl %ecx, %ebx
movl %ebx, %edi
cmpq 0x58(%rsp), %r13
je 0x411568
movl 0x8(%r13), %eax
movl %eax, %r14d
subl %ecx, %r14d
jbe 0x41145b
shlq $0x2, %rdi
movq 0x8(%rsp), %rax
addq (%rax), %rdi
movl 0x78(%rbp), %eax
leal (%r14,%rax), %esi
decl %esi
andl $0x0, 0x4(%rsp)
leaq 0x4(%rsp), %rdx
callq 0x412a67
movl 0x78(%rbp), %eax
addl %r14d, %ebx
addl %eax, %ebx
decl %ebx
movl 0x8(%r13), %eax
movl %eax, %esi
addl 0x4(%r13), %eax
movl %eax, 0x18(%rsp)
addq 0x60(%rsp), %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x412722
movl 0x8(%r13), %esi
addq 0x60(%rsp), %rsi
leaq 0x80(%rsp), %r12
movq %r12, %rdi
callq 0x412766
movq %rbp, %r15
movl 0x48(%rbp), %ebp
imull (%r13), %ebp
movq %r14, %rdi
movq %r12, %rsi
callq 0x408018
movl %ebx, %r14d
testb %al, %al
leaq 0x40(%rsp), %rax
cmovneq %rax, %r12
movq %r15, %rdi
movq %r12, %rsi
movl %ebp, 0x1c(%rsp)
movl %ebp, %edx
callq 0x412042
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movl %eax, (%rcx,%r14,4)
movl 0x8(%r13), %eax
movl 0x78(%r15), %r14d
addl %eax, %r14d
incl %ebx
addl 0x4(%r13), %eax
cmpq %rax, %r14
jae 0x411556
movq 0x60(%rsp), %rax
movzbl (%rax,%r14), %esi
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x4124a2
movq 0x60(%rsp), %rax
movb $0x3, %cl
subb (%rax,%r14), %cl
movzbl %cl, %esi
leaq 0x80(%rsp), %rbp
movq %rbp, %rdi
callq 0x41243a
movq %r12, %rdi
movq %rbp, %rsi
callq 0x408018
movl %ebx, %r15d
testb %al, %al
cmovneq %r12, %rbp
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movl 0x1c(%rsp), %edx
callq 0x412042
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movl %eax, (%rcx,%r15,4)
incq %r14
movl 0x8(%r13), %eax
jmp 0x4114dc
addq $0xc, %r13
movq 0x10(%rsp), %rbp
movl 0x18(%rsp), %ecx
jmp 0x411410
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rsi
subq %rax, %rsi
sarq $0x2, %rsi
subq %rdi, %rsi
jbe 0x411591
leaq (%rax,%rdi,4), %rdi
leaq 0x4(%rsp), %rdx
andl $0x0, (%rdx)
callq 0x412a8e
leaq 0x80(%rsp), %rdi
callq 0x40825c
leaq 0x40(%rsp), %rdi
callq 0x40825c
leaq 0x20(%rsp), %rdi
callq 0x412c88
leaq 0x60(%rsp), %rdi
callq 0x484210
movb $0x1, %al
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4115e2
jmp 0x4115dd
jmp 0x4115e2
movq %rax, %rbx
jmp 0x4115f2
jmp 0x4115dd
movq %rax, %rbx
jmp 0x4115fc
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x40825c
leaq 0x40(%rsp), %rdi
callq 0x40825c
leaq 0x20(%rsp), %rdi
callq 0x412c88
leaq 0x60(%rsp), %rdi
callq 0x484210
movq %rbx, %rdi
callq 0x4b8e10