// File: /workspace/github_cpp_makefile_star2_O3/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 0x1dfcc
movq 0x58(%r14), %rcx
leaq 0xb068(%rip), %rdi      # 0x30ccf
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 0xb162
leaq 0xa602(%rip), %rdi      # 0x3029b
xorl %eax, %eax
callq 0x2030
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
callq 0x28006
leaq 0x40(%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 0x2872a
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
movsd 0xa4b5(%rip), %xmm1     # 0x301a0
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, 0x10(%rsp)
leaq 0xa607(%rip), %rdi      # 0x30328
xorl %ebx, %ebx
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0xa572(%rip), %rdi      # 0x302a6
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movq %rbx, 0x80(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movq %rbx, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movq 0xa0(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
je 0x2603f
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0xb0(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %ebx, %ebx
movsd %xmm0, 0x18(%rsp)
movl %ebp, %r13d
movl (%rax,%rbx,8), %r15d
movl 0x4(%rax,%rbx,8), %ebp
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, 0x20(%rsp)
movl %ebp, %edx
callq 0x2851e
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
xorps %xmm0, %xmm0
cvtsi2sdq 0x30(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x38(%rsp), %xmm1
movsd 0xa3b8(%rip), %xmm3     # 0x301a0
divsd %xmm3, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sdq 0x40(%rsp), %xmm0
xorps %xmm2, %xmm2
cvtsi2sdq 0x48(%rsp), %xmm2
divsd %xmm3, %xmm2
addsd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, 0x88(%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, 0x9c(%rsp)
movl 0x78(%rcx,%rbp), %eax
movl %eax, 0x98(%rsp)
movl $0xa, %esi
leaq 0xc8(%rsp), %r12
movq %r12, %rdi
leaq 0xd(%rsp), %rdx
leaq 0x28(%rsp), %rcx
leaq 0xf(%rsp), %r8
leaq 0xc(%rsp), %r9
leaq 0xb(%rsp), %rax
pushq %rax
leaq 0x16(%rsp), %rax
pushq %rax
callq 0xddfc
addq $0x10, %rsp
leaq 0x30(%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 0x28770
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
xorps %xmm0, %xmm0
cvtsi2sdq 0x30(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x38(%rsp), %xmm1
movsd 0xa2ce(%rip), %xmm3     # 0x301a0
divsd %xmm3, %xmm1
addsd %xmm0, %xmm1
xorps %xmm2, %xmm2
cvtsi2sdq 0x40(%rsp), %xmm2
xorps %xmm0, %xmm0
cvtsi2sdq 0x48(%rsp), %xmm0
divsd %xmm3, %xmm0
addsd %xmm2, %xmm0
subsd %xmm1, %xmm0
cmpl $-0x1, %ebp
je 0x25f18
divsd 0xb0(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x98(%rsp), %xmm1
mulsd %xmm1, %xmm0
leaq 0xc8(%rsp), %r12
movq %r15, %r14
addsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x90(%rsp)
movsd 0xa8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
movsd %xmm1, 0xb8(%rsp)
je 0x25f6c
movsd %xmm1, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x58(%rsp)
jmp 0x25f7b
leaq 0x50(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x1b766
movsd 0x90(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
leaq 0xad69(%rip), %rdi      # 0x30cfa
movq 0xc0(%rsp), %rsi
movl 0x20(%rsp), %edx
movsd %xmm0, 0x20(%rsp)
movb $0x2, %al
callq 0x2030
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
je 0x25fda
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x88(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x78(%rsp)
jmp 0x25fec
leaq 0x70(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x1b5ee
movsd 0x10(%rsp), %xmm0
addsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r12, %rdi
callq 0xd912
incq %rbx
movq 0xa0(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0x25d98
jmp 0x26053
sarq $0x3, %rcx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
xorps %xmm2, %xmm2
cvtsi2sd %rcx, %xmm2
movsd 0x10(%rsp), %xmm1
divsd %xmm2, %xmm1
movsd 0x18(%rsp), %xmm0
divsd %xmm2, %xmm0
leaq 0xaca7(%rip), %rdi      # 0x30d1d
movb $0x2, %al
callq 0x2030
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x26094
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x260ae
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf8(%rsp), %rdi
callq 0xd912
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2611c
jmp 0x260db
jmp 0x260d6
movq %rax, %rbx
jmp 0x260eb
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0xd912
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x26102
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2611c
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf8(%rsp), %rdi
callq 0xd912
movq %rbx, %rdi
callq 0x23b0