// File: CMU-SAFARI[P]optimal-seed-solver/HashTree.cc
// Function: HashTree::calculatePrefixSumFreqMap()
void HashTree::calculatePrefixSumFreqMap()
{
	map <unsigned int, unsigned long long> prefixSumFreqMap;
	prefixSumFreqMap.clear();
	int total = 0;
	if(&freqMap != NULL)
	{
		/* Add first element */
		map<unsigned int, unsigned long long>::iterator i = freqMap.begin();
		prefixSumFreqMap[i->first] = freqMap[i->first];
		i++;
		map<unsigned int, unsigned long long>::iterator prev = freqMap.begin();
		/* Loop for prefix sum */
		for (; i!=freqMap.end(); i++, prev++)
		{
			prefixSumFreqMap[i->first] = prefixSumFreqMap[prev->first] +
				freqMap[i->first];
			total = prefixSumFreqMap[i->first];
		}

		this->prefixSumFreqMap = prefixSumFreqMap;

		/* Calculate cumulative distribution of frequencies */
		map <unsigned int, double> cdfFreqMap;

		map<unsigned int, unsigned long long>::iterator iter = prefixSumFreqMap.begin();
		while(iter != prefixSumFreqMap.end())
		{
			cdfFreqMap[iter->first] = prefixSumFreqMap[iter->first]/total;
			iter++;
		}
		this->cdfFreqMap = cdfFreqMap;
	}
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x140(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x110(%rsp), %rdi
callq 0xa3f0
leaq 0x110(%rsp), %rdi
callq 0xa960
movq 0x78(%rsp), %rax
movl $0x0, 0x10c(%rsp)
addq $0x8, %rax
cmpq $0x0, %rax
je 0x956e
movq 0x78(%rsp), %rdi
addq $0x8, %rdi
movq %rdi, 0x68(%rsp)
callq 0xab10
movq %rax, 0x100(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xab40
movq 0x68(%rsp), %rdi
movq %rax, %rsi
callq 0xa9f0
movq %rax, 0x70(%rsp)
jmp 0x9240
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x58(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xab40
movq %rax, %rsi
leaq 0x110(%rsp), %rdi
callq 0xa9f0
movq %rax, 0x60(%rsp)
jmp 0x9271
movq 0x60(%rsp), %rax
movq 0x58(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
callq 0xab60
movq 0x78(%rsp), %rdi
movq %rax, 0xe8(%rsp)
addq $0x8, %rdi
callq 0xab10
movq %rax, 0xe0(%rsp)
movq 0x78(%rsp), %rdi
addq $0x8, %rdi
callq 0xa9c0
movq %rax, 0xd8(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xaba0
testb $0x1, %al
jne 0x92df
jmp 0x9404
leaq 0xe0(%rsp), %rdi
callq 0xab40
movq %rax, %rsi
leaq 0x110(%rsp), %rdi
callq 0xa9f0
movq %rax, 0x50(%rsp)
jmp 0x9303
movq 0x78(%rsp), %rax
movq 0x50(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, 0x38(%rsp)
addq $0x8, %rax
movq %rax, 0x40(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xab40
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0xa9f0
movq %rax, 0x48(%rsp)
jmp 0x933f
movq 0x38(%rsp), %rax
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xab40
movq %rax, %rsi
leaq 0x110(%rsp), %rdi
callq 0xa9f0
movq %rax, 0x30(%rsp)
jmp 0x9378
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x100(%rsp), %rdi
callq 0xab40
movq %rax, %rsi
leaq 0x110(%rsp), %rdi
callq 0xa9f0
movq %rax, 0x20(%rsp)
jmp 0x93a9
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl %eax, 0x10c(%rsp)
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
callq 0xab60
movq %rax, 0xd0(%rsp)
leaq 0xe0(%rsp), %rdi
xorl %esi, %esi
callq 0xab60
movq %rax, 0xc8(%rsp)
jmp 0x92ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0x9583
movq 0x78(%rsp), %rdi
addq $0x38, %rdi
leaq 0x110(%rsp), %rsi
callq 0xaae0
jmp 0x941c
leaq 0x98(%rsp), %rdi
callq 0xa400
leaq 0x110(%rsp), %rdi
callq 0xab10
movq %rax, 0x90(%rsp)
leaq 0x110(%rsp), %rdi
callq 0xa9c0
movq %rax, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0xaba0
testb $0x1, %al
jne 0x9471
jmp 0x9549
leaq 0x90(%rsp), %rdi
callq 0xab40
movq %rax, %rsi
leaq 0x110(%rsp), %rdi
callq 0xa9f0
movq %rax, 0x18(%rsp)
jmp 0x9495
movq 0x18(%rsp), %rax
movq (%rax), %rax
movslq 0x10c(%rsp), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %xmm0
movaps 0x9e5a(%rip), %xmm1     # 0x13310
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x9e5e(%rip), %xmm1     # 0x13320
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x90(%rsp), %rdi
callq 0xab40
movq %rax, %rsi
leaq 0x98(%rsp), %rdi
callq 0xabc0
movq %rax, 0x10(%rsp)
jmp 0x94fb
movq 0x10(%rsp), %rax
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x90(%rsp), %rdi
xorl %esi, %esi
callq 0xab60
movq %rax, 0x80(%rsp)
jmp 0x943e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0x98(%rsp), %rdi
callq 0xa480
jmp 0x9583
movq 0x78(%rsp), %rdi
addq $0x68, %rdi
leaq 0x98(%rsp), %rsi
callq 0xacb0
jmp 0x9561
leaq 0x98(%rsp), %rdi
callq 0xa480
leaq 0x110(%rsp), %rdi
callq 0xa490
addq $0x148, %rsp            # imm = 0x148
retq
leaq 0x110(%rsp), %rdi
callq 0xa490
movq 0xf8(%rsp), %rdi
callq 0x3590
nopl (%rax)