// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdi, %r14
movl %esi, 0x4(%rsp)
movl %edx, (%rsp)
orl $-0x1, 0x3c(%rsp)
leaq 0x60(%rdi), %rsi
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x60(%rsp)
callq 0x2a78c
movq (%rbx), %r15
movq 0x8(%rbx), %rbx
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3d328
subq %r15, %rbx
pushq $0x48
popq %r15
movq %rbx, %rax
cqto
idivq %r15
leaq 0x68(%rsp), %rdi
leaq 0x40(%rsp), %rdx
leaq 0x80(%rsp), %rcx
movq %rax, %rsi
callq 0x579e8
movq 0x20(%rsp), %rax
subq 0x18(%rsp), %rax
cqto
idivq %r15
leaq 0x80(%rsp), %rdi
leaq 0x3c(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %rax, %rsi
callq 0x2a44a
movl 0x4(%rsp), %eax
movl (%rsp), %ecx
cmpl %ecx, %eax
je 0x56b68
orl %eax, %ecx
js 0x56b68
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
callq 0x10996
movl 0x24(%rax), %eax
movl %eax, 0x4(%rsp)
movq %rsp, %rsi
movq %r14, %rdi
callq 0x10996
movl 0x24(%rax), %eax
movl %eax, (%rsp)
movl 0x4(%rsp), %r14d
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0xabe2
movsd 0x38(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xabe2
movsd 0x38(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x80(%rsp), %rax
movl $0x1, (%rax,%r14,4)
leaq 0x40(%rsp), %rdi
xorl %r12d, %r12d
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3d328
movq 0x68(%rsp), %rax
imulq $0xc, %r14, %rcx
leaq 0x40(%rsp), %r13
movl 0x8(%r13), %edx
movl %edx, 0x8(%rax,%rcx)
movq (%r13), %rdx
movq %rdx, (%rax,%rcx)
movq %r15, 0xfa04d(%rip)     # 0x150770
leaq -0x23f(%rip), %rsi      # 0x564eb
movq %r13, %rdi
callq 0x57a3e
imulq $0x48, %r14, %rbx
movl %r12d, %r12d
movq 0x18(%rsp), %rcx
movq 0x28(%rcx,%rbx), %rax
subq 0x20(%rcx,%rbx), %rax
cqto
pushq $0x28
popq %rsi
idivq %rsi
cmpq %r12, %rax
jbe 0x56808
leaq (%rcx,%rbx), %rdi
addq $0x20, %rdi
movq %r12, %rsi
callq 0x29efa
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x18(%rsp), %rax
leaq (%rax,%rbx), %rdi
addq $0x20, %rdi
movq %r12, %rsi
callq 0x29efa
movslq 0x4(%rax), %rsi
movq %r15, %rdi
callq 0xabe2
movsd 0x10(%rsp), %xmm0
ucomisd 0x38(%rax), %xmm0
jbe 0x567ee
movq 0x18(%rsp), %rax
leaq (%rax,%rbx), %rdi
addq $0x20, %rdi
movq %r12, %rsi
callq 0x29efa
movslq 0x4(%rax), %rsi
movq %r15, %rdi
callq 0xabe2
movsd 0x38(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x18(%rsp), %rax
leaq (%rax,%rbx), %rdi
addq $0x20, %rdi
movq %r12, %rsi
callq 0x29efa
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rax)
movq %r12, %rsi
shlq $0x20, %rsi
orq %r14, %rsi
movq %r13, %rdi
callq 0x57a74
incl %r12d
jmp 0x56736
leaq 0x40(%rsp), %rdi
callq 0x57aa2
movq 0x48(%rsp), %rbx
subq 0x40(%rsp), %rbx
movq %rbx, %rax
shrq $0x3, %rax
testl %eax, %eax
je 0x56ae0
leaq 0x40(%rsp), %rdi
callq 0x57ab6
movq %rax, %r12
movslq %r12d, %r14
movq 0x18(%rsp), %rax
imulq $0x48, %r14, %r15
leaq (%rax,%r15), %rdi
addq $0x20, %rdi
movq %r12, %r13
sarq $0x20, %r13
movq (%rdi), %rax
imulq $0x28, %r13, %rcx
movslq 0x4(%rax,%rcx), %rbp
movq 0x80(%rsp), %rax
movl (%rax,%rbp,4), %eax
cmpl $0x1, %eax
je 0x56a46
cmpl $-0x1, %eax
jne 0x56812
movq %r13, %rsi
callq 0x29efa
movsd 0x8(%rsp), %xmm0
ucomisd 0x10(%rax), %xmm0
jbe 0x568ad
movq 0x18(%rsp), %rax
leaq (%rax,%r15), %rdi
addq $0x20, %rdi
movq %r13, %rsi
callq 0x29efa
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0xabe2
movsd 0x38(%rax), %xmm0
ucomisd 0x30(%rsp), %xmm0
jbe 0x568df
leaq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0xabe2
movsd 0x38(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
cmpl (%rsp), %ebp
je 0x56ae0
movq 0x80(%rsp), %rax
movl $0x1, (%rax,%rbp,4)
movq 0x68(%rsp), %rax
imulq $0xc, %r14, %rcx
imulq $0xc, %rbp, %r14
movl 0x8(%rax,%rcx), %edx
movl %edx, 0x8(%rax,%r14)
movq (%rax,%rcx), %rcx
movq %rcx, (%rax,%r14)
movq 0x68(%rsp), %rbx
movq 0x18(%rsp), %rax
leaq (%rax,%r15), %rdi
addq $0x20, %rdi
movq %r13, %rsi
callq 0x29efa
addq %r14, %rbx
addq $0x18, %rax
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3d380
movl %ebp, %ebx
movq 0x68(%rsp), %rcx
movq %rax, (%rcx,%r14)
movl %edx, 0x8(%rcx,%r14)
xorl %r13d, %r13d
imulq $0x48, %rbp, %r15
leaq 0x18(%rsp), %r14
movl %r13d, %r13d
movq 0x18(%rsp), %rcx
movq 0x28(%rcx,%r15), %rax
subq 0x20(%rcx,%r15), %rax
cqto
pushq $0x28
popq %rsi
idivq %rsi
cmpq %r13, %rax
jbe 0x56ad1
leaq (%rcx,%r15), %rdi
addq $0x20, %rdi
movq %r13, %rsi
callq 0x29efa
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x18(%rsp), %rax
leaq (%rax,%r15), %rdi
addq $0x20, %rdi
movq %r13, %rsi
callq 0x29efa
movslq 0x4(%rax), %rsi
movq %r14, %rdi
callq 0xabe2
movsd 0x10(%rsp), %xmm0
ucomisd 0x38(%rax), %xmm0
jbe 0x56a15
movq 0x18(%rsp), %rax
leaq (%rax,%r15), %rdi
addq $0x20, %rdi
movq %r13, %rsi
callq 0x29efa
movslq 0x4(%rax), %rsi
movq %r14, %rdi
callq 0xabe2
movsd 0x38(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x18(%rsp), %rax
leaq (%rax,%r15), %rdi
addq $0x20, %rdi
movq %r13, %rsi
callq 0x29efa
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rax)
movq 0x18(%rsp), %rax
movq 0x20(%rax,%r15), %rax
imulq $0x28, %r13, %rcx
cmpl %r12d, 0x4(%rax,%rcx)
je 0x56a3e
movq %r13, %rsi
shlq $0x20, %rsi
orq %rbx, %rsi
leaq 0x40(%rsp), %rdi
callq 0x57a74
incl %r13d
jmp 0x5695d
movq 0x68(%rsp), %r12
movq %r13, %rsi
callq 0x29efa
imulq $0xc, %r14, %rdi
addq %r12, %rdi
addq $0x18, %rax
movq %rax, %rsi
callq 0x3d380
imulq $0xc, %rbp, %rcx
addq %rcx, %r12
movq %r12, %rdi
movq %rax, %rsi
callq 0x3d332
testb %al, %al
jne 0x56812
movq 0x60(%rsp), %rax
movq (%rax), %rax
leaq (%rax,%r15), %rdi
addq $0x20, %rdi
movq %r13, %rsi
callq 0x29efa
movsd 0x8(%rsp), %xmm0
ucomisd 0x10(%rax), %xmm0
jbe 0x56812
movq 0x60(%rsp), %rax
movq (%rax), %rax
leaq (%rax,%r15), %rdi
addq $0x20, %rdi
movq %r13, %rsi
callq 0x29efa
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x56812
leaq 0x40(%rsp), %rdi
callq 0x57aa2
jmp 0x56812
movabsq $0x7fffffff8, %rax      # imm = 0x7FFFFFFF8
testq %rax, %rbx
je 0x56b0b
movsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x30(%rsp), %xmm0
addsd %xmm0, %xmm0
jmp 0x56b19
movsd 0xa97d5(%rip), %xmm0    # 0x1002e8
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0x30(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x10942
leaq 0x80(%rsp), %rdi
callq 0xb290
leaq 0x68(%rsp), %rdi
callq 0xb758
leaq 0x18(%rsp), %rdi
callq 0xae22
movsd 0x8(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf9481(%rip), %rdi     # 0x14fff0
leaq 0xacf0e(%rip), %rsi     # 0x103a84
callq 0x4480
leaq 0xab9fc(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
callq 0x4290
jmp 0x56bb4
jmp 0x56bb4
jmp 0x56bb4
jmp 0x56ba9
jmp 0x56ba9
jmp 0x56ba9
movq %rax, %rbx
jmp 0x56bce
jmp 0x56ba2
movq %rax, %rbx
jmp 0x56bd8
jmp 0x56bb4
movq %rax, %rbx
jmp 0x56bc1
jmp 0x56bb4
jmp 0x56bb4
jmp 0x56bb4
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x10942
leaq 0x80(%rsp), %rdi
callq 0xb290
leaq 0x68(%rsp), %rdi
callq 0xb758
leaq 0x18(%rsp), %rdi
callq 0xae22
movq %rbx, %rdi
callq 0x4780