// File: /workspace/github_cpp_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
leaq 0x18a1a(%rip), %rdi     # 0x30b40
callq 0x2350
movq 0x108(%r15), %rsi
leaq 0x18117(%rip), %rdi     # 0x30250
xorl %eax, %eax
callq 0x2030
movq %r15, %rdi
callq 0x1dfcc
leaq 0x1810f(%rip), %rdi     # 0x3025e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r15), %rsi
leaq 0x1810f(%rip), %rdi     # 0x30273
xorl %eax, %eax
callq 0x2030
leaq 0x182b4(%rip), %rdi     # 0x30426
xorl %eax, %eax
callq 0x2030
leaq 0x118(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
leaq 0xd8(%rsp), %rdi
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xaa33
leaq 0x128(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2360
cvtsi2sdq -0x10(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdq -0x8(%rbx), %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdq (%rbx), %xmm0
movsd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdq 0x8(%rbx), %xmm0
movapd %xmm0, 0x30(%rsp)
movq %r15, 0x10(%rsp)
movq %r15, %rdi
callq 0x1dfcc
movsd 0x17fa4(%rip), %xmm0    # 0x301a0
movsd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm1
addsd 0x8(%rsp), %xmm1
movapd 0x30(%rsp), %xmm2
divsd %xmm0, %xmm2
addsd 0x40(%rsp), %xmm2
movq %rax, %xmm0
punpckldq 0x17ff7(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subsd %xmm1, %xmm2
movapd %xmm2, 0x30(%rsp)
subpd 0x17ff5(%rip), %xmm0    # 0x30230
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
leaq 0x18204(%rip), %rdi     # 0x3045a
movb $0x1, %al
callq 0x2030
leaq 0x181e4(%rip), %rdi     # 0x30448
movapd 0x30(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movq (%r14), %rcx
movq 0x8(%r14), %rax
cmpq %rcx, %rax
jne 0x1829f
leaq 0x188a8(%rip), %rdi     # 0x30b2c
callq 0x2350
movl %ebp, %edi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x16ecd
movq (%r14), %rcx
movq 0x8(%r14), %rax
xorl %r15d, %r15d
xorpd %xmm2, %xmm2
movapd %xmm2, 0x90(%rsp)
movq %r15, 0xa0(%rsp)
movq %r15, 0xc0(%rsp)
movapd %xmm2, 0xb0(%rsp)
xorpd %xmm0, %xmm0
subq %rcx, %rax
je 0x18420
leaq 0x70(%rsp), %r15
leaq 0x50(%rsp), %r12
xorl %ebx, %ebx
movl (%rcx,%rbx,8), %r13d
movl 0x4(%rcx,%rbx,8), %ebp
xorl %eax, %eax
movq %rax, 0x80(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movq %rax, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movl $0x3, %esi
movq %r15, %rdi
callq 0xd848
movl $0x3, %esi
movq %r12, %rdi
callq 0x5be8
movq 0x10(%rsp), %rdi
movl %r13d, %esi
movl %ebp, %edx
leaq 0xd8(%rsp), %rcx
movq %r12, %r8
movq %r15, %r9
callq 0xceaf
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
callq 0x1b338
leaq 0xb0(%rsp), %rdi
movq %r12, %rsi
callq 0x1b364
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x18376
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x18390
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
incq %rbx
movq (%r14), %rcx
movq 0x8(%r14), %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %rbx, %rax
ja 0x182e1
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %rsi
subq %rcx, %rsi
je 0x1842b
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdx
movq 0xb0(%rsp), %rsi
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorpd %xmm2, %xmm2
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq (%rcx,%rdi), %r8
addl (%r8), %r14d
addl 0x4(%r8), %ebp
addl 0x8(%r8), %r15d
movq (%rsi,%rdi), %r8
addsd (%r8), %xmm0
movupd 0x8(%r8), %xmm1
addpd %xmm1, %xmm2
addq $0x18, %rdi
decq %rdx
jne 0x183f3
jmp 0x1843b
sarq $0x3, %rax
xorl %ebp, %ebp
xorl %r14d, %r14d
jmp 0x1843b
xorpd %xmm2, %xmm2
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r14d, %r14d
xorpd %xmm0, %xmm0
movapd %xmm2, 0x20(%rsp)
addsd %xmm2, %xmm0
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
movapd %xmm2, 0x40(%rsp)
addsd %xmm2, %xmm0
movq %rax, %xmm2
punpckldq 0x17dc0(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x17dc8(%rip), %xmm2    # 0x30230
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xd0(%rsp)
leaq 0x17fd6(%rip), %rdi     # 0x3045e
movb $0x1, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movq 0x10(%rsp), %rdi
callq 0x1dfcc
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0xc8(%rsp)
movapd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
xorps %xmm2, %xmm2
cvtsi2sd %ebp, %xmm2
movapd %xmm2, 0x100(%rsp)
movq %rax, %xmm0
punpckldq 0x17d3f(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x17d47(%rip), %xmm0    # 0x30230
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addpd %xmm0, %xmm1
movapd 0x20(%rsp), %xmm3
unpcklpd 0x30(%rsp), %xmm3       # xmm3 = xmm3[0],mem[0]
movapd %xmm2, %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
divpd %xmm0, %xmm3
movapd %xmm3, 0xf0(%rsp)
movl $0xa, %edi
callq 0x22f0
leaq 0x17f56(%rip), %rdi     # 0x3047d
movl %r14d, %esi
xorl %eax, %eax
callq 0x2030
leaq 0x17f56(%rip), %rdi     # 0x3048e
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
leaq 0x17f57(%rip), %rdi     # 0x3049f
movl %r15d, %esi
xorl %eax, %eax
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movapd 0xf0(%rsp), %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
movapd %xmm2, 0x10(%rsp)
movapd %xmm0, %xmm1
divsd %xmm2, %xmm1
leaq 0x17f2e(%rip), %rdi     # 0x304b0
movb $0x2, %al
callq 0x2030
movsd 0x8(%rsp), %xmm0
movapd %xmm0, %xmm1
divsd 0x10(%rsp), %xmm1
leaq 0x17f2b(%rip), %rdi     # 0x304cb
movb $0x2, %al
callq 0x2030
leaq 0x17f38(%rip), %rdi     # 0x304e6
movaps 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movapd 0x20(%rsp), %xmm1
addsd 0x40(%rsp), %xmm1
addl %r15d, %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movapd 0xf0(%rsp), %xmm1
movapd 0x10(%rsp), %xmm2
subsd %xmm2, %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm2, %xmm0
mulsd 0xc8(%rsp), %xmm0
mulsd 0x100(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x17edf(%rip), %rdi     # 0x304fd
movb $0x1, %al
callq 0x2030
movapd 0x20(%rsp), %xmm0
movapd %xmm0, %xmm1
divsd 0x10(%rsp), %xmm1
leaq 0x17edd(%rip), %rdi     # 0x30519
movb $0x2, %al
callq 0x2030
movapd 0x30(%rsp), %xmm0
divsd 0xd0(%rsp), %xmm0
leaq 0x17edc(%rip), %rdi     # 0x30535
movb $0x1, %al
callq 0x2030
leaq 0xb0(%rsp), %rdi
callq 0x5fa4
leaq 0x90(%rsp), %rdi
callq 0xd87a
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x18697
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x186e7
movq %rax, %rbx
jmp 0x18701
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x186cd
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x186e7
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xb0(%rsp), %rdi
callq 0x5fa4
leaq 0x90(%rsp), %rdi
callq 0xd87a
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x1871e
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq %rbx, %rdi
callq 0x23b0