// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %r14
movl 0x88(%rdi), %esi
leaq 0x38(%rsp), %rdi
callq 0x416258
movl 0x88(%r14), %esi
leaq 0x18(%rsp), %rdi
callq 0x416258
movl 0x78(%r14), %eax
leal -0x1(%rax), %ecx
xorl %r12d, %r12d
movl $0x0, %r13d
cmpq %rcx, 0x8(%r15)
jbe 0x4197c2
xorl %r13d, %r13d
xorl %r12d, %r12d
movl 0x88(%r14), %ebx
testl %ebx, %ebx
je 0x4195b4
movq (%r15), %rax
leal (%rbx,%r13), %ecx
movl %ebx, %esi
negl %esi
xorl %edx, %edx
movl %r13d, %edi
movl %edi, %r8d
cmpb $0x0, (%rax,%r8)
js 0x41976d
incl %edi
decl %edx
cmpl %edx, %esi
jne 0x41959b
movl %ecx, %r13d
movl %r13d, %ebp
subl %ebx, %ebp
movq (%r15), %rsi
addq %rbp, %rsi
leaq 0x38(%rsp), %rdi
callq 0x419966
movl 0x38(%rsp), %eax
movl 0x40(%rsp), %ecx
movl %eax, 0x18(%rsp)
movl %ecx, 0x20(%rsp)
movl %r13d, %eax
cmpq %rax, 0x8(%r15)
jbe 0x419768
movl %ebx, %r12d
movq (%r15), %rcx
movsbl (%rcx,%rax), %eax
testl %eax, %eax
js 0x419775
movl 0x18(%rsp), %ecx
leal (%rax,%rcx,4), %edx
andl 0x1c(%rsp), %edx
movl %edx, 0x18(%rsp)
movq 0x28(%rsp), %rax
movl (%rax,%rdx,4), %ecx
movl %ecx, 0x20(%rsp)
movl 0x40(%rsp), %eax
cmpl %eax, %ecx
jae 0x41965f
cmpl 0x78(%r14), %r12d
jb 0x419651
movl %r13d, %ecx
subl %r12d, %ecx
movq 0x50(%r14), %rdx
movl (%rdx,%rax,4), %eax
movl %eax, 0x4(%rsp)
movl %r12d, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x419d74
movl 0x78(%r14), %r12d
decl %r12d
movl 0x18(%rsp), %eax
movl 0x20(%rsp), %ecx
movl %eax, 0x38(%rsp)
jmp 0x419667
cmpl %eax, %ecx
jne 0x41968f
movl %edx, 0x38(%rsp)
movl %ecx, 0x40(%rsp)
movl %r13d, %ebp
subl 0x88(%r14), %ebp
incl %ebp
incl %r12d
incl %r13d
movq %r13, %rax
cmpq %r13, 0x8(%r15)
ja 0x4195e9
jmp 0x4197ae
movl 0x78(%r14), %ecx
addl %ebp, %ecx
decl %ecx
cmpl %r13d, %ecx
jae 0x419677
movl %r13d, %ecx
subl %r12d, %ecx
movq 0x50(%r14), %rdx
movl (%rdx,%rax,4), %eax
movl %eax, 0x4(%rsp)
movl %r12d, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x419d74
movl 0x78(%r14), %r12d
decl %r12d
leal 0x1(%rbp), %ebx
movq (%r15), %rsi
addq %rbx, %rsi
leaq 0x18(%rsp), %rdi
callq 0x419966
movl 0x18(%rsp), %eax
movl 0x20(%rsp), %ecx
movl %eax, 0x38(%rsp)
movl %ecx, 0x40(%rsp)
movl 0x88(%r14), %eax
leal (%rax,%rbp), %ecx
incl %ecx
cmpl %r13d, %ecx
ja 0x419761
movl 0x40(%rsp), %edi
movl 0x18(%rsp), %ecx
movl 0x1c(%rsp), %edx
movq (%r15), %rsi
movq 0x28(%rsp), %r8
addl $0x2, %ebp
leal (%rax,%rbp), %r9d
decl %r9d
movzbl (%rsi,%r9), %r9d
leal (%r9,%rcx,4), %ecx
andl %edx, %ecx
movl %ecx, 0x18(%rsp)
movl (%r8,%rcx,4), %r9d
movl %r9d, 0x20(%rsp)
cmpl %edi, %r9d
ja 0x419749
movl %ecx, 0x38(%rsp)
movl %r9d, 0x40(%rsp)
movl %r9d, %edi
movl %ebp, %ebx
leal (%rax,%rbp), %r9d
incl %r9d
movl %ebp, %r10d
incl %r10d
decl %r9d
movl %r10d, %ebp
cmpl %r13d, %r9d
jbe 0x419717
movl %ebx, %ebp
jmp 0x419677
movl %ebx, %r12d
jmp 0x4197ae
subl %edx, %r13d
incl %r13d
jmp 0x4197ae
cmpl 0x78(%r14), %r12d
jb 0x4197a8
movl %r13d, %eax
subl %r12d, %eax
movq 0x50(%r14), %rcx
movl 0x40(%rsp), %edx
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x4(%rsp)
movl %r12d, 0x8(%rsp)
movl %eax, 0xc(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x419d74
incl %r13d
xorl %r12d, %r12d
movl 0x78(%r14), %eax
leal (%rax,%r13), %ecx
decl %ecx
cmpq %rcx, 0x8(%r15)
ja 0x419580
cmpl %eax, %r12d
jb 0x4197ee
subl %r12d, %r13d
movq 0x50(%r14), %rax
movl 0x40(%rsp), %ecx
movl (%rax,%rcx,4), %eax
leaq 0x4(%rsp), %rsi
movl %eax, (%rsi)
movl %r12d, 0x4(%rsi)
movl %r13d, 0x8(%rsi)
movq 0x10(%rsp), %rdi
callq 0x419d74
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop