// File: /workspace/github_cpp_makefile_star2_O3/fjamour[P]icentral/src/experiments.cc
// Function: insertion_test_qube(graph_t&, int)
void insertion_test_qube(graph_t& graph, int num_edges_to_insert)
{
    //1. prepare structures to store the results for each edge 
    //2. generate random edges
    //3. run Brandes and find time
    //4. run update after each edge insertion and record results
    //5. print the results progressively
    //int num_edges_to_insert = 2;
    
    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());
    double brandes_time, muc_find_time;
    timer tm;
    
    printf("Brandes runtime: \t");
    tm.start();
    vector<double> bc_vec = brandes_betweenness_centrality(graph);
    tm.stop();
    brandes_time = tm.interval();
    printf("%f\n", brandes_time);
    
    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);
    
    vector<edge_t> rand_edge_vec;
    printf("Generating edges..n\n");
    for(int i = 0; i < num_edges_to_insert; ++i) {
        edge_t rand_edge;
        node_id_t src, dst;
        do {
            src = rand()%graph.size();
            dst = rand()%graph.size();
            rand_edge.first    = src;
            rand_edge.second   = dst;
        } while(graph.has_edge(rand_edge));
        rand_edge_vec.push_back(rand_edge);
    }

    vector<edge_stat_t> edge_stat_vec;
    
    //==========================================================
//    node_id_t nd = rand_edge_vec[0].first;
//    muc_id_t muc_id = graph.node_to_muc_vec[nd];
//    graph.muc_vec[muc_id].muc_subgraph.print_graph(false);
//    return;
    //==========================================================
    
    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();
        printf("\tTime to update MUCs: \t%f\n", edge_stat.edge_ins_time);

        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);
        tm.stop();
        edge_stat.muc_bc_update_time = tm.interval();
        printf("\tTime to update BC: \t%f\n", edge_stat.muc_bc_update_time);
        printf("\tSpeedup: \t\t%f\n", brandes_time/edge_stat.muc_bc_update_time);
        printf("\tMUC # nodes: \t\t%d\n", edge_stat.muc_num_nodes);
        printf("\tMUC # edges: \t\t%d\n", edge_stat.muc_num_edges);
        edge_stat_vec.push_back(edge_stat);
    }
    
    
    double total_muc_update_time = 0;
    for(int i = 0; i < edge_stat_vec.size(); ++i) {
        total_muc_update_time += edge_stat_vec[i].muc_bc_update_time;
    }
    double avg_speedup = (num_edges_to_insert*brandes_time)/total_muc_update_time;
    
    printf("[[Average speedup: %f]]\n", avg_speedup);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %esi, 0x4(%rsp)
movq %rdi, %r14
leaq 0x199e8(%rip), %rdi     # 0x30b40
callq 0x2350
movq 0x108(%r14), %rsi
leaq 0x190e5(%rip), %rdi     # 0x30250
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x1dfcc
leaq 0x190dd(%rip), %rdi     # 0x3025e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0x190dd(%rip), %rdi     # 0x30273
xorl %eax, %eax
callq 0x2030
leaq 0x190e4(%rip), %rdi     # 0x30288
xorl %eax, %eax
callq 0x2030
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2360
leaq 0x90(%rsp), %rdi
movq %r14, %rsi
callq 0xa361
leaq 0x58(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x2360
cvtsi2sdq -0x10(%r15), %xmm3
cvtsi2sdq -0x8(%r15), %xmm1
movsd 0x18fb3(%rip), %xmm4    # 0x301a0
divsd %xmm4, %xmm1
cvtsi2sdq (%r15), %xmm2
cvtsi2sdq 0x8(%r15), %xmm0
addsd %xmm3, %xmm1
divsd %xmm4, %xmm0
addsd %xmm2, %xmm0
subsd %xmm1, %xmm0
leaq 0x19247(%rip), %rdi     # 0x3045a
movsd %xmm0, 0x80(%rsp)
movb $0x1, %al
callq 0x2030
leaq 0x19071(%rip), %rdi     # 0x3029b
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
callq 0x28006
movq %r15, %rdi
xorl %esi, %esi
callq 0x2360
movq 0x48(%rsp), %rbx
movq 0x50(%rsp), %r15
movq 0x58(%rsp), %r12
movq 0x60(%rsp), %r13
movq %r14, %rdi
callq 0x2872a
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
movsd 0x18f27(%rip), %xmm1    # 0x301a0
divsd %xmm1, %xmm0
xorps %xmm2, %xmm2
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, 0x88(%rsp)
leaq 0x19073(%rip), %rdi     # 0x30328
xorl %r15d, %r15d
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x18fdd(%rip), %rdi     # 0x302a6
movsd 0x88(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x1980b(%rip), %rdi     # 0x30afe
callq 0x2350
cmpl $0x0, 0x4(%rsp)
jle 0x173a9
leaq 0xa8(%rsp), %rbx
movq $0x0, 0xa8(%rsp)
callq 0x2070
movl %eax, %ebp
movq %r14, %rdi
callq 0x1dfcc
movq %rax, %r13
callq 0x2070
movl %eax, %r12d
movq %r14, %rdi
callq 0x1dfcc
movq %rax, %rcx
movslq %r12d, %rsi
movslq %ebp, %rax
xorl %edx, %edx
divq %r13
movq %rdx, %rdi
movq %rsi, %rax
xorl %edx, %edx
divq %rcx
movl %edi, 0xa8(%rsp)
movl %edx, 0xac(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1e644
testb %al, %al
jne 0x17317
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1738e
movq 0xa8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x1739b
leaq 0x10(%rsp), %rdi
movq %rbx, %rdx
callq 0x16d4c
incl %r15d
cmpl 0x4(%rsp), %r15d
jne 0x1730b
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x10(%rsp), %rax
xorpd %xmm2, %xmm2
cmpq %rax, 0x18(%rsp)
je 0x1762d
leaq 0x48(%rsp), %r13
leaq 0xa8(%rsp), %rbx
xorl %r15d, %r15d
movl (%rax,%r15,8), %r12d
movl 0x4(%rax,%r15,8), %ebp
leaq 0x18ece(%rip), %rdi     # 0x302be
movl %r12d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2030
movq %r13, %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x2851e
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2360
xorps %xmm0, %xmm0
cvtsi2sdq 0x48(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x50(%rsp), %xmm1
movsd 0x18d62(%rip), %xmm3    # 0x301a0
divsd %xmm3, %xmm1
addsd %xmm0, %xmm1
xorps %xmm2, %xmm2
cvtsi2sdq 0x58(%rsp), %xmm2
xorps %xmm0, %xmm0
cvtsi2sdq 0x60(%rsp), %xmm0
divsd %xmm3, %xmm0
addsd %xmm2, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
leaq 0x18e61(%rip), %rdi     # 0x302d4
movb $0x1, %al
callq 0x2030
movq 0x18(%r14), %rax
movq 0x60(%r14), %rcx
movl (%rax,%r12,4), %eax
imulq $0x568, %rax, %r12      # imm = 0x568
movl 0xb8(%rcx,%r12), %eax
movl %eax, 0x7c(%rsp)
movl 0x78(%rcx,%r12), %eax
movl %eax, 0x78(%rsp)
movl $0xa, %esi
movq %rbx, %rdi
leaq 0xc(%rsp), %rdx
leaq 0xf(%rsp), %rcx
leaq 0xe(%rsp), %r8
leaq 0xb(%rsp), %r9
leaq 0xa(%rsp), %rax
pushq %rax
leaq 0x15(%rsp), %rax
pushq %rax
callq 0xddfc
addq $0x10, %rsp
movq %r13, %rdi
xorl %esi, %esi
callq 0x2360
addq 0x60(%r14), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x28770
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2360
xorps %xmm0, %xmm0
cvtsi2sdq 0x48(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x50(%rsp), %xmm1
movsd 0x18c89(%rip), %xmm3    # 0x301a0
divsd %xmm3, %xmm1
addsd %xmm0, %xmm1
xorps %xmm2, %xmm2
cvtsi2sdq 0x58(%rsp), %xmm2
xorps %xmm0, %xmm0
cvtsi2sdq 0x60(%rsp), %xmm0
divsd %xmm3, %xmm0
addsd %xmm2, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x18da3(%rip), %rdi     # 0x302ef
movb $0x1, %al
callq 0x2030
movsd 0x80(%rsp), %xmm0
divsd 0x70(%rsp), %xmm0
leaq 0x18d9f(%rip), %rdi     # 0x30308
movb $0x1, %al
callq 0x2030
movl 0x78(%rsp), %esi
leaq 0x18d9d(%rip), %rdi     # 0x30318
xorl %eax, %eax
callq 0x2030
movl 0x7c(%rsp), %esi
leaq 0x18d9f(%rip), %rdi     # 0x3032c
xorl %eax, %eax
callq 0x2030
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x175bb
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x68(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x38(%rsp)
jmp 0x175ca
leaq 0x30(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x1b5ee
movq %rbx, %rdi
callq 0xd912
incq %r15
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x173e0
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rdx
subq %rax, %rdx
xorpd %xmm2, %xmm2
je 0x1762d
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
addq $0x8, %rax
addsd (%rax), %xmm2
addq $0x18, %rax
decq %rcx
jne 0x17620
xorps %xmm1, %xmm1
cvtsi2sdl 0x4(%rsp), %xmm1
movsd 0x80(%rsp), %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x18cf2(%rip), %rdi     # 0x30340
movb $0x1, %al
callq 0x2030
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1766c
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x17683
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x176a0
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x17703
jmp 0x176e9
jmp 0x176bb
movq %rax, %rbx
jmp 0x176d0
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0xd912
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x176ec
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
jmp 0x176ec
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x17703
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x17720
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq %rbx, %rdi
callq 0x23b0