// File: 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:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x130(%rsp)
movq %rsi, 0x128(%rsp)
movl %edx, 0x124(%rsp)
movq 0x130(%rsp), %rdi
movq %rdi, 0x88(%rsp)
addq $0x30, %rdi
movq 0x128(%rsp), %rsi
xorps %xmm0, %xmm0
callq 0x53d40
cmpl $-0x1, 0x124(%rsp)
jne 0x3e721
movl $0x0, 0x120(%rsp)
movq 0x88(%rsp), %rdi
movslq 0x120(%rsp), %rax
movq %rax, 0x80(%rsp)
addq $0x2d8, %rdi            # imm = 0x2D8
callq 0x1ac90
movq %rax, %rcx
movq 0x80(%rsp), %rax
cmpq %rcx, %rax
jae 0x3e71c
movq 0x88(%rsp), %rdi
movl 0x120(%rsp), %eax
movl %eax, 0x11c(%rsp)
movl 0x11c(%rsp), %esi
movq 0x128(%rsp), %rdx
callq 0x3eb50
movl 0x120(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x120(%rsp)
jmp 0x3e6ab
jmp 0x3e7cc
movl $0x0, 0x118(%rsp)
movl $0x0, 0x114(%rsp)
movq 0x88(%rsp), %rdi
movslq 0x114(%rsp), %rax
movq %rax, 0x78(%rsp)
addq $0x2d8, %rdi            # imm = 0x2D8
callq 0x1ac90
movq %rax, %rcx
movq 0x78(%rsp), %rax
cmpq %rcx, %rax
jae 0x3e7ca
movq 0x88(%rsp), %rdi
movl 0x114(%rsp), %eax
movl %eax, 0x110(%rsp)
movl 0x118(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x118(%rsp)
movl 0x110(%rsp), %esi
movq 0x128(%rsp), %rdx
callq 0x3eb50
movl 0x118(%rsp), %eax
cmpl 0x124(%rsp), %eax
jne 0x3e7b2
jmp 0x3e7ca
jmp 0x3e7b4
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0x3e737
jmp 0x3e7cc
cmpl $-0x1, 0x124(%rsp)
jne 0x3eb32
movq 0x88(%rsp), %rdi
callq 0x3acb0
movq %rax, 0x100(%rsp)
movq %rdx, 0x108(%rsp)
movq 0x88(%rsp), %rdi
callq 0x10710
movq %rax, 0xf0(%rsp)
movq %rdx, 0xf8(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x10630
testb $0x1, %al
jne 0x3e832
jmp 0x3ea8d
leaq 0xd8(%rsp), %rdi
callq 0xfc40
leaq 0x100(%rsp), %rdi
callq 0x1e5f0
movq %rax, 0x70(%rsp)
jmp 0x3e853
movq 0x70(%rsp), %rsi
addq $0x8, %rsi
leaq 0xd8(%rsp), %rdi
callq 0x21960
jmp 0x3e86b
leaq 0xd8(%rsp), %rdi
callq 0x1eb00
cmpq $0x1, %rax
jbe 0x3ea6e
movl $0x0, 0xc8(%rsp)
movl $0x0, 0xc4(%rsp)
movslq 0xc4(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x1eb00
movq %rax, %rcx
movq 0x68(%rsp), %rax
cmpq %rcx, %rax
jae 0x3e947
movslq 0xc4(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0x64(%rsp)
movslq 0xc4(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0xfc50
movq %rax, %rcx
movl 0x64(%rsp), %eax
imull (%rcx), %eax
addl 0xc8(%rsp), %eax
movl %eax, 0xc8(%rsp)
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x3e898
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0xfc70
jmp 0x3eb3a
leaq 0x100(%rsp), %rdi
callq 0x1e5f0
movq %rax, 0x58(%rsp)
jmp 0x3e95b
movq 0x58(%rsp), %rdi
addq $0x8, %rdi
callq 0x109f0
movq %rax, 0xb8(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x1e5f0
movq %rax, 0x50(%rsp)
jmp 0x3e985
movq 0x50(%rsp), %rdi
addq $0x8, %rdi
callq 0x10a20
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
xorl %edx, %edx
callq 0x10750
movl %eax, 0x4c(%rsp)
jmp 0x3e9b8
movl 0x4c(%rsp), %eax
movl %eax, 0xc0(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x1e5f0
movq %rax, 0x40(%rsp)
jmp 0x3e9e4
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x2d310
movq %rax, 0x30(%rsp)
jmp 0x3e9fa
movq 0x30(%rsp), %rax
movsd (%rax), %xmm0
movl 0xc0(%rsp), %eax
imull %eax, %eax
cvtsi2sd %eax, %xmm1
addsd %xmm1, %xmm0
cvtsi2sdl 0xc8(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x1e5f0
movq %rax, 0x28(%rsp)
jmp 0x3ea49
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0x2d310
movq %rax, 0x10(%rsp)
jmp 0x3ea5f
movq 0x10(%rsp), %rax
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0xd8(%rsp), %rdi
callq 0xfc70
leaq 0x100(%rsp), %rdi
callq 0x3acf0
jmp 0x3e7f7
movq 0x128(%rsp), %rdi
callq 0x2d790
movq %rax, 0xa0(%rsp)
movq %rdx, 0xa8(%rsp)
movq 0x128(%rsp), %rdi
callq 0x2d7f0
movq %rax, 0x90(%rsp)
movq %rdx, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x2d7d0
testb $0x1, %al
jne 0x3eae2
jmp 0x3eb30
leaq 0xa0(%rsp), %rdi
callq 0x2d830
movsd 0x8(%rax), %xmm0
movsd 0x3c50c(%rip), %xmm1    # 0x7b008
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x2d830
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
leaq 0xa0(%rsp), %rdi
callq 0x2d840
jmp 0x3eaaa
jmp 0x3eb32
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xd0(%rsp), %rdi
callq 0x9cf0
nopw (%rax,%rax)