// File: /workspace/github_cpp_makefile_star2_O3/ChnMasterOG[P]KmerGO2/kmc_api/kmc_file.cpp
// Function: CKMCFile::ReadNextKmer(CKmerAPI&, unsigned int&)
bool CKMCFile::ReadNextKmer(CKmerAPI &kmer, uint32 &count)
{
	uint64 prefix_mask = (1 << 2 * lut_prefix_length) - 1; //for kmc2 db

	if(is_opened != opened_for_listing)
		return false;
	do
	{
		if(end_of_file)
			return false;
		
		if(sufix_number == prefix_file_buf[prefix_index + 1]) 
		{
			prefix_index++;
						
			while (prefix_file_buf[prefix_index] == prefix_file_buf[prefix_index + 1])
				prefix_index++;
		}
	
		uint32 off = (sizeof(prefix_index) * 8) - (lut_prefix_length * 2) - kmer.byte_alignment * 2;
			
		uint64 temp_prefix = (prefix_index & prefix_mask) << off;	// shift prefix towards MSD. "& prefix_mask" necessary for kmc2 db format
		
		kmer.kmer_data[0] = temp_prefix;			// store prefix in an object CKmerAPI

		for(uint32 i = 1; i < kmer.no_of_rows; i++)
			kmer.kmer_data[i] = 0;

		//read sufix:
		uint32 row_index = 0;
 		uint64 suf = 0;
	
		off = off - 8;
				
 		for(uint32 a = 0; a < sufix_size; a ++)
		{
			if(index_in_partial_buf == part_size)
				Reload_sufix_file_buf();
						
			suf = sufix_file_buf[index_in_partial_buf++];
			suf = suf << off;
			kmer.kmer_data[row_index] = kmer.kmer_data[row_index] | suf;

			if (off == 0)				//the end of a word in kmer_data
			{
					off = 56;
					row_index++;
			}
			else
					off -=8;
		}
	
		//read counter:
		if(index_in_partial_buf == part_size)
			Reload_sufix_file_buf();
		
		count = sufix_file_buf[index_in_partial_buf++];

		for(uint32 b = 1; b < counter_size; b++)
		{
			if(index_in_partial_buf == part_size)
				Reload_sufix_file_buf();
			
			uint32 aux = 0x000000ff & sufix_file_buf[index_in_partial_buf++];
			aux = aux << 8 * ( b);
			count = aux | count;
		}
			
		sufix_number++;
	
		if(sufix_number == total_kmers)
			end_of_file = true;

		if (mode != 0)
		{
			float float_counter;
			memcpy(&float_counter, &count, counter_size);
			if ((float_counter < min_count) || (float_counter > max_count))
				continue;
			else
				break;
		}

	}
	while((count < min_count) || (count > max_count));

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movb 0x84(%rdi), %cl
addb %cl, %cl
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
shll %cl, %r12d
movq %rsi, 0x8(%rsp)
cmpl $0x2, (%rdi)
jne 0x416eaa
movq %rdi, %rbx
movq %rdx, %r14
notl %r12d
movq %r12, 0x10(%rsp)
movb 0x18(%rbx), %al
movl %eax, (%rsp)
testb %al, %al
jne 0x416ea3
movq 0x68(%rbx), %rax
movq 0x30(%rbx), %rcx
movq 0x40(%rbx), %rdx
cmpq 0x8(%rcx,%rdx,8), %rax
jne 0x416cad
leaq 0x1(%rdx), %rax
movq %rax, 0x40(%rbx)
movq 0x8(%rcx,%rdx,8), %rsi
cmpq 0x10(%rcx,%rdx,8), %rsi
movq %rax, %rdx
je 0x416c94
jmp 0x416cb0
movq %rdx, %rax
movq 0x8(%rsp), %rdx
movzbl 0xc(%rdx), %r15d
addl 0x84(%rbx), %r15d
addl %r15d, %r15d
andl %r12d, %eax
movl %r15d, %ecx
negb %cl
shlq %cl, %rax
movq (%rdx), %rbp
movq %rax, (%rbp)
movl 0x10(%rdx), %edx
cmpl $0x2, %edx
jb 0x416cef
leaq 0x8(%rbp), %rdi
decl %edx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x401098
movl 0xa8(%rbx), %eax
testl %eax, %eax
je 0x416d6f
movl $0x38, %r13d
subl %r15d, %r13d
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x70(%rbx), %rcx
cmpq 0x202465(%rip), %rcx    # 0x619178
jne 0x416d2f
movq %rbx, %rdi
callq 0x416ec0
movq 0x70(%rbx), %rcx
movq 0x8(%rsp), %rax
movq (%rax), %rbp
movl 0xa8(%rbx), %eax
movq 0x60(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x70(%rbx)
movzbl (%rdx,%rcx), %edx
movl %r13d, %ecx
shlq %cl, %rdx
movl %r15d, %ecx
orq %rdx, (%rbp,%rcx,8)
xorl %ecx, %ecx
testl %r13d, %r13d
leal -0x8(%r13), %edx
sete %cl
movl $0x38, %esi
cmovel %esi, %edx
addl %ecx, %r15d
incl %r12d
movl %edx, %r13d
cmpl %eax, %r12d
jb 0x416d08
movq 0x70(%rbx), %rdx
cmpq 0x2023fe(%rip), %rdx    # 0x619178
jne 0x416d88
movq %rbx, %rdi
callq 0x416ec0
movq 0x70(%rbx), %rdx
movq 0x60(%rbx), %rax
leaq 0x1(%rdx), %rcx
movq %rcx, 0x70(%rbx)
movzbl (%rax,%rdx), %esi
movl %esi, (%r14)
movl 0x80(%rbx), %edi
cmpl $0x2, %edi
jb 0x416e07
movl $0x1, %r12d
movl $0x8, %r13d
movq 0x2023bf(%rip), %rdx    # 0x619178
cmpq %rdx, %rcx
jne 0x416dd8
movq %rbx, %rdi
callq 0x416ec0
movq 0x2023ab(%rip), %rdx    # 0x619178
movq 0x60(%rbx), %rax
movq 0x70(%rbx), %rcx
movl (%r14), %esi
leaq 0x1(%rcx), %r8
movq %r8, 0x70(%rbx)
movzbl (%rax,%rcx), %ebp
movl %r13d, %ecx
shll %cl, %ebp
orl %esi, %ebp
movl %ebp, (%r14)
incl %r12d
movl 0x80(%rbx), %edi
addl $0x8, %r13d
movl %ebp, %esi
movq %r8, %rcx
cmpl %edi, %r12d
jb 0x416db9
jmp 0x416e09
movl %esi, %ebp
movq 0x68(%rbx), %rax
incq %rax
movq %rax, 0x68(%rbx)
cmpq 0x98(%rbx), %rax
jne 0x416e21
movb $0x1, 0x18(%rbx)
cmpl $0x0, 0x7c(%rbx)
movl 0x8c(%rbx), %r15d
movq 0x10(%rsp), %r12
je 0x416e8b
movl %edi, %edx
leaq 0x4(%rsp), %rdi
movq %r14, %rsi
callq 0x401080
movl %r15d, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
movss 0x4(%rsp), %xmm0
ucomiss %xmm0, %xmm1
ja 0x416e8b
movq 0x90(%rbx), %rax
testq %rax, %rax
js 0x416e6e
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
jmp 0x416e86
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x416ebb
cmpl %r15d, %ebp
jb 0x416c73
movl %ebp, %eax
cmpq %rax, 0x90(%rbx)
jb 0x416c73
movl (%rsp), %eax
xorb $0x1, %al
jmp 0x416eac
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
jmp 0x416eac
nop