// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/channel.cc
// Function: PORE::reconstruct()
void PORE::reconstruct(){
    vector<bool> haveVisited = vector<bool>(nodes.size(),false);
    vector<DELTA_POS> displacements = vector<DELTA_POS>(nodes.size());
    unsigned int visitCount = 0;
    
    //Search through the PORE, emphasizing nodes located in the current unit
    //cell or in previously visited unit cells. Record the unit cell within which
    //each node is encountered
    comparer = ReconstructorComparator();
    HEAP< pair<int,DELTA_POS> > stack (compareNodes);
    stack.insert(pair<int,DELTA_POS> (0, DELTA_POS(0,0,0))); // Pick the first node as the starting point
    DELTA_POS curPos = DELTA_POS(0,0,0);
    
    // Continue reconstruction until all nodes have been visited
    while(visitCount < nodes.size()){
        if(stack.size() == 0){
            cerr << "Error: Stack empties prior to pore reconstruction completion." << "\n"
            << "Please contact the source code provided with this message." << "\n"
            << "Exiting..." << "\n"
            << "Nnodes = " << nodes.size() << "  visitCount= " << visitCount << "\n";
            
            exit(1);
        }
        
        pair<int,DELTA_POS> best = stack.pop();
        
        if(!haveVisited.at(best.first)){
            visitCount++;
            haveVisited.at(best.first) = true;
            displacements.at(best.first) = best.second;
            
            // If changed unit cell, need to restructure heap
            if(!best.second.equals(curPos)){
                comparer.setPosition(best.second);
                stack.reHeapify();
                curPos = best.second;
            }
            
            // Add all the nodes from the current node to the stack that
            // have not yet been visited
            DIJKSTRA_NODE curNode = nodes.at(best.first);
            for(unsigned int j = 0; j < curNode.connections.size(); j++){
                CONN curConn = curNode.connections.at(j);
                if(!haveVisited.at(curConn.to)){
                    DELTA_POS newPos = curPos + curConn.deltaPos;
                    stack.insert(pair<int,DELTA_POS>(curConn.to,newPos));
                }
            }
        }
    }
    
    map<DELTA_POS, vector<int> ,  bool(*)(DELTA_POS,DELTA_POS)> results (fn_pt);
    
    //Store the list of nodes and unit cells in a usable format
    for(unsigned int i = 0; i < nodes.size(); i++){
        map<DELTA_POS, vector<int> >::iterator iter = results.find(displacements.at(i));
        if(iter == results.end()){
            vector<int> newList; newList.push_back(i);
            results.insert(pair<DELTA_POS, vector<int> > (displacements.at(i),newList));
        }
        else
            iter->second.push_back(i);
    }
    
    // Copy the unit cells visited and their corresponding node ids to intrinsic
    // data structures
    map<DELTA_POS, vector<int> >::iterator rIter = results.begin();
    while(rIter != results.end()){
        unitCells.push_back(rIter->first);
        ucNodes.push_back(rIter->second);
        rIter++;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
movq 0x68(%rdi), %rsi
subq 0x60(%rdi), %rsi
sarq $0x3, %rsi
movabsq $-0x71c71c71c71c71c7, %r14 # imm = 0x8E38E38E38E38E39
imulq %r14, %rsi
leaq 0x90(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0xf0(%rsp), %rdi
leaq 0x50(%rsp), %rcx
callq 0x37f36
movq 0x68(%rbx), %rsi
subq 0x60(%rbx), %rsi
sarq $0x3, %rsi
imulq %r14, %rsi
leaq 0x78(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x75c22
leaq 0x90(%rsp), %rdi
callq 0x72488
leaq 0xa0(%rsp), %r14
movl -0x8(%r14), %eax
movl %eax, 0x1261f2(%rip)    # 0x195730
movq -0x10(%r14), %rax
movq %rax, 0x1261df(%rip)    # 0x195728
movq (%r14), %rax
movq %rax, 0x1261e5(%rip)    # 0x195738
leaq 0x1261de(%rip), %rdi    # 0x195738
callq 0x76256
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x6f5b2
leaq 0xa8(%rsp), %rcx
movl (%rcx), %edx
movl %edx, 0x1261c8(%rip)    # 0x195740
leaq 0x1261c1(%rip), %rdx    # 0x195740
movq %rax, 0x1261c2(%rip)    # 0x195748
movups 0x10(%rcx), %xmm0
movups %xmm0, 0x1261bf(%rip)   # 0x195750
movq %rdx, 0x8(%rax)
movq 0x20(%rcx), %rax
movq %rax, 0x1261c0(%rip)    # 0x195760
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq %r14, %rdi
callq 0x390be
leaq 0x3086(%rip), %rax      # 0x72647
movq %rax, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
leaq 0x90(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x506b0
movq 0x94(%rsp), %rdx
movl 0x90(%rsp), %esi
shlq $0x20, %rsi
leaq 0x20(%rsp), %rdi
callq 0x75cb4
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x506b0
movq 0x68(%rbx), %rax
movq %rax, %rcx
cmpq 0x60(%rbx), %rax
je 0x6fa1e
movabsq $0xffffffff0, %r12      # imm = 0xFFFFFFFF0
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
xorl %r13d, %r13d
testq %r12, %rax
je 0x6fcc8
leaq 0x20(%rsp), %rbp
movq %rbp, %rdi
callq 0x75d26
movq %rax, (%rsp)
movq %rdx, 0x8(%rsp)
movslq %eax, %rsi
leaq 0xf0(%rsp), %rdi
callq 0xee36
testq %rdx, (%rax)
jne 0x6f8d6
movslq (%rsp), %rsi
leaq 0xf0(%rsp), %rdi
callq 0xee36
orq %rdx, (%rax)
movslq (%rsp), %rsi
movq 0x78(%rsp), %rax
movq 0x80(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x6fcac
leaq (%rsi,%rsi,2), %rcx
leaq 0x4(%rsp), %rdi
movl 0x8(%rdi), %edx
movl %edx, 0x8(%rax,%rcx,4)
movq (%rdi), %rdx
movq %rdx, (%rax,%rcx,4)
movq 0x40(%rsp), %rsi
movl 0x48(%rsp), %edx
callq 0x506ba
testb %al, %al
jne 0x6f767
movq 0x4(%rsp), %rax
movl 0xc(%rsp), %ecx
movq %rax, 0x90(%rsp)
movl %ecx, 0x98(%rsp)
leaq 0x126032(%rip), %rdi    # 0x195738
leaq 0x90(%rsp), %rsi
callq 0x3c45a
movl 0x98(%rsp), %eax
movl %eax, 0x126010(%rip)    # 0x195730
movq 0x90(%rsp), %rax
movq %rax, 0x125ff9(%rip)    # 0x195728
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x38(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x90(%rsp), %rdx
callq 0x76ff4
leaq 0x4(%rsp), %rcx
movq (%rcx), %rax
movq %rax, 0x40(%rsp)
movl 0x8(%rcx), %eax
movl %eax, 0x48(%rsp)
movslq (%rsp), %rsi
movq 0x60(%rbx), %r14
movq 0x68(%rbx), %rdx
subq %r14, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %rdx
cmpq %rsi, %rdx
jbe 0x6fcba
movq %r13, %r15
movq %r12, %r13
leaq (%rsi,%rsi,8), %r12
leaq (%r14,%r12,8), %rsi
addq $0x20, %rsi
movups -0x20(%rsi), %xmm0
movups -0x10(%rsi), %xmm1
movaps %xmm1, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
leaq 0xb0(%rsp), %rbp
movq %rbp, %rdi
callq 0x37e9e
leaq (%r14,%r12,8), %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%rbp)
movq 0x38(%rax), %rax
movq %rax, 0x18(%rbp)
movq 0xb0(%rsp), %rdi
cmpq %rdi, 0xb8(%rsp)
je 0x6f8b3
movl $0x1, %r14d
xorl %eax, %eax
movq %r13, %r12
movq %r15, %r13
leaq 0x68(%rsp), %r15
leaq 0x20(%rsp), %rbp
leaq (%rax,%rax,4), %rax
movups (%rdi,%rax,8), %xmm0
movups 0x10(%rdi,%rax,8), %xmm1
movaps %xmm0, 0x50(%rsp)
movq 0x20(%rdi,%rax,8), %rax
movq %rax, 0x70(%rsp)
movaps %xmm1, 0x60(%rsp)
movslq 0x54(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
callq 0xee36
testq %rdx, (%rax)
jne 0x6f87d
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x50708
movq %rax, 0xe0(%rsp)
movl %edx, 0xe8(%rsp)
movl 0x54(%rsp), %ecx
movq 0xe4(%rsp), %rdx
shlq $0x20, %rax
orq %rcx, %rax
movq %rbp, %rdi
movq %rax, %rsi
callq 0x75cb4
movl %r14d, %eax
movq 0xb0(%rsp), %rdi
movq 0xb8(%rsp), %rcx
subq %rdi, %rcx
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rcx
incl %r14d
cmpq %rax, %rcx
ja 0x6f80b
jmp 0x6f8be
movq %r13, %r12
movq %r15, %r13
leaq 0x20(%rsp), %rbp
testq %rdi, %rdi
je 0x6f8d3
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incl %r13d
movl %r13d, %r14d
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rsi # imm = 0x8E38E38E38E38E39
imulq %rsi, %rdx
cmpq %r14, %rdx
jbe 0x6fa1e
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
testq %r12, %rax
jne 0x6f64d
movq 0x1256d4(%rip), %rdi    # 0x194ff0
leaq 0xe50dc(%rip), %rsi     # 0x1549ff
movl $0x3d, %edx
callq 0x44e0
movq 0x1256bc(%rip), %rdi    # 0x194ff0
leaq 0xe3ce3(%rip), %rsi     # 0x15361e
movl $0x1, %edx
callq 0x44e0
movq 0x1256a4(%rip), %rdi    # 0x194ff0
leaq 0xe50ea(%rip), %rsi     # 0x154a3d
movl $0x3a, %edx
callq 0x44e0
movq 0x12568c(%rip), %rdi    # 0x194ff0
leaq 0xe3cb3(%rip), %rsi     # 0x15361e
movl $0x1, %edx
callq 0x44e0
movq 0x125674(%rip), %rdi    # 0x194ff0
leaq 0xe4d47(%rip), %rsi     # 0x1546ca
movl $0xa, %edx
callq 0x44e0
movq 0x12565c(%rip), %rdi    # 0x194ff0
leaq 0xe3c83(%rip), %rsi     # 0x15361e
movl $0x1, %edx
callq 0x44e0
movq 0x125644(%rip), %rdi    # 0x194ff0
leaq 0xe50c5(%rip), %rsi     # 0x154a78
movl $0x9, %edx
callq 0x44e0
movq 0x68(%rbx), %rsi
subq 0x60(%rbx), %rsi
sarq $0x3, %rsi
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %rsi
movq 0x125612(%rip), %rdi    # 0x194ff0
callq 0x42b0
movq %rax, %rbx
leaq 0xe5095(%rip), %rsi     # 0x154a82
movl $0xe, %edx
movq %rax, %rdi
callq 0x44e0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x42b0
leaq 0xe3c12(%rip), %rsi     # 0x15361e
movq %rax, %rdi
callq 0x4440
movl $0x1, %edi
callq 0x72bc
movq 0x125a33(%rip), %rdx    # 0x195458
leaq 0x98(%rsp), %r13
movq %rdx, -0x8(%r13)
movl $0x0, (%r13)
xorl %edx, %edx
movq %rdx, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq %rdx, 0x20(%r13)
cmpq %rax, %rcx
je 0x6fc1d
movl $0x1, %r12d
xorl %ebp, %ebp
leaq 0x90(%rsp), %r15
movq 0x78(%rsp), %rax
movq 0x80(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rbp, %rdx
jbe 0x6fc8a
leaq (,%rbp,2), %r14
addq %rbp, %r14
leaq (%rax,%r14,4), %rsi
movq %r15, %rdi
callq 0x77056
leal -0x1(%r12), %ecx
cmpq %r13, %rax
je 0x6fad1
movl %ecx, 0x50(%rsp)
movq 0x38(%rax), %rsi
cmpq 0x40(%rax), %rsi
je 0x6fb7a
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rax)
jmp 0x6fb8b
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movl %ecx, 0x50(%rsp)
movq %rsp, %rdi
xorl %esi, %esi
leaq 0x50(%rsp), %rdx
callq 0x14198
movq 0x78(%rsp), %rax
movq 0x80(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rbp, %rdx
jbe 0x6fc9b
movl 0x8(%rax,%r14,4), %ecx
movl %ecx, 0x58(%rsp)
movq (%rax,%r14,4), %rax
movq %rax, 0x50(%rsp)
leaq 0x60(%rsp), %rdi
movq %rsp, %rsi
callq 0xe8f8
movq %r15, %rdi
leaq 0x50(%rsp), %rsi
callq 0x770c6
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x6fb62
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x6fb8b
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x6fb8b
addq $0x30, %rax
movq %rax, %rdi
leaq 0x50(%rsp), %rdx
callq 0x14198
movl %r12d, %ebp
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
sarq $0x3, %rax
movabsq $-0x71c71c71c71c71c7, %rcx # imm = 0x8E38E38E38E38E39
imulq %rcx, %rax
incl %r12d
cmpq %rbp, %rax
ja 0x6fa64
movq 0xa8(%rsp), %r14
cmpq %r13, %r14
je 0x6fc1d
leaq 0x90(%rbx), %r15
leaq 0xa8(%rbx), %r12
leaq 0x20(%r14), %rdx
movq 0x98(%rbx), %rsi
cmpq 0xa0(%rbx), %rsi
je 0x6fbf9
movl 0x8(%rdx), %eax
movl %eax, 0x8(%rsi)
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0xc, 0x98(%rbx)
jmp 0x6fc01
movq %r15, %rdi
callq 0x77270
leaq 0x30(%r14), %rsi
movq %r12, %rdi
callq 0xf03a
movq %r14, %rdi
callq 0x42d0
movq %rax, %r14
cmpq %r13, %rax
jne 0x6fbcf
leaq 0x90(%rsp), %rdi
callq 0x76284
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x6fc41
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x6fc5b
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x6fc78
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdda64(%rip), %rdi     # 0x14d6f5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xdda53(%rip), %rdi     # 0x14d6f5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xdda42(%rip), %rdi     # 0x14d6f5
xorl %eax, %eax
callq 0x4630
leaq 0xdda34(%rip), %rdi     # 0x14d6f5
xorl %eax, %eax
callq 0x4630
xorl %r14d, %r14d
jmp 0x6f915
movq %rax, %rbx
jmp 0x6fd7f
movq %rax, %rbx
jmp 0x6fd99
jmp 0x6fd41
jmp 0x6fd2d
jmp 0x6fd41
jmp 0x6fd41
jmp 0x6fd41
jmp 0x6fd41
jmp 0x6fd0c
jmp 0x6fd0c
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x6fd0f
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x6fd0f
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x6fd30
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x6fd30
jmp 0x6fd2d
jmp 0x6fd41
jmp 0x6fd2d
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x76284
jmp 0x6fd68
jmp 0x6fd41
movq %rax, %rbx
jmp 0x6fd68
jmp 0x6fd48
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x6fd68
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x6fd7f
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x6fd99
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x6fdb6
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780