// File: /workspace/github_cpp_makefile_star2_O1/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 %rsi, %rbx
movq 0x8(%rsi), %rsi
movq %rdi, %r15
movl 0x78(%rdi), %eax
movq %rsi, 0x8(%rsp)
subq %rax, %rsi
incq %rsi
movq %rdx, 0x10(%rsp)
movq %rdx, %rdi
callq 0x419934
leaq 0x78(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rbx), %rsi
movq %rbx, 0x30(%rsp)
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x40805e
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x418f99
movq 0x68(%rsp), %rcx
xorl %edx, %edx
movq $0x1b71940, %rsi        # imm = 0x1B71940
movzbl (%rcx,%rdx), %edi
movb (%rsi,%rdi), %dil
movb %dil, (%rcx,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0x418f85
movq %r15, %rdi
movl 0x78(%r15), %r15d
testl %r15d, %r15d
movq %rdi, (%rsp)
je 0x419000
movl %r15d, %eax
andl $0x3, %eax
movb $0x4, %cl
subb %al, %cl
testl %eax, %eax
movzbl %cl, %ecx
cmovel %eax, %ecx
movb %cl, 0x24(%rsp)
movzbl %cl, %r13d
addl %r15d, %r13d
movl %r13d, %eax
andl $0x1f, %eax
shrl $0x5, %r13d
cmpl $0x1, %eax
sbbl $-0x1, %r13d
movl %r13d, 0x28(%rsp)
shll $0x3, %r13d
movq %r13, %rdi
callq 0x41c2a0
movq %rax, 0x18(%rsp)
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x401098
movq (%rsp), %rdi
jmp 0x419016
movq $0x0, 0x18(%rsp)
movl $0x0, 0x28(%rsp)
movb $0x0, 0x24(%rsp)
leaq 0x18(%rsp), %rdx
movl %r15d, 0x8(%rdx)
movzbl 0xc(%rdx), %esi
leal (%rsi,%rsi), %ecx
movq $-0x1, %rax
shlq %cl, %rax
movq (%rdx), %rbp
movl 0x10(%rdx), %ebx
notq %rax
negb %cl
shlq %cl, %rax
leaq (,%rbx,8), %rcx
movq %rcx, 0x40(%rsp)
notq %rax
addl %esi, %r15d
negl %r15d
addl %r15d, %r15d
andl $0x3e, %r15d
movq %r15, 0x58(%rsp)
leal -0x1(%rbx), %ecx
movq %rcx, 0x50(%rsp)
xorl %r13d, %r13d
movq %rsi, 0x38(%rsp)
cmpl $0x1, %esi
movl $0x0, %ecx
sbbq %rcx, %rcx
orq %rax, %rcx
movq %rcx, 0x48(%rsp)
movq $0x1b71940, %r11        # imm = 0x1B71940
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x8(%rsp), %r9
movl 0x78(%rdi), %eax
addl %r14d, %eax
decl %eax
cmpl %r9d, %eax
jae 0x4192c0
cmpl %r9d, %r14d
setb %al
cmpl 0x78(%rdi), %r12d
setb %r15b
andb %al, %r15b
cmpb $0x1, %r15b
jne 0x4191a5
movq 0x30(%rsp), %rax
movq (%rax), %rdx
movl %r14d, %eax
movzbl (%rdx,%rax), %ecx
movb (%r11,%rcx), %cl
testb %cl, %cl
js 0x419136
movq 0x38(%rsp), %rsi
addl %r12d, %esi
leal (%rsi,%rsi), %r10d
incl %r12d
movzbl %cl, %r8d
movl %r10d, %ecx
notb %cl
andb $0x3e, %cl
shlq %cl, %r8
movl %esi, %ecx
shrl $0x5, %ecx
addq %r8, (%rbp,%rcx,8)
leal 0x1(%rax), %ecx
cmpl %r9d, %ecx
setb %cl
cmpl 0x78(%rdi), %r12d
setb %r15b
andb %cl, %r15b
je 0x4191a0
movzbl 0x1(%rdx,%rax), %ecx
movb (%r11,%rcx), %cl
incl %esi
addl $0x2, %r10d
incl %r12d
incq %rax
testb %cl, %cl
jns 0x4190e7
movl %eax, %r14d
movq %rbp, %rdi
xorl %esi, %esi
movq 0x40(%rsp), %rdx
callq 0x401098
incl %r14d
movl %r14d, %ecx
movq %r13, %r12
subl %r12d, %ecx
movq 0x10(%rsp), %rdx
movq (%rdx), %rax
movq 0x8(%rdx), %r13
subq %rax, %r13
shrq $0x2, %r13
subl %r12d, %r13d
cmpl %r13d, %ecx
cmovbl %ecx, %r13d
testl %r13d, %r13d
je 0x419188
movl %r12d, %ecx
leaq (%rax,%rcx,4), %rdi
movl %r13d, %edx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x401098
addl %r12d, %r13d
xorl %r12d, %r12d
movq (%rsp), %rdi
movq 0x8(%rsp), %r9
movq $0x1b71940, %r11        # imm = 0x1B71940
jmp 0x4191a5
incl %eax
movl %eax, %r14d
testb %r15b, %r15b
je 0x4191b1
xorl %eax, %eax
jmp 0x4192b8
movb $0x1, %al
cmpl 0x78(%rdi), %r12d
jne 0x4192b8
leaq 0x18(%rsp), %rsi
callq 0x419478
movq 0x8(%rsp), %r9
movl %r13d, %ecx
movq 0x10(%rsp), %rdx
movq (%rdx), %r15
movl %eax, (%r15,%rcx,4)
incl %r13d
cmpl %r9d, %r14d
jae 0x4192a0
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x60(%rsp)
movq $0x1b71940, %r11        # imm = 0x1B71940
movl %r14d, %eax
movq 0x60(%rsp), %rcx
movzbl (%rcx,%rax), %eax
movsbq (%r11,%rax), %rax
testq %rax, %rax
js 0x4192af
movq (%rbp), %rcx
shlq $0x2, %rcx
andq 0x48(%rsp), %rcx
movq %rcx, (%rbp)
cmpl $0x2, %ebx
movq (%rsp), %rdi
jb 0x419260
movq (%rbp), %rdx
movl $0x1, %ecx
movq (%rbp,%rcx,8), %rsi
movq %rsi, %r8
shrq $0x3e, %r8
addq %rdx, %r8
movq %r8, -0x8(%rbp,%rcx,8)
shlq $0x2, %rsi
movq %rsi, (%rbp,%rcx,8)
incq %rcx
movq %rsi, %rdx
cmpq %rcx, %rbx
jne 0x419238
movq 0x58(%rsp), %rcx
shlq %cl, %rax
movq 0x50(%rsp), %rcx
addq %rax, (%rbp,%rcx,8)
leaq 0x18(%rsp), %rsi
callq 0x419478
incl %r14d
movl %r13d, %ecx
movl %eax, (%r15,%rcx,4)
incl %r13d
movq 0x8(%rsp), %r9
cmpl %r9d, %r14d
movq $0x1b71940, %r11        # imm = 0x1B71940
jne 0x4191fb
jmp 0x4192b2
xorl %eax, %eax
movq (%rsp), %rdi
movq $0x1b71940, %r11        # imm = 0x1B71940
jmp 0x4192b8
xorl %r12d, %r12d
xorl %eax, %eax
movq (%rsp), %rdi
testb %al, %al
je 0x419095
movl %r13d, %eax
movq 0x10(%rsp), %rdx
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
movq %rdx, %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
cmpq %rax, %rsi
jbe 0x4192f8
leaq (%rcx,%rax,4), %rdi
subq %rdi, %rdx
addq $-0x4, %rdx
andq $-0x4, %rdx
addq $0x4, %rdx
xorl %esi, %esi
callq 0x401098
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
leaq 0x78(%rsp), %rbx
je 0x41930c
callq 0x41b3b0
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x419323
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x41b3a0
movb $0x1, %al
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r14, %rdi
je 0x419351
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x41b3a0
movq %rbx, %rdi
callq 0x4c0230
nop