// File: /workspace/github_cpp_makefile_star2_O2/ratulSharker[P]Havec/src/vector_with_rehash_8_hash_with_N_detection_5_bytes.cpp
// Function: reCheckTheKhmerExistence5Byte(khmerInfo5Byte*, unsigned long long, char*, unsigned short)
void reCheckTheKhmerExistence5Byte(struct khmerInfo5Byte * memBlock, unsigned long long blockSize, char *fileName,unsigned short int khmerSize){
	//opening the given file
		std::ifstream inputFile;
		inputFile.open(fileName,std::fstream::in);
		std::string buf,temp="";
		bool isFirstKhmer = true;
		unsigned long long *lastFoundKHashVal;
		lastFoundKHashVal=new unsigned long long[LAST_HASH_FUNC+1];		
		unsigned long long consumedRead = 0;
		unsigned int lastHashFuncUsed = 0;//containe the value that is last used to store last khmers
		unsigned long mem_block_occupied_stat = 0;
		unsigned long list_occupied_stat = 0;
		
		bool n_found = false;//added for the purpose of detecting N in the khmer
		
		//for stat purpose use only:)
		unsigned long found_khmer = 0,not_found=0;

		//error log if can't be opened
		if(inputFile.fail() == true){
			/*
			 * if fail to load the file -- return
			 */
			std::cout<<"Fail to open the "<<fileName << std::endl;
			return;
		}


		//if successfull then log it !!!
		std::cout<<"Rechecking... "<<fileName<<std::endl;

		//parsing the fasta file
		while(getline(inputFile,buf)){//reading a line

				if(buf[0] == '>'){
					//its a sequence name -- omit it !!! -- before omit clear the temp
					n_found = false;//new sequence so assign false to the N found tag
					temp = ""; //cleaning the old remaining khmer
					isFirstKhmer = true;
					continue;
				}
				else if (n_found == false){
					//here come the one sequnece of read
					buf = temp + buf;//no new read sequnence is found so the next line of read must be appended to the last
					unsigned int i;
					unsigned int bufSize = buf.size();//for optimization purpose only
					unsigned int loopTime = bufSize - khmerSize;//for optimization purpose only
					unsigned int addResult; //for optimization only

					if(isFirstKhmer == true){
						//its the first read line of the multiple read lines
						i = 1;
					}
					else{
						//its not the first line of the multiple read line
						i= 0;
					}

					//if it the first line then consume it explicitly by using fullHasher
					if(isFirstKhmer == true){
						if(bufSize < khmerSize){
						/*cout<<"**************************************************"<<endl;						
						cout<<"Problem detected !!!"<<endl;
						cout<<"read sequence size is less then the khmer size -- processing next read :("<<endl;
						cout<<"seq :: "<<buf<<endl;
						cout<<"**************************************************"<<endl;
						*/
						continue;						
					}
						//start of a new read detected
						temp = buf.substr(0,khmerSize); //here temp denote the string khmer
						
						//lastFoundKHashVal = fullHasher(temp); //saving the hash value
						//std::cout<<"recheck khmer's in the read (first) :: "<<temp<<std::endl;

						
						
						if(bufSize > khmerSize){
							
							bool found = false;
							
							for(int ii=0;ii<=LAST_HASH_FUNC;ii++){
							
							
								lastFoundKHashVal[ii] = fullHasher(temp,ii); 
									
								if(buf.length() > khmerSize ){//checking that next khmer is not invalid
									switch(toupper(buf[khmerSize])){
										case 'A':
										case 'T':
										case 'G':
										case 'C':
										break;
										
										default:
										neucleotide_status = N_FOUND_IN_NEUCLEOTIDE;
										break;
									}
								}
							
								if(neucleotide_status == N_FOUND_IN_NEUCLEOTIDE){
									n_found = true;
									break;//breaking the hash loop !!!!
								}
								
								//std::cout<<"try to find("<<ii<<")"<<endl;
								
								//khmer has a neighbour :) -- so put the khmer in the blockArray
								//cout<<"trying to find "<<termp<<endl;
								switch(findGivenKhmer5Byte(temp,memBlock,blockSize,lastFoundKHashVal[ii],ii)){

								case FOUND:
									found_khmer++;
									//std::cout<<temp<< " -- found"<<std::endl;
									found = true;
									lastHashFuncUsed=ii;
									break;
								case NOT_FOUND:
									//std::cout<<temp<< " -- not found"<<std::endl;
									found = false;
									break;
								}
								if(found){
								break; //break out from the for loop
							}
						}
						
						if(n_found == true){ //main while loop continues -- allowing to consume the line of read
							continue ;
						}
						else if(n_found  == false && found == false){//error reporting that -- the khmer is not found
							not_found++;
							std::cout<<temp<< "at first -- not found "<<std::endl;
							std::cout<<"buffer :: " <<buf<<std::endl;
						}
						
						//for debug purpose
						//std::cout<<"inside firstkhmer "<<std::endl;
						//std::cout<<temp<<std::endl;
					}
					isFirstKhmer = false;
				}

				if(n_found == true){ //main while loop continues -- allowing to consume the line of read
					continue ;
				}
				
				for( ; i <= loopTime && n_found == false; i++){
					temp = buf.substr(i,khmerSize);

					//std::cout<<"recheck khmer's in the read (intermediate) :: "<<temp<<std::endl;
					
					addResult = i + khmerSize;
					
					if(bufSize > addResult){
						
						bool found = false;
						for(int ii=0;ii<=LAST_HASH_FUNC;ii++){
						
							if(ii<=lastHashFuncUsed){
								//last used hash func & current hashfunc is same -- so partial hasher would do the job
								
								//neighbour left so put it into the memBlock
								lastFoundKHashVal[ii] = partialHasher(lastFoundKHashVal[ii],temp[khmerSize - 1],khmerSize,ii);
								//lastFoundKHashVal = fullHasher(temp,ii);
							}
							else{
								lastFoundKHashVal[ii] = fullHasher(temp,ii); //saving the hash
								
							}
							
							if(buf.length() >= addResult + 1){//checking that next khmer is not invalid
								switch(toupper(buf[addResult])){
									case 'A':
									case 'T':
									case 'G':
									case 'C':
									break;
									
									default:
									neucleotide_status = N_FOUND_IN_NEUCLEOTIDE;
									break;
								}
							}
							
							if(neucleotide_status == N_FOUND_IN_NEUCLEOTIDE){
								n_found = true;
								break;
							}
							
							//std::cout<<"try to find("<<ii<<")"<<endl;
							
							//neighbour left so put it into the memBlock
							//lastFoundKHashVal[ii] = partialHasher(lastFoundKHashVal,temp[khmerSize - 1],khmerSize,ii);
							switch(findGivenKhmer5Byte(temp,memBlock,blockSize,lastFoundKHashVal[ii],ii)){
								case FOUND:
									found_khmer++;
									//std::cout<<temp<< " -- found"<<std::endl;
									lastHashFuncUsed = ii;
									found = true;
									break;
								case NOT_FOUND:
									//cout<<temp<< " -- not found"<<std::endl;
									found = false;
									break;
							}

							//for debug purpose
							//std::cout<<"\tinside loop "<<std::endl;
							//std::cout<<"\t\t"<<temp<<std::endl;
							if(found){								
								break; //break out from the for loop
							}
						}
						
						if(n_found == false && found == false){//error reporting that -- the khmer is not found
							not_found++;
							std::cout<<temp<< " -- not found"<<std::endl;
						}

					}
					
					if(n_found == true){
						break;
					}
					
				}
				//temp = temp.substr(1,khmerSize-1);//advance to next khmer one time of ahead

				//std::cout<<"one line of read consumed" <<std::endl;
			}
		}

		//spit out the stats
		std::cout<<"stat from recheck function :: "<<endl
				<<"\tkhmer found :: "<<found_khmer<<endl<<"\tkhmer not found:: "<<not_found<<endl<<endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, 0x98(%rsp)
movq %rdi, 0x90(%rsp)
leaq 0x140(%rsp), %r14
movq %r14, %rdi
callq 0x22b0
pushq $0x8
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2140
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x5383(%rip), %rsi      # 0x85c8
leaq 0x50(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x421e
leaq 0x8036(%rip), %rax      # 0xb294
movl (%rax), %edi
incl %edi
shlq $0x3, %rdi
callq 0x2030
movq %rax, 0x28(%rsp)
movq 0x140(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x160(%rsp,%rax)
je 0x32a9
movq 0x7d43(%rip), %rdi      # 0xafd0
leaq 0x4e55(%rip), %rsi      # 0x80e9
callq 0x2220
movq %rax, %rdi
movq %r15, %rsi
callq 0x2220
jmp 0x37ed
movq 0x7d20(%rip), %rdi      # 0xafd0
leaq 0x4edb(%rip), %rsi      # 0x8192
callq 0x2220
movq %rax, %rdi
movq %r15, %rsi
callq 0x2220
movq %rax, %rdi
callq 0x20e0
movzwl %bx, %r15d
movb $0x1, 0x10(%rsp)
movq $0x0, 0x40(%rsp)
leaq 0x140(%rsp), %r12
leaq 0x70(%rsp), %r13
movl $0x0, 0x8(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movq %r15, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x378a
movq 0x70(%rsp), %rax
cmpb $0x3e, (%rax)
je 0x34b7
testb $0x1, 0x8(%rsp)
jne 0x330d
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
movq %r13, %rdx
callq 0x4259
movq %r13, %rdi
movq %rbx, %rsi
callq 0x22e0
movq %rbx, %rdi
callq 0x20c0
movl 0x78(%rsp), %eax
testb $0x1, 0x10(%rsp)
je 0x34da
cmpl %r15d, %eax
jb 0x330d
movl %eax, 0x1c(%rsp)
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x2270
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x22e0
movq %rbx, %rdi
callq 0x20c0
cmpl %r15d, 0x1c(%rsp)
jbe 0x377d
xorl %ebx, %ebx
leaq 0x7ed1(%rip), %rax      # 0xb294
movl (%rax), %eax
cmpq %rax, %rbx
ja 0x34ee
leaq 0xe0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2340
leaq 0xe0(%rsp), %rbp
movq %rbp, %rdi
movl %ebx, %esi
callq 0x76af
movq %rax, %r14
movq 0x28(%rsp), %rax
movq %r14, (%rax,%rbx,8)
movq %rbp, %rdi
callq 0x20c0
cmpq %r15, 0x78(%rsp)
jbe 0x3436
movq 0x70(%rsp), %rax
movsbl (%rax,%r15), %edi
callq 0x2430
addl $-0x41, %eax
cmpl $0x13, %eax
ja 0x3765
movl $0x80045, %ecx          # imm = 0x80045
btl %eax, %ecx
jae 0x3765
leaq 0x7e7b(%rip), %rax      # 0xb2b8
cmpl $0x7, (%rax)
je 0x3772
leaq 0x120(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2340
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
movq %r14, %rcx
movl %ebx, %r8d
callq 0x30ba
movl %eax, %r14d
leaq 0x120(%rsp), %rdi
callq 0x20c0
incq %rbx
cmpl $0x4, %r14d
jne 0x33bc
sete %al
movzbl %al, %eax
addq %rax, 0x30(%rsp)
decl %ebx
movl $0x0, 0xc(%rsp)
movq %rbx, 0x40(%rsp)
movl 0x8(%rsp), %ebp
movb 0x10(%rsp), %bl
jmp 0x3551
movb $0x1, 0x10(%rsp)
movl $0x0, 0x8(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x50f8(%rip), %rsi      # 0x85c8
callq 0x2450
jmp 0x330d
movl %eax, 0x1c(%rsp)
movb 0x10(%rsp), %bl
movl %ebx, %eax
movl %eax, 0xc(%rsp)
movl 0x8(%rsp), %ebp
jmp 0x3551
movq 0x7adb(%rip), %rdi      # 0xafd0
leaq 0x50(%rsp), %rsi
callq 0x21e0
movl 0x8(%rsp), %ebp
movb 0x10(%rsp), %bl
movq %rax, %rdi
leaq 0x4c90(%rip), %rsi      # 0x81a1
callq 0x2220
movq %rax, %rdi
callq 0x20e0
movq 0x7aab(%rip), %rdi      # 0xafd0
leaq 0x4c8c(%rip), %rsi      # 0x81b8
callq 0x2220
movq %rax, %rdi
movq %r13, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
incq 0x38(%rsp)
movl $0x0, 0xc(%rsp)
andb $0x1, %bl
movzbl %bl, %r13d
movl 0x1c(%rsp), %eax
subl 0x20(%rsp), %eax
movl %eax, 0x4c(%rsp)
testb $0x1, %bpl
jne 0x3742
cmpl 0x4c(%rsp), %r13d
ja 0x3742
movl %r13d, %edx
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
leaq 0x70(%rsp), %rsi
movq 0x20(%rsp), %rbx
movq %rbx, %rcx
callq 0x2270
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x22e0
movq %r14, %rdi
callq 0x20c0
leal (%rbx,%r13), %eax
cmpl 0x1c(%rsp), %eax
jae 0x3735
movl %ebp, 0x8(%rsp)
leal 0x1(%rax), %r15d
movl %eax, %eax
movq %rax, 0x10(%rsp)
movl 0x40(%rsp), %ebp
xorl %ebx, %ebx
leaq 0x7cbc(%rip), %rax      # 0xb294
movl (%rax), %eax
cmpq %rax, %rbx
ja 0x36e5
cmpq %rbp, %rbx
jbe 0x3622
leaq 0xc0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2340
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
movl %ebx, %esi
callq 0x76af
movq %rax, %r14
movq 0x28(%rsp), %rax
movq %r14, (%rax,%rbx,8)
movq %r12, %rdi
callq 0x20c0
jmp 0x364d
movq 0x28(%rsp), %rax
movq (%rax,%rbx,8), %rdi
movq 0x50(%rsp), %rax
movq 0x20(%rsp), %rdx
movsbl -0x1(%rax,%rdx), %esi
movl %ebx, %ecx
callq 0x7760
movq %rax, %r14
movq 0x28(%rsp), %rax
movq %r14, (%rax,%rbx,8)
cmpq %r15, 0x78(%rsp)
jb 0x3679
movq 0x70(%rsp), %rax
movq 0x10(%rsp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x2430
addl $-0x41, %eax
cmpl $0x13, %eax
ja 0x36ed
movl $0x80045, %ecx          # imm = 0x80045
btl %eax, %ecx
jae 0x36ed
leaq 0x7c38(%rip), %rax      # 0xb2b8
cmpl $0x7, (%rax)
je 0x36fa
leaq 0x100(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2340
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
movq %r14, %rcx
movl %ebx, %r8d
callq 0x30ba
movl %eax, %r14d
leaq 0x100(%rsp), %rdi
callq 0x20c0
incq %rbx
cmpl $0x4, %r14d
jne 0x35d1
sete %al
movzbl %al, %eax
addq %rax, 0x30(%rsp)
decl %ebx
movb $0x1, %al
movq %rbx, 0x40(%rsp)
jmp 0x36e7
xorl %eax, %eax
movl 0x8(%rsp), %ebp
jmp 0x36ff
leaq 0x7bc4(%rip), %rax      # 0xb2b8
movl $0x7, (%rax)
movb $0x1, %bpl
xorl %eax, %eax
movl %ebp, %ecx
andb $0x1, %cl
orb %al, %cl
jne 0x3735
movq 0x78c1(%rip), %rdi      # 0xafd0
leaq 0x50(%rsp), %rsi
callq 0x21e0
movq %rax, %rdi
leaq 0x4aa0(%rip), %rsi      # 0x81c3
callq 0x2220
movq %rax, %rdi
callq 0x20e0
incq 0x38(%rsp)
incl %r13d
testb $0x1, %bpl
je 0x3564
movl %ebp, 0x8(%rsp)
movl 0xc(%rsp), %eax
movb %al, 0x10(%rsp)
movq 0x20(%rsp), %r15
leaq 0x140(%rsp), %r12
leaq 0x70(%rsp), %r13
jmp 0x330d
leaq 0x7b4c(%rip), %rax      # 0xb2b8
movl $0x7, (%rax)
movb $0x1, %al
movl %eax, 0x8(%rsp)
jmp 0x330d
movl $0x0, 0xc(%rsp)
jmp 0x34aa
movq 0x783f(%rip), %rdi      # 0xafd0
leaq 0x4a39(%rip), %rsi      # 0x81d1
callq 0x2220
movq %rax, %rdi
callq 0x20e0
leaq 0x4a44(%rip), %rsi      # 0x81f0
movq %rax, %rdi
callq 0x2220
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20e0
leaq 0x4a31(%rip), %rsi      # 0x8201
movq %rax, %rdi
callq 0x2220
movq %rax, %rdi
movq 0x38(%rsp), %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
leaq 0x50(%rsp), %rdi
callq 0x20c0
leaq 0x70(%rsp), %rdi
callq 0x20c0
leaq 0x140(%rsp), %rdi
callq 0x2070
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3865
jmp 0x3865
jmp 0x3865
jmp 0x3865
movq %rax, %rbx
jmp 0x3872
movq %rax, %rbx
jmp 0x387c
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
jmp 0x385e
jmp 0x3865
jmp 0x3865
jmp 0x3865
jmp 0x3865
jmp 0x3865
jmp 0x3865
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x20c0
jmp 0x3868
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x20c0
leaq 0x70(%rsp), %rdi
callq 0x20c0
leaq 0x140(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x2400