// File: /workspace/github_cpp_makefile_star2_O3/ChnMasterOG[P]KmerGO2/kmc_api/kmc_file.cpp
// Function: CKMCFile::GetCountersForRead_kmc1_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_kmc1_both_strands(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), kmer_rev(kmer_length);
	uint32 pos = 0;
	uint32 rev_pos = kmer_length - 1;

	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;
				rev_pos = kmer_length - 1;
				kmer.clear();
				kmer_rev.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_rev.insert2bits(rev_pos--, 3 - CKmerAPI::num_codes[(uchar)read[i]]);
				kmer.insert2bits(pos++, CKmerAPI::num_codes[(uchar)read[i++]]);
				
			}
		}
		if (contains_N)
			continue;
		if (pos == kmer_length)
		{
			if(kmer < kmer_rev)
				counters[counters_pos++] = count_for_kmer_kmc1(kmer);
			else
				counters[counters_pos++] = count_for_kmer_kmc1(kmer_rev);
		}
		else
			break;

		while (i < read_len)
		{
			if (CKmerAPI::num_codes[(uchar)read[i]] < 0)
			{
				pos = 0;
				break;
			}
			kmer_rev.SHR_insert2bits(3 - CKmerAPI::num_codes[(uchar)read[i]]);
			kmer.SHL_insert2bits(CKmerAPI::num_codes[(uchar)read[i++]]);
			if(kmer < kmer_rev)
				counters[counters_pos++] = count_for_kmer_kmc1(kmer);
			else
				counters[counters_pos++] = count_for_kmer_kmc1(kmer_rev);
		}
	}
	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 $0x108, %rsp            # imm = 0x108
movq %rsi, %r13
movq %rdi, %r14
movq 0x8(%rsi), %rsi
movl 0x78(%rdi), %eax
movq %rsi, 0x20(%rsp)
subq %rax, %rsi
incq %rsi
movq %rdx, 0x38(%rsp)
movq %rdx, %rdi
callq 0x4193bc
leaq 0xa8(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %r15
movq %r15, %rdi
callq 0x408000
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x418307
movq 0x98(%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 0x4182f3
movl 0x78(%r14), %ecx
testl %ecx, %ecx
je 0x4183be
movq %r13, 0x18(%rsp)
movl %ecx, %eax
andl $0x3, %eax
movq %rcx, %rbx
movb $0x4, %cl
subb %al, %cl
testl %eax, %eax
movzbl %cl, %ebp
cmovel %eax, %ebp
movb %bpl, 0x4c(%rsp)
movzbl %bpl, %r12d
addl %ebx, %r12d
movl %r12d, %eax
andl $0x1f, %eax
shrl $0x5, %r12d
cmpl $0x1, %eax
sbbl $-0x1, %r12d
movl %r12d, 0x50(%rsp)
leal (,%r12,8), %r13d
movq %r13, %rdi
callq 0x41bd90
movq %rax, %r15
movq %rax, 0x40(%rsp)
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x401098
movq %rbx, 0x8(%rsp)
movl %ebx, 0x48(%rsp)
movb %bpl, 0x8c(%rsp)
movq %r12, %rbx
movl %r12d, 0x90(%rsp)
movq %r13, %rdi
callq 0x41bd90
movq %rax, %r12
movq %rax, 0x80(%rsp)
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x401098
movq 0x8(%rsp), %rcx
movq %rbx, %rdi
movq 0x18(%rsp), %r13
jmp 0x4183f1
xorl %edi, %edi
movq %rdi, 0x40(%rsp)
movl %edi, 0x50(%rsp)
movb %dil, 0x4c(%rsp)
movl %edi, 0x48(%rsp)
movq %rdi, 0x80(%rsp)
movl %edi, 0x90(%rsp)
movb %dil, 0x8c(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %ebp, %ebp
movl %ecx, 0x88(%rsp)
leal -0x1(%rcx), %eax
xorl %ebx, %ebx
movq 0x20(%rsp), %rdx
movq %rax, 0x28(%rsp)
cmpl %edx, %eax
jae 0x4188aa
movzbl %bpl, %r8d
leal -0x1(%rdi), %r9d
movq %r9, 0x70(%rsp)
leal (%rcx,%r8), %r10d
movq %rcx, %rsi
movl %r9d, %ecx
shll $0x6, %ecx
subl %r10d, %ecx
subl %r10d, %ecx
movq $-0x1, %rax
movq $-0x1, %r11
shlq %cl, %r11
movq %r11, 0xe8(%rsp)
leal (%r8,%r8), %ecx
shlq %cl, %rax
notq %rax
movq %rcx, 0xe0(%rsp)
negb %cl
shlq %cl, %rax
movl %edi, %ebp
notq %rax
negl %r10d
addl %r10d, %r10d
andl $0x3e, %r10d
movq %r10, 0xf0(%rsp)
leaq (,%rbp,8), %rcx
movq %rcx, 0x60(%rsp)
movq (%r13), %rcx
movq %rcx, 0x18(%rsp)
movq 0x38(%rsp), %rcx
movq (%rcx), %r10
movq 0x8(%rcx), %r11
movq %rsi, %rcx
movq %r10, 0x68(%rsp)
subq %r10, %r11
shrq $0x2, %r11
movq %r11, 0xb8(%rsp)
movq %r8, 0xc0(%rsp)
cmpb $0x1, %r8b
movl $0x0, %esi
sbbq %rsi, %rsi
orq %rax, %rsi
movq %rsi, 0xd8(%rsp)
leaq -0x1(%rbp), %rax
movq %rax, 0x78(%rsp)
leaq -0x1(%r9), %rax
movq %rax, 0xd0(%rsp)
xorl %esi, %esi
xorl %r13d, %r13d
movq %rdi, 0x10(%rsp)
movq %r14, 0x58(%rsp)
cmpl %edx, %ebx
movq %rcx, 0x8(%rsp)
jae 0x418611
cmpl %ecx, %esi
jae 0x418611
movl %ebx, %ecx
movq 0x18(%rsp), %rax
movq %rcx, 0x30(%rsp)
leaq (%rax,%rcx), %rdx
movl %esi, %eax
movq %rax, 0xf8(%rsp)
movq 0xc0(%rsp), %r11
movq %rsi, 0xc8(%rsp)
leal (%r11,%rsi), %edi
movl %edi, %r8d
addl %edi, %r8d
movq 0x28(%rsp), %rax
movl %eax, %ecx
movq %rcx, 0x100(%rsp)
leal (%r11,%rax), %r10d
addl %r10d, %r10d
xorl %r14d, %r14d
movzbl (%rdx,%r14), %ecx
movq $0x1b70940, %r9         # imm = 0x1B70940
movb (%r9,%rcx), %cl
testb %cl, %cl
js 0x41880a
movb $0x3, %al
subb %cl, %al
movzbl %al, %eax
movq 0x100(%rsp), %rcx
leal (%rcx,%r11), %esi
movl %r10d, %ecx
notb %cl
andb $0x3e, %cl
shlq %cl, %rax
shrl $0x5, %esi
addq %rax, (%r12,%rsi,8)
movzbl (%rdx,%r14), %eax
movzbl (%r9,%rax), %eax
leal (%rdi,%r14), %esi
movl %r8d, %ecx
notb %cl
andb $0x3e, %cl
shlq %cl, %rax
shrl $0x5, %esi
addq %rax, (%r15,%rsi,8)
movl %r14d, %ecx
movq 0x30(%rsp), %rax
addl %ecx, %eax
incl %eax
incq %r14
cmpl 0x20(%rsp), %eax
jae 0x4185e7
movq 0xf8(%rsp), %rax
addl %ecx, %eax
incl %eax
addl $0x2, %r8d
decq %r11
addl $-0x2, %r10d
cmpl 0x8(%rsp), %eax
jb 0x418554
addl %r14d, %ebx
movq 0xc8(%rsp), %rsi
addl %r14d, %esi
movq 0x28(%rsp), %rax
subl %r14d, %eax
movq %rax, 0x28(%rsp)
movq 0x58(%rsp), %r14
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rdi
cmpl %ecx, %esi
jne 0x4188a7
testl %edi, %edi
movq 0x78(%rsp), %rdi
je 0x41865b
movq (%r12), %rcx
movq (%r15), %rdx
leaq 0x40(%rsp), %rsi
cmpq %rdx, %rcx
ja 0x418663
xorl %eax, %eax
cmpq %rdx, %rcx
jb 0x41865b
cmpq %rax, %rdi
je 0x41865b
movq 0x8(%r12,%rax,8), %rcx
movq 0x8(%r15,%rax,8), %rdx
incq %rax
cmpq %rdx, %rcx
jbe 0x418635
leaq 0x40(%rsp), %rsi
cmpq %rbp, %rax
jb 0x418663
leaq 0x80(%rsp), %rsi
movq %r14, %rdi
callq 0x418efa
movl %r13d, %ecx
movq 0x68(%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
incl %r13d
movq 0x20(%rsp), %rdx
cmpl %edx, %ebx
jae 0x418800
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x70(%rsp), %r10
movq $0x1b70940, %r11        # imm = 0x1B70940
movl %ebx, %eax
movq 0x18(%rsp), %rcx
movzbl (%rcx,%rax), %ecx
movb (%r11,%rcx), %cl
testb %cl, %cl
js 0x41888d
testq %r10, %r10
movq 0x10(%rsp), %r9
je 0x4186f7
movq 0xd0(%rsp), %rsi
movq %rsi, %rdx
movq 0x8(%r12,%rsi,8), %rdi
movq %rdi, %r8
shrq $0x2, %r8
movq %r8, 0x8(%r12,%rsi,8)
movl %esi, %r8d
movq (%r12,%r8,8), %r8
shldq $0x3e, %rdi, %r8
movq %r8, 0x8(%r12,%rsi,8)
decq %rdx
testl %esi, %esi
movq %rdx, %rsi
jne 0x4186cb
shrq $0x2, (%r12)
movq 0xe8(%rsp), %rdx
andq %rdx, (%r12,%r10,8)
movb $0x3, %dl
subb %cl, %dl
movzbl %dl, %edx
shlq $0x3e, %rdx
movq 0xe0(%rsp), %rcx
shrq %cl, %rdx
addq %rdx, (%r12)
movq (%r15), %rcx
shlq $0x2, %rcx
andq 0xd8(%rsp), %rcx
movq 0x18(%rsp), %rdx
movzbl (%rdx,%rax), %eax
movzbl (%r11,%rax), %eax
movq %rcx, (%r15)
cmpl $0x2, %r9d
jb 0x418773
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, %rbp
jne 0x41874d
movq 0xf0(%rsp), %rcx
shlq %cl, %rax
addq %rax, (%r15,%r10,8)
testl %r9d, %r9d
movq 0x78(%rsp), %rdi
je 0x4187c5
movq (%r12), %rcx
movq (%r15), %rdx
leaq 0x40(%rsp), %rsi
cmpq %rdx, %rcx
ja 0x4187cd
xorl %eax, %eax
cmpq %rdx, %rcx
jb 0x4187c5
cmpq %rax, %rdi
je 0x4187c5
movq 0x8(%r12,%rax,8), %rcx
movq 0x8(%r15,%rax,8), %rdx
incq %rax
cmpq %rdx, %rcx
jbe 0x41879f
leaq 0x40(%rsp), %rsi
cmpq %rbp, %rax
jb 0x4187cd
leaq 0x80(%rsp), %rsi
incl %ebx
movq %r14, %rdi
callq 0x418efa
movq 0x70(%rsp), %r10
movl %r13d, %ecx
movq 0x30(%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
incl %r13d
movq 0x20(%rsp), %rdx
cmpl %edx, %ebx
movq $0x1b70940, %r11        # imm = 0x1B70940
jne 0x41869f
movl %edx, %ebx
movq 0x8(%rsp), %rax
jmp 0x41888f
movq %r15, %rdi
xorl %esi, %esi
movq 0x60(%rsp), %rdx
callq 0x401098
movq %r12, %rdi
xorl %esi, %esi
movq 0x60(%rsp), %rdx
callq 0x401098
subl %r13d, %ebx
leal (%rbx,%r14), %eax
incl %eax
movq 0xb8(%rsp), %rcx
movl %ecx, %edx
subl %r13d, %edx
cmpl %edx, %eax
cmovbl %eax, %edx
testl %edx, %edx
je 0x418864
movl %r13d, %eax
movq 0x68(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
movl %edx, %ebx
movl %edx, %edx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x401098
movl %ebx, %edx
movq 0x8(%rsp), %rax
decl %eax
movq 0x30(%rsp), %rcx
leaq (%rcx,%r14), %rbx
incq %rbx
addl %edx, %r13d
movq %rax, 0x28(%rsp)
xorl %eax, %eax
movq 0x58(%rsp), %r14
movq 0x20(%rsp), %rdx
jmp 0x41888f
xorl %eax, %eax
movq 0x10(%rsp), %rdi
movl %eax, %esi
movl 0x78(%r14), %ecx
leal (%rbx,%rcx), %eax
decl %eax
cmpl %edx, %eax
jb 0x4184f2
movl %r13d, %ebx
movq 0x38(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
movq %rdx, %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0x4188df
leaq (%rax,%rbx,4), %rdi
subq %rdi, %rdx
addq $-0x4, %rdx
andq $-0x4, %rdx
addq $0x4, %rdx
xorl %esi, %esi
callq 0x401098
testq %r12, %r12
je 0x4188ec
movq %r12, %rdi
callq 0x41aea0
testq %r15, %r15
je 0x4188f9
movq %r15, %rdi
callq 0x41aea0
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x41891e
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x41ae90
movb $0x1, %al
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r15, %rdi
callq 0x41aea0
jmp 0x418942
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x418967
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x41ae90
movq %rbx, %rdi
callq 0x4bfce0
nop