// File: 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:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdx, 0x78(%rsp)
movq %rdi, 0x1d0(%rsp)
movl %esi, 0x1cc(%rsp)
movq %rdx, 0x1c0(%rsp)
movsd %xmm0, 0x1b8(%rsp)
movq 0x1d0(%rsp), %rdi
addq $0x108, %rdi            # imm = 0x108
callq 0x9250
movq %rax, 0x80(%rsp)
movq 0x1d0(%rsp), %rdi
callq 0x56b40
movq %rax, 0x88(%rsp)
movq 0x1d0(%rsp), %rdi
addq $0x30, %rdi
callq 0x4dbe0
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %rax, %rcx
movsd 0x1b8(%rsp), %xmm0
leaq 0x1708e(%rip), %rdi     # 0x7bd6f
movb $0x1, %al
callq 0x9040
movq 0x1d0(%rsp), %rsi
leaq 0x160(%rsp), %rdi
movl $0x1, %edx
callq 0x29120
leaq 0x1665e(%rip), %rdi     # 0x7b367
xorl %eax, %eax
callq 0x9040
jmp 0x64d12
leaq 0x190(%rsp), %rdi
callq 0x2d430
jmp 0x64d21
movq 0x1d0(%rsp), %rdi
callq 0x68030
jmp 0x64d30
leaq 0x190(%rsp), %rdi
callq 0x2d450
jmp 0x64d3f
leaq 0x190(%rsp), %rdi
callq 0x2d470
movsd %xmm0, 0x70(%rsp)
jmp 0x64d54
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x1b0(%rsp)
movq 0x1d0(%rsp), %rdi
callq 0x68af0
movq %rax, 0x68(%rsp)
jmp 0x64d77
movq 0x68(%rsp), %rsi
leaq 0x16686(%rip), %rdi     # 0x7b409
xorl %eax, %eax
callq 0x9040
jmp 0x64d8c
movsd 0x1b0(%rsp), %xmm0
leaq 0x165d6(%rip), %rdi     # 0x7b372
movb $0x1, %al
callq 0x9040
jmp 0x64da5
leaq 0x138(%rsp), %rdi
callq 0x4dca0
xorps %xmm0, %xmm0
movsd %xmm0, 0x130(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x128(%rsp)
leaq 0x110(%rsp), %rdi
callq 0xfa00
movl $0x0, 0x10c(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x10c(%rsp), %rax
movq %rax, 0x60(%rsp)
callq 0x47680
movq %rax, %rcx
movq 0x60(%rsp), %rax
cmpq %rcx, %rax
jae 0x6519b
movq 0x78(%rsp), %rdi
movslq 0x10c(%rsp), %rsi
callq 0x4dbc0
movq (%rax), %rax
movq %rax, 0x100(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x2d430
jmp 0x64e36
movq 0x1d0(%rsp), %rdi
movl 0x100(%rsp), %esi
movl 0x104(%rsp), %edx
callq 0x68820
jmp 0x64e53
leaq 0x190(%rsp), %rdi
callq 0x2d450
jmp 0x64e62
leaq 0x190(%rsp), %rdi
callq 0x2d470
movsd %xmm0, 0x58(%rsp)
jmp 0x64e77
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0xe8(%rsp)
movq 0x1d0(%rsp), %rdi
addq $0x18, %rdi
movl 0x100(%rsp), %eax
movl %eax, %esi
callq 0xfbc0
movl (%rax), %eax
movl %eax, 0xe4(%rsp)
movq 0x1d0(%rsp), %rdi
addq $0x60, %rdi
movl 0xe4(%rsp), %eax
movl %eax, %esi
callq 0x4dcb0
movq %rax, %rdi
addq $0x90, %rdi
callq 0x4dbe0
movl %eax, 0xfc(%rsp)
movq 0x1d0(%rsp), %rdi
addq $0x60, %rdi
movl 0xe4(%rsp), %eax
movl %eax, %esi
callq 0x4dcb0
movq %rax, %rdi
addq $0x60, %rdi
callq 0x4dcd0
movq %rax, 0x50(%rsp)
jmp 0x64f06
movq 0x50(%rsp), %rax
movl %eax, 0xf8(%rsp)
leaq 0xad(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x2d1e0
movq 0x48(%rsp), %r8
leaq 0xb0(%rsp), %rdi
movl $0xa, %esi
leaq 0xaf(%rsp), %rdx
leaq 0xae(%rsp), %rcx
callq 0x2d1f0
jmp 0x64f4d
leaq 0xad(%rsp), %rdi
callq 0x2d230
leaq 0x190(%rsp), %rdi
callq 0x2d430
jmp 0x64f69
movq 0x1d0(%rsp), %rdi
addq $0x60, %rdi
movl 0xe4(%rsp), %eax
movl %eax, %esi
callq 0x4dcb0
movq %rax, %rdi
movl 0x1cc(%rsp), %edx
leaq 0xb0(%rsp), %rsi
callq 0x68b80
jmp 0x64f9c
leaq 0x190(%rsp), %rdi
callq 0x2d450
jmp 0x64fab
cmpl $-0x1, 0x1cc(%rsp)
jne 0x65060
leaq 0x190(%rsp), %rdi
callq 0x2d470
movsd %xmm0, 0x40(%rsp)
jmp 0x64fce
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
jmp 0x6509e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x652b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x65297
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0xad(%rsp), %rdi
callq 0x2d230
jmp 0x65297
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x2d420
jmp 0x65297
leaq 0x190(%rsp), %rdi
callq 0x2d470
movsd %xmm0, 0x38(%rsp)
jmp 0x65075
movsd 0x38(%rsp), %xmm0
cvtsi2sdl 0x1cc(%rsp), %xmm1
divsd %xmm1, %xmm0
cvtsi2sdl 0xf8(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0xe8(%rsp), %xmm1
movsd 0xf0(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0x1b8(%rsp), %xmm0
movsd 0xf0(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0xa0(%rsp), %xmm1
movsd 0x130(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x130(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x4de20
jmp 0x65112
movsd 0xf0(%rsp), %xmm1
movsd 0x128(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x128(%rsp)
movl 0x100(%rsp), %esi
movl 0x104(%rsp), %edx
movsd 0xf0(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm1
leaq 0x16c42(%rip), %rdi     # 0x7bd9a
movb $0x2, %al
callq 0x9040
jmp 0x65161
leaq 0x138(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x4dce0
jmp 0x65178
leaq 0xb0(%rsp), %rdi
callq 0x2d420
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0x64de2
movq 0x78(%rsp), %rdi
movsd 0x130(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x47680
movsd 0x8(%rsp), %xmm0
movq 0x78(%rsp), %rdi
movq %rax, %xmm1
movaps 0x160e5(%rip), %xmm2    # 0x7b2b0
movaps %xmm2, 0x10(%rsp)
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x160e4(%rip), %xmm2    # 0x7b2c0
movaps %xmm2, 0x20(%rsp)
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x128(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
callq 0x47680
movaps 0x10(%rsp), %xmm3
movaps 0x20(%rsp), %xmm2
movsd 0x30(%rsp), %xmm0
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rsp)
movsd 0x90(%rsp), %xmm0
movsd 0x98(%rsp), %xmm1
leaq 0x16b5e(%rip), %rdi     # 0x7bdbd
movb $0x2, %al
callq 0x9040
jmp 0x65268
leaq 0x110(%rsp), %rdi
callq 0xfa50
leaq 0x138(%rsp), %rdi
callq 0x4dd90
leaq 0x160(%rsp), %rdi
callq 0x2d420
addq $0x1d8, %rsp            # imm = 0x1D8
retq
leaq 0x110(%rsp), %rdi
callq 0xfa50
leaq 0x138(%rsp), %rdi
callq 0x4dd90
leaq 0x160(%rsp), %rdi
callq 0x2d420
movq 0x158(%rsp), %rdi
callq 0x9cf0
nopl (%rax,%rax)