// File: ChnMasterOG[P]KmerGO2/kmc_api/kmc_file.cpp
// Function: CKMCFile::CheckKmer(CKmerAPI&, unsigned long long&)
bool CKMCFile::CheckKmer(CKmerAPI &kmer, uint64 &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;
	}
	return BinarySearch(index_start, index_stop, kmer, count, pattern_offset);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpl $0x1, (%rax)
je 0x424afa
movb $0x0, -0x1(%rbp)
jmp 0x424c53
movq -0x50(%rbp), %rax
testb $0x1, 0x18(%rax)
je 0x424b0d
movb $0x0, -0x1(%rbp)
jmp 0x424c53
movq -0x50(%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 -0x50(%rbp), %rcx
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq 0x38(%rcx), %rax
jb 0x424b7b
movb $0x0, -0x1(%rbp)
jmp 0x424c53
movq -0x50(%rbp), %rax
cmpl $0x200, 0xa4(%rax)      # imm = 0x200
jne 0x424bf9
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rdi
movl 0x88(%rax), %esi
callq 0x4280f0
movl %eax, %ecx
movq -0x50(%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 0x424c31
movq -0x50(%rbp), %rax
cmpl $0x0, 0xa4(%rax)
jne 0x424c2f
movq -0x50(%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 0x424c31
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movl -0x2c(%rbp), %r9d
callq 0x424750
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nop