// File: ChnMasterOG[P]KmerGO2/kmc_api/kmc_file.cpp
// Function: CKMCFile::CheckKmer(CKmerAPI&, unsigned int&)
bool CKMCFile::CheckKmer(CKmerAPI &kmer, uint32 &count)
{
	if(is_opened != opened_for_RA)
		return false;
	if(end_of_file)
		return false;
	
	//recognize a prefix:
	uint64 pattern_prefix_value = kmer.kmer_data[0];

	uint32 pattern_offset = (sizeof(pattern_prefix_value)* 8) - (lut_prefix_length * 2) - (kmer.byte_alignment * 2);
	int64 index_start = 0, index_stop = 0;

	pattern_prefix_value = pattern_prefix_value >> pattern_offset;  //complements with 0
	if (pattern_prefix_value >= prefix_file_buf_size)
		return false;

	if (kmc_version == 0x200)
	{
		uint32 signature = kmer.get_signature(signature_len);
		uint32 bin_start_pos = signature_map[signature];
		bin_start_pos *= single_LUT_size;				
		//look into the array with data
		index_start = *(prefix_file_buf + bin_start_pos + pattern_prefix_value);
		index_stop = *(prefix_file_buf + bin_start_pos + pattern_prefix_value + 1) - 1;
	}
	else if (kmc_version == 0)
	{
		//look into the array with data
		index_start = prefix_file_buf[pattern_prefix_value];
		index_stop = prefix_file_buf[pattern_prefix_value + 1] - 1;
	}
	uint64 tmp_count ;
	bool res = BinarySearch(index_start, index_stop, kmer, tmp_count, pattern_offset);
	count = (uint32)tmp_count;
	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpl $0x1, (%rax)
je 0x4245ca
movb $0x0, -0x1(%rbp)
jmp 0x424737
movq -0x60(%rbp), %rax
testb $0x1, 0x18(%rax)
je 0x4245dd
movb $0x0, -0x1(%rbp)
jmp 0x424737
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rcx
movq %rcx, -0x28(%rbp)
movl 0x84(%rax), %eax
shll %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x40, %eax
subq %rcx, %rax
movq -0x18(%rbp), %rcx
movzbl 0xc(%rcx), %ecx
shll %ecx
movslq %ecx, %rcx
subq %rcx, %rax
movl %eax, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
shrq %cl, %rax
movq -0x60(%rbp), %rcx
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq 0x38(%rcx), %rax
jb 0x42464b
movb $0x0, -0x1(%rbp)
jmp 0x424737
movq -0x60(%rbp), %rax
cmpl $0x200, 0xa4(%rax)      # imm = 0x200
jne 0x4246c9
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rdi
movl 0x88(%rax), %esi
callq 0x4280f0
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, -0x44(%rbp)
movq 0x50(%rax), %rcx
movl -0x44(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x48(%rbp)
movl 0x48(%rax), %ecx
imull -0x48(%rbp), %ecx
movl %ecx, -0x48(%rbp)
movq 0x30(%rax), %rcx
movl -0x48(%rbp), %edx
shlq $0x3, %rdx
addq %rdx, %rcx
movq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, -0x38(%rbp)
movq 0x30(%rax), %rax
movl -0x48(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x424701
movq -0x60(%rbp), %rax
cmpl $0x0, 0xa4(%rax)
jne 0x4246ff
movq -0x60(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, -0x38(%rbp)
movq 0x30(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x424701
movq -0x60(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %r9d
leaq -0x50(%rbp), %r8
callq 0x424750
andb $0x1, %al
movb %al, -0x51(%rbp)
movq -0x50(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movb -0x51(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)