// File: 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:
subq $0x198, %rsp            # imm = 0x198
movq %rdx, 0x40(%rsp)
movq %rdi, 0x190(%rsp)
movl %esi, 0x18c(%rsp)
movq %rdx, 0x180(%rsp)
movsd %xmm0, 0x178(%rsp)
leaq 0x1594d(%rip), %rdi     # 0x7b2e0
movb $0x0, %al
callq 0x9040
movq 0x190(%rsp), %rdi
addq $0x108, %rdi            # imm = 0x108
callq 0x9250
movq %rax, %rsi
leaq 0x15964(%rip), %rdi     # 0x7b31c
movb $0x0, %al
callq 0x9040
movq 0x190(%rsp), %rdi
callq 0x56b40
movq %rax, %rsi
leaq 0x15954(%rip), %rdi     # 0x7b32a
movb $0x0, %al
callq 0x9040
movq 0x190(%rsp), %rdi
addq $0x30, %rdi
callq 0x4dbe0
movq %rax, %rsi
leaq 0x15947(%rip), %rdi     # 0x7b33f
movb $0x0, %al
callq 0x9040
movq 0x190(%rsp), %rsi
leaq 0x148(%rsp), %rdi
movl $0x1, %edx
callq 0x29120
xorps %xmm0, %xmm0
movsd %xmm0, 0x120(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x118(%rsp)
cmpl $-0x1, 0x18c(%rsp)
jne 0x65a66
leaq 0x15cf1(%rip), %rdi     # 0x7b733
xorl %eax, %eax
callq 0x9040
jmp 0x65a4b
jmp 0x65a7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x66079
movl 0x18c(%rsp), %esi
leaq 0x16842(%rip), %rdi     # 0x7c2b6
xorl %eax, %eax
callq 0x9040
jmp 0x65a7d
jmp 0x65a7f
leaq 0xf0(%rsp), %rdi
callq 0x4e090
leaq 0xd8(%rsp), %rdi
callq 0xfa00
movl $0x0, 0xd4(%rsp)
movq 0x40(%rsp), %rdi
movslq 0xd4(%rsp), %rax
movq %rax, 0x38(%rsp)
callq 0x47680
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
jae 0x65fe4
movq 0x40(%rsp), %rdi
movslq 0xd4(%rsp), %rsi
callq 0x4dbc0
movq (%rax), %rax
movq %rax, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
movl 0x68(%rsp), %esi
movl 0x6c(%rsp), %edx
leaq 0x15b44(%rip), %rdi     # 0x7b642
xorl %eax, %eax
callq 0x9040
jmp 0x65b07
leaq 0x128(%rsp), %rdi
callq 0x2d430
jmp 0x65b16
movq 0x190(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x6c(%rsp), %edx
movl 0x18c(%rsp), %r9d
leaq 0x70(%rsp), %rcx
movl %r9d, %r8d
callq 0x575f0
jmp 0x65b3d
leaq 0x128(%rsp), %rdi
callq 0x2d450
jmp 0x65b4c
cmpl $-0x1, 0x18c(%rsp)
jne 0x65ba3
movsd 0xb0(%rsp), %xmm0
addsd 0xa8(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
jmp 0x65ba3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0xfa50
leaq 0xf0(%rsp), %rdi
callq 0x4e110
jmp 0x66079
movq 0x190(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x6c(%rsp), %edx
leaq 0x58(%rsp), %rcx
movl $0xa, %r8d
callq 0x57880
jmp 0x65bc5
leaq 0x128(%rsp), %rdi
callq 0x2d470
movsd %xmm0, 0x30(%rsp)
jmp 0x65bda
movsd 0x30(%rsp), %xmm0
addsd 0x120(%rsp), %xmm0
movsd %xmm0, 0x120(%rsp)
cmpl $0x0, 0x80(%rsp)
jne 0x65c13
movl $0x1, 0x80(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x90(%rsp)
cmpl $0x0, 0x84(%rsp)
jne 0x65c34
movl $0x1, 0x84(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
cmpl $0x0, 0x88(%rsp)
jne 0x65c55
movl $0x1, 0x88(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
cmpl $-0x1, 0x18c(%rsp)
je 0x65cbd
movsd 0x98(%rsp), %xmm0
cvtsi2sdl 0xc4(%rsp), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl 0x84(%rsp), %xmm1
divsd %xmm1, %xmm0
addsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0xa0(%rsp), %xmm0
cvtsi2sdl 0xc8(%rsp), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl 0x88(%rsp), %xmm1
divsd %xmm1, %xmm0
addsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x178(%rsp), %xmm1
movsd 0x60(%rsp), %xmm0
divsd %xmm0, %xmm1
movsd 0x118(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x118(%rsp)
movsd 0x178(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x4e170
jmp 0x65d13
movl 0x70(%rsp), %eax
movl %eax, 0x1c(%rsp)
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x190(%rsp), %rdi
callq 0x56b40
movq %rax, 0x28(%rsp)
jmp 0x65d39
movl 0x1c(%rsp), %esi
movsd 0x20(%rsp), %xmm0
movq 0x28(%rsp), %rax
movq %rax, %xmm1
movaps 0x1555c(%rip), %xmm2    # 0x7b2b0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x15560(%rip), %xmm2    # 0x7b2c0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x159f6(%rip), %rdi     # 0x7b770
movb $0x1, %al
callq 0x9040
jmp 0x65d83
movl 0x74(%rsp), %eax
movl %eax, 0x18(%rsp)
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x190(%rsp), %rdi
addq $0x30, %rdi
callq 0x4dbe0
movsd 0x10(%rsp), %xmm0
movl 0x18(%rsp), %esi
movq %rax, %xmm1
movaps 0x154f4(%rip), %xmm2    # 0x7b2b0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x154f8(%rip), %xmm2    # 0x7b2c0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x159ae(%rip), %rdi     # 0x7b790
movb $0x1, %al
callq 0x9040
jmp 0x65deb
leaq 0x16030(%rip), %rdi     # 0x7be22
xorl %eax, %eax
callq 0x9040
jmp 0x65dfb
movsd 0x60(%rsp), %xmm0
leaq 0x159a8(%rip), %rdi     # 0x7b7b0
movb $0x1, %al
callq 0x9040
jmp 0x65e11
movsd 0x178(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x164a5(%rip), %rdi     # 0x7c2d0
movb $0x1, %al
callq 0x9040
jmp 0x65e34
leaq 0x15fe7(%rip), %rdi     # 0x7be22
xorl %eax, %eax
callq 0x9040
jmp 0x65e44
movsd 0x98(%rsp), %xmm0
cvtsi2sdl 0x84(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0x58(%rsp), %xmm2
movaps %xmm0, %xmm1
divsd %xmm2, %xmm1
leaq 0x1597e(%rip), %rdi     # 0x7b7ec
movb $0x2, %al
callq 0x9040
jmp 0x65e77
movsd 0xa0(%rsp), %xmm0
cvtsi2sdl 0x88(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0x58(%rsp), %xmm2
movaps %xmm0, %xmm1
divsd %xmm2, %xmm1
leaq 0x15973(%rip), %rdi     # 0x7b814
movb $0x2, %al
callq 0x9040
jmp 0x65eaa
movsd 0x58(%rsp), %xmm0
movaps %xmm0, %xmm1
divsd %xmm1, %xmm1
leaq 0x1597e(%rip), %rdi     # 0x7b83c
movb $0x2, %al
callq 0x9040
jmp 0x65ec7
leaq 0x15f54(%rip), %rdi     # 0x7be22
xorl %eax, %eax
callq 0x9040
jmp 0x65ed7
movl 0x80(%rsp), %edx
movl 0xc0(%rsp), %r8d
cvtsi2sd %r8d, %xmm0
cvtsi2sdl 0x70(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x1596f(%rip), %rdi     # 0x7b86b
movl $0x8, %ecx
movb $0x1, %al
movl %ecx, %esi
callq 0x9040
jmp 0x65f0c
movl 0x84(%rsp), %edx
movl 0xc4(%rsp), %r8d
cvtsi2sd %r8d, %xmm0
cvtsi2sdl 0x70(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x15968(%rip), %rdi     # 0x7b899
movl $0x8, %ecx
movb $0x1, %al
movl %ecx, %esi
callq 0x9040
jmp 0x65f41
movl 0x88(%rsp), %edx
movl 0xc8(%rsp), %r8d
cvtsi2sd %r8d, %xmm0
cvtsi2sdl 0x70(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x15961(%rip), %rdi     # 0x7b8c7
movl $0x8, %ecx
movb $0x1, %al
movl %ecx, %esi
callq 0x9040
jmp 0x65f76
leaq 0x15ea5(%rip), %rdi     # 0x7be22
xorl %eax, %eax
callq 0x9040
jmp 0x65f86
movsd 0xa8(%rsp), %xmm0
leaq 0x1595f(%rip), %rdi     # 0x7b8f5
movb $0x1, %al
callq 0x9040
jmp 0x65f9f
movsd 0xb8(%rsp), %xmm0
leaq 0x15960(%rip), %rdi     # 0x7b90f
movb $0x1, %al
callq 0x9040
jmp 0x65fb8
leaq 0xf0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x4e0a0
jmp 0x65fcc
jmp 0x65fce
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x65aa4
movq 0x40(%rsp), %rdi
movsd 0x118(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x47680
movsd 0x8(%rsp), %xmm0
movq %rax, %xmm1
movaps 0x152a1(%rip), %xmm2    # 0x7b2b0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x152a5(%rip), %xmm2    # 0x7b2c0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
leaq 0x162a0(%rip), %rdi     # 0x7c2e1
movb $0x1, %al
callq 0x9040
jmp 0x6604a
leaq 0xd8(%rsp), %rdi
callq 0xfa50
leaq 0xf0(%rsp), %rdi
callq 0x4e110
leaq 0x148(%rsp), %rdi
callq 0x2d420
addq $0x198, %rsp            # imm = 0x198
retq
leaq 0x148(%rsp), %rdi
callq 0x2d420
movq 0x110(%rsp), %rdi
callq 0x9cf0
nopw %cs:(%rax,%rax)
nopl (%rax)