// File: /workspace/github_cpp_makefile_star2_O1/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 0xb2b9(%rip), %rdi      # 0x31b40
callq 0x2350
movq 0x108(%r14), %rsi
leaq 0xa9b6(%rip), %rdi      # 0x31250
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x1e160
leaq 0xa9ae(%rip), %rdi      # 0x3125e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0xa9ae(%rip), %rdi      # 0x31273
xorl %eax, %eax
callq 0x2030
leaq 0xf8(%rsp), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xb150
cmpl $-0x1, %ebp
je 0x268f8
leaq 0xb90b(%rip), %rdi      # 0x321f8
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
jmp 0x26904
leaq 0xb213(%rip), %rdi      # 0x31b12
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 0x26d4d
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorl %r15d, %r15d
movl (%rax,%r15,8), %r13d
movl 0x4(%rax,%r15,8), %r12d
leaq 0xac00(%rip), %rdi      # 0x3154c
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 0x68(%rsp), %rcx
movl %ebp, %r8d
movl %ebp, %r9d
callq 0x1e9f4
leaq 0xe8(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
cmpl $-0x1, %ebp
je 0x2699b
xorpd %xmm0, %xmm0
jmp 0x269ad
movsd 0xa8(%rsp), %xmm0
addsd 0xa0(%rsp), %xmm0
movapd %xmm0, 0x50(%rsp)
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
leaq 0x8(%rsp), %rcx
movl $0xa, %r8d
callq 0x1ec3a
cmpl $0x0, 0x78(%rsp)
jne 0x269e7
movl $0x1, 0x78(%rsp)
movq $0x0, 0x88(%rsp)
cmpl $0x0, 0x7c(%rsp)
jne 0x26a02
movl $0x1, 0x7c(%rsp)
movq $0x0, 0x90(%rsp)
cmpl $0x0, 0x80(%rsp)
jne 0x26a23
movl $0x1, 0x80(%rsp)
movq $0x0, 0x98(%rsp)
cmpl $-0x1, %ebp
je 0x26a5c
movupd 0x90(%rsp), %xmm0
cvtdq2pd 0xbc(%rsp), %xmm1
mulpd %xmm0, %xmm1
cvtdq2pd 0x7c(%rsp), %xmm0
divpd %xmm0, %xmm1
movapd 0x50(%rsp), %xmm2
addsd %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm1, %xmm2
jmp 0x26a62
movapd 0x50(%rsp), %xmm2
movsd 0xc8(%rsp), %xmm0
movapd %xmm2, 0x50(%rsp)
divsd %xmm2, %xmm0
movsd %xmm0, 0xd0(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
movsd %xmm0, 0x60(%rsp)
je 0x26a9f
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x26ab1
leaq 0x10(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
callq 0x1bd76
movl 0x68(%rsp), %r12d
movq %r14, %rdi
callq 0x1e160
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movq %rax, %xmm1
movq 0xa74d(%rip), %xmm2     # 0x31220
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xa751(%rip), %xmm2     # 0x31230
subpd %xmm2, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
leaq 0xab65(%rip), %rdi      # 0x3165f
movl %r12d, %esi
movb $0x1, %al
callq 0x2030
movl 0x6c(%rsp), %esi
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
movsd 0x58(%r14), %xmm1
unpcklps 0xa704(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xa70c(%rip), %xmm1     # 0x31230
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
leaq 0xab44(%rip), %rdi      # 0x3167f
movb $0x1, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
leaq 0xab4c(%rip), %rdi      # 0x3169f
movaps 0x50(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
leaq 0xb6ac(%rip), %rdi      # 0x32212
movsd 0x60(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movsd 0x90(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x7c(%rsp), %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm1
divsd 0x8(%rsp), %xmm1
leaq 0xab37(%rip), %rdi      # 0x316db
movb $0x2, %al
callq 0x2030
movsd 0x98(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x80(%rsp), %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm1
divsd 0x8(%rsp), %xmm1
leaq 0xab2e(%rip), %rdi      # 0x31703
movb $0x2, %al
callq 0x2030
movsd 0x8(%rsp), %xmm0
movapd %xmm0, %xmm1
divsd %xmm0, %xmm1
leaq 0xab3a(%rip), %rdi      # 0x3172b
movb $0x2, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movl 0xb8(%rsp), %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
movl 0x78(%rsp), %edx
xorps %xmm1, %xmm1
cvtsi2sdl 0x68(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0xab30(%rip), %rdi      # 0x3175a
movl $0x8, %esi
movl $0x8, %ecx
movb $0x1, %al
callq 0x2030
movl 0xbc(%rsp), %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
movl 0x7c(%rsp), %edx
xorps %xmm1, %xmm1
cvtsi2sdl 0x68(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0xab25(%rip), %rdi      # 0x31788
movl $0x8, %esi
movl $0x8, %ecx
movb $0x1, %al
callq 0x2030
movl 0xc0(%rsp), %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
movl 0x80(%rsp), %edx
xorps %xmm1, %xmm1
cvtsi2sdl 0x68(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0xab17(%rip), %rdi      # 0x317b6
movl $0x8, %esi
movl $0x8, %ecx
movb $0x1, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movsd 0xa0(%rsp), %xmm0
leaq 0xab1a(%rip), %rdi      # 0x317e4
movb $0x1, %al
callq 0x2030
movsd 0xb0(%rsp), %xmm0
leaq 0xab1d(%rip), %rdi      # 0x317fe
movb $0x1, %al
callq 0x2030
movq 0x38(%rsp), %rax
cmpq 0x40(%rsp), %rax
je 0x26d0f
movl $0xc, %ecx
movq %rax, %rdi
leaq 0x68(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
addq $0x60, %rax
movq %rax, 0x38(%rsp)
jmp 0x26d21
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
leaq 0x68(%rsp), %rdx
callq 0x1bc08
movsd (%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movsd %xmm0, (%rsp)
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x2693c
jmp 0x26d5a
sarq $0x3, %rcx
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movq %rcx, %xmm0
punpckldq 0xa4b9(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xa4c1(%rip), %xmm0     # 0x31230
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd (%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0xb498(%rip), %rdi      # 0x32223
movb $0x1, %al
callq 0x2030
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x26da9
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x26dc0
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf8(%rsp), %rdi
callq 0xd8b4
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x26de3
jmp 0x26de3
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x26dfd
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x26e14
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf8(%rsp), %rdi
callq 0xd8b4
movq %rbx, %rdi
callq 0x23b0
nopl (%rax)