// File: /workspace/github_cpp_makefile_star2_O3/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 0x183fb(%rip), %rdi     # 0x30b40
callq 0x2350
movq 0x108(%r14), %rsi
leaq 0x17af8(%rip), %rdi     # 0x30250
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x1dfcc
leaq 0x17af0(%rip), %rdi     # 0x3025e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0x17af0(%rip), %rdi     # 0x30273
xorl %eax, %eax
callq 0x2030
leaq 0x120(%rsp), %rbx
movq %rbx, %rdi
callq 0x152ae
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1cf40
leaq 0x120(%rsp), %rdi
callq 0x1c4e0
movq %rax, %rbx
leaq 0x17acc(%rip), %rdi     # 0x30288
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 0xd272
leaq 0x80(%rsp), %r12
xorl %r15d, %r15d
movq %r12, %rdi
xorl %esi, %esi
callq 0x2360
cvtsi2sdq -0x10(%r12), %xmm4
cvtsi2sdq -0x8(%r12), %xmm1
movsd 0x1798c(%rip), %xmm3    # 0x301a0
divsd %xmm3, %xmm1
cvtsi2sdq (%r12), %xmm2
cvtsi2sdq 0x8(%r12), %xmm0
addsd %xmm4, %xmm1
divsd %xmm3, %xmm0
addsd %xmm2, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x17c18(%rip), %rdi     # 0x3045a
movb $0x1, %al
callq 0x2030
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
movsd 0x60(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x17af8(%rip), %rdi     # 0x30359
movb $0x1, %al
callq 0x2030
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x182aa(%rip), %rdi     # 0x30b2c
callq 0x2350
cmpl $0x0, 0xc(%rsp)
jle 0x1894f
leaq 0x90(%rsp), %rbx
movq $0x0, 0x90(%rsp)
callq 0x2070
movl %eax, %ebp
movq %r14, %rdi
callq 0x1dfcc
movq %rax, %r12
callq 0x2070
movl %eax, %r13d
movq %r14, %rdi
callq 0x1dfcc
movq %rax, %rcx
movslq %r13d, %rsi
movslq %ebp, %rax
xorl %edx, %edx
divq %r12
movq %rdx, %rdi
movq %rsi, %rax
xorl %edx, %edx
divq %rcx
movl %edi, 0x90(%rsp)
movl %edx, 0x94(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1e644
testb %al, %al
jne 0x188a6
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
callq 0x1b3f6
movq 0x18(%rsp), %rsi
cmpq %rsi, %rax
jne 0x188a6
cmpq 0x20(%rsp), %rax
je 0x18934
movq 0x90(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x18941
leaq 0x10(%rsp), %rdi
movq %rbx, %rdx
callq 0x16d4c
incl %r15d
cmpl 0xc(%rsp), %r15d
jne 0x1889a
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x18be5
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x90(%rsp), %rbp
leaq 0x17c97(%rip), %rbx     # 0x30622
xorl %r12d, %r12d
movl (%rax,%r12,8), %r13d
movl 0x4(%rax,%r12,8), %r15d
leaq 0x17bae(%rip), %rdi     # 0x3054c
movl %r13d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x2030
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
movq %rbp, %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x1e880
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x2360
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
leaq 0x68(%rsp), %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x1eac6
xorps %xmm0, %xmm0
cvtsi2sdq 0x70(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x78(%rsp), %xmm1
movsd 0x17788(%rip), %xmm2    # 0x301a0
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 0x17b21(%rip), %rdi     # 0x30578
xorl %eax, %eax
callq 0x2030
movl 0x94(%rsp), %esi
leaq 0x17b22(%rip), %rdi     # 0x3058e
xorl %eax, %eax
callq 0x2030
movl $0xa, %edi
callq 0x22f0
leaq 0x1786b(%rip), %rdi     # 0x302ef
movsd 0x38(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movsd 0x60(%rsp), %xmm0
divsd 0x38(%rsp), %xmm0
leaq 0x17864(%rip), %rdi     # 0x30308
movsd %xmm0, 0x38(%rsp)
movb $0x1, %al
callq 0x2030
movl $0xa, %edi
callq 0x22f0
movl 0xa0(%rsp), %esi
leaq 0x17adb(%rip), %rdi     # 0x305a4
xorl %eax, %eax
callq 0x2030
movsd 0xb0(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xa0(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x17aca(%rip), %rdi     # 0x305ba
movb $0x1, %al
callq 0x2030
movl 0xa4(%rsp), %esi
leaq 0x17ac9(%rip), %rdi     # 0x305ce
xorl %eax, %eax
callq 0x2030
movsd 0xb8(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xa4(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x17ab8(%rip), %rdi     # 0x305e4
movb $0x1, %al
callq 0x2030
movl 0xa8(%rsp), %esi
leaq 0x17ab7(%rip), %rdi     # 0x305f8
xorl %eax, %eax
callq 0x2030
movsd 0xc0(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xa8(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x17aa6(%rip), %rdi     # 0x3060e
movb $0x1, %al
callq 0x2030
movsd 0x68(%rsp), %xmm0
movq %rbx, %rdi
movb $0x1, %al
callq 0x2030
movq 0x48(%rsp), %rax
cmpq 0x50(%rsp), %rax
je 0x18ba4
movl $0xc, %ecx
movq %rax, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
addq $0x60, %rax
movq %rax, 0x48(%rsp)
jmp 0x18bb4
leaq 0x40(%rsp), %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x1bb22
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 0x1898e
jmp 0x18bef
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
xorps %xmm1, %xmm1
cvtsi2sdl 0xc(%rsp), %xmm1
movsd 0x30(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x17737(%rip), %rdi     # 0x30340
movb $0x1, %al
callq 0x2030
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x18c27
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x18c3e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf0(%rsp), %rdi
callq 0xd912
leaq 0x120(%rsp), %rdi
callq 0x15650
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18c6e
jmp 0x18c6e
movq %rax, %rbx
jmp 0x18cbc
jmp 0x18c95
jmp 0x18c77
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x18c98
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
jmp 0x18c98
jmp 0x18c95
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x18caf
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2250
leaq 0xf0(%rsp), %rdi
callq 0xd912
leaq 0x120(%rsp), %rdi
callq 0x15650
movq %rbx, %rdi
callq 0x23b0