// File: 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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x49f200
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x49f200
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
movq -0xe8(%rbp), %rax
movl 0x78(%rax), %eax
subq %rax, %rsi
addq $0x1, %rsi
callq 0x4282c0
movq -0x10(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x4a15e0
leaq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x49f100
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0x49f120
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x428350
testb $0x1, %al
jne 0x4273d4
jmp 0x427405
leaq -0x50(%rbp), %rdi
callq 0x408440
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
movq $0x1b8f8e0, %rax        # imm = 0x1B8F8E0
movb (%rax,%rcx), %cl
movq -0x60(%rbp), %rax
movb %cl, (%rax)
leaq -0x50(%rbp), %rdi
callq 0x428390
jmp 0x4273c1
movq -0xe8(%rbp), %rax
movl $0x0, -0x64(%rbp)
movl 0x78(%rax), %esi
leaq -0x80(%rbp), %rdi
callq 0x40b540
jmp 0x427421
movl $0x0, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movq -0xe8(%rbp), %rcx
movl -0x64(%rbp), %eax
addl 0x78(%rcx), %eax
subl $0x1, %eax
cmpl -0x1c(%rbp), %eax
jae 0x427754
movb $0x0, -0x95(%rbp)
movl -0x64(%rbp), %ecx
xorl %eax, %eax
cmpl -0x1c(%rbp), %ecx
movb %al, -0xf1(%rbp)
jae 0x42747e
movq -0xe8(%rbp), %rcx
movl -0x90(%rbp), %eax
cmpl 0x78(%rcx), %eax
setb %al
movb %al, -0xf1(%rbp)
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0x42748d
jmp 0x42763a
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %eax
movl %eax, %esi
callq 0x49f500
movzbl (%rax), %eax
movl %eax, %ecx
movq $0x1b8f8e0, %rax        # imm = 0x1B8F8E0
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jge 0x4275e9
movl $0x0, -0x90(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4283b0
jmp 0x4274c9
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
subl -0x94(%rbp), %eax
movl %eax, -0xf8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x420d40
movq %rax, %rcx
movl -0xf8(%rbp), %eax
subl -0x94(%rbp), %ecx
cmpl %ecx, %eax
jae 0x42750e
movl -0x64(%rbp), %eax
subl -0x94(%rbp), %eax
movl %eax, -0xfc(%rbp)
jmp 0x427523
movq -0x18(%rbp), %rdi
callq 0x420d40
subl -0x94(%rbp), %eax
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x420c40
movq %rax, -0xb0(%rbp)
movl -0x94(%rbp), %eax
movl %eax, %esi
leaq -0xb0(%rbp), %rdi
callq 0x428440
movq %rax, -0xa8(%rbp)
movl -0x9c(%rbp), %esi
movl $0x0, -0xb4(%rbp)
movq -0xa8(%rbp), %rdi
leaq -0xb4(%rbp), %rdx
callq 0x4283e0
movq %rax, -0x108(%rbp)
jmp 0x427586
movq -0x108(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl -0x9c(%rbp), %eax
addl -0x94(%rbp), %eax
movl %eax, -0x94(%rbp)
movb $0x1, -0x95(%rbp)
jmp 0x42763a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x42781f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x40bcf0
jmp 0x42781f
movl -0x90(%rbp), %eax
movl %eax, -0x10c(%rbp)
incl %eax
movl %eax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %eax
movl %eax, %esi
movl %esi, %eax
incl %eax
movl %eax, -0x64(%rbp)
callq 0x49f500
movl -0x10c(%rbp), %esi
movzbl (%rax), %eax
movl %eax, %ecx
movq $0x1b8f8e0, %rax        # imm = 0x1B8F8E0
movzbl (%rax,%rcx), %edx
leaq -0x80(%rbp), %rdi
callq 0x428480
jmp 0x427633
jmp 0x427635
jmp 0x427455
testb $0x1, -0x95(%rbp)
je 0x427648
jmp 0x427435
movq -0xe8(%rbp), %rcx
movl -0x90(%rbp), %eax
cmpl 0x78(%rcx), %eax
jne 0x42769a
movq -0xe8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x427a00
movl %eax, -0x110(%rbp)
jmp 0x427672
movq -0x18(%rbp), %rdi
movl -0x94(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x94(%rbp)
movl %eax, %eax
movl %eax, %esi
callq 0x40b8b0
movl -0x110(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x42769f
jmp 0x427754
jmp 0x4276a1
movl -0x64(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x42774f
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %eax
movl %eax, %esi
callq 0x49f500
movzbl (%rax), %eax
movl %eax, %ecx
movq $0x1b8f8e0, %rax        # imm = 0x1B8F8E0
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jge 0x4276dc
movl $0x0, -0x90(%rbp)
jmp 0x42774f
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %eax
movl %eax, %esi
movl %esi, %eax
incl %eax
movl %eax, -0x64(%rbp)
callq 0x49f500
movzbl (%rax), %eax
movl %eax, %ecx
movq $0x1b8f8e0, %rax        # imm = 0x1B8F8E0
movzbl (%rax,%rcx), %esi
leaq -0x80(%rbp), %rdi
callq 0x4285c0
jmp 0x42770c
movq -0xe8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x427a00
movl %eax, -0x114(%rbp)
jmp 0x427724
movq -0x18(%rbp), %rdi
movl -0x94(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x94(%rbp)
movl %eax, %eax
movl %eax, %esi
callq 0x40b8b0
movl -0x114(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x4276a1
jmp 0x427435
movl -0x94(%rbp), %eax
movq %rax, -0x120(%rbp)
movq -0x18(%rbp), %rdi
callq 0x420d40
movq %rax, %rcx
movq -0x120(%rbp), %rax
cmpq %rcx, %rax
jae 0x427800
movq -0x18(%rbp), %rdi
callq 0x420c40
movq %rax, -0xd0(%rbp)
movl -0x94(%rbp), %eax
movl %eax, %esi
leaq -0xd0(%rbp), %rdi
callq 0x428440
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x420d40
movq %rax, %rsi
movl -0x94(%rbp), %eax
subq %rax, %rsi
movl $0x0, -0xd4(%rbp)
movq -0xc8(%rbp), %rdi
leaq -0xd4(%rbp), %rdx
callq 0x4286d0
movq %rax, -0x128(%rbp)
jmp 0x4277e3
movq -0x128(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x420d40
movl %eax, -0x94(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x40bcf0
leaq -0x40(%rbp), %rdi
callq 0x49efd0
movb $0x1, %al
andb $0x1, %al
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x49efd0
movq -0x88(%rbp), %rdi
callq 0x4d3c10
nopw %cs:(%rax,%rax)