// File: sebastienmeyer2[P]mst-clustering/src/mst_prim_kumar.cpp
// Function: PrimKumarAlgorithm::compute_mst()
void PrimKumarAlgorithm::compute_mst() 
{
    /*!
     * @brief Computes the Minimum Spanning Tree of the initial graph using 
     * Prim-Kumar's algorithm. More specifically, initialize a priority queue to 
     * sort the edges by their weight. At each iteration, it adds the edge with 
     * minimal weight to the MST and checks for new edges to discover. 
     * 
     */


    int n_slaves = this->world_size;
    int n_nodes = this->initial_graph->get_number_of_nodes();

    int min_nodes_per_proc = n_nodes/(n_slaves);
    int split_nodes = n_nodes % n_slaves;

    int nodes_interval[2];

    nodes_interval[0] = this->rank*min_nodes_per_proc + (this->rank < split_nodes ? this->rank : split_nodes);  
    nodes_interval[1] = nodes_interval[0] + min_nodes_per_proc + (this->rank < split_nodes);

    int node_id_min = nodes_interval[0];
    int node_id_max = nodes_interval[1]; 

    struct {double d; int edge_id;} iter_res;
    struct {double d; int edge_id;} reduction_res;


    this->mst_weight = 0.0;

    std::chrono::steady_clock::time_point begin;
    if(this->rank == 0){
        std::cout << "Computing the MST using Prim-Kumar's algorithm...";
        begin = std::chrono::steady_clock::now();
    }

    int n = this->initial_graph->get_number_of_nodes();
    //std::vector<Node*> nodes = this->initial_graph->get_nodes();

    auto cmp = [](const Edge* e1, const Edge* e2) 
        { 
            double w1 = e1->weight;
            double w2 = e2->weight;

            if (w1 < w2) {
                return true;
            } else if (w1 > w2) {
                return false;
            } else { // Allows multiple keys for same weight values
                intptr_t p1 = reinterpret_cast<intptr_t>(e1);
                intptr_t p2 = reinterpret_cast<intptr_t>(e2);

                return p1 < p2;
            }
        };

    // initialization of the priority queue (ie set), best edge per vertex and beginning vertex
    std::unordered_map<Node*, Edge*> min_edge;
    std::set<Edge*, decltype(cmp)> pq(cmp);


    Node* current_node = this->initial_graph->get_node(0);




    this->mst_graph.add_node(current_node); // just to have the source node in the MST

    std::unordered_set<Edge*> connected_edges = this->initial_graph->connected_edges(current_node);

    for (Edge* e : connected_edges) {

        Node* other_node = e->other_node(current_node);
        if(IS_NODE_ALLOCATED_TO_ME(other_node->get_id())){
            if (!this->mst_graph.has_node(other_node)) {
                if (min_edge.find(other_node) != min_edge.end()) 
                {
                    if (*e < *min_edge.at(other_node)) {
                        pq.erase(min_edge.at(other_node));
                        min_edge.erase(other_node);

                        min_edge.insert(std::pair<Node*, Edge*>(other_node, e));
                        pq.insert(e);
                    }
                }
                else 
                {
                    min_edge.insert(std::pair<Node*, Edge*>(other_node, e));
                    pq.insert(e);
                }
            }
        } 
    }

    //std::printf("Proc %d, %d remaning items in queue\n", this->rank, pq.size());

    // filling the MST with new nodes until it forms a tree 
    while (this->mst_graph.get_number_of_nodes() < n) {

        Edge* new_edge;

        if(!pq.empty()){
            // adding the new edge and node to the MST and the visited nodes
            Edge* new_edge = *pq.begin();

            // We shall now send this to the root processor, so that it decides which edge is the best
            iter_res.edge_id = new_edge->id;
            iter_res.d = new_edge->weight;            
        } else {
            iter_res.d = std::numeric_limits<double>::infinity();
        }


        //std::printf("Proc %d, %d remaning items in queue\n", this->rank, pq.size());
        MPI_Barrier(MPI_COMM_WORLD);
        MPI_Allreduce(&iter_res, &reduction_res, 1, MPI_DOUBLE_INT, MPI_MINLOC, MPI_COMM_WORLD);
        MPI_Barrier(MPI_COMM_WORLD);


        // This is the REAL new edge
        new_edge = this->initial_graph->get_edge(reduction_res.edge_id);

        if(reduction_res.d == std::numeric_limits<double>::infinity()){
            printf("ARRRHS\n");
        } else {
            //printf("Elected edge %d\n", reduction_res.edge_id);
        }

        Node* p1 = new_edge->p1;
        Node* p2 = new_edge->p2;
        Node* new_node = (this->mst_graph.has_node(p1)) ? p2 : p1;

        this->mst_graph.add_edge(new_edge);
        this->mst_weight += new_edge->weight;



        this->mst_graph.add_node(new_node);
        
        pq.erase(new_edge);

        if(IS_NODE_ALLOCATED_TO_ME(p1->get_id()) || IS_NODE_ALLOCATED_TO_ME(p2->get_id())){
            // we won't need the best edge for this node anymore
            min_edge.erase(new_node);

        }


        // updating the external nodes best edges
        connected_edges = this->initial_graph->connected_edges(new_node);
            for (Edge* e : connected_edges) {
                Node* other_node = e->other_node(new_node);
                if(IS_NODE_ALLOCATED_TO_ME(other_node->get_id())){
                    if (!this->mst_graph.has_node(other_node)) {
                        if (min_edge.find(other_node) != min_edge.end()) 
                        {
                            if (*e < *min_edge.at(other_node)) {
                                pq.erase(min_edge.at(other_node));
                                min_edge.erase(other_node);

                                min_edge.insert(std::pair<Node*, Edge*>(other_node, e));
                                pq.insert(e);
                            }
                        }
                        else 
                        {
                            min_edge.insert(std::pair<Node*, Edge*>(other_node, e));
                            pq.insert(e);
                        }
                    }
                }
            }
    }
    
    MPI_Barrier(MPI_COMM_WORLD);
    if(this->rank == 0){
        std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
        std::cout << "[OK]" << std::endl;
        this->treatment_done();

        std::cout << "Total weight of the MST: " << this->mst_weight << std::endl;

        std::cout << "Time spent by the algorithm: " << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << " µs" << std::endl;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movl 0x104(%rax), %ecx
movl %ecx, -0xc(%rbp)
movq 0x8(%rax), %rdi
callq 0xd510
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cltd
idivl -0xc(%rbp)
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %eax
cltd
idivl -0xc(%rbp)
movq -0x2a8(%rbp), %rax
movl %edx, -0x18(%rbp)
movl 0x108(%rax), %ecx
imull -0x14(%rbp), %ecx
movl %ecx, -0x29c(%rbp)
movl 0x108(%rax), %eax
cmpl -0x18(%rbp), %eax
jge 0x2f37a
movq -0x2a8(%rbp), %rax
movl 0x108(%rax), %eax
movl %eax, -0x2ac(%rbp)
jmp 0x2f383
movl -0x18(%rbp), %eax
movl %eax, -0x2ac(%rbp)
movq -0x2a8(%rbp), %rax
movl -0x29c(%rbp), %ecx
movl -0x2ac(%rbp), %edx
addl %edx, %ecx
movl %ecx, -0x20(%rbp)
movl -0x20(%rbp), %ecx
addl -0x14(%rbp), %ecx
movl 0x108(%rax), %edx
cmpl -0x18(%rbp), %edx
setl %dl
andb $0x1, %dl
movzbl %dl, %edx
addl %edx, %ecx
movl %ecx, -0x1c(%rbp)
movl -0x20(%rbp), %ecx
movl %ecx, -0x24(%rbp)
movl -0x1c(%rbp), %ecx
movl %ecx, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xf8(%rax)
leaq -0x50(%rbp), %rdi
callq 0x30f40
movq -0x2a8(%rbp), %rax
cmpl $0x0, 0x108(%rax)
jne 0x2f40c
movq 0x20bc1(%rip), %rdi     # 0x4ffb0
leaq 0x8592(%rip), %rsi      # 0x37988
callq 0xa780
callq 0xaa70
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x2a8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xd510
movl %eax, -0x5c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x2b4a0
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x27c50
movq -0x2b8(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
leaq -0x5d(%rbp), %rsi
callq 0x30080
jmp 0x2f457
leaq -0xc9(%rbp), %rdi
callq 0x27f60
movq -0x2a8(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
callq 0xd850
movq %rax, -0x2c0(%rbp)
jmp 0x2f47e
movq -0x2a8(%rbp), %rdi
movq -0x2c0(%rbp), %rax
movq %rax, -0xe8(%rbp)
addq $0x10, %rdi
movq -0xe8(%rbp), %rsi
callq 0xd2f0
jmp 0x2f4a5
movq -0x2a8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0xe8(%rbp), %rsi
callq 0xd4e0
movq %rax, -0x2c8(%rbp)
jmp 0x2f4c5
movq -0x2c8(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0xe370
jmp 0x2f4da
leaq -0x120(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rdi
callq 0xe520
movq %rax, -0x130(%rbp)
movq -0x128(%rbp), %rdi
callq 0xe550
movq %rax, -0x138(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0xe580
testb $0x1, %al
jne 0x2f52a
jmp 0x2f878
leaq -0x130(%rbp), %rdi
callq 0xe5b0
movq (%rax), %rax
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rdi
movq -0xe8(%rbp), %rsi
callq 0xb480
movq %rax, -0x2d0(%rbp)
jmp 0x2f55c
movq -0x2d0(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x24680
movl %eax, -0x2d4(%rbp)
jmp 0x2f57e
movl -0x2d4(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x2f865
movq -0x148(%rbp), %rdi
callq 0x24680
movl %eax, -0x2d8(%rbp)
jmp 0x2f5a1
movl -0x2d8(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x2f865
movq -0x2a8(%rbp), %rdi
addq $0x10, %rdi
movq -0x148(%rbp), %rsi
callq 0xd490
movb %al, -0x2d9(%rbp)
jmp 0x2f5cf
movb -0x2d9(%rbp), %al
testb $0x1, %al
jne 0x2f863
jmp 0x2f5df
leaq -0x98(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x2b4f0
movq %rax, -0x2e8(%rbp)
jmp 0x2f5fb
movq -0x2e8(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x2b520
movq %rax, -0x158(%rbp)
leaq -0x150(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x2b4c0
testb $0x1, %al
jne 0x2f638
jmp 0x2f7cd
movq -0x140(%rbp), %rax
movq %rax, -0x2f8(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x2b550
movq %rax, -0x2f0(%rbp)
jmp 0x2f662
movq -0x2f8(%rbp), %rdi
movq -0x2f0(%rbp), %rax
movq (%rax), %rsi
callq 0xb4f0
movb %al, -0x2f9(%rbp)
jmp 0x2f680
movb -0x2f9(%rbp), %al
testb $0x1, %al
jne 0x2f68f
jmp 0x2f7c8
leaq -0x98(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x2b550
movq %rax, -0x308(%rbp)
jmp 0x2f6ab
movq -0x308(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x30100
jmp 0x2f6c0
leaq -0x98(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x2b580
jmp 0x2f6d5
leaq -0x168(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x2b5f0
jmp 0x2f6f1
leaq -0x98(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x2b5b0
movb %dl, -0x311(%rbp)
movq %rax, -0x310(%rbp)
jmp 0x2f713
movb -0x311(%rbp), %al
movq -0x310(%rbp), %rcx
movq %rcx, -0x178(%rbp)
movb %al, -0x170(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x30130
movb %dl, -0x321(%rbp)
movq %rax, -0x320(%rbp)
jmp 0x2f74f
movb -0x321(%rbp), %al
movq -0x320(%rbp), %rcx
movq %rcx, -0x188(%rbp)
movb %al, -0x180(%rbp)
jmp 0x2f7c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
leaq -0xc9(%rbp), %rdi
callq 0x27f60
jmp 0x3005e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x30052
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
leaq -0x120(%rbp), %rdi
callq 0xdf50
jmp 0x30052
jmp 0x2f861
leaq -0x198(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x2b5f0
jmp 0x2f7e9
leaq -0x98(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x2b5b0
movb %dl, -0x331(%rbp)
movq %rax, -0x330(%rbp)
jmp 0x2f80b
movb -0x331(%rbp), %al
movq -0x330(%rbp), %rcx
movq %rcx, -0x1a8(%rbp)
movb %al, -0x1a0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x30130
movb %dl, -0x341(%rbp)
movq %rax, -0x340(%rbp)
jmp 0x2f847
movb -0x341(%rbp), %al
movq -0x340(%rbp), %rcx
movq %rcx, -0x1b8(%rbp)
movb %al, -0x1b0(%rbp)
jmp 0x2f863
jmp 0x2f865
jmp 0x2f867
leaq -0x130(%rbp), %rdi
callq 0xe5e0
jmp 0x2f50e
jmp 0x2f87a
movq -0x2a8(%rbp), %rdi
addq $0x10, %rdi
callq 0xd510
movl %eax, -0x348(%rbp)
jmp 0x2f892
movl -0x348(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x2fe99
leaq -0xc8(%rbp), %rdi
callq 0x30180
testb $0x1, %al
jne 0x2f8fa
leaq -0xc8(%rbp), %rdi
callq 0x301a0
movq %rax, -0x1d0(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x2b620
movq (%rax), %rax
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x1c8(%rbp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x2f904
callq 0x30f70
movsd %xmm0, -0x38(%rbp)
movq 0x20685(%rip), %rdi     # 0x4ff90
callq 0xa520
jmp 0x2f912
movq 0x206af(%rip), %rcx     # 0x4ffc8
movq 0x20680(%rip), %r8      # 0x4ffa0
movq 0x20669(%rip), %r9      # 0x4ff90
leaq -0x38(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0x1, %edx
callq 0xa980
jmp 0x2f93b
movq 0x2064e(%rip), %rdi     # 0x4ff90
callq 0xa520
jmp 0x2f949
movq -0x2a8(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x40(%rbp), %esi
callq 0xd880
movq %rax, -0x350(%rbp)
jmp 0x2f965
movq -0x350(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x358(%rbp)
callq 0x30f70
movaps %xmm0, %xmm1
movsd -0x358(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x2f9aa
jp 0x2f9aa
leaq 0x801b(%rip), %rdi      # 0x379ba
xorl %eax, %eax
callq 0xa050
jmp 0x2f9a8
jmp 0x2f9ac
jmp 0x2f9ac
movq -0x2a8(%rbp), %rdi
movq -0x1c0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1d8(%rbp)
movq -0x1c0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1e0(%rbp)
addq $0x10, %rdi
movq -0x1d8(%rbp), %rsi
callq 0xd490
movb %al, -0x359(%rbp)
jmp 0x2f9ee
movb -0x359(%rbp), %al
testb $0x1, %al
jne 0x2f9fa
jmp 0x2fa0a
movq -0x1e0(%rbp), %rax
movq %rax, -0x368(%rbp)
jmp 0x2fa18
movq -0x1d8(%rbp), %rax
movq %rax, -0x368(%rbp)
movq -0x2a8(%rbp), %rdi
movq -0x368(%rbp), %rax
movq %rax, -0x1e8(%rbp)
addq $0x10, %rdi
movq -0x1c0(%rbp), %rsi
callq 0xcef0
jmp 0x2fa3f
movq -0x2a8(%rbp), %rdi
movq -0x1c0(%rbp), %rax
movsd 0x10(%rax), %xmm1
movsd 0xf8(%rdi), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xf8(%rdi)
addq $0x10, %rdi
movq -0x1e8(%rbp), %rsi
callq 0xd2f0
jmp 0x2fa78
leaq -0xc8(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x30100
jmp 0x2fa8d
movq -0x1d8(%rbp), %rdi
callq 0x24680
movl %eax, -0x36c(%rbp)
jmp 0x2faa1
movl -0x36c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x2facb
movq -0x1d8(%rbp), %rdi
callq 0x24680
movl %eax, -0x370(%rbp)
jmp 0x2fac0
movl -0x370(%rbp), %eax
cmpl -0x28(%rbp), %eax
jl 0x2fb09
movq -0x1e0(%rbp), %rdi
callq 0x24680
movl %eax, -0x374(%rbp)
jmp 0x2fadf
movl -0x374(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x2fb20
movq -0x1e0(%rbp), %rdi
callq 0x24680
movl %eax, -0x378(%rbp)
jmp 0x2fafe
movl -0x378(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x2fb20
leaq -0x98(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x2b580
jmp 0x2fb1e
jmp 0x2fb20
movq -0x2a8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x1e8(%rbp), %rsi
callq 0xd4e0
movq %rax, -0x380(%rbp)
jmp 0x2fb40
movq -0x380(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x2b640
jmp 0x2fb55
leaq -0x120(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movq -0x1f0(%rbp), %rdi
callq 0xe520
movq %rax, -0x1f8(%rbp)
movq -0x1f0(%rbp), %rdi
callq 0xe550
movq %rax, -0x200(%rbp)
leaq -0x1f8(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0xe580
testb $0x1, %al
jne 0x2fba5
jmp 0x2fe94
leaq -0x1f8(%rbp), %rdi
callq 0xe5b0
movq (%rax), %rax
movq %rax, -0x208(%rbp)
movq -0x208(%rbp), %rdi
movq -0x1e8(%rbp), %rsi
callq 0xb480
movq %rax, -0x388(%rbp)
jmp 0x2fbd7
movq -0x388(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x210(%rbp), %rdi
callq 0x24680
movl %eax, -0x38c(%rbp)
jmp 0x2fbf9
movl -0x38c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x2fe81
movq -0x210(%rbp), %rdi
callq 0x24680
movl %eax, -0x390(%rbp)
jmp 0x2fc1c
movl -0x390(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x2fe81
movq -0x2a8(%rbp), %rdi
addq $0x10, %rdi
movq -0x210(%rbp), %rsi
callq 0xd490
movb %al, -0x391(%rbp)
jmp 0x2fc4a
movb -0x391(%rbp), %al
testb $0x1, %al
jne 0x2fe7f
jmp 0x2fc5a
leaq -0x98(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x2b4f0
movq %rax, -0x3a0(%rbp)
jmp 0x2fc76
movq -0x3a0(%rbp), %rax
movq %rax, -0x218(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x2b520
movq %rax, -0x220(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x2b4c0
testb $0x1, %al
jne 0x2fcb3
jmp 0x2fde9
movq -0x208(%rbp), %rax
movq %rax, -0x3b0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x2b550
movq %rax, -0x3a8(%rbp)
jmp 0x2fcdd
movq -0x3b0(%rbp), %rdi
movq -0x3a8(%rbp), %rax
movq (%rax), %rsi
callq 0xb4f0
movb %al, -0x3b1(%rbp)
jmp 0x2fcfb
movb -0x3b1(%rbp), %al
testb $0x1, %al
jne 0x2fd0a
jmp 0x2fde4
leaq -0x98(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x2b550
movq %rax, -0x3c0(%rbp)
jmp 0x2fd26
movq -0x3c0(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x30100
jmp 0x2fd3b
leaq -0x98(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x2b580
jmp 0x2fd50
leaq -0x230(%rbp), %rdi
leaq -0x210(%rbp), %rsi
leaq -0x208(%rbp), %rdx
callq 0x2b5f0
jmp 0x2fd6c
leaq -0x98(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x2b5b0
movb %dl, -0x3c9(%rbp)
movq %rax, -0x3c8(%rbp)
jmp 0x2fd8e
movb -0x3c9(%rbp), %al
movq -0x3c8(%rbp), %rcx
movq %rcx, -0x240(%rbp)
movb %al, -0x238(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x30130
movb %dl, -0x3d9(%rbp)
movq %rax, -0x3d8(%rbp)
jmp 0x2fdca
movb -0x3d9(%rbp), %al
movq -0x3d8(%rbp), %rcx
movq %rcx, -0x250(%rbp)
movb %al, -0x248(%rbp)
jmp 0x2fe7d
leaq -0x260(%rbp), %rdi
leaq -0x210(%rbp), %rsi
leaq -0x208(%rbp), %rdx
callq 0x2b5f0
jmp 0x2fe05
leaq -0x98(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x2b5b0
movb %dl, -0x3e9(%rbp)
movq %rax, -0x3e8(%rbp)
jmp 0x2fe27
movb -0x3e9(%rbp), %al
movq -0x3e8(%rbp), %rcx
movq %rcx, -0x270(%rbp)
movb %al, -0x268(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x30130
movb %dl, -0x3f9(%rbp)
movq %rax, -0x3f8(%rbp)
jmp 0x2fe63
movb -0x3f9(%rbp), %al
movq -0x3f8(%rbp), %rcx
movq %rcx, -0x280(%rbp)
movb %al, -0x278(%rbp)
jmp 0x2fe7f
jmp 0x2fe81
jmp 0x2fe83
leaq -0x1f8(%rbp), %rdi
callq 0xe5e0
jmp 0x2fb89
jmp 0x2f87a
movq 0x200f0(%rip), %rdi     # 0x4ff90
callq 0xa520
jmp 0x2fea7
movq -0x2a8(%rbp), %rax
cmpl $0x0, 0x108(%rax)
jne 0x30025
callq 0xaa70
movq %rax, -0x288(%rbp)
movq 0x200e2(%rip), %rdi     # 0x4ffb0
leaq 0x79d3(%rip), %rsi      # 0x378a8
callq 0xa780
movq %rax, -0x408(%rbp)
jmp 0x2fee3
movq -0x408(%rbp), %rdi
movq 0x20097(%rip), %rsi     # 0x4ff88
callq 0xa7e0
jmp 0x2fef8
movq -0x2a8(%rbp), %rdi
callq 0x265c0
jmp 0x2ff06
movq 0x200a3(%rip), %rdi     # 0x4ffb0
leaq 0x7999(%rip), %rsi      # 0x378ad
callq 0xa780
movq %rax, -0x410(%rbp)
jmp 0x2ff22
movq -0x410(%rbp), %rdi
movq -0x2a8(%rbp), %rax
movsd 0xf8(%rax), %xmm0
callq 0xaee0
movq %rax, -0x418(%rbp)
jmp 0x2ff46
movq -0x418(%rbp), %rdi
movq 0x20034(%rip), %rsi     # 0x4ff88
callq 0xa7e0
jmp 0x2ff5b
movq 0x2004e(%rip), %rdi     # 0x4ffb0
leaq 0x795e(%rip), %rsi      # 0x378c7
callq 0xa780
movq %rax, -0x420(%rbp)
jmp 0x2ff77
leaq -0x288(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2b6a0
movq %rax, -0x428(%rbp)
jmp 0x2ff90
movq -0x428(%rbp), %rax
movq %rax, -0x298(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x2b670
movq %rax, -0x430(%rbp)
jmp 0x2ffb3
movq -0x430(%rbp), %rax
movq %rax, -0x290(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x2b6f0
movq %rax, -0x438(%rbp)
jmp 0x2ffd6
movq -0x438(%rbp), %rsi
movq -0x420(%rbp), %rdi
callq 0xae50
movq %rax, -0x440(%rbp)
jmp 0x2fff2
movq -0x440(%rbp), %rdi
leaq 0x78e5(%rip), %rsi      # 0x378e5
callq 0xa780
movq %rax, -0x448(%rbp)
jmp 0x3000e
movq -0x448(%rbp), %rdi
movq 0x1ff6c(%rip), %rsi     # 0x4ff88
callq 0xa7e0
jmp 0x30023
jmp 0x30025
leaq -0x120(%rbp), %rdi
callq 0xdf50
leaq -0xc8(%rbp), %rdi
callq 0x301d0
leaq -0x98(%rbp), %rdi
callq 0x2b710
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
leaq -0xc8(%rbp), %rdi
callq 0x301d0
leaq -0x98(%rbp), %rdi
callq 0x2b710
movq -0xd8(%rbp), %rdi
callq 0xade0
nopw %cs:(%rax,%rax)