// File: /workspace/github_cpp_makefile_star2_O3/fjamour[P]icentral/src/paper_exp.cc
// Function: exp_fuad_p(graph_t&, int, std::vector<std::pair<unsigned int, unsigned int>, std::allocator<std::pair<unsigned int, unsigned int>>>, double)
void    exp_fuad_p(graph_t& graph,
            int num_iter,
            vector<edge_t> rand_edge_vec,
            double brandes_time)
{
    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());
    
    tr1_map_t(double) bc_vec = brandes_bc_hash_out(graph, 1);
    timer tm;

    double tot_fuad_time = 0;
    double tot_speedup = 0;
    if(num_iter == -1) {
        printf("WILL DO ALL ITERATIONS...\n");
    } else {
        printf("WILL DO %d ITERATIONS...\n", num_iter);
    }
    vector<bcc_stat_t>  bcc_stat_vec;
    vector<double>      speedup_vec;
    for(int i = 0; i < rand_edge_vec.size(); ++i) {
        bcc_stat_t bcc_stat;
        edge_t rand_edge = rand_edge_vec[i];
        double est_time = 0;
        
        printf("Inserting edge (%d, %d) and updating bc...\n", rand_edge.first, rand_edge.second);
        tm.start();
        graph.insert_edge_update_bc_experimental(rand_edge.first, rand_edge.second, bcc_stat, num_iter, num_iter);
        tm.stop();
        if(num_iter == -1) {
            est_time = bcc_stat.bc_update_time + bcc_stat.bcc_find_time;
        }
        
        double avg_iter_time_naive;
        graph.approx_bcc_iter_tm(rand_edge.first, rand_edge.second, avg_iter_time_naive, 10);
        tot_fuad_time += tm.interval();
        
        //fix counts if will produce errors:
        if(bcc_stat.num_d0_iter == 0) {
            bcc_stat.num_d0_iter = 1;
            bcc_stat.tot_d0_tm = 0;
        }
        if(bcc_stat.num_d1_iter == 0) {
            bcc_stat.num_d1_iter = 1;
            bcc_stat.tot_d1_tm = 0;
        }
        if(bcc_stat.num_d2_iter == 0) {
            bcc_stat.num_d2_iter = 1;
            bcc_stat.tot_d2_tm = 0;
        }
        ////
        if(num_iter != -1) {
            est_time += bcc_stat.tot_d1_tm*bcc_stat.tot_d1_iter/bcc_stat.num_d1_iter;
            est_time += bcc_stat.tot_d2_tm*bcc_stat.tot_d2_iter/bcc_stat.num_d2_iter;
        }
       
        tot_speedup += (brandes_time/est_time);
        speedup_vec.push_back(brandes_time/est_time);
        
        printf("\tBCC num nodes: \t\t\t%d (%f G_n)\n",
                bcc_stat.bcc_num_nodes,
                (double)bcc_stat.bcc_num_nodes/graph.size());
        printf("\tBCC num edges: \t\t\t%d (%f G_m)\n",
                bcc_stat.bcc_num_edges,
                (double)bcc_stat.bcc_num_edges/graph.edge_set.size());
        printf("\n");
        printf("\tTime to update BC: \t\t%f\n",
                est_time);
        printf("\tSpeedup: \t\t\t%f\n",
                brandes_time/est_time);
        printf("\n");
        printf("\tBCC d1 time: \t\t\t%f (%f to naive iter)\n",
                bcc_stat.tot_d1_tm/bcc_stat.num_d1_iter,
                (bcc_stat.tot_d1_tm/bcc_stat.num_d1_iter)/avg_iter_time_naive);
        printf("\tBCC d2 time: \t\t\t%f (%f to naive iter)\n",
                bcc_stat.tot_d2_tm/bcc_stat.num_d2_iter,
                (bcc_stat.tot_d2_tm/bcc_stat.num_d2_iter)/avg_iter_time_naive);
        printf("\tavg iter time naive: \t\t%f (%f to naive iter)\n",
                avg_iter_time_naive,
                avg_iter_time_naive/avg_iter_time_naive);
        printf("\n");
        printf("\tBCC num/tot d0 BFS: \t\t%*d/%*d (%f to BCC_n)\n",
                8,
                bcc_stat.num_d0_iter,
                8,
                bcc_stat.tot_d0_iter,
                bcc_stat.tot_d0_iter/(double)bcc_stat.bcc_num_nodes);
        printf("\tBCC num/tot d1 BFS: \t\t%*d/%*d (%f to BCC_n)\n",
                8,
                bcc_stat.num_d1_iter,
                8,
                bcc_stat.tot_d1_iter,
                bcc_stat.tot_d1_iter/(double)bcc_stat.bcc_num_nodes);
        printf("\tBCC num/tot d2 BFS: \t\t%*d/%*d (%f to BCC_n)\n",
                8,
                bcc_stat.num_d2_iter,
                8,
                bcc_stat.tot_d2_iter,
                bcc_stat.tot_d2_iter/(double)bcc_stat.bcc_num_nodes);
        printf("\n");
        printf("\tBCC bcc find time: \t\t%f\n", bcc_stat.bcc_find_time);
        printf("\tBCC sssp time: \t\t\t%f\n", bcc_stat.sssp_tm);
        
        bcc_stat_vec.push_back(bcc_stat);
        
        //dont remove the edge, to have fair comparison to QUBE
        //in my QUBE implementation the MUC update after edge removal is not
        //implemented
        //graph.remove_edge(rand_edge.first, rand_edge.second);
    }
    
    //double avg_speedup = (num_edges_to_insert*brandes_time)/tot_fuad_time;
    double avg_speedup = tot_speedup/rand_edge_vec.size();
    
    printf("[[Avg. speedup (fuad): %f]]\n", avg_speedup);
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movsd %xmm0, 0xc8(%rsp)
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
leaq 0xa4c8(%rip), %rdi      # 0x30b40
callq 0x2350
movq 0x108(%r14), %rsi
leaq 0x9bc5(%rip), %rdi      # 0x30250
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x1dfcc
leaq 0x9bbd(%rip), %rdi      # 0x3025e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0x9bbd(%rip), %rdi      # 0x30273
xorl %eax, %eax
callq 0x2030
leaq 0xf8(%rsp), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xb162
cmpl $-0x1, %ebp
je 0x266e9
leaq 0xab1a(%rip), %rdi      # 0x311f8
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
jmp 0x266f5
leaq 0xa422(%rip), %rdi      # 0x30b12
callq 0x2350
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %rax, 0x20(%rsp)
movapd %xmm0, 0x10(%rsp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
je 0x26b39
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorl %r15d, %r15d
movl (%rax,%r15,8), %r13d
movl 0x4(%rax,%r15,8), %r12d
leaq 0x9e0f(%rip), %rdi      # 0x3054c
movl %r13d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2030
leaq 0xd8(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
leaq 0x50(%rsp), %rcx
movl %ebp, %r8d
movl %ebp, %r9d
callq 0x1e880
leaq 0xe8(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movsd 0x90(%rsp), %xmm0
addsd 0x88(%rsp), %xmm0
movapd %xmm0, 0xb0(%rsp)
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
leaq 0x8(%rsp), %rcx
movl $0xa, %r8d
callq 0x1eac6
cmpl $0x0, 0x60(%rsp)
jne 0x267cd
movl $0x1, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movl 0x64(%rsp), %eax
testl %eax, %eax
jne 0x267eb
movl $0x1, 0x64(%rsp)
movq $0x0, 0x78(%rsp)
movl $0x1, %eax
movl 0x68(%rsp), %ecx
testl %ecx, %ecx
jne 0x2680c
movl $0x1, 0x68(%rsp)
movq $0x0, 0x80(%rsp)
movl $0x1, %ecx
cmpl $-0x1, %ebp
je 0x26855
movd %ecx, %xmm0
movd %eax, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm0
cvtdq2pd 0xa4(%rsp), %xmm2
movupd 0x78(%rsp), %xmm1
mulpd %xmm1, %xmm2
divpd %xmm0, %xmm2
movapd %xmm2, %xmm0
addsd 0x99b4(%rip), %xmm0     # 0x301f8
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm0, %xmm2
movapd %xmm2, 0xb0(%rsp)
movsd 0xc8(%rsp), %xmm0
divsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0xd0(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
movsd %xmm0, 0x48(%rsp)
je 0x26891
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x268a3
leaq 0x10(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
callq 0x1bc90
movl 0x50(%rsp), %r12d
movq %r14, %rdi
callq 0x1dfcc
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movq %rax, %xmm1
movq 0x995b(%rip), %xmm2     # 0x30220
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x995f(%rip), %xmm2     # 0x30230
subpd %xmm2, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
leaq 0x9d73(%rip), %rdi      # 0x3065f
movl %r12d, %esi
movb $0x1, %al
callq 0x2030
movl 0x54(%rsp), %esi
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
movsd 0x58(%r14), %xmm1
unpcklps 0x9912(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x991a(%rip), %xmm1     # 0x30230
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
leaq 0x9d52(%rip), %rdi      # 0x3067f
movb $0x1, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
leaq 0x9d5a(%rip), %rdi      # 0x3069f
movaps 0xb0(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
leaq 0xa8b7(%rip), %rdi      # 0x31212
movsd 0x48(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movsd 0x78(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x64(%rsp), %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm1
divsd 0x8(%rsp), %xmm1
leaq 0x9d45(%rip), %rdi      # 0x306db
movb $0x2, %al
callq 0x2030
movsd 0x80(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x68(%rsp), %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm1
divsd 0x8(%rsp), %xmm1
leaq 0x9d3f(%rip), %rdi      # 0x30703
movb $0x2, %al
callq 0x2030
movsd 0x8(%rsp), %xmm0
movapd %xmm0, %xmm1
divsd %xmm0, %xmm1
leaq 0x9d4b(%rip), %rdi      # 0x3072b
movb $0x2, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movl 0xa0(%rsp), %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
movl 0x60(%rsp), %edx
xorps %xmm1, %xmm1
cvtsi2sdl 0x50(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x9d41(%rip), %rdi      # 0x3075a
movl $0x8, %esi
movl $0x8, %ecx
movb $0x1, %al
callq 0x2030
movl 0xa4(%rsp), %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
movl 0x64(%rsp), %edx
xorps %xmm1, %xmm1
cvtsi2sdl 0x50(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x9d36(%rip), %rdi      # 0x30788
movl $0x8, %esi
movl $0x8, %ecx
movb $0x1, %al
callq 0x2030
movl 0xa8(%rsp), %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
movl 0x68(%rsp), %edx
xorps %xmm1, %xmm1
cvtsi2sdl 0x50(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x9d2b(%rip), %rdi      # 0x307b6
movl $0x8, %esi
movl $0x8, %ecx
movb $0x1, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movsd 0x88(%rsp), %xmm0
leaq 0x9d2e(%rip), %rdi      # 0x307e4
movb $0x1, %al
callq 0x2030
movsd 0x98(%rsp), %xmm0
leaq 0x9d31(%rip), %rdi      # 0x307fe
movb $0x1, %al
callq 0x2030
movq 0x38(%rsp), %rax
cmpq 0x40(%rsp), %rax
je 0x26afb
movl $0xc, %ecx
movq %rax, %rdi
leaq 0x50(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
addq $0x60, %rax
movq %rax, 0x38(%rsp)
jmp 0x26b0d
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
leaq 0x50(%rsp), %rdx
callq 0x1bb22
movsd (%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rsp)
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x2672d
jmp 0x26b46
sarq $0x3, %rcx
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
movsd (%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0xa6c5(%rip), %rdi      # 0x31223
movb $0x1, %al
callq 0x2030
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x26b7c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x26b93
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf8(%rsp), %rdi
callq 0xd912
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x26bb6
jmp 0x26bb6
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x26bd0
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x26be7
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf8(%rsp), %rdi
callq 0xd912
movq %rbx, %rdi
callq 0x23b0