// File: /workspace/github_cpp_makefile_star2_O3/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 $0xa8, %rsp
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %rbp
movq 0x8(%rsi), %rsi
movl 0x78(%rdi), %eax
movq %rsi, 0x20(%rsp)
subq %rax, %rsi
incq %rsi
movq %rdx, %rdi
callq 0x4193bc
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rbx), %rsi
movq %rbx, 0x10(%rsp)
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %r15
movq %r15, %rdi
callq 0x408000
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x4189fd
movq 0x88(%rsp), %rcx
xorl %edx, %edx
movq $0x1b70940, %rsi        # imm = 0x1B70940
movzbl (%rcx,%rdx), %edi
movb (%rsi,%rdi), %dil
movb %dil, (%rcx,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0x4189e9
movl 0x78(%rbp), %edx
testl %edx, %edx
movq %r12, 0x28(%rsp)
je 0x418a6c
movl %edx, %eax
andl $0x3, %eax
movb $0x4, %cl
subb %al, %cl
testl %eax, %eax
movzbl %cl, %ebx
cmovel %eax, %ebx
movb %bl, 0x4c(%rsp)
movzbl %bl, %ecx
movq %rdx, %r13
addl %edx, %ecx
movl %ecx, %eax
andl $0x1f, %eax
shrl $0x5, %ecx
cmpl $0x1, %eax
sbbl $-0x1, %ecx
movl %ecx, 0x50(%rsp)
movq %rcx, 0x18(%rsp)
leal (,%rcx,8), %r12d
movq %r12, %rdi
callq 0x41bd90
movq %rax, %r15
movq %rax, 0x40(%rsp)
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x401098
movq 0x28(%rsp), %r12
movq %r13, %rdx
jmp 0x418a90
movq $0x0, 0x40(%rsp)
movl $0x0, 0x50(%rsp)
movb $0x0, 0x4c(%rsp)
movq $0x0, 0x18(%rsp)
xorl %r15d, %r15d
xorl %ebx, %ebx
movl %edx, 0x48(%rsp)
leal -0x1(%rdx), %eax
xorl %r13d, %r13d
movq 0x20(%rsp), %r11
cmpl %r11d, %eax
jae 0x418d43
movzbl %bl, %esi
leal (%rsi,%rsi), %ecx
movq $-0x1, %rax
shlq %cl, %rax
notq %rax
negb %cl
shlq %cl, %rax
notq %rax
movq 0x18(%rsp), %rbx
movl %ebx, %r14d
movq %rdx, 0x8(%rsp)
leal (%rdx,%rsi), %ecx
negl %ecx
addl %ecx, %ecx
andl $0x3e, %ecx
movq %rcx, 0x80(%rsp)
leal -0x1(%rbx), %ecx
movq %rcx, 0x78(%rsp)
leaq (,%r14,8), %rcx
movq %rcx, 0x60(%rsp)
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, 0x38(%rsp)
movq (%r12), %rcx
movq 0x8(%r12), %rdx
movq %rcx, 0x10(%rsp)
subq %rcx, %rdx
shrq $0x2, %rdx
movq %rdx, 0x58(%rsp)
movq %rsi, 0x68(%rsp)
cmpb $0x1, %sil
movl $0x0, %ecx
sbbq %rcx, %rcx
orq %rax, %rcx
movq %rcx, 0x70(%rsp)
xorl %eax, %eax
xorl %r12d, %r12d
movq %rbp, 0x30(%rsp)
cmpl %r11d, %r13d
jae 0x418bd8
cmpl 0x8(%rsp), %eax
jae 0x418bd8
movl %r13d, %ebx
movq 0x38(%rsp), %rcx
leaq (%rcx,%rbx), %rdx
movl %eax, %esi
movq 0x68(%rsp), %rcx
leal (%rcx,%rax), %edi
movl %edi, %r8d
addl %edi, %r8d
xorl %ebp, %ebp
movzbl (%rdx,%rbp), %ecx
movq $0x1b70940, %r9         # imm = 0x1B70940
movsbq (%r9,%rcx), %r9
testq %r9, %r9
js 0x418cb5
leal (%rdi,%rbp), %r10d
movl %r8d, %ecx
notb %cl
andb $0x3e, %cl
shlq %cl, %r9
shrl $0x5, %r10d
addq %r9, (%r15,%r10,8)
leaq (%rbx,%rbp), %r9
incq %r9
movq %rbp, %rcx
incq %rcx
cmpl %r11d, %r9d
jae 0x418bc9
leal (%rsi,%rbp), %r9d
incl %r9d
addl $0x2, %r8d
movq %rcx, %rbp
cmpl 0x8(%rsp), %r9d
jb 0x418b72
addl %ecx, %r13d
addl %ecx, %eax
movq 0x30(%rsp), %rbp
movq 0x18(%rsp), %rbx
cmpl 0x8(%rsp), %eax
jne 0x418d33
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
callq 0x418efa
movq 0x20(%rsp), %r11
movl %r12d, %ecx
movq 0x10(%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
incl %r12d
cmpl %r11d, %r13d
jae 0x418cae
movl %r13d, %eax
movq 0x38(%rsp), %rcx
movzbl (%rcx,%rax), %eax
movq $0x1b70940, %rcx        # imm = 0x1B70940
movsbq (%rcx,%rax), %rax
testq %rax, %rax
js 0x418d1b
movq (%r15), %rcx
shlq $0x2, %rcx
andq 0x70(%rsp), %rcx
movq %rcx, (%r15)
cmpl $0x2, %ebx
jb 0x418c6b
movl $0x1, %edx
movq (%r15,%rdx,8), %rsi
movq %rsi, %rdi
shrq $0x3e, %rdi
addq %rcx, %rdi
movq %rdi, -0x8(%r15,%rdx,8)
shlq $0x2, %rsi
movq %rsi, (%r15,%rdx,8)
incq %rdx
movq %rsi, %rcx
cmpq %rdx, %r14
jne 0x418c45
movq 0x80(%rsp), %rcx
shlq %cl, %rax
movq 0x78(%rsp), %rcx
addq %rax, (%r15,%rcx,8)
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
callq 0x418efa
incl %r13d
movl %r12d, %ecx
movq 0x10(%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
incl %r12d
movq 0x20(%rsp), %r11
cmpl %r11d, %r13d
jne 0x418c0b
movl %r11d, %r13d
movq 0x8(%rsp), %rax
jmp 0x418d1d
movq %r15, %rdi
xorl %esi, %esi
movq 0x60(%rsp), %rdx
callq 0x401098
subl %r12d, %r13d
leal 0x1(%r13,%rbp), %eax
movq 0x58(%rsp), %rcx
movl %ecx, %edx
subl %r12d, %edx
cmpl %edx, %eax
cmovbl %eax, %edx
testl %edx, %edx
je 0x418cfe
movl %r12d, %eax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
movl %edx, %r13d
movl %edx, %edx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x401098
movl %r13d, %edx
leaq (%rbx,%rbp), %r13
incq %r13
addl %edx, %r12d
xorl %eax, %eax
movq 0x30(%rsp), %rbp
movq 0x20(%rsp), %r11
movq 0x18(%rsp), %rbx
jmp 0x418d1d
xorl %eax, %eax
movl 0x78(%rbp), %ecx
movq %rcx, 0x8(%rsp)
addl %r13d, %ecx
decl %ecx
cmpl %r11d, %ecx
jb 0x418b41
movl %r12d, %r13d
leaq 0x98(%rsp), %r14
movq 0x28(%rsp), %r12
movq (%r12), %rax
movq 0x8(%r12), %rdx
movq %rdx, %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r13, %rcx
jbe 0x418d75
leaq (%rax,%r13,4), %rdi
subq %rdi, %rdx
addq $-0x4, %rdx
andq $-0x4, %rdx
addq $0x4, %rdx
xorl %esi, %esi
callq 0x401098
testq %r15, %r15
je 0x418d82
movq %r15, %rdi
callq 0x41aea0
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x418d9f
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x41ae90
movb $0x1, %al
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x418dd3
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x41ae90
movq %rbx, %rdi
callq 0x4bfce0
nop