// File: fjamour[P]icentral/src/_bc.cc
// Function: partial_BBFS_addition(iter_info_t&, component_t&, unsigned int, std::pair<unsigned int, unsigned int>)
void partial_BBFS_addition(
        iter_info_t&    iter_info,  // iteration info to be computed
        component_t&    comp,       // component
        node_id_t       s,          // source of the iteration
        edge_t          e           // inserted edge
        )
{
    subgraph_t& g = comp.subgraph;
    
    vector<vector<node_id_t> >&  P = iter_info.P; 
    vector<int>&                 path_cnt_vec = iter_info.sigma_vec;
    vector<int>&                 path_cnt_inc_map = iter_info.sigma_inc_vec;
    vector<int>&                 dist_map = iter_info.dist_vec;
    vector<bool>&                visited_vec = iter_info.visited_vec;
    vector<node_id_t>&           S = iter_info.S;
    
    queue<node_id_t>             Q;
    node_id_t src, dst;
    if(dist_map[e.first] > dist_map[e.second]) {
        src = e.second;
        dst = e.first;
    } else {
        src = e.first;
        dst = e.second;
    }
        
    //Compute new path counts and paths
    if(dist_map[dst] != dist_map[src]+1) {
        P[dst].clear();
        P[dst].push_back(src);
        path_cnt_vec[dst] = path_cnt_vec[src];
    } else {
        P[dst].push_back(src);
        path_cnt_vec[dst] += path_cnt_vec[src];
    }
        

    Q.push(dst);
    dist_map[dst] = dist_map[src] + 1;
    path_cnt_inc_map[dst] = path_cnt_vec[src];
    visited_vec[dst] = true;

    while (!Q.empty()) {
        node_id_t v = Q.front();
        Q.pop();
        vector<node_id_t> nbr_vec = g.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_map[w] > (dist_map[v] + 1)) {
                dist_map[w] = dist_map[v] + 1;
                P[w].clear();
                P[w].push_back(v);
                path_cnt_vec[w] = 0;
                path_cnt_inc_map[w] = path_cnt_inc_map[v];
                path_cnt_vec[w] += path_cnt_inc_map[w];
                if (!visited_vec[w]) {
                    visited_vec[w] = true;
                    Q.push(w);
                }
            } else if (dist_map[w] == (dist_map[v] + 1)) {
                path_cnt_inc_map[w] += path_cnt_inc_map[v];
                path_cnt_vec[w] += path_cnt_inc_map[v];
                if (find(P[w].begin(), P[w].end(), v) == P[w].end()) {
                    P[w].push_back(v);
                }
                if (!visited_vec[w]) {
                    visited_vec[w] = true;
                    Q.push(w);
                }
            }
        }
    }


    //fix order of S
    //IMP::THIS CAN BE MADE MUCH BETTER!
    //HEAP FOR EXAMPLE
    //EVEN THE SWAPPING CAN BE DONE MORE EFFICIENTLY
    //for now it's not a bottleneck
    for (int i = 1; i < S.size(); ++i) {
        if (dist_map[S[i - 1]] > dist_map[S[i]]) {
            int j = i;
            while (dist_map[S[j - 1]] > dist_map[S[j]]) {
                node_id_t tmp = S[j - 1];
                S[j - 1] = S[j];
                S[j] = tmp;
                --j;
            }
        }
    }
}

// Assembly:
subq $0x258, %rsp            # imm = 0x258
movq %rcx, 0x250(%rsp)
movq %rdi, 0x248(%rsp)
movq %rsi, 0x240(%rsp)
movl %edx, 0x23c(%rsp)
movq 0x240(%rsp), %rax
movq %rax, 0x230(%rsp)
movq 0x248(%rsp), %rax
movq %rax, 0x228(%rsp)
movq 0x248(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x220(%rsp)
movq 0x248(%rsp), %rax
addq $0xc0, %rax
movq %rax, 0x218(%rsp)
movq 0x248(%rsp), %rax
addq $0x30, %rax
movq %rax, 0x210(%rsp)
movq 0x248(%rsp), %rax
addq $0xd8, %rax
movq %rax, 0x208(%rsp)
movq 0x248(%rsp), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, 0x200(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x10580
movq 0x210(%rsp), %rdi
movl 0x250(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0xf0(%rsp)
movq 0x210(%rsp), %rdi
movl 0x254(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movq %rax, %rcx
movl 0xf0(%rsp), %eax
cmpl (%rcx), %eax
jle 0xc79e
movl 0x254(%rsp), %eax
movl %eax, 0x1ac(%rsp)
movl 0x250(%rsp), %eax
movl %eax, 0x1a8(%rsp)
jmp 0xc7ba
movl 0x250(%rsp), %eax
movl %eax, 0x1ac(%rsp)
movl 0x254(%rsp), %eax
movl %eax, 0x1a8(%rsp)
movq 0x210(%rsp), %rdi
movl 0x1a8(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0xec(%rsp)
movq 0x210(%rsp), %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movq %rax, %rcx
movl 0xec(%rsp), %eax
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0xc8a8
movq 0x228(%rsp), %rdi
movl 0x1a8(%rsp), %eax
movl %eax, %esi
callq 0x100e0
movq %rax, %rdi
callq 0x10a50
movq 0x228(%rsp), %rdi
movl 0x1a8(%rsp), %eax
movl %eax, %esi
callq 0x100e0
movq %rax, %rdi
leaq 0x1ac(%rsp), %rsi
callq 0xfce0
jmp 0xc84c
movq 0x220(%rsp), %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0xe8(%rsp)
movq 0x220(%rsp), %rdi
movl 0x1a8(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl 0xe8(%rsp), %ecx
movl %ecx, (%rax)
jmp 0xc910
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0xd1de
movq 0x228(%rsp), %rdi
movl 0x1a8(%rsp), %eax
movl %eax, %esi
callq 0x100e0
movq %rax, %rdi
leaq 0x1ac(%rsp), %rsi
callq 0xfce0
jmp 0xc8d0
movq 0x220(%rsp), %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0xe4(%rsp)
movq 0x220(%rsp), %rdi
movl 0x1a8(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl 0xe4(%rsp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
leaq 0x1b0(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x105b0
jmp 0xc927
movq 0x210(%rsp), %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
incl %eax
movl %eax, 0xc8(%rsp)
movq 0x210(%rsp), %rdi
movl 0x1a8(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl 0xc8(%rsp), %ecx
movl %ecx, (%rax)
movq 0x220(%rsp), %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0xcc(%rsp)
movq 0x218(%rsp), %rdi
movl 0x1a8(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl 0xcc(%rsp), %ecx
movl %ecx, (%rax)
movq 0x208(%rsp), %rdi
movl 0x1a8(%rsp), %eax
movl %eax, %esi
callq 0x10a70
movq %rdx, 0xd0(%rsp)
movq %rax, 0xd8(%rsp)
jmp 0xc9cd
movq 0xd0(%rsp), %rax
movq 0xd8(%rsp), %rcx
movq %rcx, 0x188(%rsp)
movq %rax, 0x190(%rsp)
leaq 0x188(%rsp), %rdi
movl $0x1, %esi
callq 0x10ad0
leaq 0x1b0(%rsp), %rdi
callq 0x105e0
movb %al, 0xc7(%rsp)
jmp 0xca15
movb 0xc7(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xca27
jmp 0xcfdf
leaq 0x1b0(%rsp), %rdi
callq 0x10600
movq %rax, 0xb8(%rsp)
jmp 0xca3e
movq 0xb8(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x184(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x10610
jmp 0xca5e
movq 0x230(%rsp), %rdi
movl 0x184(%rsp), %esi
callq 0x76f50
movq %rax, 0xb0(%rsp)
jmp 0xca7c
movq 0xb0(%rsp), %rsi
leaq 0x168(%rsp), %rdi
callq 0x10b20
jmp 0xca93
movl $0x0, 0x164(%rsp)
movslq 0x164(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x168(%rsp), %rdi
callq 0xfd50
movq %rax, %rcx
movq 0xa8(%rsp), %rax
cmpq %rcx, %rax
jae 0xcfcd
movslq 0x164(%rsp), %rsi
leaq 0x168(%rsp), %rdi
callq 0xfbc0
movl (%rax), %eax
movl %eax, 0x160(%rsp)
movq 0x210(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0xa4(%rsp)
movq 0x210(%rsp), %rdi
movl 0x184(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movq %rax, %rcx
movl 0xa4(%rsp), %eax
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0xcd53
movq 0x210(%rsp), %rdi
movl 0x184(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
incl %eax
movl %eax, 0xa0(%rsp)
movq 0x210(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl 0xa0(%rsp), %ecx
movl %ecx, (%rax)
movq 0x228(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x100e0
movq %rax, %rdi
callq 0x10a50
movq 0x228(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x100e0
movq %rax, %rdi
leaq 0x184(%rsp), %rsi
callq 0xfce0
jmp 0xcbbf
movq 0x220(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl $0x0, (%rax)
movq 0x218(%rsp), %rdi
movl 0x184(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0x88(%rsp)
movq 0x218(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl 0x88(%rsp), %ecx
movl %ecx, (%rax)
movq 0x218(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0x8c(%rsp)
movq 0x220(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl 0x8c(%rsp), %edx
movl (%rax), %ecx
addl %edx, %ecx
movl %ecx, (%rax)
movq 0x208(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x10a70
movq %rdx, 0x90(%rsp)
movq %rax, 0x98(%rsp)
jmp 0xcc83
movq 0x90(%rsp), %rax
movq 0x98(%rsp), %rcx
movq %rcx, 0x150(%rsp)
movq %rax, 0x158(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x10c20
xorb $-0x1, %al
testb $0x1, %al
jne 0xccbb
jmp 0xcd4e
movq 0x208(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x10a70
movq %rdx, 0x78(%rsp)
movq %rax, 0x80(%rsp)
jmp 0xcce0
movq 0x78(%rsp), %rax
movq 0x80(%rsp), %rcx
movq %rcx, 0x140(%rsp)
movq %rax, 0x148(%rsp)
leaq 0x140(%rsp), %rdi
movl $0x1, %esi
callq 0x10ad0
leaq 0x1b0(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x105b0
jmp 0xcd26
jmp 0xcd4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x10520
jmp 0xd1de
jmp 0xcfb5
movq 0x210(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0x74(%rsp)
movq 0x210(%rsp), %rdi
movl 0x184(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movq %rax, %rcx
movl 0x74(%rsp), %eax
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0xcfb3
movq 0x218(%rsp), %rdi
movl 0x184(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0x60(%rsp)
movq 0x218(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl 0x60(%rsp), %edx
movl (%rax), %ecx
addl %edx, %ecx
movl %ecx, (%rax)
movq 0x218(%rsp), %rdi
movl 0x184(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0x64(%rsp)
movq 0x220(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0xfc50
movl 0x64(%rsp), %edx
movl (%rax), %ecx
addl %edx, %ecx
movl %ecx, (%rax)
movq 0x228(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x100e0
movq %rax, %rdi
callq 0x10cf0
movq %rax, 0x130(%rsp)
movq 0x228(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x100e0
movq %rax, %rdi
callq 0x10d20
movq %rax, 0x128(%rsp)
movq 0x130(%rsp), %rdi
movq 0x128(%rsp), %rsi
leaq 0x184(%rsp), %rdx
callq 0x10c90
movq %rax, 0x68(%rsp)
jmp 0xce81
movq 0x68(%rsp), %rax
movq %rax, 0x138(%rsp)
movq 0x228(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x100e0
movq %rax, %rdi
callq 0x10d20
movq %rax, 0x120(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x10c50
testb $0x1, %al
jne 0xcecf
jmp 0xcef9
movq 0x228(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x100e0
movq %rax, %rdi
leaq 0x184(%rsp), %rsi
callq 0xfce0
jmp 0xcef7
jmp 0xcef9
movq 0x208(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x10a70
movq %rdx, 0x50(%rsp)
movq %rax, 0x58(%rsp)
jmp 0xcf1b
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
movq %rcx, 0x110(%rsp)
movq %rax, 0x118(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x10c20
xorb $-0x1, %al
testb $0x1, %al
jne 0xcf4a
jmp 0xcfb1
movq 0x208(%rsp), %rdi
movl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x10a70
movq %rdx, 0x40(%rsp)
movq %rax, 0x48(%rsp)
jmp 0xcf6c
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, 0x100(%rsp)
movq %rax, 0x108(%rsp)
leaq 0x100(%rsp), %rdi
movl $0x1, %esi
callq 0x10ad0
leaq 0x1b0(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x105b0
jmp 0xcfaf
jmp 0xcfb1
jmp 0xcfb3
jmp 0xcfb5
jmp 0xcfb7
movl 0x164(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x164(%rsp)
jmp 0xca9e
leaq 0x168(%rsp), %rdi
callq 0x10520
jmp 0xc9ff
movl $0x1, 0xfc(%rsp)
movslq 0xfc(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x200(%rsp), %rdi
callq 0xfd50
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
jae 0xd1c9
movq 0x210(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x200(%rsp), %rdi
movl 0xfc(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xfbc0
movq 0x20(%rsp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0x34(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x200(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xfbc0
movq 0x28(%rsp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0xfc50
movq %rax, %rcx
movl 0x34(%rsp), %eax
cmpl (%rcx), %eax
jle 0xd1b1
movl 0xfc(%rsp), %eax
movl %eax, 0xf8(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x200(%rsp), %rdi
movl 0xf8(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xfbc0
movq 0x8(%rsp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0xfc50
movl (%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x200(%rsp), %rdi
movslq 0xf8(%rsp), %rsi
callq 0xfbc0
movq 0x10(%rsp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0xfc50
movq %rax, %rcx
movl 0x1c(%rsp), %eax
cmpl (%rcx), %eax
jle 0xd1af
movq 0x200(%rsp), %rdi
movl 0xf8(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xfbc0
movl (%rax), %eax
movl %eax, 0xf4(%rsp)
movq 0x200(%rsp), %rdi
movslq 0xf8(%rsp), %rsi
callq 0xfbc0
movl (%rax), %eax
movl %eax, (%rsp)
movq 0x200(%rsp), %rdi
movl 0xf8(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xfbc0
movl (%rsp), %ecx
movl %ecx, (%rax)
movl 0xf4(%rsp), %eax
movl %eax, 0x4(%rsp)
movq 0x200(%rsp), %rdi
movslq 0xf8(%rsp), %rsi
callq 0xfbc0
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movl 0xf8(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xf8(%rsp)
jmp 0xd09d
jmp 0xd1b1
jmp 0xd1b3
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0xcfea
leaq 0x1b0(%rsp), %rdi
callq 0x10620
addq $0x258, %rsp            # imm = 0x258
retq
leaq 0x1b0(%rsp), %rdi
callq 0x10620
movq 0x1a0(%rsp), %rdi
callq 0x9cf0
nopl (%rax,%rax)