// File: /workspace/github_cpp_makefile_star2_O3/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, 0x38(%rsp)
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, 0x30(%rsp)
movq 0x10(%rdx), %rcx
testq %rcx, %rcx
je 0x7e6c
movq %rdi, %r14
addq $0x10, %r14
leaq 0x50(%rsp), %r12
leaq 0x40(%rsp), %rbx
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x28(%rsp)
movl 0x8(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq 0x40(%rax), %r13
testq %r13, %r13
je 0x7c79
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x8(%r13), %rsi
movq %r14, %rdi
callq 0x8b00
testq %rax, %rax
je 0x7c0a
movq 0x8(%r13), %rsi
movq %r14, %rdi
callq 0x874c
movq (%rax), %r15
movq 0x8(%rax), %rbp
cmpq %rbp, %r15
je 0x7c6c
movl (%r15), %eax
movl %eax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x8dd8
movss 0x10(%r13), %xmm0
movss %xmm0, 0xc(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x905a
movss 0xc(%rsp), %xmm0
addss (%rax), %xmm0
movss %xmm0, (%rax)
addq $0x4, %r15
jmp 0x7bbb
movss 0x10(%r13), %xmm0
ucomiss 0x8(%rsp), %xmm0
jb 0x7c6c
movq 0x18(%rsp), %rsi
jbe 0x7c30
movq 0x10(%rsp), %rax
cmpq %rax, %rsi
je 0x7c30
movq %rax, 0x18(%rsp)
movq %rax, %rsi
movq 0x8(%r13), %rdx
cmpq 0x20(%rsp), %rsi
je 0x7c50
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
movss %xmm0, 0x8(%rsp)
jmp 0x7c6c
leaq 0x10(%rsp), %rdi
movss %xmm0, 0xc(%rsp)
callq 0x8310
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movq (%r13), %r13
testq %r13, %r13
jne 0x7b97
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x7cbd
xorps %xmm0, %xmm0
movq %rdi, %rax
movss 0xc(%rax), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x7ca5
movl 0x8(%rax), %ecx
movl %ecx, 0x4(%rsp)
movaps %xmm1, %xmm0
movq (%rax), %rax
testq %rax, %rax
jne 0x7c91
movq (%rdi), %r15
callq 0x2220
movq %r15, %rdi
testq %r15, %r15
jne 0x7cad
movq 0x28(%rsp), %rax
leaq 0x8(%rax), %r15
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 0x7d17
leaq 0xc0(%rsp), %rdi
movq %r15, %rsi
callq 0x874c
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x7d65
movl 0x4(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x7d72
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 0x874c
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x7de0
movl (%r15), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x7deb
movq %rax, %rdi
leaq 0x4(%rsp), %rdx
callq 0x8310
leaq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0x8b00
testq %rax, %rax
je 0x7deb
leaq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0x874c
movq (%rax), %r15
movq 0x8(%rax), %r13
cmpq %r13, %r15
je 0x7deb
leaq 0xc0(%rsp), %rdi
movq %r15, %rsi
callq 0x874c
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x7dcd
movl 0x4(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x7dda
movq %rax, %rdi
leaq 0x4(%rsp), %rdx
callq 0x8310
addq $0x4, %r15
jmp 0x7d9e
movq %rax, %rdi
movq %r15, %rdx
callq 0x8310
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x7b69
movq 0xd0(%rsp), %r12
testq %r12, %r12
je 0x7e65
leaq 0x8(%r12), %rbx
movq 0x10(%r12), %r15
movq 0x18(%r12), %r13
cmpq %r13, %r15
je 0x7e52
movq %r14, %rdi
movq %rbx, %rsi
callq 0x874c
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x7e41
movl (%r15), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x7e4c
movq %rax, %rdi
movq %r15, %rdx
callq 0x8310
addq $0x4, %r15
jmp 0x7e18
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x910e
movq (%r12), %r12
jmp 0x7e04
movq 0x10(%rsp), %rdi
jmp 0x7e6e
xorl %edi, %edi
testq %rdi, %rdi
je 0x7e78
callq 0x2220
leaq 0x88(%rsp), %rdi
callq 0x8024
leaq 0xc0(%rsp), %rdi
callq 0x8024
leaq 0x50(%rsp), %rdi
callq 0x817a
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7ec2
jmp 0x7ec2
jmp 0x7ec2
jmp 0x7ec2
jmp 0x7ec2
jmp 0x7ec2
jmp 0x7ec2
jmp 0x7ec2
jmp 0x7ec2
jmp 0x7ec2
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7ed4
callq 0x2220
leaq 0x88(%rsp), %rdi
callq 0x8024
leaq 0xc0(%rsp), %rdi
callq 0x8024
leaq 0x50(%rsp), %rdi
callq 0x817a
movq %rbx, %rdi
callq 0x23d0