// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movl %esi, %ebp
movq %rdi, %r14
leaq 0x1994a(%rip), %rdi     # 0x31b40
callq 0x2350
movq 0x108(%r14), %rsi
leaq 0x19047(%rip), %rdi     # 0x31250
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x1e160
leaq 0x1903f(%rip), %rdi     # 0x3125e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0x1903f(%rip), %rdi     # 0x31273
xorl %eax, %eax
callq 0x2030
leaq 0x191e4(%rip), %rdi     # 0x31426
xorl %eax, %eax
callq 0x2030
leaq 0x118(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
leaq 0xd8(%rsp), %rdi
movq %r14, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xaa17
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, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdq (%rbx), %xmm0
movsd %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdq 0x8(%rbx), %xmm0
movapd %xmm0, 0x30(%rsp)
movq %r14, 0x20(%rsp)
movq %r14, %rdi
callq 0x1e160
movsd 0x18ed4(%rip), %xmm0    # 0x311a0
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
addsd 0x8(%rsp), %xmm1
movapd 0x30(%rsp), %xmm2
divsd %xmm0, %xmm2
addsd 0x60(%rsp), %xmm2
movq %rax, %xmm0
punpckldq 0x18f27(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subsd %xmm1, %xmm2
movapd %xmm2, 0x30(%rsp)
subpd 0x18f25(%rip), %xmm0    # 0x31230
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
leaq 0x19134(%rip), %rdi     # 0x3145a
movb $0x1, %al
callq 0x2030
leaq 0x19114(%rip), %rdi     # 0x31448
movapd 0x30(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movq 0x8(%r15), %rax
cmpq (%r15), %rax
jne 0x18365
leaq 0x197db(%rip), %rdi     # 0x31b2c
callq 0x2350
movl %ebp, %edi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x16f89
xorpd %xmm1, %xmm1
movapd %xmm1, 0x70(%rsp)
xorl %r14d, %r14d
movq %r14, 0x80(%rsp)
movq %r14, 0xc0(%rsp)
movapd %xmm1, 0xb0(%rsp)
movq (%r15), %rcx
movq 0x8(%r15), %rax
subq %rcx, %rax
je 0x18483
movq %r15, 0x10(%rsp)
leaq 0x90(%rsp), %r12
leaq 0x40(%rsp), %r13
xorl %r15d, %r15d
movl (%rcx,%r15,8), %ebx
movl 0x4(%rcx,%r15,8), %ebp
xorl %eax, %eax
movq %rax, 0xa0(%rsp)
movapd %xmm1, 0x90(%rsp)
movq %rax, 0x50(%rsp)
movapd %xmm1, 0x40(%rsp)
movl $0x3, %esi
movq %r12, %rdi
callq 0xd7da
movl $0x3, %esi
movq %r13, %rdi
callq 0x5c58
movq 0x20(%rsp), %rdi
movl %ebx, %esi
movl %ebp, %edx
leaq 0xd8(%rsp), %rcx
movq %r13, %r8
movq %r12, %r9
callq 0xceaf
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x1b3de
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x1b40a
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x18441
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x1845e
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
incq %r15
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %r15, %rax
xorpd %xmm1, %xmm1
ja 0x183b0
jmp 0x18487
sarq $0x3, %rax
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rsi
subq %rcx, %rsi
je 0x184f3
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdx
movq 0xb0(%rsp), %rsi
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r14d, %r14d
movq (%rcx,%rdi), %r8
addl (%r8), %r15d
addl 0x4(%r8), %ebp
addl 0x8(%r8), %r14d
movq (%rsi,%rdi), %r8
addsd (%r8), %xmm0
movupd 0x8(%r8), %xmm2
addpd %xmm2, %xmm1
addq $0x18, %rdi
decq %rdx
jne 0x184c6
jmp 0x184fc
xorpd %xmm0, %xmm0
xorl %ebp, %ebp
xorl %r15d, %r15d
movapd %xmm1, 0x10(%rsp)
addsd %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
movapd %xmm1, 0x60(%rsp)
addsd %xmm1, %xmm0
movq %rax, %xmm2
punpckldq 0x18cff(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x18d07(%rip), %xmm2    # 0x31230
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x18f1e(%rip), %rdi     # 0x3145e
movsd %xmm0, 0xd0(%rsp)
movb $0x1, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movq 0x20(%rsp), %rdi
callq 0x1e160
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0xc8(%rsp)
movapd 0x60(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
xorps %xmm2, %xmm2
cvtsi2sd %ebp, %xmm2
movapd %xmm2, 0x100(%rsp)
movq %rax, %xmm0
punpckldq 0x18c7e(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x18c86(%rip), %xmm0    # 0x31230
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addpd %xmm0, %xmm1
movapd 0x10(%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 0x18e95(%rip), %rdi     # 0x3147d
movl %r15d, %esi
xorl %eax, %eax
callq 0x2030
leaq 0x18e95(%rip), %rdi     # 0x3148e
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
leaq 0x18e96(%rip), %rdi     # 0x3149f
movl %r14d, %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, 0x20(%rsp)
movapd %xmm0, %xmm1
divsd %xmm2, %xmm1
leaq 0x18e6d(%rip), %rdi     # 0x314b0
movb $0x2, %al
callq 0x2030
movsd 0x8(%rsp), %xmm0
movapd %xmm0, %xmm1
divsd 0x20(%rsp), %xmm1
leaq 0x18e6a(%rip), %rdi     # 0x314cb
movb $0x2, %al
callq 0x2030
leaq 0x18e77(%rip), %rdi     # 0x314e6
movaps 0x20(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movapd 0x10(%rsp), %xmm1
addsd 0x60(%rsp), %xmm1
addl %r14d, %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movapd 0xf0(%rsp), %xmm1
movapd 0x20(%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 0x18e1e(%rip), %rdi     # 0x314fd
movb $0x1, %al
callq 0x2030
movapd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm1
divsd 0x20(%rsp), %xmm1
leaq 0x18e1c(%rip), %rdi     # 0x31519
movb $0x2, %al
callq 0x2030
movapd 0x30(%rsp), %xmm0
divsd 0xd0(%rsp), %xmm0
leaq 0x18e1b(%rip), %rdi     # 0x31535
movb $0x1, %al
callq 0x2030
leaq 0xb0(%rsp), %rdi
callq 0x602e
leaq 0x70(%rsp), %rdi
callq 0xd80c
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x18755
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 0x1879d
movq %rax, %rbx
jmp 0x187b4
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1878b
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0x40(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x28db
leaq 0xb0(%rsp), %rdi
callq 0x602e
leaq 0x70(%rsp), %rdi
callq 0xd80c
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x187d1
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq %rbx, %rdi
callq 0x23b0