// File: fjamour[P]icentral/src/experiments.cc
// Function: qube_ideal_speedup(graph_t&, int, std::vector<std::pair<unsigned int, unsigned int>, std::allocator<std::pair<unsigned int, unsigned int>>>)
void qube_ideal_speedup(graph_t& graph,
        int num_edges_to_insert,
        vector<edge_t> rand_edge_vec)
{
    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, muc_find_time;
    timer tm;
  
    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);
    
    printf("Generating edges...\n");
    if(rand_edge_vec.size() == 0) {
        gen_rand_edges(num_edges_to_insert, graph, rand_edge_vec);
    }
    vector<edge_stat_t> edge_stat_vec;
    
    double tot_ideal_speedup = 0;
    
    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();

        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();
        
        //estimating ideal speedup using the node and edge proportions
        double ideal_speedup;
        double V  = graph.size(); double E = graph.edge_set.size();
        double Vm = edge_stat.muc_num_nodes; double Em = edge_stat.muc_num_edges;
        ideal_speedup = ((V+E)/(Vm+Em))*(V/Vm);
        tot_ideal_speedup += ideal_speedup;
        ////
        
        printf("\tMUC # nodes: \t\t%d (%f G_n)\n",
                edge_stat.muc_num_nodes,
                edge_stat.muc_num_nodes/(double)graph.size());
        printf("\tMUC # edges: \t\t%d (%f G_M)\n",
                edge_stat.muc_num_edges,
                edge_stat.muc_num_edges/(double)graph.edge_set.size());
        printf("\n");
        printf("\tSpeedup (ideal): \t%f\n", ideal_speedup);
        printf("\n");
        printf("\tTime to update MUCs: \t%f\n", edge_stat.edge_ins_time);

        edge_stat_vec.push_back(edge_stat);
    }
    
    double avg_ideal_speedup = tot_ideal_speedup/num_edges_to_insert;
    printf("[[Average speedup (ideal): %f]]\n",
        avg_ideal_speedup);
}

// Assembly:
subq $0x418, %rsp            # imm = 0x418
movq %rdx, 0x80(%rsp)
movq %rdi, 0x410(%rsp)
movl %esi, 0x40c(%rsp)
movq %rdx, 0x400(%rsp)
leaq 0x2e1d3(%rip), %rdi     # 0x7b2e0
xorl %eax, %eax
movb %al, 0x8f(%rsp)
callq 0x9040
movq 0x410(%rsp), %rdi
addq $0x108, %rdi            # imm = 0x108
callq 0x9250
movq %rax, %rsi
movb 0x8f(%rsp), %al
leaq 0x2e1dc(%rip), %rdi     # 0x7b31c
callq 0x9040
movq 0x410(%rsp), %rdi
callq 0x56b40
movq %rax, %rsi
movb 0x8f(%rsp), %al
leaq 0x2e1c7(%rip), %rdi     # 0x7b32a
callq 0x9040
movq 0x410(%rsp), %rdi
addq $0x30, %rdi
callq 0x4dbe0
movq %rax, %rsi
movb 0x8f(%rsp), %al
leaq 0x2e1b5(%rip), %rdi     # 0x7b33f
callq 0x9040
leaq 0x158(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x41780
movq 0x90(%rsp), %rdi
movq 0x410(%rsp), %rsi
callq 0x53670
jmp 0x4d1bb
leaq 0x2e1a5(%rip), %rdi     # 0x7b367
xorl %eax, %eax
callq 0x9040
jmp 0x4d1cb
leaq 0x118(%rsp), %rdi
callq 0x2d430
jmp 0x4d1da
movq 0x410(%rsp), %rdi
callq 0x68030
jmp 0x4d1e9
leaq 0x118(%rsp), %rdi
callq 0x2d450
jmp 0x4d1f8
leaq 0x118(%rsp), %rdi
callq 0x2d470
movsd %xmm0, 0x78(%rsp)
jmp 0x4d20d
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x138(%rsp)
movq 0x410(%rsp), %rdi
callq 0x68af0
movq %rax, 0x70(%rsp)
jmp 0x4d230
movq 0x70(%rsp), %rsi
leaq 0x2e1cd(%rip), %rdi     # 0x7b409
xorl %eax, %eax
callq 0x9040
jmp 0x4d245
movsd 0x138(%rsp), %xmm0
leaq 0x2e11d(%rip), %rdi     # 0x7b372
movb $0x1, %al
callq 0x9040
jmp 0x4d25e
leaq 0x2e1f1(%rip), %rdi     # 0x7b456
xorl %eax, %eax
callq 0x9040
jmp 0x4d26e
movq 0x80(%rsp), %rdi
callq 0x47680
cmpq $0x0, %rax
jne 0x4d2ba
movq 0x80(%rsp), %rdx
movl 0x40c(%rsp), %edi
movq 0x410(%rsp), %rsi
callq 0x47910
jmp 0x4d29f
jmp 0x4d2ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0x4d725
leaq 0x100(%rsp), %rdi
callq 0x4dca0
xorps %xmm0, %xmm0
movsd %xmm0, 0xf8(%rsp)
movl $0x0, 0xf4(%rsp)
movq 0x80(%rsp), %rdi
movslq 0xf4(%rsp), %rax
movq %rax, 0x68(%rsp)
callq 0x47680
movq %rax, %rcx
movq 0x68(%rsp), %rax
cmpq %rcx, %rax
jae 0x4d6cb
movq 0x80(%rsp), %rdi
movslq 0xf4(%rsp), %rsi
callq 0x4dbc0
movq (%rax), %rax
movq %rax, 0xe8(%rsp)
movl 0xe8(%rsp), %esi
movl 0xec(%rsp), %edx
leaq 0x2e061(%rip), %rdi     # 0x7b39f
xorl %eax, %eax
callq 0x9040
jmp 0x4d347
leaq 0x118(%rsp), %rdi
callq 0x2d430
jmp 0x4d356
movq 0x410(%rsp), %rdi
movl 0xe8(%rsp), %esi
movl 0xec(%rsp), %edx
callq 0x68820
jmp 0x4d373
leaq 0x118(%rsp), %rdi
callq 0x2d450
jmp 0x4d382
leaq 0x118(%rsp), %rdi
callq 0x2d470
movsd %xmm0, 0x60(%rsp)
jmp 0x4d397
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0xd0(%rsp)
movq 0x410(%rsp), %rdi
addq $0x18, %rdi
movl 0xe8(%rsp), %eax
movl %eax, %esi
callq 0xfbc0
movl (%rax), %eax
movl %eax, 0xcc(%rsp)
movq 0x410(%rsp), %rdi
addq $0x60, %rdi
movl 0xcc(%rsp), %eax
movl %eax, %esi
callq 0x4dcb0
movq %rax, %rdi
addq $0x90, %rdi
callq 0x4dbe0
movl %eax, 0xe4(%rsp)
movq 0x410(%rsp), %rdi
addq $0x60, %rdi
movl 0xcc(%rsp), %eax
movl %eax, %esi
callq 0x4dcb0
movq %rax, %rdi
addq $0x60, %rdi
callq 0x4dcd0
movq %rax, 0x58(%rsp)
jmp 0x4d426
movq 0x58(%rsp), %rax
movl %eax, 0xe0(%rsp)
movq 0x410(%rsp), %rdi
callq 0x56b40
movq %rax, 0x50(%rsp)
jmp 0x4d446
movq 0x50(%rsp), %rax
movq %rax, %xmm0
movaps 0x2de59(%rip), %xmm1    # 0x7b2b0
movaps %xmm1, 0x10(%rsp)
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2de58(%rip), %xmm1    # 0x7b2c0
movaps %xmm1, 0x20(%rsp)
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0xb8(%rsp)
movq 0x410(%rsp), %rdi
addq $0x30, %rdi
callq 0x4dbe0
movaps 0x10(%rsp), %xmm2
movaps 0x20(%rsp), %xmm1
movq %rax, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0xb0(%rsp)
cvtsi2sdl 0xe0(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
cvtsi2sdl 0xe4(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0xb8(%rsp), %xmm1
movsd 0xb0(%rsp), %xmm2
movaps %xmm1, %xmm0
addsd %xmm2, %xmm0
movsd 0xa8(%rsp), %xmm2
movsd 0xa0(%rsp), %xmm4
movaps %xmm2, %xmm3
addsd %xmm4, %xmm3
divsd %xmm3, %xmm0
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0xc0(%rsp)
movsd 0xc0(%rsp), %xmm1
movsd 0xf8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xf8(%rsp)
movl 0xe0(%rsp), %eax
movl %eax, 0x3c(%rsp)
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x410(%rsp), %rdi
callq 0x56b40
movq %rax, 0x48(%rsp)
jmp 0x4d574
movl 0x3c(%rsp), %esi
movsd 0x40(%rsp), %xmm0
movq 0x48(%rsp), %rax
movq %rax, %xmm1
movaps 0x2dd21(%rip), %xmm2    # 0x7b2b0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x2dd25(%rip), %xmm2    # 0x7b2c0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x2deb6(%rip), %rdi     # 0x7b46b
movb $0x1, %al
callq 0x9040
jmp 0x4d5be
movl 0xe4(%rsp), %eax
movl %eax, 0xc(%rsp)
cvtsi2sd %eax, %xmm0
movsd %xmm0, (%rsp)
movq 0x410(%rsp), %rdi
addq $0x30, %rdi
callq 0x4dbe0
movsd (%rsp), %xmm0
movl 0xc(%rsp), %esi
movq %rax, %xmm1
movaps 0x2dcb8(%rip), %xmm2    # 0x7b2b0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x2dcbc(%rip), %xmm2    # 0x7b2c0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x2de6a(%rip), %rdi     # 0x7b488
movb $0x1, %al
callq 0x9040
jmp 0x4d627
leaq 0x2e7f4(%rip), %rdi     # 0x7be22
xorl %eax, %eax
callq 0x9040
jmp 0x4d637
movsd 0xc0(%rsp), %xmm0
leaq 0x2e53c(%rip), %rdi     # 0x7bb83
movb $0x1, %al
callq 0x9040
jmp 0x4d650
leaq 0x2e7cb(%rip), %rdi     # 0x7be22
xorl %eax, %eax
callq 0x9040
jmp 0x4d660
movsd 0xd0(%rsp), %xmm0
leaq 0x2dd45(%rip), %rdi     # 0x7b3b5
movb $0x1, %al
callq 0x9040
jmp 0x4d679
leaq 0x100(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x4dce0
jmp 0x4d690
jmp 0x4d692
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x4d2de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x4dd90
jmp 0x4d725
movsd 0xf8(%rsp), %xmm0
cvtsi2sdl 0x40c(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x98(%rsp), %xmm0
leaq 0x2e4a0(%rip), %rdi     # 0x7bb9a
movb $0x1, %al
callq 0x9040
jmp 0x4d703
leaq 0x100(%rsp), %rdi
callq 0x4dd90
leaq 0x158(%rsp), %rdi
callq 0x41f20
addq $0x418, %rsp            # imm = 0x418
retq
leaq 0x158(%rsp), %rdi
callq 0x41f20
movq 0x150(%rsp), %rdi
callq 0x9cf0
nop