// File: /workspace/github_cpp_makefile_star2_O2/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 0x14b8a(%rip), %rdi     # 0x28b00
callq 0x2360
movq 0x108(%r14), %rsi
leaq 0x14287(%rip), %rdi     # 0x28210
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x18d3c
leaq 0x1427f(%rip), %rdi     # 0x2821e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0x1427f(%rip), %rdi     # 0x28233
xorl %eax, %eax
callq 0x2030
leaq 0x120(%rsp), %rbx
movq %rbx, %rdi
callq 0x11468
movq %rbx, %rdi
movq %r14, %rsi
callq 0x17db0
leaq 0x120(%rsp), %rdi
callq 0x176f6
movq %rax, %r12
leaq 0x1425b(%rip), %rdi     # 0x28248
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2030
leaq 0xd0(%rsp), %rdi
callq 0xb094
leaq 0xf0(%rsp), %rdi
leaq 0x120(%rsp), %rsi
pushq $-0x1
popq %rdx
callq 0xab13
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
callq 0xb09c
movq %r15, %rdi
callq 0xb0a8
movsd %xmm0, 0x18(%rsp)
leaq 0x143da(%rip), %rdi     # 0x2841a
movb $0x1, %al
callq 0x2030
cvtsi2sd %r12d, %xmm1
movsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x142bc(%rip), %rdi     # 0x28319
movb $0x1, %al
callq 0x2030
xorpd %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x14a6f(%rip), %rdi     # 0x28aec
callq 0x2360
movl 0xc(%rsp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movl %ecx, 0x10(%rsp)
leaq 0x50(%rsp), %r15
cmpl 0x10(%rsp), %ebx
je 0x14128
andq $0x0, 0x50(%rsp)
callq 0x2070
movl %eax, %ebp
movq %r14, %rdi
callq 0x18d3c
movq %rax, %r12
callq 0x2070
movl %eax, %r13d
movq %r14, %rdi
callq 0x18d3c
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, 0x50(%rsp)
movl %edx, 0x54(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x191b4
testb %al, %al
jne 0x140a9
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x1658d
cmpq 0x28(%rsp), %rax
jne 0x140a9
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x117e2
incl %ebx
jmp 0x14099
xorpd %xmm0, %xmm0
leaq 0xb0(%rsp), %rax
andq $0x0, 0x10(%rax)
movapd %xmm0, (%rax)
xorpd %xmm0, %xmm0
leaq 0xd0(%rsp), %r13
pushq $-0x1
popq %rbx
xorl %r12d, %r12d
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
jbe 0x14324
movsd %xmm0, 0x10(%rsp)
movl (%rax,%r12,8), %r15d
movl 0x4(%rax,%r12,8), %ebp
leaq 0x1438d(%rip), %rdi     # 0x2850c
movl %r15d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2030
movq %r13, %rdi
callq 0xb094
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
leaq 0x50(%rsp), %rcx
movl %ebx, %r8d
movl %ebx, %r9d
callq 0x1930a
movq %r13, %rdi
callq 0xb09c
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
leaq 0x48(%rsp), %rcx
movl %ebx, %r8d
callq 0x19462
movq %r13, %rdi
callq 0xb0a8
movq %r13, %rdi
callq 0xb0a8
movsd %xmm0, 0x40(%rsp)
movl 0x50(%rsp), %esi
leaq 0x1434f(%rip), %rdi     # 0x28538
xorl %eax, %eax
callq 0x2030
movl 0x54(%rsp), %esi
leaq 0x14353(%rip), %rdi     # 0x2854e
xorl %eax, %eax
callq 0x2030
pushq $0xa
popq %rbp
movl %ebp, %edi
callq 0x2300
movq %r13, %rdi
callq 0xb0a8
leaq 0x14094(%rip), %rdi     # 0x282af
movb $0x1, %al
callq 0x2030
movq %r13, %rdi
callq 0xb0a8
movsd 0x18(%rsp), %xmm1
divsd %xmm0, %xmm1
leaq 0x1408d(%rip), %rdi     # 0x282c8
movapd %xmm1, %xmm0
movb $0x1, %al
callq 0x2030
movl %ebp, %edi
callq 0x2300
movl 0x60(%rsp), %esi
leaq 0x1430c(%rip), %rdi     # 0x28564
xorl %eax, %eax
callq 0x2030
movsd 0x70(%rsp), %xmm0
cvtsi2sdl 0x60(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x14304(%rip), %rdi     # 0x2857a
movb $0x1, %al
callq 0x2030
movl 0x64(%rsp), %esi
leaq 0x14306(%rip), %rdi     # 0x2858e
xorl %eax, %eax
callq 0x2030
movsd 0x78(%rsp), %xmm0
cvtsi2sdl 0x64(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x142fe(%rip), %rdi     # 0x285a4
movb $0x1, %al
callq 0x2030
movl 0x68(%rsp), %esi
leaq 0x14300(%rip), %rdi     # 0x285b8
xorl %eax, %eax
callq 0x2030
movsd 0x80(%rsp), %xmm0
cvtsi2sdl 0x68(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x142f5(%rip), %rdi     # 0x285ce
movb $0x1, %al
callq 0x2030
movsd 0x48(%rsp), %xmm0
leaq 0x142f5(%rip), %rdi     # 0x285e2
movb $0x1, %al
callq 0x2030
leaq 0xb0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x1646c
movsd 0x18(%rsp), %xmm1
divsd 0x40(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
incq %r12
jmp 0x1414f
cvtsi2sdl 0xc(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x13fcb(%rip), %rdi     # 0x28300
movb $0x1, %al
callq 0x2030
leaq 0xb0(%rsp), %rdi
callq 0x16c2c
leaq 0x20(%rsp), %rdi
callq 0x16656
leaq 0xf0(%rsp), %rdi
callq 0xb070
leaq 0x120(%rsp), %rdi
callq 0x1173e
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14383
jmp 0x14383
movq %rax, %rbx
jmp 0x143ba
jmp 0x143a0
jmp 0x1438c
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x16c2c
jmp 0x143a3
jmp 0x143a0
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x16656
leaq 0xf0(%rsp), %rdi
callq 0xb070
leaq 0x120(%rsp), %rdi
callq 0x1173e
movq %rbx, %rdi
callq 0x23d0