// File: CMU-SAFARI[P]optimal-seed-solver/spacedSeedSolver.cc
// Function: SpacedSeedSolver::generateHash(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void SpacedSeedSolver::generateHash(string refName, string mask) {
	refDB.loadRefFile(refName);

	this->mask = mask;

	unsigned int oneCount = 0;
	for (int i = 0; i < mask.length(); i++) {
		if (mask[i] == '1')
			oneCount++;
	}

	freqTable.resize( (1 << (2 * oneCount) ), 0);

	seed = string(oneCount, 'N');

	for (unsigned int chromoCount = 0; chromoCount < refDB.getNumOfChromo(); chromoCount++) {
		refDB.loadChromo(chromoCount);
		for (unsigned int refPos = 0; refPos < refDB.getChromoLength() - mask.length(); refPos++) {
			string spacedSeed = refDB.getRefSeq(refPos, mask.length() );
			if (spacedSeed.find('N') == string::npos && spacedSeed.find('M') == string::npos && spacedSeed.find('R') == string::npos) {
				oneCount = 0;
				for (int i = 0; i < spacedSeed.length(); i++) {
				   if (mask[i] == '1') {
						seed[oneCount] = spacedSeed[i];
						oneCount++;
				   }
				}
				unsigned int hash = hashGen.calculateHash(seed, seed.length() );
				freqTable[hash]++;
			}
		}
	}	
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdx, 0x78(%rsp)
movq %rdi, 0x130(%rsp)
movq %rsi, 0x128(%rsp)
movq %rdx, 0x120(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x100(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x3160
movq 0x80(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x127b0
jmp 0x61f0
leaq 0x100(%rsp), %rdi
callq 0x31d0
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
addq $0x2a8, %rdi            # imm = 0x2A8
callq 0x3050
movl $0x0, 0xf0(%rsp)
movl $0x0, 0xec(%rsp)
movq 0x78(%rsp), %rdi
movslq 0xec(%rsp), %rax
movq %rax, 0x70(%rsp)
callq 0x34d0
movq %rax, %rcx
movq 0x70(%rsp), %rax
cmpq %rcx, %rax
jae 0x62bb
movq 0x78(%rsp), %rdi
movslq 0xec(%rsp), %rsi
callq 0x3650
movsbl (%rax), %eax
cmpl $0x31, %eax
jne 0x62a3
movl 0xf0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf0(%rsp)
jmp 0x62a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x31d0
jmp 0x6671
jmp 0x62a5
movl 0xec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xec(%rsp)
jmp 0x622c
movq 0x80(%rsp), %rdi
addq $0x290, %rdi            # imm = 0x290
movb 0xf0(%rsp), %cl
addb %cl, %cl
movl $0x1, %eax
shll %cl, %eax
movl %eax, %esi
movl $0x0, 0xe8(%rsp)
leaq 0xe8(%rsp), %rdx
callq 0x6cd0
movl 0xf0(%rsp), %eax
movq %rax, 0x60(%rsp)
leaq 0xc7(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x35d0
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rcx
leaq 0xc8(%rsp), %rdi
movl $0x4e, %edx
callq 0x6d90
jmp 0x6330
movq 0x80(%rsp), %rdi
addq $0x270, %rdi            # imm = 0x270
leaq 0xc8(%rsp), %rsi
callq 0x33b0
leaq 0xc8(%rsp), %rdi
callq 0x31d0
leaq 0xc7(%rsp), %rdi
callq 0x3330
movl $0x0, 0xc0(%rsp)
movq 0x80(%rsp), %rdi
movl 0xc0(%rsp), %eax
movl %eax, 0x5c(%rsp)
callq 0x12f00
movl %eax, %ecx
movl 0x5c(%rsp), %eax
cmpl %ecx, %eax
jae 0x6669
movq 0x80(%rsp), %rdi
movl 0xc0(%rsp), %esi
callq 0x12c30
movl $0x0, 0xbc(%rsp)
movq 0x80(%rsp), %rdi
movl 0xbc(%rsp), %eax
movq %rax, 0x50(%rsp)
callq 0x12ee0
movq 0x78(%rsp), %rdi
movl %eax, %eax
movq %rax, 0x48(%rsp)
callq 0x34d0
movq 0x48(%rsp), %rcx
movq %rax, %rdx
movq 0x50(%rsp), %rax
subq %rdx, %rcx
cmpq %rcx, %rax
jae 0x6651
movq 0x78(%rsp), %rdi
movl 0xbc(%rsp), %eax
movl %eax, 0x44(%rsp)
callq 0x34d0
movq 0x80(%rsp), %rsi
movl 0x44(%rsp), %edx
movl %eax, %ecx
leaq 0x98(%rsp), %rdi
callq 0x12f50
leaq 0x98(%rsp), %rdi
movl $0x4e, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3420
cmpq $-0x1, %rax
jne 0x662e
leaq 0x98(%rsp), %rdi
movl $0x4d, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3420
cmpq $-0x1, %rax
jne 0x662e
leaq 0x98(%rsp), %rdi
movl $0x52, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3420
cmpq $-0x1, %rax
jne 0x662e
movl $0x0, 0xf0(%rsp)
movl $0x0, 0x94(%rsp)
movslq 0x94(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x34d0
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
jae 0x65c1
movq 0x78(%rsp), %rdi
movslq 0x94(%rsp), %rsi
callq 0x3650
movq %rax, 0x30(%rsp)
jmp 0x64e3
movq 0x30(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x31, %eax
jne 0x65a9
movslq 0x94(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x3650
movq %rax, 0x28(%rsp)
jmp 0x6510
movq 0x80(%rsp), %rdi
movq 0x28(%rsp), %rax
movb (%rax), %al
movb %al, 0x1f(%rsp)
addq $0x270, %rdi            # imm = 0x270
movl 0xf0(%rsp), %eax
movl %eax, %esi
callq 0x3650
movq %rax, 0x20(%rsp)
jmp 0x653f
movq 0x20(%rsp), %rax
movb 0x1f(%rsp), %cl
movb %cl, (%rax)
movl 0xf0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf0(%rsp)
jmp 0x65a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0xc7(%rsp), %rdi
callq 0x3330
jmp 0x6671
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x31d0
jmp 0x6671
jmp 0x65ab
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x649f
movq 0x80(%rsp), %rdi
movq %rdi, %rax
addq $0x268, %rax            # imm = 0x268
movq %rax, 0x8(%rsp)
addq $0x270, %rdi            # imm = 0x270
movq %rdi, 0x10(%rsp)
callq 0x34d0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %eax, %edx
callq 0x14390
movl %eax, 0x18(%rsp)
jmp 0x65ff
movq 0x80(%rsp), %rdi
movl 0x18(%rsp), %eax
movl %eax, 0x90(%rsp)
addq $0x290, %rdi            # imm = 0x290
movl 0x90(%rsp), %eax
movl %eax, %esi
callq 0x6e10
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x98(%rsp), %rdi
callq 0x31d0
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x63b6
jmp 0x6653
movl 0xc0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc0(%rsp)
jmp 0x6371
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xf8(%rsp), %rdi
callq 0x35c0
nop