// File: /workspace/github_cpp_makefile_star2_O2/fjamour[P]icentral/src/experiments.cc
// Function: incremental_brandes_test(graph_t&, int, std::vector<std::pair<unsigned int, unsigned int>, std::allocator<std::pair<unsigned int, unsigned int>>>)
void incremental_brandes_test(graph_t& graph, int num_edges_to_insert, vector<edge_t> rand_edge_vec)
{
    printf("==========================================================\n");
    printf("Graph: \t\t\t%s\n", graph.graph_name.c_str());
    printf("Graph # nodes: \t\t%d\n", graph.size());
    printf("Graph # edges: \t\t%d\n", graph.edge_set.size());
    double brandes_time;
    timer tm;
    
    printf("Brandes avg time per iteration: \t");
    tm.start();
    vector<double> bc_vec = brandes_bc(graph);
    tm.stop();
    brandes_time = tm.interval();
    printf("%f\n", brandes_time/graph.size());
    printf("Brandes time: \t\t\t\t%f\n", brandes_time);
    
    if(rand_edge_vec.size() == 0) {
        printf("Generating edges...\n");
        gen_rand_edges(num_edges_to_insert, graph, rand_edge_vec);
    }

    vector<edge_stat_t> edge_stat_vec;
 
    vector<vector<int> >    cnt_vec2;
    vector<vector<double> > time_vec2;
    
    for(int i = 0; i < rand_edge_vec.size(); ++i) {
        //printf("Inserting edge [%d]...\n", i);
        edge_t rand_edge = rand_edge_vec[i];
        
        vector<int> cnt_vec;
        vector<double> time_vec;
        cnt_vec.resize(3);
        time_vec.resize(3);
        
        
        incremental_brandes_experimental(graph,
                rand_edge.first, 
                rand_edge.second, 
                bc_vec,
                time_vec,
                cnt_vec);
        cnt_vec2.push_back(cnt_vec);
        time_vec2.push_back(time_vec);
    }

    int tot_cnt_arr[] = {0, 0, 0};
    double tot_time_arr[] = {0, 0, 0};
    double tot_avg_arr[] = {0, 0, 0};
    
    for(int i = 0; i < cnt_vec2.size(); ++i) {
        tot_cnt_arr[0] += cnt_vec2[i][0];
        tot_cnt_arr[1] += cnt_vec2[i][1];
        tot_cnt_arr[2] += cnt_vec2[i][2];
        
        tot_time_arr[0] += time_vec2[i][0];
        tot_time_arr[1] += time_vec2[i][1];
        tot_time_arr[2] += time_vec2[i][2];
        
        tot_avg_arr[0] += (time_vec2[i][0]/cnt_vec2[i][0]);
        tot_avg_arr[1] += (time_vec2[i][1]/cnt_vec2[i][1]);
        tot_avg_arr[2] += (time_vec2[i][2]/cnt_vec2[i][2]);
    }
    double inc_tot_time = tot_time_arr[0] + tot_time_arr[1] + tot_time_arr[2];
    double inc_avg_time = inc_tot_time/rand_edge_vec.size();
    printf("Incremental Brandes time:\t\t%f\n", inc_avg_time);
    printf("\n");
    double avg_d1_tm = tot_time_arr[1]/tot_cnt_arr[1];
    double avg_d2_tm = tot_time_arr[2]/tot_cnt_arr[2];
    double avg_br_tm = brandes_time/graph.size();
    printf("\n");
    printf("Tot d0 BFS:\t\t%d\n", tot_cnt_arr[0]);
    printf("Tot d1 BFS:\t\t%d\n", tot_cnt_arr[1]);
    printf("Tot d2 BFS:\t\t%d\n", tot_cnt_arr[2]);
    printf("\n");
    printf("Avg d1 BFS time:\t\t%f (%f)\n", avg_d1_tm, avg_d1_tm/avg_br_tm);
    printf("Avg d2 BFS time:\t\t%f (%f)\n", avg_d2_tm, avg_d2_tm/avg_br_tm);
    printf("Avg Brandes time:\t\t%f\n", avg_br_tm);
    double avg_inc_iter = 
    (tot_time_arr[1] + tot_time_arr[2])/(tot_cnt_arr[1] + tot_cnt_arr[2]);
    
    double mem_dag_time = (avg_d1_tm-avg_br_tm)*tot_cnt_arr[1] + (avg_d2_tm-avg_br_tm)*tot_cnt_arr[2];
    double mem_dag_speedup = brandes_time/mem_dag_time;
    printf("Ideal mem DAG speedup:\t %f\n", mem_dag_speedup);
    printf("Avg inc BFS time:\t\t%f (%f)\n", avg_inc_iter, avg_inc_iter/avg_br_tm);
    printf("[[Avg speedup:\t\t\t%f]]\n", brandes_time/inc_avg_time);
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %r14
leaq 0x150b3(%rip), %rdi     # 0x28b00
callq 0x2360
movq 0x108(%r14), %rsi
leaq 0x147b0(%rip), %rdi     # 0x28210
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x18d3c
leaq 0x147a8(%rip), %rdi     # 0x2821e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0x147a8(%rip), %rdi     # 0x28233
xorl %eax, %eax
callq 0x2030
leaq 0x1494d(%rip), %rdi     # 0x283e6
xorl %eax, %eax
callq 0x2030
leaq 0x138(%rsp), %rbx
movq %rbx, %rdi
callq 0xb094
leaq 0x108(%rsp), %rdi
pushq $-0x1
popq %rdx
movq %r14, %rsi
callq 0x8fa3
movq %rbx, %rdi
callq 0xb09c
movq %rbx, %rdi
callq 0xb0a8
movapd %xmm0, 0x10(%rsp)
movq %r14, (%rsp)
movq %r14, %rdi
callq 0x18d3c
movq %rax, %xmm0
punpckldq 0x146fe(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x14706(%rip), %xmm0    # 0x28200
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x14903(%rip), %rdi     # 0x2841a
movb $0x1, %al
callq 0x2030
leaq 0x148e3(%rip), %rdi     # 0x28408
movapd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movq 0x8(%r15), %rax
cmpq (%r15), %rax
jne 0x13b55
leaq 0x14faa(%rip), %rdi     # 0x28aec
callq 0x2360
movl %ebp, %edi
movq (%rsp), %rsi
movq %r15, %rdx
callq 0x12cba
xorpd %xmm0, %xmm0
andq $0x0, 0x100(%rsp)
leaq 0x40(%rsp), %rax
andq $0x0, 0x10(%rax)
movapd %xmm0, 0xf0(%rsp)
movapd %xmm0, (%rax)
leaq 0x70(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
xorl %r14d, %r14d
leaq 0xd0(%rsp), %r13
leaq 0xb0(%rsp), %rbx
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jbe 0x13c4d
movq %r15, %rbp
movl (%rax,%r14,8), %r12d
movl 0x4(%rax,%r14,8), %r15d
xorpd %xmm0, %xmm0
movapd %xmm0, 0xd0(%rsp)
andq $0x0, 0xe0(%rsp)
movapd %xmm0, 0xb0(%rsp)
andq $0x0, 0xc0(%rsp)
movq %r13, %rdi
pushq $0x3
popq %rsi
callq 0xafb8
movq %rbx, %rdi
pushq $0x3
popq %rsi
callq 0x45f0
movq (%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
leaq 0x108(%rsp), %rcx
movq %rbx, %r8
movq %r13, %r9
callq 0xa87e
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x16414
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
callq 0x16440
movq %rbx, %rdi
callq 0x5754
movq %r13, %rdi
callq 0x5720
incq %r14
movq %rbp, %r15
jmp 0x13b9a
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rax
subq %rsi, %rax
pushq $0x18
popq %rdi
cqto
idivq %rdi
xorpd %xmm2, %xmm2
xorl %edx, %edx
xorpd %xmm0, %xmm0
movq 0x70(%rsp), %rdi
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r15d, %r15d
subq $0x1, %rax
jb 0x13ca7
movq (%rsi,%rdx), %r8
addl (%r8), %r15d
addl 0x4(%r8), %r14d
addl 0x8(%r8), %ebp
movq (%rdi,%rdx), %r8
addsd (%r8), %xmm0
movupd 0x8(%r8), %xmm1
addpd %xmm1, %xmm2
addq $0x18, %rdx
jmp 0x13c79
addsd %xmm2, %xmm0
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
movapd %xmm1, 0xa0(%rsp)
addsd %xmm1, %xmm0
movapd %xmm2, 0x30(%rsp)
movq %rcx, %xmm2
punpckldq 0x1451d(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x14525(%rip), %xmm2    # 0x28200
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
leaq 0x14726(%rip), %rdi     # 0x2841e
movb $0x1, %al
callq 0x2030
pushq $0xa
popq %rdi
callq 0x2300
movq (%rsp), %rdi
callq 0x18d3c
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x60(%rsp)
movapd 0xa0(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
cvtsi2sd %r14d, %xmm2
movapd %xmm2, 0x120(%rsp)
movq %rax, %xmm0
punpckldq 0x144a8(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x144b0(%rip), %xmm0    # 0x28200
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addpd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm3
unpcklpd 0x10(%rsp), %xmm3       # xmm3 = xmm3[0],mem[0]
movapd %xmm2, %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
divpd %xmm0, %xmm3
movapd %xmm3, 0x90(%rsp)
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x2300
leaq 0x146af(%rip), %rdi     # 0x2843d
movl %r15d, %esi
xorl %eax, %eax
callq 0x2030
leaq 0x146af(%rip), %rdi     # 0x2844e
movl %r14d, %esi
xorl %eax, %eax
callq 0x2030
leaq 0x146af(%rip), %rdi     # 0x2845f
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
movl %ebx, %edi
callq 0x2300
movapd 0x90(%rsp), %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
movapd %xmm2, (%rsp)
movapd %xmm0, %xmm1
divsd %xmm2, %xmm1
leaq 0x1468b(%rip), %rdi     # 0x28470
movb $0x2, %al
callq 0x2030
movsd 0x28(%rsp), %xmm0
movapd %xmm0, %xmm1
divsd (%rsp), %xmm1
leaq 0x14689(%rip), %rdi     # 0x2848b
movb $0x2, %al
callq 0x2030
leaq 0x14696(%rip), %rdi     # 0x284a6
movaps (%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movapd 0x30(%rsp), %xmm1
addsd 0xa0(%rsp), %xmm1
addl %ebp, %r14d
cvtsi2sd %r14d, %xmm0
divsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movapd 0x90(%rsp), %xmm1
movapd (%rsp), %xmm2
subsd %xmm2, %xmm1
movsd 0x28(%rsp), %xmm0
subsd %xmm2, %xmm0
mulsd 0x60(%rsp), %xmm0
mulsd 0x120(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x14641(%rip), %rdi     # 0x284bd
movb $0x1, %al
callq 0x2030
movapd 0x30(%rsp), %xmm0
movapd %xmm0, %xmm1
divsd (%rsp), %xmm1
leaq 0x14640(%rip), %rdi     # 0x284d9
movb $0x2, %al
callq 0x2030
movapd 0x10(%rsp), %xmm0
divsd 0x68(%rsp), %xmm0
leaq 0x14642(%rip), %rdi     # 0x284f5
movb $0x1, %al
callq 0x2030
leaq 0x70(%rsp), %rdi
callq 0x49da
leaq 0x40(%rsp), %rdi
callq 0xafea
leaq 0xf0(%rsp), %rdi
callq 0x16772
leaq 0x108(%rsp), %rdi
callq 0x5754
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x13f21
movq %rax, %rbx
jmp 0x13f42
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x5754
leaq 0xd0(%rsp), %rdi
callq 0x5720
leaq 0x70(%rsp), %rdi
callq 0x49da
leaq 0x40(%rsp), %rdi
callq 0xafea
leaq 0xf0(%rsp), %rdi
callq 0x16772
leaq 0x108(%rsp), %rdi
callq 0x5754
movq %rbx, %rdi
callq 0x23d0