// File: /workspace/github_cpp_makefile_star2_O2/ChnMasterOG[P]KmerGO2/kmc_api/kmc_file.cpp
// Function: CKMCFile::GetCountersForRead_kmc1(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<unsigned int, std::allocator<unsigned int>>&)
bool CKMCFile::GetCountersForRead_kmc1(const std::string& read, std::vector<uint32>& counters)
{	
	uint32 read_len = static_cast<uint32>(read.length());
	counters.resize(read.length() - kmer_length + 1);
	std::string transformed_read = read;
	for (char& c : transformed_read)
		c = CKmerAPI::num_codes[(uchar)c];

	uint32 i = 0;
	CKmerAPI kmer(kmer_length);
	uint32 pos = 0;
	
	uint32 counters_pos = 0;

	while (i + kmer_length - 1 < read_len)
	{
		bool contains_N = false;
		while (i < read_len && pos < kmer_length)
		{
			if (CKmerAPI::num_codes[(uchar)read[i]] < 0)
			{
				pos = 0;
				kmer.clear();
				++i;
				uint32 wrong_kmers = MIN(i - counters_pos, static_cast<uint32>(counters.size()) - counters_pos);
				fill_n(counters.begin() + counters_pos, wrong_kmers, 0);
				counters_pos += wrong_kmers;
				contains_N = true;
				break;
			}
			else
				kmer.insert2bits(pos++, CKmerAPI::num_codes[(uchar)read[i++]]);
		}
		if (contains_N)
			continue;
		if (pos == kmer_length)
		{			
			counters[counters_pos++] = count_for_kmer_kmc1(kmer);
		}
		else
			break;

		while (i < read_len)
		{
			if (CKmerAPI::num_codes[(uchar)read[i]] < 0)
			{
				pos = 0;
				break;
			}
			kmer.SHL_insert2bits(CKmerAPI::num_codes[(uchar)read[i++]]);
			counters[counters_pos++] = count_for_kmer_kmc1(kmer);
		}
	}
	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 $0x88, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq 0x8(%rsi), %rsi
movq %rdi, 0x8(%rsp)
movl 0x78(%rdi), %eax
movq %rsi, 0x18(%rsp)
subq %rax, %rsi
incq %rsi
movq %rdx, %rdi
callq 0x4123ea
leaq 0x68(%rsp), %r13
movq %r13, %rdi
movq %r14, 0x38(%rsp)
movq %r14, %rsi
callq 0x486820
movq (%r13), %rax
movq 0x8(%r13), %rcx
xorl %edx, %edx
movq $0x1b6b940, %rdi        # imm = 0x1B6B940
cmpq %rdx, %rcx
je 0x411cd0
movzbl (%rax,%rdx), %esi
movb (%rdi,%rsi), %sil
movb %sil, (%rax,%rdx)
incq %rdx
jmp 0x411cba
movq 0x8(%rsp), %rax
movl 0x78(%rax), %esi
leaq 0x48(%rsp), %rdi
callq 0x407f72
movl 0x18(%rsp), %eax
movq %rax, 0x40(%rsp)
xorl %r12d, %r12d
xorl %ecx, %ecx
xorl %r13d, %r13d
movq %rbx, 0x28(%rsp)
movq 0x8(%rsp), %rax
movl 0x78(%rax), %ebp
leal -0x1(%r13,%rbp), %eax
movl %r12d, %r14d
cmpl 0x18(%rsp), %eax
jae 0x411e87
movq %r14, 0x30(%rsp)
movq %r13, 0x60(%rsp)
movl %r13d, %r13d
movl %ecx, 0x24(%rsp)
movl %ecx, %ebx
xorl %r14d, %r14d
leaq (%r14,%r13), %r15
cmpq 0x40(%rsp), %r15
jae 0x411d77
leaq (%rbx,%r14), %rsi
cmpl %ebp, %esi
jae 0x411d77
movq 0x38(%rsp), %rax
movq (%rax), %rax
addq %r13, %rax
movzbl (%r14,%rax), %eax
movq $0x1b6b940, %rcx        # imm = 0x1B6B940
movb (%rcx,%rax), %al
testb %al, %al
js 0x411e0d
movzbl %al, %edx
leaq 0x48(%rsp), %rdi
callq 0x41241c
movq 0x8(%rsp), %rax
movl 0x78(%rax), %ebp
incq %r14
jmp 0x411d28
movl 0x24(%rsp), %eax
addl %r14d, %eax
cmpl %ebp, %eax
movq 0x28(%rsp), %rbx
movq 0x30(%rsp), %r14
jne 0x411e87
movq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x411ff0
movq (%rbx), %rcx
movl %eax, (%rcx,%r14,4)
movq 0x18(%rsp), %rax
cmpl %eax, %r15d
movl %eax, %r13d
cmoval %r15d, %r13d
incl %r12d
cmpq 0x40(%rsp), %r15
jae 0x411e76
movq 0x38(%rsp), %rax
movq (%rax), %rax
movzbl (%rax,%r15), %eax
movq $0x1b6b940, %rcx        # imm = 0x1B6B940
movb (%rcx,%rax), %al
testb %al, %al
js 0x411e7d
movzbl %al, %esi
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0x4124a2
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x411ff0
incq %r15
movl %r12d, %ecx
movq (%rbx), %rdx
movl %eax, (%rdx,%rcx,4)
jmp 0x411db5
movq 0x48(%rsp), %rdi
movl 0x58(%rsp), %edx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x401090
movq 0x60(%rsp), %rax
subl %r12d, %eax
addl %r14d, %eax
incl %eax
movq 0x28(%rsp), %rbx
movq (%rbx), %rcx
movq 0x8(%rbx), %rbp
subq %rcx, %rbp
shrq $0x2, %rbp
subl %r12d, %ebp
cmpl %ebp, %eax
cmovbl %eax, %ebp
movq 0x30(%rsp), %rax
leaq (%rcx,%rax,4), %rdi
andl $0x0, 0x14(%rsp)
movl %ebp, %esi
leaq 0x14(%rsp), %rdx
callq 0x412a67
addq %r14, %r13
incq %r13
addl %r12d, %ebp
movl %ebp, %r12d
xorl %ecx, %ecx
jmp 0x411cf8
movl %ebp, %ecx
jmp 0x411cf8
xorl %ecx, %ecx
movl %r15d, %r13d
jmp 0x411cf8
movq (%rbx), %rax
movq 0x8(%rbx), %rsi
subq %rax, %rsi
sarq $0x2, %rsi
subq %r14, %rsi
jbe 0x411eab
leaq (%rax,%r14,4), %rdi
leaq 0x14(%rsp), %rdx
andl $0x0, (%rdx)
callq 0x412a8e
leaq 0x48(%rsp), %rdi
callq 0x40825c
leaq 0x68(%rsp), %rdi
callq 0x484210
movb $0x1, %al
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x411eda
movq %rax, %rbx
jmp 0x411ee7
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x40825c
leaq 0x68(%rsp), %rdi
callq 0x484210
movq %rbx, %rdi
callq 0x4b8e10
nop