// File: fjamour[P]icentral/src/unit_tests.h
// Function: timing__Update_BC_graph(graph_t&, std::vector<std::pair<unsigned int, unsigned int>, std::allocator<std::pair<unsigned int, unsigned int>>>&, int, comp_type_t, bool, double, int, bool, operation_t)
void timing__Update_BC_graph(
            graph_t&        graph,
            vector<edge_t>& edge_vec,
            int             num_sources,
            comp_type_t     algo_flag,
            bool            do_brandes = true,
            double          brandes_time = 0.0,
            int             num_threads = 1,
            bool            del_edge = false,//in case the edges are already in the graph
            operation_t     op = INSERTION
        )
{
    int rank, size;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Status    status;
    
    timer           tm;
    vector<double>  BC_vec;
    vector<double>  tm_vec;
    vector<double>  speedup_vec;
    
    BC_vec.resize(graph.size());
    if(do_brandes) {
        tm.start();
        //fast_brandes_BC(graph, BC_vec);
        BC_vec = brandes_bc(graph);
        tm.stop();
        brandes_time = tm.interval();
    }
    if(rank == 0) {
        printf("Graph[%s]  V[%d]  E[%d]  Brandes_tm[%.2f]\n",
                graph.graph_name.c_str(),
                graph.size(),
                graph.edge_set.size(),
                brandes_time);
    }
    for(int i = 0; i < edge_vec.size(); ++i) {
        edge_t e = edge_vec[i];
        if(del_edge) graph.remove_edge(e.first, e.second);
        tm.start();
        Update_BC(BC_vec, graph, algo_flag, e, num_threads, op);
        tm.stop();
        double e_time = tm.interval();
        tm_vec.push_back(e_time);
        double e_speedup = brandes_time/e_time;
        speedup_vec.push_back(e_speedup);
        
        if(rank == 0) {
            printf("e(%-6d,%-6d)  tm[%.2f]  sup[%.2f]\n",
                    e.first,
                    e.second,
                    e_time,
                    e_speedup);
        }
        if(del_edge) graph.insert_edge(e.first, e.second);
        //synchronization barrier so no one starts next edge before others
        MPI_Barrier(MPI_COMM_WORLD);
    }
    
    double tm_mean, tm_stddev, tm_median, tm_min, tm_max;
    double su_mean, su_stddev, su_median, su_min, su_max;
    simple_stats(tm_vec, tm_mean, tm_stddev, tm_median, tm_min, tm_max);
    simple_stats(speedup_vec, su_mean, su_stddev, su_median, su_min, su_max);
    
    if(rank == 0)
        printf("Avg.tm[%.2f]  Avg.sup[%.2f]\n\n", tm_mean, su_mean);
}

// Assembly:
subq $0x1d8, %rsp            # imm = 0x1D8
movl %r8d, %eax
movl %ecx, 0x30(%rsp)
movl %edx, %ecx
movl 0x30(%rsp), %edx
movl %ecx, 0x34(%rsp)
movq %rsi, %rcx
movl 0x34(%rsp), %esi
movq %rcx, 0x38(%rsp)
movq %rdi, %r8
movq 0x38(%rsp), %rdi
movb %al, %cl
movl 0x1e8(%rsp), %eax
movb 0x1e0(%rsp), %al
movq %r8, 0x1d0(%rsp)
movq %rdi, 0x1c8(%rsp)
movl %esi, 0x1c4(%rsp)
movl %edx, 0x1c0(%rsp)
andb $0x1, %cl
movb %cl, 0x1bf(%rsp)
movsd %xmm0, 0x1b0(%rsp)
movl %r9d, 0x1ac(%rsp)
andb $0x1, %al
movb %al, 0x1ab(%rsp)
movq 0x40813(%rip), %rdi     # 0x9afb8
movq %rdi, 0x40(%rsp)
leaq 0x1a4(%rsp), %rsi
callq 0x9a70
movq 0x40(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x9880
leaq 0x150(%rsp), %rdi
callq 0xfa00
leaq 0x138(%rsp), %rdi
callq 0xfa00
leaq 0x120(%rsp), %rdi
callq 0xfa00
movq 0x1d0(%rsp), %rdi
callq 0x56b40
movq %rax, 0x48(%rsp)
jmp 0x5a804
movq 0x48(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0xf680
jmp 0x5a818
testb $0x1, 0x1bf(%rsp)
je 0x5a8c3
leaq 0x168(%rsp), %rdi
callq 0x2d430
jmp 0x5a835
movq 0x1d0(%rsp), %rsi
leaq 0xf8(%rsp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x28720
jmp 0x5a851
leaq 0x150(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
movq %rsi, 0x28(%rsp)
callq 0x58bf0
movq 0x28(%rsp), %rdi
callq 0xfa50
leaq 0x168(%rsp), %rdi
callq 0x2d450
jmp 0x5a884
leaq 0x168(%rsp), %rdi
callq 0x2d470
movsd %xmm0, 0x20(%rsp)
jmp 0x5a899
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x1b0(%rsp)
jmp 0x5a8c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
jmp 0x5ac51
cmpl $0x0, 0x1a4(%rsp)
jne 0x5a933
movq 0x1d0(%rsp), %rdi
addq $0x108, %rdi            # imm = 0x108
callq 0x9250
movq %rax, 0x10(%rsp)
movq 0x1d0(%rsp), %rdi
callq 0x56b40
movq %rax, 0x18(%rsp)
jmp 0x5a8fa
movq 0x1d0(%rsp), %rdi
addq $0x30, %rdi
callq 0x4dbe0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
movsd 0x1b0(%rsp), %xmm0
leaq 0x21447(%rip), %rdi     # 0x7bd6f
movb $0x1, %al
callq 0x9040
jmp 0x5a931
jmp 0x5a933
movl $0x0, 0xf4(%rsp)
movslq 0xf4(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x1c8(%rsp), %rdi
callq 0x47680
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0x5ab10
movq 0x1c8(%rsp), %rdi
movslq 0xf4(%rsp), %rsi
callq 0x4dbc0
movq (%rax), %rax
movq %rax, 0xec(%rsp)
testb $0x1, 0x1ab(%rsp)
je 0x5a9b2
movq 0x1d0(%rsp), %rdi
movl 0xec(%rsp), %esi
movl 0xf0(%rsp), %edx
callq 0x56850
jmp 0x5a9b0
jmp 0x5a9b2
leaq 0x168(%rsp), %rdi
callq 0x2d430
jmp 0x5a9c1
movq 0x1d0(%rsp), %rsi
movl 0x1c0(%rsp), %edx
movq 0xec(%rsp), %rax
movq %rax, 0xe0(%rsp)
movl 0x1ac(%rsp), %r8d
movl 0x1e8(%rsp), %r9d
movq 0xe0(%rsp), %rcx
leaq 0x150(%rsp), %rdi
callq 0xa4e0
jmp 0x5aa07
leaq 0x168(%rsp), %rdi
callq 0x2d450
jmp 0x5aa16
leaq 0x168(%rsp), %rdi
callq 0x2d470
movsd %xmm0, (%rsp)
jmp 0x5aa2a
movsd (%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x4de20
jmp 0x5aa4f
movsd 0x1b0(%rsp), %xmm0
movsd 0xd8(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xd0(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x4de20
jmp 0x5aa85
cmpl $0x0, 0x1a4(%rsp)
jne 0x5aac1
movl 0xec(%rsp), %esi
movl 0xf0(%rsp), %edx
movsd 0xd8(%rsp), %xmm0
movsd 0xd0(%rsp), %xmm1
leaq 0x212e4(%rip), %rdi     # 0x7bd9a
movb $0x2, %al
callq 0x9040
jmp 0x5aabf
jmp 0x5aac1
testb $0x1, 0x1ab(%rsp)
je 0x5aaea
movq 0x1d0(%rsp), %rdi
movl 0xec(%rsp), %esi
movl 0xf0(%rsp), %edx
callq 0x56720
jmp 0x5aae8
jmp 0x5aaea
movq 0x404c7(%rip), %rdi     # 0x9afb8
callq 0x94e0
jmp 0x5aaf8
jmp 0x5aafa
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x5a93e
leaq 0x68(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x4de90
jmp 0x5ab24
leaq 0x68(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
leaq 0xb8(%rsp), %rcx
leaq 0xb0(%rsp), %r8
leaq 0xa8(%rsp), %r9
callq 0x78710
jmp 0x5ab58
leaq 0x68(%rsp), %rdi
callq 0xfa50
leaq 0x50(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x4de90
jmp 0x5ab76
leaq 0x50(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x98(%rsp), %rdx
leaq 0x90(%rsp), %rcx
leaq 0x88(%rsp), %r8
leaq 0x80(%rsp), %r9
callq 0x78710
jmp 0x5abaa
leaq 0x50(%rsp), %rdi
callq 0xfa50
cmpl $0x0, 0x1a4(%rsp)
jne 0x5ac22
movsd 0xc8(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm1
leaq 0x211e6(%rip), %rdi     # 0x7bdbd
movb $0x2, %al
callq 0x9040
jmp 0x5abe0
jmp 0x5ac22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0x68(%rsp), %rdi
callq 0xfa50
jmp 0x5ac51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xfa50
jmp 0x5ac51
leaq 0x120(%rsp), %rdi
callq 0xfa50
leaq 0x138(%rsp), %rdi
callq 0xfa50
leaq 0x150(%rsp), %rdi
callq 0xfa50
addq $0x1d8, %rsp            # imm = 0x1D8
retq
leaq 0x120(%rsp), %rdi
callq 0xfa50
leaq 0x138(%rsp), %rdi
callq 0xfa50
leaq 0x150(%rsp), %rdi
callq 0xfa50
movq 0x118(%rsp), %rdi
callq 0x9cf0
nopw %cs:(%rax,%rax)