// File: /workspace/github_cpp_makefile_star2_O1/fjamour[P]icentral/src/paper_exp.cc
// Function: exp_qube_p(graph_t&, int, std::vector<std::pair<unsigned int, unsigned int>, std::allocator<std::pair<unsigned int, unsigned int>>>, double)
void    exp_qube_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());
    printf("Graph[%s]  V[%d]  E[%d]  Brandes_tm[%.2f]\n",
        graph.graph_name.c_str(),
        graph.size(),
        graph.edge_set.size(),
        brandes_time);
    
    double muc_find_time;
    timer tm;
    tr1_map_t(double) bc_vec = brandes_bc_hash_out(graph, 1);
    printf("# MUCs: \t\t");
    tm.start();
    graph.find_mucs();
    tm.stop();
    muc_find_time = tm.interval();
    printf("%d\n", graph.get_num_mucs());
    printf("Time to find MUCs: \t%f\n", muc_find_time);
    
//    if(num_iter == -1) {
//        printf("WILL DO ALL ITERATIONS...\n");
//    } else {
//        printf("WILL DO %d ITERATIONS...\n", num_iter);
//    }
    
    vector<edge_stat_t> edge_stat_vec;
    
    double tot_speedup = 0;
    double tot_time = 0;
    
    vector<double> speedup_vec;
    for(int i = 0; i < rand_edge_vec.size(); ++i) {
        edge_t rand_edge = rand_edge_vec[i];
        edge_stat_t edge_stat;
//        printf("Adding edge (%d, %d)\n", rand_edge.first, rand_edge.second);
        tm.start();
        graph.insert_edge_update_muc(rand_edge.first, rand_edge.second);
        tm.stop();
        edge_stat.edge_ins_time = tm.interval();

        muc_id_t muc_id = graph.node_to_muc_vec[rand_edge.first];
        edge_stat.muc_num_edges = graph.muc_vec[muc_id].muc_subgraph.edge_set.size();
        edge_stat.muc_num_nodes = graph.muc_vec[muc_id].muc_subgraph.nodes_map.size();
        tr1::unordered_map<node_id_t, double> bc_map;
        tm.start();
        graph.muc_vec[muc_id].compute_bc(bc_map, num_iter);
        tm.stop();
        if(num_iter == -1)
            edge_stat.muc_bc_update_time = tm.interval();
        else
            edge_stat.muc_bc_update_time = (tm.interval()/num_iter)*edge_stat.muc_num_nodes;
        //TMP CODE XXX FIX THIS SHIT
        edge_stat.muc_bc_update_time += edge_stat.edge_ins_time;
        ////
        
        double speedup = brandes_time/edge_stat.muc_bc_update_time;
        tot_speedup += speedup;
        speedup_vec.push_back(speedup);
        
        tot_time += edge_stat.muc_bc_update_time;
        
//        printf("\tMUC # nodes: \t\t%d (%f G_n)\n",
//                edge_stat.muc_num_nodes,
//                edge_stat.muc_num_nodes/(double)graph.size());
//        printf("\tMUC # edges: \t\t%d (%f G_M)\n",
//                edge_stat.muc_num_edges,
//                edge_stat.muc_num_edges/(double)graph.edge_set.size());
//        printf("\n");
//        printf("\tTime to update BC: \t%f\n", edge_stat.muc_bc_update_time);
//        printf("\tSpeedup: \t\t%f\n", speedup);
//        printf("\n");
//        printf("\tQUBE avg iter time: \t%f\n",
//                edge_stat.muc_bc_update_time/edge_stat.muc_num_nodes);
//        printf("\tTime to update MUCs: \t%f\n", edge_stat.edge_ins_time);
        
        printf("e(%-6d,%-6d)  tm[%.2f]  sup[%.2f]\n",
                rand_edge.first,
                rand_edge.second,
                edge_stat.muc_bc_update_time,
                speedup);

        edge_stat_vec.push_back(edge_stat);
    }
    
    double avg_speedup = tot_speedup/rand_edge_vec.size();
//    printf("[[Avg. speedup (qube): %f]]\n", avg_speedup);
    double avg_time = tot_time/rand_edge_vec.size();
    printf("Avg.tm[%.2f]  Avg.sup[%.2f]\n\n", avg_time, avg_speedup);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movsd %xmm0, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movl %esi, %ebp
movq %rdi, %r14
movq 0x108(%rdi), %r15
callq 0x1e160
movq 0x58(%r14), %rcx
leaq 0xbe9b(%rip), %rdi      # 0x31ccf
movq %r15, %rsi
movq %rax, %rdx
movsd 0xa8(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
leaq 0xf8(%rsp), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xb150
leaq 0xb435(%rip), %rdi      # 0x3129b
xorl %eax, %eax
callq 0x2030
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
callq 0x282ae
leaq 0x50(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x2360
movq -0x10(%r13), %rbx
movq -0x8(%r13), %r15
movq (%r13), %r12
movq 0x8(%r13), %r13
movq %r14, %rdi
callq 0x289cc
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
movsd 0xb2e8(%rip), %xmm1     # 0x311a0
divsd %xmm1, %xmm0
cvtsi2sd %r12, %xmm2
addsd %xmm0, %xmm2
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rbx, %xmm1
addsd %xmm0, %xmm1
subsd %xmm1, %xmm2
movsd %xmm2, 0x8(%rsp)
leaq 0xb43a(%rip), %rdi      # 0x31328
xorl %ebx, %ebx
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0xb3a5(%rip), %rdi      # 0x312a6
movsd 0x8(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movq %rbx, 0x90(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x80(%rsp)
movq %rbx, 0x70(%rsp)
movapd %xmm0, 0x60(%rsp)
movq 0xa0(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
je 0x2620e
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0xb0(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ebx, %ebx
movsd %xmm0, 0x10(%rsp)
movl %ebp, %r13d
movl (%rax,%rbx,8), %r15d
movl 0x4(%rax,%rbx,8), %ebp
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, 0x30(%rsp)
movl %ebp, %edx
callq 0x287c6
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
xorps %xmm0, %xmm0
cvtsi2sdq 0x40(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x48(%rsp), %xmm1
movsd 0xb1e8(%rip), %xmm3     # 0x311a0
divsd %xmm3, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sdq 0x50(%rsp), %xmm0
xorps %xmm2, %xmm2
cvtsi2sdq 0x58(%rsp), %xmm2
divsd %xmm3, %xmm2
addsd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, 0x18(%rsp)
movq 0x18(%r14), %rax
movq 0x60(%r14), %rcx
movq %r15, 0xc0(%rsp)
movl (%rax,%r15,4), %eax
imulq $0x568, %rax, %rbp      # imm = 0x568
movl 0xb8(%rcx,%rbp), %eax
movl %eax, 0x2c(%rsp)
movl 0x78(%rcx,%rbp), %eax
movl %eax, 0x28(%rsp)
movl $0xa, %esi
leaq 0xc8(%rsp), %r12
movq %r12, %rdi
leaq 0x5(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0x7(%rsp), %r8
leaq 0x4(%rsp), %r9
leaq 0x3(%rsp), %rax
pushq %rax
leaq 0xe(%rsp), %rax
pushq %rax
callq 0xddc0
addq $0x10, %rsp
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %r15
addq 0x60(%r14), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movl %r13d, %ebp
movl %r13d, %edx
callq 0x28a12
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
xorps %xmm0, %xmm0
cvtsi2sdq 0x40(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x48(%rsp), %xmm1
movsd 0xb107(%rip), %xmm3     # 0x311a0
divsd %xmm3, %xmm1
addsd %xmm0, %xmm1
xorps %xmm2, %xmm2
cvtsi2sdq 0x50(%rsp), %xmm2
xorps %xmm0, %xmm0
cvtsi2sdq 0x58(%rsp), %xmm0
divsd %xmm3, %xmm0
addsd %xmm2, %xmm0
subsd %xmm1, %xmm0
cmpl $-0x1, %ebp
je 0x260e4
divsd 0xb0(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x28(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
jmp 0x260ea
movsd %xmm0, 0x20(%rsp)
leaq 0xc8(%rsp), %r12
movq %r15, %r14
movsd 0x18(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0xa8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
movsd %xmm1, 0xb8(%rsp)
je 0x2613e
movsd %xmm1, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x68(%rsp)
jmp 0x2614d
leaq 0x60(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x1b82c
movsd 0x20(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
leaq 0xbb9a(%rip), %rdi      # 0x31cfa
movq 0xc0(%rsp), %rsi
movl 0x30(%rsp), %edx
movsd %xmm0, 0x30(%rsp)
movb $0x2, %al
callq 0x2030
movq 0x88(%rsp), %rsi
cmpq 0x90(%rsp), %rsi
je 0x261a9
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x18(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x88(%rsp)
jmp 0x261bb
leaq 0x80(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x1b6b4
movsd 0x8(%rsp), %xmm0
addsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
callq 0xd8b4
incq %rbx
movq 0xa0(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0x25f68
jmp 0x26222
sarq $0x3, %rcx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rcx, %xmm0
punpckldq 0xaff1(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xaff9(%rip), %xmm0     # 0x31230
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
movsd 0x8(%rsp), %xmm1
divsd %xmm2, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm2, %xmm0
leaq 0xbabf(%rip), %rdi      # 0x31d1d
movb $0x2, %al
callq 0x2030
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x2627c
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x26299
movq 0x90(%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
movq %rax, %rbx
jmp 0x2630a
jmp 0x262c6
jmp 0x262c1
movq %rax, %rbx
jmp 0x262d6
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0xd8b4
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x262ed
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x2630a
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf8(%rsp), %rdi
callq 0xd8b4
movq %rbx, %rdi
callq 0x23b0