// File: /workspace/github_cpp_makefile_star2_O2/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 $0x138, %rsp            # imm = 0x138
movsd %xmm0, 0x88(%rsp)
movq %rdx, 0x90(%rsp)
movl %esi, %ebp
movq %rdi, %r14
leaq 0x9851(%rip), %rdi      # 0x28b00
callq 0x2360
movq 0x108(%r14), %rsi
leaq 0x8f4e(%rip), %rdi      # 0x28210
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x18d3c
leaq 0x8f46(%rip), %rdi      # 0x2821e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0x8f46(%rip), %rdi      # 0x28233
xorl %eax, %eax
callq 0x2030
leaq 0xe8(%rsp), %rdi
pushq $0x1
popq %rdx
movq %r14, %rsi
callq 0x946d
cmpl $-0x1, %ebp
je 0x1f31e
leaq 0x9ea5(%rip), %rdi      # 0x291b8
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
jmp 0x1f32a
leaq 0x97ad(%rip), %rdi      # 0x28ad2
callq 0x2360
xorpd %xmm0, %xmm0
leaq 0xd0(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0xb0(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x118(%rsp), %r15
leaq 0x10(%rsp), %r13
xorpd %xmm0, %xmm0
xorl %edx, %edx
movq 0x90(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rdx, %rcx
jbe 0x1f6e6
movsd %xmm0, 0xa0(%rsp)
movl %ebp, %r12d
movq %r15, %rbp
movl (%rax,%rdx,8), %r15d
movq %rdx, 0x98(%rsp)
movl 0x4(%rax,%rdx,8), %ebx
leaq 0x9164(%rip), %rdi      # 0x2850c
movl %r15d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2030
movq %rbp, %rdi
callq 0xb094
movq %r14, %rdi
movl %r15d, %esi
movl %ebx, %edx
movq %r13, %rcx
movl %r12d, %r8d
movl %r12d, %r13d
movl %r12d, %r9d
callq 0x1930a
movq %rbp, %rdi
callq 0xb09c
movsd 0x50(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movapd %xmm0, 0x70(%rsp)
movq %r14, %rdi
movl %r15d, %esi
movl %ebx, %edx
movq %rsp, %rcx
pushq $0xa
popq %r12
movl %r12d, %r8d
callq 0x19462
movq %rbp, %r15
movl %r13d, %ebp
leaq 0x10(%rsp), %r13
movq %r15, %rdi
callq 0xb0a8
cmpl $0x0, 0x20(%rsp)
jne 0x1f42e
movl $0x1, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movl 0x24(%rsp), %eax
testl %eax, %eax
jne 0x1f447
movl $0x1, 0x24(%rsp)
andq $0x0, 0x38(%rsp)
pushq $0x1
popq %rax
movl 0x28(%rsp), %ecx
testl %ecx, %ecx
jne 0x1f460
movl $0x1, 0x28(%rsp)
andq $0x0, 0x40(%rsp)
pushq $0x1
popq %rcx
cmpl $-0x1, %ebp
je 0x1f4a3
movd %ecx, %xmm0
movd %eax, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm0
cvtdq2pd 0x64(%rsp), %xmm2
movupd 0x38(%rsp), %xmm1
mulpd %xmm1, %xmm2
divpd %xmm0, %xmm2
movapd %xmm2, %xmm0
addsd 0x8d2b(%rip), %xmm0     # 0x281c0
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm0, %xmm2
movapd %xmm2, 0x70(%rsp)
movsd 0x88(%rsp), %xmm0
divsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x16dca
movl 0x10(%rsp), %ebx
movq %r14, %rdi
callq 0x18d3c
cvtsi2sd %ebx, %xmm0
movq %rax, %xmm1
movq 0x8cfd(%rip), %xmm2     # 0x281f0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x8d01(%rip), %xmm2     # 0x28200
subpd %xmm2, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
leaq 0x9105(%rip), %rdi      # 0x2861f
movl %ebx, %esi
movb $0x1, %al
callq 0x2030
movl 0x14(%rsp), %esi
cvtsi2sd %esi, %xmm0
movsd 0x58(%r14), %xmm1
unpcklps 0x8cb8(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x8cc0(%rip), %xmm1     # 0x28200
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
leaq 0x90e8(%rip), %rdi      # 0x2863f
movb $0x1, %al
callq 0x2030
movl %r12d, %edi
callq 0x2300
leaq 0x90f2(%rip), %rdi      # 0x2865f
movaps 0x70(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
leaq 0x9c52(%rip), %rdi      # 0x291d2
movsd 0x8(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movl %r12d, %edi
callq 0x2300
movsd 0x38(%rsp), %xmm0
cvtsi2sdl 0x24(%rsp), %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm1
divsd (%rsp), %xmm1
leaq 0x90e6(%rip), %rdi      # 0x2869b
movb $0x2, %al
callq 0x2030
movsd 0x40(%rsp), %xmm0
cvtsi2sdl 0x28(%rsp), %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm1
divsd (%rsp), %xmm1
leaq 0x90e7(%rip), %rdi      # 0x286c3
movb $0x2, %al
callq 0x2030
movsd (%rsp), %xmm0
movapd %xmm0, %xmm1
divsd %xmm0, %xmm1
leaq 0x90f4(%rip), %rdi      # 0x286eb
movb $0x2, %al
callq 0x2030
movl %r12d, %edi
callq 0x2300
movl 0x60(%rsp), %r8d
cvtsi2sd %r8d, %xmm0
movl 0x20(%rsp), %edx
cvtsi2sdl 0x10(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x90f5(%rip), %rdi      # 0x2871a
pushq $0x8
popq %rbx
movl %ebx, %esi
movl %ebx, %ecx
movb $0x1, %al
callq 0x2030
movl 0x64(%rsp), %r8d
cvtsi2sd %r8d, %xmm0
movl 0x24(%rsp), %edx
cvtsi2sdl 0x10(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x90f6(%rip), %rdi      # 0x28748
movl %ebx, %esi
movl %ebx, %ecx
movb $0x1, %al
callq 0x2030
movl 0x68(%rsp), %r8d
cvtsi2sd %r8d, %xmm0
movl 0x28(%rsp), %edx
cvtsi2sdl 0x10(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x90fa(%rip), %rdi      # 0x28776
movl %ebx, %esi
movl %ebx, %ecx
movb $0x1, %al
callq 0x2030
movl %r12d, %edi
callq 0x2300
movsd 0x48(%rsp), %xmm0
leaq 0x9108(%rip), %rdi      # 0x287a4
movb $0x1, %al
callq 0x2030
movsd 0x58(%rsp), %xmm0
leaq 0x910e(%rip), %rdi      # 0x287be
movb $0x1, %al
callq 0x2030
leaq 0xd0(%rsp), %rdi
movq %r13, %rsi
callq 0x1646c
movsd 0xa0(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
movq 0x98(%rsp), %rdx
incq %rdx
jmp 0x1f363
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
leaq 0x9aed(%rip), %rdi      # 0x291e3
movb $0x1, %al
callq 0x2030
leaq 0xb0(%rsp), %rdi
callq 0x5754
leaq 0xd0(%rsp), %rdi
callq 0x16c2c
leaq 0xe8(%rsp), %rdi
callq 0xb070
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1f73a
jmp 0x1f73a
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x5754
leaq 0xd0(%rsp), %rdi
callq 0x16c2c
leaq 0xe8(%rsp), %rdi
callq 0xb070
movq %rbx, %rdi
callq 0x23d0