// File: /workspace/github_cpp_makefile_star2_O1/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 0x1a92c(%rip), %rdi     # 0x31b40
callq 0x2350
movq 0x108(%r14), %rsi
leaq 0x1a029(%rip), %rdi     # 0x31250
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x1e160
leaq 0x1a021(%rip), %rdi     # 0x3125e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0x1a021(%rip), %rdi     # 0x31273
xorl %eax, %eax
callq 0x2030
leaq 0x1a028(%rip), %rdi     # 0x31288
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 0xa35d
leaq 0x58(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x2360
cvtsi2sdq -0x10(%r15), %xmm3
cvtsi2sdq -0x8(%r15), %xmm1
movsd 0x19ef7(%rip), %xmm4    # 0x311a0
divsd %xmm4, %xmm1
cvtsi2sdq (%r15), %xmm2
cvtsi2sdq 0x8(%r15), %xmm0
addsd %xmm3, %xmm1
divsd %xmm4, %xmm0
addsd %xmm2, %xmm0
subsd %xmm1, %xmm0
leaq 0x1a18b(%rip), %rdi     # 0x3145a
movsd %xmm0, 0x80(%rsp)
movb $0x1, %al
callq 0x2030
leaq 0x19fb5(%rip), %rdi     # 0x3129b
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
callq 0x282ae
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 0x289cc
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
movsd 0x19e6b(%rip), %xmm1    # 0x311a0
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 0x19fb7(%rip), %rdi     # 0x31328
xorl %r15d, %r15d
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x19f21(%rip), %rdi     # 0x312a6
movsd 0x88(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x1a74f(%rip), %rdi     # 0x31afe
callq 0x2350
cmpl $0x0, 0x4(%rsp)
jle 0x17465
leaq 0xa8(%rsp), %rbx
movq $0x0, 0xa8(%rsp)
callq 0x2070
movl %eax, %ebp
movq %r14, %rdi
callq 0x1e160
movq %rax, %r13
callq 0x2070
movl %eax, %r12d
movq %r14, %rdi
callq 0x1e160
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 0x1e7bc
testb %al, %al
jne 0x173d3
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1744a
movq 0xa8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x17457
leaq 0x10(%rsp), %rdi
movq %rbx, %rdx
callq 0x16e08
incl %r15d
cmpl 0x4(%rsp), %r15d
jne 0x173c7
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x176a7
leaq 0x48(%rsp), %r13
leaq 0xa8(%rsp), %rbx
xorl %r15d, %r15d
movl (%rax,%r15,8), %r12d
movl 0x4(%rax,%r15,8), %ebp
leaq 0x19e16(%rip), %rdi     # 0x312be
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 0x287c6
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 0x19caa(%rip), %xmm3    # 0x311a0
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 0x19da9(%rip), %rdi     # 0x312d4
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 0xddc0
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 0x28a12
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2360
xorps %xmm0, %xmm0
cvtsi2sdq 0x48(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x50(%rsp), %xmm1
movsd 0x19bd1(%rip), %xmm3    # 0x311a0
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 0x19ceb(%rip), %rdi     # 0x312ef
movb $0x1, %al
callq 0x2030
movsd 0x80(%rsp), %xmm0
divsd 0x70(%rsp), %xmm0
leaq 0x19ce7(%rip), %rdi     # 0x31308
movb $0x1, %al
callq 0x2030
movl 0x78(%rsp), %esi
leaq 0x19ce5(%rip), %rdi     # 0x31318
xorl %eax, %eax
callq 0x2030
movl 0x7c(%rsp), %esi
leaq 0x19ce7(%rip), %rdi     # 0x3132c
xorl %eax, %eax
callq 0x2030
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x17673
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x68(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x38(%rsp)
jmp 0x17682
leaq 0x30(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x1b6b4
movq %rbx, %rdi
callq 0xd8b4
incq %r15
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x17498
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rdx
subq %rax, %rdx
je 0x176e7
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
addq $0x8, %rax
xorpd %xmm2, %xmm2
addsd (%rax), %xmm2
addq $0x18, %rax
decq %rcx
jne 0x176d8
jmp 0x176eb
xorpd %xmm2, %xmm2
xorps %xmm1, %xmm1
cvtsi2sdl 0x4(%rsp), %xmm1
movsd 0x80(%rsp), %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x19c34(%rip), %rdi     # 0x31340
movb $0x1, %al
callq 0x2030
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1772a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x17741
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x1775e
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 0x177c1
jmp 0x177a7
jmp 0x17779
movq %rax, %rbx
jmp 0x1778e
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0xd8b4
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x177aa
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
jmp 0x177aa
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x177c1
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x177de
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq %rbx, %rdi
callq 0x23b0