// File: /workspace/github_cpp_makefile_star2_O1/rtackx[P]ComSim/community.cpp
// Function: Community::aggregate(Graph*&, std::unordered_set<unsigned int, std::hash<unsigned int>, std::equal_to<unsigned int>, std::allocator<unsigned int>>&)
void Community::aggregate(Graph*& graph_projection, unordered_set<unsigned int>& list_remaining_nodes)
{
	Node* node;
	unsigned int index_com_similar;
	float max_similarity;
	unordered_map<unsigned int, float> map_similar_community;
	unordered_map<unsigned int, vector<unsigned int>> map_community_tmp;
	unordered_map<unsigned int, vector<unsigned int>> map_best_similarity;
	vector<unsigned int> list_similarity;
	
	for(auto& index : list_remaining_nodes)
	{
		node = graph_projection->list_nodes[index];

		max_similarity = 0.0;
		for(auto& neighbor : node->neighbor_weights)
		{
			if(map_community.find(neighbor.first->index) != map_community.end())
			{	
				for(auto& index_com : map_community[neighbor.first->index])
				{
					map_similar_community.emplace(make_pair(index_com, 0.0));
					map_similar_community[index_com] += neighbor.second;
				}
			}
			else
			{
				if(neighbor.second >= max_similarity)
				{
					if(neighbor.second > max_similarity)
						list_similarity.clear();

					max_similarity = neighbor.second;
					list_similarity.push_back(neighbor.first->index);
				}
			}
		}

		max_similarity = 0.0;
		index_com_similar = -1;

		for(auto& e : map_similar_community)
		{
			if(e.second > max_similarity)
			{
				max_similarity = e.second;
				index_com_similar = e.first;
			}
		}
		map_similar_community.clear();
		
		if(index_com_similar == -1)
			map_best_similarity[list_similarity[rand() % list_similarity.size()]].push_back(index);
		else
		{
			map_community_tmp[index].push_back(index_com_similar);
			
			// Add neighors of "index" into community
			if(map_best_similarity.find(index) != map_best_similarity.end())
			{
				for(auto& index_neighbor : map_best_similarity[index])
					map_community_tmp[index_neighbor].push_back(index_com_similar);
			}
		}
	}
	
	// Saving modification
	for(auto& e : map_community_tmp)
	{
		for(auto& index_com : e.second)
			map_community[e.first].push_back(index_com);

		list_remaining_nodes.erase(e.first);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, 0x30(%rsp)
movq %rdi, %r14
leaq 0x80(%rsp), %rax
movq %rax, -0x30(%rax)
movl $0x1, %ecx
movq %rcx, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, %esi       # imm = 0x3F800000
movl %esi, -0x10(%rax)
movups %xmm0, -0x8(%rax)
leaq 0xf0(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %esi, -0x10(%rax)
movups %xmm0, -0x8(%rax)
leaq 0xb8(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %esi, -0x10(%rax)
movups %xmm0, -0x8(%rax)
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq %rdx, 0x38(%rsp)
movq 0x10(%rdx), %r12
testq %r12, %r12
je 0x7f83
leaq 0x10(%r14), %r13
leaq 0x50(%rsp), %r15
movq %r13, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movl 0x8(%r12), %ecx
movq (%rax,%rcx,8), %rax
movq 0x40(%rax), %rbp
testq %rbp, %rbp
je 0x7db2
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x8(%rbp), %rcx
movl (%rcx), %r8d
movq %r8, %rax
xorl %edx, %edx
divq 0x18(%r14)
movq %r13, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
callq 0x8a56
testq %rax, %rax
je 0x7d38
cmpq $0x0, (%rax)
je 0x7d38
movq 0x8(%rbp), %rsi
movq %r13, %rdi
callq 0x88fe
movq %r14, %r13
movq %r12, %r14
movq (%rax), %rbx
movq 0x8(%rax), %r12
cmpq %r12, %rbx
je 0x7d7c
movl (%rbx), %eax
movl %eax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
callq 0x8f90
movss 0x10(%rbp), %xmm0
movss %xmm0, 0xc(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x926c
movss 0xc(%rsp), %xmm0
addss (%rax), %xmm0
movss %xmm0, (%rax)
addq $0x4, %rbx
jmp 0x7ce9
movss 0x10(%rbp), %xmm0
ucomiss 0x8(%rsp), %xmm0
jb 0x7da5
jbe 0x7d57
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x7d57
movq %rax, 0x18(%rsp)
movq 0x8(%rbp), %rdx
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x7d89
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
movss %xmm0, 0x8(%rsp)
jmp 0x7da5
movq %r14, %r12
movq %r13, %r14
movq 0x28(%rsp), %r13
jmp 0x7da5
leaq 0x10(%rsp), %rdi
movss %xmm0, 0xc(%rsp)
callq 0x8498
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movq (%rbp), %rbp
testq %rbp, %rbp
jne 0x7ca4
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x7df6
xorps %xmm0, %xmm0
movq %rdi, %rax
movss 0xc(%rax), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x7dde
movl 0x8(%rax), %ecx
movl %ecx, 0x4(%rsp)
movaps %xmm1, %xmm0
movq (%rax), %rax
testq %rax, %rax
jne 0x7dca
movq (%rdi), %rbx
callq 0x2220
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x7de6
leaq 0x8(%r12), %rbx
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x2120
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rax
movups %xmm0, (%rax)
cmpl $-0x1, 0x4(%rsp)
je 0x7e4c
leaq 0xc0(%rsp), %rdi
movq %rbx, %rsi
callq 0x88fe
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x7e95
movl 0x4(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x7ea2
callq 0x20a0
cltq
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
xorl %edx, %edx
divq %rsi
leaq (%rcx,%rdx,4), %rsi
leaq 0x88(%rsp), %rdi
callq 0x88fe
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x7f03
movl (%rbx), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x7f76
movq %rax, %rdi
leaq 0x4(%rsp), %rdx
callq 0x8498
movl (%rbx), %ecx
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq %rdx, %rsi
movq (%rdi,%rdx,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0x7f12
movq (%rdx), %r9
movq %rdx, %rax
cmpl 0x8(%r9), %ecx
je 0x7f12
movq %r9, %r10
movq (%r9), %r9
testq %r9, %r9
je 0x7f10
movl 0x8(%r9), %edi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
movl $0x0, %eax
cmpq %rsi, %rdx
jne 0x7f12
movq %r10, %rax
cmpl %edi, %ecx
jne 0x7ed9
jmp 0x7f12
movq %rax, %rdi
movq %rbx, %rdx
callq 0x8498
jmp 0x7f76
xorl %eax, %eax
testq %rax, %rax
je 0x7f76
cmpq $0x0, (%rax)
je 0x7f76
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
callq 0x88fe
movq (%rax), %rbx
movq 0x8(%rax), %rbp
cmpq %rbp, %rbx
je 0x7f76
leaq 0xc0(%rsp), %rdi
movq %rbx, %rsi
callq 0x88fe
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x7f63
movl 0x4(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x7f70
movq %rax, %rdi
leaq 0x4(%rsp), %rdx
callq 0x8498
addq $0x4, %rbx
jmp 0x7f34
movq (%r12), %r12
testq %r12, %r12
jne 0x7c79
movq 0xd0(%rsp), %r12
testq %r12, %r12
je 0x7ff3
addq $0x10, %r14
leaq 0x8(%r12), %rbx
movq 0x10(%r12), %r15
movq 0x18(%r12), %r13
cmpq %r13, %r15
je 0x7fdd
movq %r14, %rdi
movq %rbx, %rsi
callq 0x88fe
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x7fcc
movl (%r15), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x7fd7
movq %rax, %rdi
movq %r15, %rdx
callq 0x8498
addq $0x4, %r15
jmp 0x7fa3
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x930e
movq (%r12), %r12
testq %r12, %r12
jne 0x7f94
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8002
callq 0x2220
leaq 0x88(%rsp), %rdi
callq 0x81ac
leaq 0xc0(%rsp), %rdi
callq 0x81ac
leaq 0x50(%rsp), %rdi
callq 0x8302
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x804a
jmp 0x804a
jmp 0x804a
jmp 0x804a
jmp 0x804a
jmp 0x804a
jmp 0x804a
jmp 0x804a
jmp 0x804a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x805c
callq 0x2220
leaq 0x88(%rsp), %rdi
callq 0x81ac
leaq 0xc0(%rsp), %rdi
callq 0x81ac
leaq 0x50(%rsp), %rdi
callq 0x8302
movq %rbx, %rdi
callq 0x23d0