// File: /workspace/github_cpp_makefile_star2_O3/ChnMasterOG[P]KmerGO2/kmc_api/kmc_file.cpp
// Function: CKMCFile::GetSuperKmers(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<std::tuple<unsigned int, unsigned int, unsigned int>, std::allocator<std::tuple<unsigned int, unsigned int, unsigned int>>>&)
void CKMCFile::GetSuperKmers(const std::string& transformed_read, super_kmers_t& super_kmers)
{
	uint32 i = 0;
	uint32 len = 0; //length of super k-mer
	uint32 signature_start_pos;
	CMmer current_signature(signature_len), end_mmer(signature_len);

	while (i + kmer_length - 1 < transformed_read.length())
	{
		bool contains_N = false;
		//building first signature after 'N' or at the read beginning
		for (uint32 j = 0; j < signature_len; ++j, ++i)
		{
			if (transformed_read[i] < 0)//'N'
			{
				contains_N = true;
				break;
			}
		}
		//signature must be shorter than k-mer so if signature contains 'N', k-mer will contains it also
		if (contains_N)
		{
			++i;
			continue;
		}
		len = signature_len;
		signature_start_pos = i - signature_len;
		current_signature.insert(transformed_read.c_str() + signature_start_pos);
		end_mmer.set(current_signature);

		for (; i < transformed_read.length(); ++i)
		{
			if (transformed_read[i] < 0)//'N'
			{
				if (len >= kmer_length)
				{
					super_kmers.push_back(std::make_tuple(i - len, len, signature_map[current_signature.get()]));
				}
				len = 0;
				++i;
				break;
			}
			end_mmer.insert(transformed_read[i]);
			if (end_mmer < current_signature)//signature at the end of current k-mer is lower than current
			{
				if (len >= kmer_length)
				{
					super_kmers.push_back(std::make_tuple(i - len, len, signature_map[current_signature.get()]));
					len = kmer_length - 1;
				}
				current_signature.set(end_mmer);
				signature_start_pos = i - signature_len + 1;
			}
			else if (end_mmer == current_signature)
			{
				current_signature.set(end_mmer);
				signature_start_pos = i - signature_len + 1;
			}
			else if (signature_start_pos + kmer_length - 1 < i)//need to find new signature
			{
				super_kmers.push_back(std::make_tuple(i - len, len, signature_map[current_signature.get()]));
				len = kmer_length - 1;
				//looking for new signature
				++signature_start_pos;
				//building first signature in current k-mer
				end_mmer.insert(transformed_read.c_str() + signature_start_pos);
				current_signature.set(end_mmer);
				for (uint32 j = signature_start_pos + signature_len; j <= i; ++j)
				{
					end_mmer.insert(transformed_read[j]);
					if (end_mmer <= current_signature)
					{
						current_signature.set(end_mmer);
						signature_start_pos = j - signature_len + 1;
					}
				}
			}
			++len;
		}
	}
	if (len >= kmer_length)//last one in read
	{
		super_kmers.push_back(std::make_tuple(i - len, len, signature_map[current_signature.get()]));
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movl 0x88(%rdi), %esi
leaq 0x38(%rsp), %rdi
callq 0x415e00
movl 0x88(%r14), %esi
leaq 0x10(%rsp), %rdi
callq 0x415e00
movl 0x78(%r14), %ecx
leal -0x1(%rcx), %esi
movq 0x8(%r15), %rdx
xorl %eax, %eax
movl $0x0, %r13d
cmpq %rsi, %rdx
jbe 0x41924e
xorl %r13d, %r13d
xorl %eax, %eax
movq %rbx, 0x30(%rsp)
movl 0x88(%r14), %r12d
movq (%r15), %rsi
testl %r12d, %r12d
je 0x41903f
leal (%r12,%r13), %ecx
movl %r12d, %r8d
negl %r8d
xorl %edi, %edi
movl %r13d, %r9d
movl %r9d, %r10d
cmpb $0x0, (%rsi,%r10)
js 0x4191fb
incl %r9d
decl %edi
cmpl %edi, %r8d
jne 0x419024
movl %ecx, %r13d
movl %r13d, %ebp
subl %r12d, %ebp
addq %rbp, %rsi
leaq 0x38(%rsp), %rdi
callq 0x4193ee
movl 0x38(%rsp), %ecx
movl 0x40(%rsp), %eax
movl %ecx, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movl %r13d, %esi
movq 0x8(%r15), %rdx
cmpq %rsi, %rdx
jbe 0x4191f6
movq (%r15), %rdi
movb (%rdi,%rsi), %sil
testb %sil, %sil
js 0x419203
movzbl %sil, %edx
leal (%rdx,%rcx,4), %ecx
andl 0x14(%rsp), %ecx
movl %ecx, 0x10(%rsp)
movq 0x20(%rsp), %rdx
movl (%rdx,%rcx,4), %edx
movl %edx, 0x18(%rsp)
cmpl %eax, %edx
jae 0x4190b2
cmpl 0x78(%r14), %r12d
jae 0x41918f
movl %edx, %eax
jmp 0x4191c7
je 0x4191c7
movl 0x78(%r14), %edx
addl %ebp, %edx
decl %edx
cmpl %r13d, %edx
jae 0x4191db
movl %r13d, %ecx
subl %r12d, %ecx
movq 0x50(%r14), %rdx
movl %eax, %eax
movl (%rdx,%rax,4), %eax
movl %eax, 0x4(%rsp)
movl %r12d, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0x41980e
movl 0x78(%r14), %r12d
decl %r12d
leal 0x1(%rbp), %ebx
movq (%r15), %rsi
addq %rbx, %rsi
leaq 0x10(%rsp), %rdi
callq 0x4193ee
movl 0x10(%rsp), %ecx
movl 0x18(%rsp), %eax
movl %ecx, 0x38(%rsp)
movl %eax, 0x40(%rsp)
movl 0x88(%r14), %edx
leal (%rdx,%rbp), %esi
incl %esi
cmpl %r13d, %esi
ja 0x419186
movq (%r15), %rsi
movl 0x14(%rsp), %edi
movq 0x20(%rsp), %r8
addl $0x2, %ebp
leal (%rdx,%rbp), %r9d
decl %r9d
movzbl (%rsi,%r9), %r9d
leal (%r9,%rcx,4), %ecx
andl %edi, %ecx
movl %ecx, 0x10(%rsp)
movl (%r8,%rcx,4), %r9d
movl %r9d, 0x18(%rsp)
cmpl %eax, %r9d
ja 0x41916e
movl %ecx, 0x38(%rsp)
movl %r9d, 0x40(%rsp)
movl %r9d, %eax
movl %ebp, %ebx
leal (%rdx,%rbp), %r9d
incl %r9d
movl %ebp, %r10d
incl %r10d
decl %r9d
movl %r10d, %ebp
cmpl %r13d, %r9d
jbe 0x41913c
movl %ebx, %ebp
movq 0x30(%rsp), %rbx
jmp 0x4191db
movl %r13d, %ecx
subl %r12d, %ecx
movq 0x50(%r14), %rdx
movl %eax, %eax
movl (%rdx,%rax,4), %eax
movl %eax, 0x4(%rsp)
movl %r12d, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0x41980e
movl 0x78(%r14), %r12d
decl %r12d
movl 0x10(%rsp), %ecx
movl 0x18(%rsp), %eax
movl %ecx, 0x38(%rsp)
movl %eax, 0x40(%rsp)
movl %r13d, %ebp
subl 0x88(%r14), %ebp
incl %ebp
incl %r12d
incl %r13d
movq 0x8(%r15), %rdx
cmpq %r13, %rdx
jbe 0x4191f6
movq (%r15), %rsi
movb (%rsi,%r13), %sil
jmp 0x419079
movl %r12d, %eax
jmp 0x41923b
subl %edi, %r13d
incl %r13d
jmp 0x41923b
cmpl 0x78(%r14), %r12d
jb 0x419236
movl %r13d, %ecx
subl %r12d, %ecx
movq 0x50(%r14), %rdx
movl %eax, %eax
movl (%rdx,%rax,4), %eax
movl %eax, 0x4(%rsp)
movl %r12d, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0x41980e
movq 0x8(%r15), %rdx
incl %r13d
xorl %eax, %eax
movl 0x78(%r14), %ecx
leal (%rcx,%r13), %esi
decl %esi
cmpq %rsi, %rdx
ja 0x419006
cmpl %ecx, %eax
jb 0x419276
subl %eax, %r13d
movq 0x50(%r14), %rcx
movl 0x40(%rsp), %edx
movl (%rcx,%rdx,4), %ecx
leaq 0x4(%rsp), %rsi
movl %ecx, (%rsi)
movl %eax, 0x4(%rsi)
movl %r13d, 0x8(%rsi)
movq %rbx, %rdi
callq 0x41980e
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop