// File: /workspace/github_cpp_makefile_star2_O1/fjamour[P]icentral/src/experiments.cc
// Function: insertion_test_fuad_hash(graph_t&, int)
void insertion_test_fuad_hash(graph_t& graph, int num_edges_to_insert)
{
    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());
    graph_hash_t g;
    g.fill_graph(graph);
    
    double brandes_time;
    timer tm;
    
    int num_iter = g.size();
    printf("Brandes runtime: \t");
    tm.start();
    tr1_map_t(double) bc_vec = brandes_bc_hash(g);
    tm.stop();
    brandes_time = tm.interval();
    printf("%f\n", brandes_time);
    printf("Brandes avg iter time: \t%f\n", brandes_time/num_iter);
    
    vector<edge_t> rand_edge_vec;
    printf("Generating edges...\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) ||
                find(rand_edge_vec.begin(), rand_edge_vec.end(), rand_edge) != rand_edge_vec.end());
        rand_edge_vec.push_back(rand_edge);
    }

    double tot_fuad_time = 0;
    double tot_speedup = 0;
    
    vector<bcc_stat_t> bcc_stat_vec;
    for(int i = 0; i < rand_edge_vec.size(); ++i) {
        bcc_stat_t bcc_stat;
        edge_t rand_edge = rand_edge_vec[i];
        printf("Inserting edge (%d, %d) and updating bc...\n", rand_edge.first, rand_edge.second);
        tm.start();
        graph.insert_edge_update_bc_experimental(rand_edge.first, rand_edge.second, bcc_stat);
        tm.stop();
        
        double avg_iter_time_naive;
        graph.approx_bcc_iter_tm(rand_edge.first, rand_edge.second, avg_iter_time_naive);
        tot_fuad_time += tm.interval();
        
        tot_speedup += (brandes_time/tm.interval());
        
        printf("\tBCC num nodes: \t\t%d\n", bcc_stat.bcc_num_nodes);
        printf("\tBCC num edges: \t\t%d\n", bcc_stat.bcc_num_edges);
        printf("\n");
        printf("\tTime to update BC: \t%f\n", tm.interval());
        printf("\tSpeedup: \t\t%f\n", brandes_time/tm.interval());
        printf("\n");
        printf("\tBCC num d0 BFS: \t%d\n", bcc_stat.num_d0_iter);
        printf("\tBCC d0 time: \t\t%f\n", bcc_stat.tot_d0_tm/bcc_stat.num_d0_iter);
        printf("\tBCC num d1 BFS: \t%d\n", bcc_stat.num_d1_iter);
        printf("\tBCC d1 time: \t\t%f\n", bcc_stat.tot_d1_tm/bcc_stat.num_d1_iter);
        printf("\tBCC num d2 BFS: \t%d\n", bcc_stat.num_d2_iter);
        printf("\tBCC d2 time: \t\t%f\n", bcc_stat.tot_d2_tm/bcc_stat.num_d2_iter);
        printf("\tavg iter time naive: \t%f\n", avg_iter_time_naive);
        //printf("\tBCC bcc find time: \t%f\n", bcc_stat.bcc_find_time);
        //printf("\tBCC sssp time: \t\t%f\n", bcc_stat.sssp_tm);
        
        
        
        bcc_stat_vec.push_back(bcc_stat);
    }
    
    //double avg_speedup = (num_edges_to_insert*brandes_time)/tot_fuad_time;
    double avg_speedup = tot_speedup/num_edges_to_insert;
    
    printf("[[Average speedup: %f]]\n", avg_speedup); 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3c8, %rsp            # imm = 0x3C8
movl %esi, 0xc(%rsp)
movq %rdi, %r14
leaq 0x19348(%rip), %rdi     # 0x31b40
callq 0x2350
movq 0x108(%r14), %rsi
leaq 0x18a45(%rip), %rdi     # 0x31250
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x1e160
leaq 0x18a3d(%rip), %rdi     # 0x3125e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0x18a3d(%rip), %rdi     # 0x31273
xorl %eax, %eax
callq 0x2030
leaq 0x120(%rsp), %rbx
movq %rbx, %rdi
callq 0x153ae
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1d062
leaq 0x120(%rsp), %rdi
callq 0x1c62c
movq %rax, %r15
leaq 0x18a19(%rip), %rdi     # 0x31288
xorl %eax, %eax
callq 0x2030
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
leaq 0xf0(%rsp), %rdi
leaq 0x120(%rsp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xd21a
leaq 0x80(%rsp), %rbx
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2360
cvtsi2sdq -0x10(%rbx), %xmm4
cvtsi2sdq -0x8(%rbx), %xmm1
movsd 0x188db(%rip), %xmm3    # 0x311a0
divsd %xmm3, %xmm1
cvtsi2sdq (%rbx), %xmm2
cvtsi2sdq 0x8(%rbx), %xmm0
addsd %xmm4, %xmm1
divsd %xmm3, %xmm0
addsd %xmm2, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x18b69(%rip), %rdi     # 0x3145a
movb $0x1, %al
callq 0x2030
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
movsd 0x60(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x18a48(%rip), %rdi     # 0x31359
movb $0x1, %al
callq 0x2030
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x191fa(%rip), %rdi     # 0x31b2c
callq 0x2350
cmpl $0x0, 0xc(%rsp)
jle 0x189fe
leaq 0x90(%rsp), %r15
movq $0x0, 0x90(%rsp)
callq 0x2070
movl %eax, %ebx
movq %r14, %rdi
callq 0x1e160
movq %rax, %r13
callq 0x2070
movl %eax, %ebp
movq %r14, %rdi
callq 0x1e160
movq %rax, %rcx
movslq %ebp, %rsi
movslq %ebx, %rax
xorl %edx, %edx
divq %r13
movq %rdx, %rdi
movq %rsi, %rax
xorl %edx, %edx
divq %rcx
movl %edi, 0x90(%rsp)
movl %edx, 0x94(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x1e7bc
testb %al, %al
jne 0x18956
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x1b49c
movq 0x18(%rsp), %rsi
cmpq %rsi, %rax
jne 0x18956
cmpq 0x20(%rsp), %rsi
je 0x189e3
movq 0x90(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x189f0
leaq 0x10(%rsp), %rdi
movq %r15, %rdx
callq 0x16e08
incl %r12d
cmpl 0xc(%rsp), %r12d
jne 0x1894a
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x18c91
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x90(%rsp), %rbp
leaq 0x18be8(%rip), %r13     # 0x31622
xorl %r12d, %r12d
movl (%rax,%r12,8), %ebx
movl 0x4(%rax,%r12,8), %r15d
leaq 0x18aff(%rip), %rdi     # 0x3154c
movl %ebx, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x2030
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
movl %ebx, %esi
movl %r15d, %edx
movq %rbp, %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x1e9f4
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
movl %ebx, %esi
movl %r15d, %edx
leaq 0x68(%rsp), %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x1ec3a
xorps %xmm0, %xmm0
cvtsi2sdq 0x70(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x78(%rsp), %xmm1
movsd 0x186dc(%rip), %xmm2    # 0x311a0
divsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sdq 0x80(%rsp), %xmm0
cvtsi2sdq 0x88(%rsp), %xmm3
divsd %xmm2, %xmm3
addsd %xmm0, %xmm3
subsd %xmm1, %xmm3
movsd %xmm3, 0x38(%rsp)
movl 0x90(%rsp), %esi
leaq 0x18a75(%rip), %rdi     # 0x31578
xorl %eax, %eax
callq 0x2030
movl 0x94(%rsp), %esi
leaq 0x18a76(%rip), %rdi     # 0x3158e
xorl %eax, %eax
callq 0x2030
movl $0xa, %edi
callq 0x22f0
leaq 0x187bf(%rip), %rdi     # 0x312ef
movsd 0x38(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movsd 0x60(%rsp), %xmm0
divsd 0x38(%rsp), %xmm0
leaq 0x187b8(%rip), %rdi     # 0x31308
movsd %xmm0, 0x38(%rsp)
movb $0x1, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movl 0xa0(%rsp), %esi
leaq 0x18a2f(%rip), %rdi     # 0x315a4
xorl %eax, %eax
callq 0x2030
movsd 0xb0(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xa0(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x18a1e(%rip), %rdi     # 0x315ba
movb $0x1, %al
callq 0x2030
movl 0xa4(%rsp), %esi
leaq 0x18a1d(%rip), %rdi     # 0x315ce
xorl %eax, %eax
callq 0x2030
movsd 0xb8(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xa4(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x18a0c(%rip), %rdi     # 0x315e4
movb $0x1, %al
callq 0x2030
movl 0xa8(%rsp), %esi
leaq 0x18a0b(%rip), %rdi     # 0x315f8
xorl %eax, %eax
callq 0x2030
movsd 0xc0(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xa8(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x189fa(%rip), %rdi     # 0x3160e
movb $0x1, %al
callq 0x2030
movsd 0x68(%rsp), %xmm0
movq %r13, %rdi
movb $0x1, %al
callq 0x2030
movq 0x48(%rsp), %rax
cmpq 0x50(%rsp), %rax
je 0x18c50
movl $0xc, %ecx
movq %rax, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
addq $0x60, %rax
movq %rax, 0x48(%rsp)
jmp 0x18c60
leaq 0x40(%rsp), %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x1bc08
movsd 0x30(%rsp), %xmm0
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
incq %r12
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
ja 0x18a3d
jmp 0x18c9b
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
xorps %xmm1, %xmm1
cvtsi2sdl 0xc(%rsp), %xmm1
movsd 0x30(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x1868b(%rip), %rdi     # 0x31340
movb $0x1, %al
callq 0x2030
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x18cd3
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x18cea
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf0(%rsp), %rdi
callq 0xd8b4
leaq 0x120(%rsp), %rdi
callq 0x15750
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18d1a
jmp 0x18d1a
movq %rax, %rbx
jmp 0x18d68
jmp 0x18d41
jmp 0x18d23
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x18d44
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
jmp 0x18d44
jmp 0x18d41
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x18d5b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf0(%rsp), %rdi
callq 0xd8b4
leaq 0x120(%rsp), %rdi
callq 0x15750
movq %rbx, %rdi
callq 0x23b0