// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/channel.cc
// Function: PORE::getFreeIncludedSphereDiameterforNodePair(int, int)
pair <double, double> PORE::getFreeIncludedSphereDiameterforNodePair(int node1, int node2){
    //Define three access types
    const int ACCESSED   =  1;
    const int UNKNOWN      = -1;

    // flag that is used to terminate the search
    
    bool node2FoundFlag = false;

    // Make a local copy of nodes vector as it will be modified
    vector<DIJKSTRA_NODE> lnodes = nodes;
    
    // Initialize the unit cell position of each node
    vector<DELTA_POS> directions = vector<DELTA_POS> (lnodes.size(), DELTA_POS(0,0,0));
    
    // Initialize the status of each node as UNKNOWN
    vector<int> accessStatuses = vector<int> (lnodes.size(), UNKNOWN);
    unsigned int nodeIndex = 0;
    
    double di,df;

    if(node1 == node2 || node1 < 0 || node2 < 0){
      cerr << "Requesting Df/Dif conculation for nodes of incorrect IDs.\n" << "\n";
      abort();
      };

    // node1 and node2 are provided

    node1 = idMappings.find(node1)->second;
    node2 = idMappings.find(node2)->second;
    
    // Start analysis for node of id = nodeid
    
    nodeIndex = node1; // node1 is w.r.t pore node index (use PORE reverseMapping to retrieve original node
    
    // accept the initial node
    di=lnodes.at(nodeIndex).max_radius;
    df=lnodes.at(nodeIndex).max_radius;
    
    accessStatuses[nodeIndex] = ACCESSED;
    
    directions[nodeIndex] = DELTA_POS(0,0,0);
    
    compareConnections_ptr = &lnodes;
    HEAP< pair<int,int> > stack(compareConnections);
    
    // loop over all connections and add them to stack
    for(unsigned int i=0; i<lnodes[nodeIndex].connections.size(); i++)
    {
        if(lnodes[nodeIndex].connections.at(i).max_radius > lnodes.at(lnodes[nodeIndex].connections.at(i).to).max_radius)
            lnodes[nodeIndex].connections.at(i).max_radius = lnodes.at(lnodes[nodeIndex].connections.at(i).to).max_radius;
        
        stack.insert(pair<int,int>(nodeIndex,i));
    };
    
    stack.reHeapify();
    
    bool flag=true;
    
    while(stack.size() != 0&&flag){
        //loop with Dijkstra-like propagation
        
        // select the path with largest opening
        pair<int,int> best = stack.pop();
        
        int best_node = lnodes[best.first].connections[best.second].to;
        
        if(accessStatuses[best_node]==UNKNOWN)
        {
            // going to accept the best_node and update di and df
            // update df and di
            if(lnodes[best.first].connections.at(best.second).max_radius<df) df=lnodes[best.first].connections.at(best.second).max_radius;
            
            if(lnodes.at(best_node).max_radius > di) di = lnodes.at(best_node).max_radius;

            // in the desired node is reached, and the loop 
            
            if(best_node == node2)
              {
              node2FoundFlag = true; 
              flag = true; // stop flag set
              break;
              };
            
            // otherwise continue

            // check new connections, add to heap or terminane
            
            accessStatuses[best_node]=ACCESSED; 
            directions[best_node]=directions[best.first];
            directions[best_node]=directions[best_node] + (lnodes[best.first].connections.at(best.second).deltaPos);
            
            // going to add new connections to the heap
            for(unsigned int i=0; i<lnodes[best_node].connections.size(); i++)
            {
                if(lnodes[best_node].connections.at(i).max_radius > lnodes.at(lnodes[best_node].connections.at(i).to).max_radius)
                    lnodes[best_node].connections.at(i).max_radius = lnodes.at(lnodes[best_node].connections.at(i).to).max_radius;
                
                if(lnodes[best_node].connections[i].to!=best.first)
                    stack.insert(pair<int,int>(best_node,i));
            };	
            stack.reHeapify(); 
        }
        
        else if(accessStatuses[best_node]==ACCESSED){
            //selected connection leads to a node that is on stact
            //need to check in which unit cell it is
            
            
            if(!(directions[best_node]).equals(directions[best.first] + lnodes[best.first].connections.at(best.second).deltaPos))
            {
                // if nodes are in different unit cells (a loop is found); just update df and continue 
                if(df>nodes[best.first].connections.at(best.second).max_radius) df=nodes[best.first].connections.at(best.second).max_radius;
            };
            // otherwise do nothing
            // need to make sure heap is correct (which should be true as nothing was added)
        }
        
        else{
            //
            // need this section ?
            //
        };
        
    };
    
    // change radii to diameter
    df=df*2.0;
    di=di*2.0;
    
    if(node2FoundFlag == false)
      {
      df = -1;
      di = -1;
      };

    pair<double,double>  resultdfdif;
    resultdfdif.first=df;
    resultdfdif.second=di;
    
    return resultdfdif;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, %r12
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
leaq 0x60(%rdi), %rsi
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movq %rsi, 0x90(%rsp)
callq 0x38b26
movq (%r14), %rbx
movq 0x8(%r14), %r13
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x506b0
subq %rbx, %r13
sarq $0x3, %r13
movabsq $-0x71c71c71c71c71c7, %rbx # imm = 0x8E38E38E38E38E39
imulq %rbx, %r13
leaq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0x78(%rsp), %rcx
movq %r13, %rsi
callq 0x7608a
movq 0x40(%rsp), %rsi
subq 0x38(%rsp), %rsi
sarq $0x3, %rsi
imulq %rbx, %rsi
leaq 0x78(%rsp), %rdi
leaq 0x54(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x3864a
cmpl %ebp, %r15d
je 0x74e8d
movl %ebp, %eax
orl %r15d, %eax
js 0x74e8d
movq 0x10(%r12), %rcx
leaq 0x8(%r12), %rax
testq %rcx, %rcx
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
je 0x7490c
movq %rcx, %rsi
movq %rax, %rdx
xorl %edi, %edi
cmpl %r15d, 0x20(%rsi)
setl %dil
cmovgeq %rsi, %rdx
movq 0x10(%rsi,%rdi,8), %rsi
testq %rsi, %rsi
jne 0x748b6
movq %rax, %rsi
cmpq %rax, %rdx
je 0x748e1
cmpl %r15d, 0x20(%rdx)
cmovgq %rax, %rdx
movq %rdx, %rsi
movl 0x24(%rsi), %edx
movq %rax, %rsi
xorl %edi, %edi
cmpl %ebp, 0x20(%rcx)
setl %dil
cmovgeq %rcx, %rsi
movq 0x10(%rcx,%rdi,8), %rcx
testq %rcx, %rcx
jne 0x748e7
cmpq %rax, %rsi
je 0x74911
cmpl %ebp, 0x20(%rsi)
cmovleq %rsi, %rax
jmp 0x74911
movl 0x2c(%r12), %edx
movl %edx, %r15d
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r8, %rdx
cmpq %r15, %rdx
jbe 0x74ebd
movl 0x24(%rax), %eax
movl %eax, 0x50(%rsp)
leaq (%r15,%r15,8), %rbx
movsd 0x38(%rcx,%rbx,8), %xmm0
movsd %xmm0, (%rsp)
movq 0x78(%rsp), %rax
movl $0x1, (%rax,%r15,4)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x506b0
movq 0x58(%rsp), %rax
leaq (%r15,%r15,2), %rcx
movl 0x18(%rsp), %edx
movl %edx, 0x8(%rax,%rcx,4)
movq 0x10(%rsp), %rdx
movq %rdx, (%rax,%rcx,4)
movq %r14, 0x120de2(%rip)    # 0x195768
leaq -0x2cc(%rip), %rax      # 0x746c1
movq %rax, 0x28(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x38(%rsp), %rcx
movq 0x20(%rcx,%rbx,8), %rdi
cmpq %rdi, 0x28(%rcx,%rbx,8)
movabsq $-0x71c71c71c71c71c7, %r9 # imm = 0x8E38E38E38E38E39
je 0x74a67
movl $0x1, %ebp
xorl %esi, %esi
leaq 0x10(%rsp), %r14
movabsq $-0x3333333333333333, %r12 # imm = 0xCCCCCCCCCCCCCCCD
leaq (%rsi,%rsi,4), %r8
movslq 0x4(%rdi,%r8,8), %rax
movq 0x40(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r9, %rdx
cmpq %rax, %rdx
jbe 0x74e57
leaq (%rdi,%r8,8), %rdx
movsd 0x10(%rdx), %xmm1
leaq (%rax,%rax,8), %rax
movsd 0x38(%rcx,%rax,8), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x74a1a
movsd %xmm0, 0x10(%rdx)
shlq $0x20, %rsi
orq %r15, %rsi
movq %r14, %rdi
callq 0x7611c
movl %ebp, %esi
movq 0x38(%rsp), %rcx
movq 0x20(%rcx,%rbx,8), %rdi
movq 0x28(%rcx,%rbx,8), %rax
subq %rdi, %rax
sarq $0x3, %rax
imulq %r12, %rax
incl %ebp
cmpq %rsi, %rax
movabsq $-0x71c71c71c71c71c7, %r9 # imm = 0x8E38E38E38E38E39
ja 0x749da
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rax
jmp 0x74a6b
xorl %esi, %esi
xorl %edi, %edi
leaq 0x70(%rsp), %rdx
movq %rax, (%rdx)
callq 0x68ddd
movabsq $0x7fffffff8, %r13      # imm = 0x7FFFFFFF8
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
subq %rdi, %rax
movb $0x1, %cl
movl %ecx, 0x34(%rsp)
testq %r13, %rax
je 0x74d86
movsd (%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x761b8
movq %rax, %r12
movl %r12d, %ebp
movslq %r12d, %rax
movq 0x38(%rsp), %rcx
leaq (%rax,%rax,8), %r15
leaq (%rcx,%r15,8), %rdx
addq $0x20, %rdx
sarq $0x20, %r12
movq (%rdx), %r8
leaq (%r12,%r12,4), %r10
leaq (%r8,%r10,8), %rsi
movslq 0x4(%rsi), %rbx
movq 0x78(%rsp), %rdi
movl (%rdi,%rbx,4), %r9d
cmpl $0x1, %r9d
je 0x74cd4
cmpl $-0x1, %r9d
jne 0x74d6e
movq 0x8(%rdx), %rdx
subq %r8, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %r8 # imm = 0xCCCCCCCCCCCCCCCD
imulq %r8, %rdx
cmpq %r12, %rdx
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
jbe 0x74e6b
movq 0x40(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r8, %rdx
cmpq %rbx, %rdx
jbe 0x74e68
movsd 0x10(%rsi), %xmm0
minsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq (%rbx,%rbx,8), %r13
movsd 0x38(%rcx,%r13,8), %xmm0
maxsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
cmpl 0x50(%rsp), %ebx
je 0x74d98
movl $0x1, (%rdi,%rbx,4)
movq 0x58(%rsp), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rbx,%rbx,2), %r14
movl 0x8(%rcx,%rax,4), %edx
movl %edx, 0x8(%rcx,%r14,4)
movq (%rcx,%rax,4), %rax
movq %rax, (%rcx,%r14,4)
movq 0x38(%rsp), %rcx
movq 0x20(%rcx,%r15,8), %rax
movq 0x28(%rcx,%r15,8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x74e7c
leaq (,%r14,4), %rdi
addq 0x58(%rsp), %rdi
leaq (%rax,%r10,8), %rsi
addq $0x18, %rsi
callq 0x50708
movq 0x58(%rsp), %rcx
movq %rax, (%rcx,%r14,4)
movl %edx, 0x8(%rcx,%r14,4)
movq 0x38(%rsp), %rcx
movq 0x20(%rcx,%r13,8), %rdi
cmpq %rdi, 0x28(%rcx,%r13,8)
movabsq $-0x71c71c71c71c71c7, %r9 # imm = 0x8E38E38E38E38E39
je 0x74ca7
movl %ebx, %ebx
movl $0x1, %r14d
xorl %esi, %esi
leaq (%rsi,%rsi,4), %r8
movslq 0x4(%rdi,%r8,8), %rax
movq 0x40(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r9, %rdx
cmpq %rax, %rdx
jbe 0x74e46
leaq (%rdi,%r8,8), %rdx
movsd 0x10(%rdx), %xmm1
leaq (%rax,%rax,8), %rdi
movsd 0x38(%rcx,%rdi,8), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x74c55
movsd %xmm0, 0x10(%rdx)
cmpl %ebp, %eax
je 0x74c79
shlq $0x20, %rsi
orq %rbx, %rsi
leaq 0x10(%rsp), %rdi
callq 0x7611c
movq 0x38(%rsp), %rcx
movabsq $-0x71c71c71c71c71c7, %r9 # imm = 0x8E38E38E38E38E39
movl %r14d, %esi
movq 0x20(%rcx,%r13,8), %rdi
movq 0x28(%rcx,%r13,8), %rax
subq %rdi, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rax
incl %r14d
cmpq %rsi, %rax
ja 0x74c15
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x70(%rsp), %rdx
callq 0x68ddd
movabsq $0x7fffffff8, %r13      # imm = 0x7FFFFFFF8
jmp 0x74d6e
movq 0x8(%rdx), %rdx
subq %r8, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x74e6b
movq %r10, %rbp
movq 0x58(%rsp), %r14
leaq (%rax,%rax,2), %rax
leaq (%r14,%rax,4), %rdi
addq $0x18, %rsi
callq 0x50708
leaq (%rbx,%rbx,2), %rcx
leaq (%r14,%rcx,4), %rdi
movq %rax, %rsi
callq 0x506ba
testb %al, %al
jne 0x74d6e
movq 0x90(%rsp), %rax
movq (%rax), %rcx
movq 0x20(%rcx,%r15,8), %rax
movq 0x28(%rcx,%r15,8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x74e6b
movsd 0x10(%rax,%rbp,8), %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x74d6e
movsd %xmm0, 0x8(%rsp)
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
subq %rdi, %rax
testq %r13, %rax
jne 0x74aa9
jmp 0x74da5
movsd (%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, (%rsp)
jmp 0x74da5
movq 0x10(%rsp), %rdi
movl $0x0, 0x34(%rsp)
testq %rdi, %rdi
je 0x74db7
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x74dd1
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x74de8
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd 0xdc570(%rip), %xmm1    # 0x151360
movapd %xmm1, %xmm0
cmpb $0x0, 0x34(%rsp)
jne 0x74e04
movsd (%rsp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, (%rsp)
jne 0x74e19
movsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm0
movapd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
leaq 0x38(%rsp), %rdi
callq 0xf10e
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd88a8(%rip), %rdi     # 0x14d6f5
movq %rax, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xd8897(%rip), %rdi     # 0x14d6f5
movq %rax, %rsi
xorl %eax, %eax
callq 0x4630
movq %rbx, %r12
leaq 0xd8883(%rip), %rdi     # 0x14d6f5
movq %r12, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xd8872(%rip), %rdi     # 0x14d6f5
movq %r12, %rsi
xorl %eax, %eax
callq 0x4630
movq 0x12015c(%rip), %rdi    # 0x194ff0
leaq 0xdfc91(%rip), %rsi     # 0x154b2c
movl $0x3a, %edx
callq 0x44e0
movq 0x120144(%rip), %rdi    # 0x194ff0
leaq 0xde76b(%rip), %rsi     # 0x15361e
callq 0x4440
callq 0x4260
leaq 0xd8831(%rip), %rdi     # 0x14d6f5
movq %r15, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x74ef3
jmp 0x74ede
movq %rax, %rbx
jmp 0x74f27
jmp 0x74ed9
movq %rax, %rbx
jmp 0x74f3e
movq %rax, %rbx
jmp 0x74f0d
jmp 0x74ef3
jmp 0x74ef3
jmp 0x74ef3
jmp 0x74ef3
jmp 0x74ef3
jmp 0x74ef3
jmp 0x74ef3
jmp 0x74ef3
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x74f0d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x74f27
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x74f3e
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x38(%rsp), %rdi
callq 0xf10e
movq %rbx, %rdi
callq 0x4780