// File: fjamour[P]icentral/src/bc.cc
// Function: brandes_iter(graph_hash_t&, unsigned int, 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>>>&)
void brandes_iter(graph_hash_t& graph_in,
        node_id_t s,
        tr1_map_t(double)& bc_vec)
{
    tr1_map_t(vector<node_id_t> )&      P = graph_in.P;
    tr1_map_t(int)&                     path_cnt_vec = graph_in.path_cnt_vec;
    tr1_map_t(int)&                     dist_vec = graph_in.dist_vec;
    tr1_map_t(double)&                  pair_dep_vec = graph_in.pair_dep_vec;
    vector<node_id_t>&                  S = graph_in.S;
    queue<node_id_t>&                   Q = graph_in.Q;
    
    graph_in.init_maps();
    
    S.clear();
    
    path_cnt_vec[s] = 1;
    dist_vec[s] = 0;

    Q.push(s);

    while (!Q.empty()) {
        node_id_t v = Q.front();
        Q.pop();
        S.push_back(v);
        vector<node_id_t> nbr_vec = graph_in.get_nbrs(v);
        for (int nbr_idx = 0; nbr_idx < nbr_vec.size(); ++nbr_idx) {
            node_id_t w = nbr_vec[nbr_idx];
            if (dist_vec[w] < 0) {
                Q.push(w);
                dist_vec[w] = dist_vec[v] + 1;
            }
            if (dist_vec[w] == dist_vec[v] + 1) {
                path_cnt_vec[w] += path_cnt_vec[v];
                P[w].push_back(v);
            }
        }
    }

    for(int i = S.size()-1; i >= 0; --i) {
        node_id_t w = S[i];
        for(int idx = 0; idx < P[w].size(); ++idx) {
            node_id_t v = P[w][idx];
            pair_dep_vec[v] += (((double) path_cnt_vec[v] / path_cnt_vec[w]) * (1 + pair_dep_vec[w]));
        }
        if (w != s) {
            bc_vec[w] += pair_dep_vec[w];
        }
    }    
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
movl %esi, 0x10c(%rsp)
movq %rdx, 0x100(%rsp)
movq 0x110(%rsp), %rax
addq $0x60, %rax
movq %rax, 0xf8(%rsp)
movq 0x110(%rsp), %rax
addq $0x90, %rax
movq %rax, 0xf0(%rsp)
movq 0x110(%rsp), %rax
addq $0xf0, %rax
movq %rax, 0xe8(%rsp)
movq 0x110(%rsp), %rax
addq $0x120, %rax            # imm = 0x120
movq %rax, 0xe0(%rsp)
movq 0x110(%rsp), %rax
addq $0x240, %rax            # imm = 0x240
movq %rax, 0xd8(%rsp)
movq 0x110(%rsp), %rax
addq $0x258, %rax            # imm = 0x258
movq %rax, 0xd0(%rsp)
movq 0x110(%rsp), %rdi
callq 0x52170
movq 0xd8(%rsp), %rdi
callq 0x10a50
movq 0xf0(%rsp), %rdi
leaq 0x10c(%rsp), %rsi
callq 0x2d870
movl $0x1, (%rax)
movq 0xe8(%rsp), %rdi
leaq 0x10c(%rsp), %rsi
callq 0x2d870
movl $0x0, (%rax)
movq 0xd0(%rsp), %rdi
leaq 0x10c(%rsp), %rsi
callq 0x105b0
movq 0xd0(%rsp), %rdi
callq 0x105e0
xorb $-0x1, %al
testb $0x1, %al
jne 0x2caad
jmp 0x2cd23
movq 0xd0(%rsp), %rdi
callq 0x10600
movl (%rax), %eax
movl %eax, 0xcc(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x10610
movq 0xd8(%rsp), %rdi
leaq 0xcc(%rsp), %rsi
callq 0xfce0
movq 0x110(%rsp), %rdi
movl 0xcc(%rsp), %esi
callq 0x52140
movq %rax, %rsi
leaq 0xb0(%rsp), %rdi
callq 0x10b20
movl $0x0, 0xac(%rsp)
movslq 0xac(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0xfd50
movq %rax, %rcx
movq 0x80(%rsp), %rax
cmpq %rcx, %rax
jae 0x2cd11
movslq 0xac(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0xfbc0
movl (%rax), %eax
movl %eax, 0xa8(%rsp)
movq 0xe8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2d870
movq %rax, 0x78(%rsp)
jmp 0x2cb7f
movq 0x78(%rsp), %rax
cmpl $0x0, (%rax)
jge 0x2cc1c
movq 0xd0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x105b0
jmp 0x2cba4
movq 0xe8(%rsp), %rdi
leaq 0xcc(%rsp), %rsi
callq 0x2d870
movq %rax, 0x70(%rsp)
jmp 0x2cbc0
movq 0x70(%rsp), %rax
movl (%rax), %eax
incl %eax
movl %eax, 0x64(%rsp)
movq 0xe8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2d870
movq %rax, 0x68(%rsp)
jmp 0x2cbe9
movq 0x68(%rsp), %rax
movl 0x64(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x2cc1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x10520
jmp 0x2cf01
movq 0xe8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2d870
movq %rax, 0x58(%rsp)
jmp 0x2cc38
movq 0x58(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x4c(%rsp)
movq 0xe8(%rsp), %rdi
leaq 0xcc(%rsp), %rsi
callq 0x2d870
movq %rax, 0x50(%rsp)
jmp 0x2cc5f
movl 0x4c(%rsp), %eax
movq 0x50(%rsp), %rcx
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2ccf9
movq 0xf0(%rsp), %rdi
leaq 0xcc(%rsp), %rsi
callq 0x2d870
movq %rax, 0x40(%rsp)
jmp 0x2cc91
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x34(%rsp)
movq 0xf0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2d870
movq %rax, 0x38(%rsp)
jmp 0x2ccb8
movq 0x38(%rsp), %rax
movl 0x34(%rsp), %edx
movl (%rax), %ecx
addl %edx, %ecx
movl %ecx, (%rax)
movq 0xf8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2d980
movq %rax, 0x28(%rsp)
jmp 0x2cce3
movq 0x28(%rsp), %rdi
leaq 0xcc(%rsp), %rsi
callq 0xfce0
jmp 0x2ccf7
jmp 0x2ccf9
jmp 0x2ccfb
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x2cb14
leaq 0xb0(%rsp), %rdi
callq 0x10520
jmp 0x2ca95
movq 0xd8(%rsp), %rdi
callq 0xfd50
subq $0x1, %rax
movl %eax, 0x98(%rsp)
cmpl $0x0, 0x98(%rsp)
jl 0x2cef9
movq 0xd8(%rsp), %rdi
movslq 0x98(%rsp), %rsi
callq 0xfbc0
movl (%rax), %eax
movl %eax, 0x94(%rsp)
movl $0x0, 0x90(%rsp)
movslq 0x90(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xf8(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x2d980
movq %rax, %rdi
callq 0xfd50
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x2ce91
movq 0xf8(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x2d980
movq %rax, %rdi
movslq 0x90(%rsp), %rsi
callq 0xfbc0
movl (%rax), %eax
movl %eax, 0x8c(%rsp)
movq 0xf0(%rsp), %rdi
leaq 0x8c(%rsp), %rsi
callq 0x2d870
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xf0(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x2d870
movsd 0x8(%rsp), %xmm0
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0xe0(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x2d310
movsd 0x4e1d0(%rip), %xmm0    # 0x7b010
addsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0xe0(%rsp), %rdi
leaq 0x8c(%rsp), %rsi
callq 0x2d310
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm2
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl 0x90(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x90(%rsp)
jmp 0x2cd72
movl 0x94(%rsp), %eax
cmpl 0x10c(%rsp), %eax
je 0x2cee1
movq 0xe0(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x2d310
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq 0x100(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x2d310
movsd (%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
jmp 0x2cee3
movl 0x98(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0x2cd3b
addq $0x118, %rsp            # imm = 0x118
retq
movq 0xa0(%rsp), %rdi
callq 0x9cf0
nop