// File: /workspace/github_cpp_makefile_star2_O2/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 $0x138, %rsp            # imm = 0x138
movsd %xmm0, 0x30(%rsp)
movq %rdx, 0x60(%rsp)
movl %esi, 0x1c(%rsp)
movq %rdi, %r14
movq 0x108(%rdi), %rbx
callq 0x18d3c
movq 0x58(%r14), %rcx
leaq 0xa09e(%rip), %rdi      # 0x28c8f
movq %rbx, %rsi
movq %rax, %rdx
movsd 0x30(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
leaq 0x108(%rsp), %rdi
pushq $0x1
popq %rdx
movq %r14, %rsi
callq 0x946d
leaq 0x963d(%rip), %rdi      # 0x2825b
xorl %eax, %eax
callq 0x2030
leaq 0xb8(%rsp), %rdi
callq 0xb094
movq %r14, %rdi
callq 0x2058a
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
callq 0xb09c
movq %rbx, %rdi
callq 0xb0a8
movsd %xmm0, 0x10(%rsp)
movq %r14, %rdi
callq 0x20b20
leaq 0x9681(%rip), %rdi      # 0x282e8
xorl %ebx, %ebx
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x95ec(%rip), %rdi      # 0x28266
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x80(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
cvtsi2sdl 0x1c(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0xb8(%rsp), %r15
leaq 0x38(%rsp), %rbp
movsd %xmm0, 0x28(%rsp)
movq 0x60(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
jbe 0x1ee75
movl (%rax,%rbx,8), %r12d
movq %rbx, 0x78(%rsp)
movl 0x4(%rax,%rbx,8), %ebx
movq %r15, %rdi
callq 0xb094
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, 0x20(%rsp)
movl %ebx, %edx
callq 0x20972
movq %r15, %rdi
callq 0xb09c
movq %r15, %rdi
callq 0xb0a8
movsd %xmm0, 0x40(%rsp)
movq 0x18(%r14), %rax
movq 0x60(%r14), %rcx
movq %r12, 0x70(%rsp)
movl (%rax,%r12,4), %eax
imulq $0x568, %rax, %rbx      # imm = 0x568
movl 0xb8(%rcx,%rbx), %eax
movl %eax, 0x54(%rsp)
movl 0x78(%rcx,%rbx), %eax
movl %eax, 0x50(%rsp)
leaq 0xd8(%rsp), %r13
movq %r13, %rdi
pushq $0xa
popq %rsi
movq %rbp, %r12
movq %rbp, %rdx
leaq 0xf(%rsp), %rcx
leaq 0xe(%rsp), %r8
callq 0xb770
movq %r15, %rdi
callq 0xb094
movq %r14, %rbp
addq 0x60(%r14), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movl 0x1c(%rsp), %ebx
movl %ebx, %edx
callq 0x20b58
movq %r15, %rdi
callq 0xb09c
movq %r15, %r13
movq %r15, %rdi
callq 0xb0a8
cmpl $-0x1, %ebx
je 0x1edc1
divsd 0x58(%rsp), %xmm0
cvtsi2sdl 0x50(%rsp), %xmm1
mulsd %xmm1, %xmm0
movq %rbp, %r14
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x30(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x68(%rsp)
movsd %xmm1, 0x38(%rsp)
leaq 0x80(%rsp), %rdi
movq %r12, %rbp
movq %r12, %rsi
callq 0x163a4
movq %r13, %r15
movsd 0x48(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
leaq 0x9eab(%rip), %rdi      # 0x28cba
movq 0x70(%rsp), %rsi
movl 0x20(%rsp), %edx
movsd %xmm0, 0x20(%rsp)
movb $0x2, %al
callq 0x2030
leaq 0xa0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1637e
movsd 0x28(%rsp), %xmm0
addsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x10(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0xb070
movq 0x78(%rsp), %rbx
incq %rbx
jmp 0x1ecd3
cvtsi2sd %rcx, %xmm2
movsd 0x28(%rsp), %xmm1
divsd %xmm2, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm2, %xmm0
leaq 0x9e48(%rip), %rdi      # 0x28cdd
movb $0x2, %al
callq 0x2030
leaq 0x80(%rsp), %rdi
callq 0x5754
leaq 0xa0(%rsp), %rdi
callq 0x16772
leaq 0x108(%rsp), %rdi
callq 0xb070
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x1ef0d
jmp 0x1eede
jmp 0x1eee3
movq %rax, %rbx
jmp 0x1eef3
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0xb070
leaq 0x80(%rsp), %rdi
callq 0x5754
leaq 0xa0(%rsp), %rdi
callq 0x16772
leaq 0x108(%rsp), %rdi
callq 0xb070
movq %rbx, %rdi
callq 0x23d0