// File: /workspace/github_cpp_makefile_star2_O3/fjamour[P]icentral/src/bcc_scratch.cc
// Function: bcc_scratch_t::compute_bc(std::tr1::unordered_map<unsigned int, double, std::tr1::hash<unsigned int>, std::equal_to<unsigned int>, std::allocator<std::pair<unsigned int const, double>>>&, int)
void bcc_scratch_t::compute_bc(tr1::unordered_map<node_id_t, double>& bc_map, int max_iter)
{
    //bc_map will have for each vertex in the muc it's betweenness centrality
    //init bc of all nodes to zero
    //XXX why fill this bc_map? Should have all vertices in the graph, here we increment/decrement
    bcc_subgraph.i_fill_map<double>(bc_map, 0);
    
    //do BFS's from the nodes in the bcc
    if(max_iter == -1) {
        for(int i = 0; i < bcc_fast_subgraph.nodes_vec.size(); ++i) {
            node_id_t s = i;
            bc_iter(s, bc_map);
        }  
    } else {
        int cnt = 0;
        for(int i = 0; i < bcc_fast_subgraph.nodes_vec.size(); ++i) {
            node_id_t s = i;
            ++cnt;
            bc_iter(s, bc_map);
            if(cnt == max_iter)
                break;
        }  
    }

    if(max_iter == -1) {
        for(art_pt_map_t::iterator
            it =  art_pt_map.begin();
            it != art_pt_map.end();
            ++it) {
            vector<int> size_vec;
            size_vec = it->second;
            if(size_vec.size() > 1) {
                int sub = 0;
                for(int i = 0; i < size_vec.size(); ++i) {
                    sub += size_vec[i]*size_vec[i];
                }
                int VG_i = accumulate(it->second.begin(), it->second.end(), 0);
                bc_map[it->first] = bc_map[it->first] + VG_i*VG_i - sub;
            }
        }
        for (tr1::unordered_map<node_id_t, double>::iterator
            it = bc_map.begin();
                it != bc_map.end();
                ++it) {
            it->second = it->second / 2;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
addq $0x30, %rdi
xorpd %xmm0, %xmm0
callq 0x1d358
movq 0x2d8(%r14), %rax
movq 0x2e0(%r14), %rcx
cmpl $-0x1, %r15d
je 0x13a57
cmpq %rax, %rcx
je 0x13c0d
leal -0x1(%r15), %r13d
xorl %r12d, %r12d
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
movq %r14, %rdi
movl %r12d, %esi
movq %rbx, %rdx
callq 0x13c40
cmpq %r12, %r13
je 0x13a95
movq 0x2e0(%r14), %rax
subq 0x2d8(%r14), %rax
incq %r12
sarq $0x3, %rax
imulq %rbp, %rax
cmpq %r12, %rax
ja 0x13a24
jmp 0x13a95
cmpq %rax, %rcx
je 0x13a9f
xorl %r12d, %r12d
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
movq %r14, %rdi
movl %r12d, %esi
movq %rbx, %rdx
callq 0x13c40
movq 0x2e0(%r14), %rax
subq 0x2d8(%r14), %rax
incq %r12
sarq $0x3, %rax
imulq %r13, %rax
cmpq %r12, %rax
ja 0x13a69
cmpl $-0x1, %r15d
jne 0x13c0d
movq 0x8(%r14), %rax
movq (%rax), %r15
movq %rax, %r13
testq %r15, %r15
jne 0x13abe
movq %rax, %r13
movq 0x8(%r13), %r15
addq $0x8, %r13
testq %r15, %r15
je 0x13ab1
movq 0x10(%r14), %rcx
cmpq (%rax,%rcx,8), %r15
je 0x13bb3
movq %rsp, %r12
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x8(%r15), %rsi
movq %r12, %rdi
callq 0x8c34
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
subq %rdi, %rax
sarq $0x2, %rax
cmpq $0x2, %rax
jb 0x13b7c
xorl %ecx, %ecx
xorl %ebp, %ebp
movl (%rdi,%rcx,4), %edx
imull %edx, %edx
addl %edx, %ebp
incq %rcx
cmpq %rcx, %rax
jne 0x13b07
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
xorl %r12d, %r12d
cmpq %rcx, %rax
je 0x13b30
addl (%rax), %r12d
addq $0x4, %rax
jmp 0x13b22
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd8ce
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd8ce
imull %r12d, %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd 0x20(%rsp), %xmm2
addsd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, (%rax)
movq (%rsp), %rdi
movq %rsp, %r12
testq %rdi, %rdi
je 0x13b8e
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x13ba1
movq 0x8(%r13), %r15
addq $0x8, %r13
jmp 0x13b92
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
cmpq (%rax,%rcx,8), %r15
jne 0x13acf
movq 0x8(%rbx), %rdx
movq (%rdx), %rcx
movq %rdx, %rax
testq %rcx, %rcx
jne 0x13bd2
movq %rdx, %rax
movq 0x8(%rax), %rcx
addq $0x8, %rax
testq %rcx, %rcx
je 0x13bc5
movq 0x10(%rbx), %rsi
movq (%rdx,%rsi,8), %rdx
cmpq %rdx, %rcx
je 0x13c0d
movsd 0x1c451(%rip), %xmm0    # 0x30038
movsd 0x8(%rcx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rcx)
movq 0x10(%rcx), %rcx
testq %rcx, %rcx
jne 0x13c08
movq 0x8(%rax), %rcx
addq $0x8, %rax
jmp 0x13bf9
cmpq %rdx, %rcx
jne 0x13be7
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x13c1e
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x13c37
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq %rbx, %rdi
callq 0x23b0
nop