// File: /workspace/github_cpp_makefile_star2_O1/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, %r12d
movq %rdi, %r15
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
leaq 0x60(%rdi), %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rsi, 0x90(%rsp)
callq 0x38ec6
movq (%r14), %rbx
movq 0x8(%r14), %r13
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x509d8
subq %rbx, %r13
sarq $0x3, %r13
movabsq $-0x71c71c71c71c71c7, %rbx # imm = 0x8E38E38E38E38E39
imulq %rbx, %r13
leaq 0x50(%rsp), %rdi
leaq 0x28(%rsp), %rdx
leaq 0x78(%rsp), %rcx
movq %r13, %rsi
callq 0x76d3a
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x3, %rsi
imulq %rbx, %rsi
leaq 0x78(%rsp), %rdi
leaq 0x4c(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x38af6
cmpl %ebp, %r12d
je 0x75bbc
movl %ebp, %eax
orl %r12d, %eax
js 0x75bbc
movq 0x10(%r15), %rax
addq $0x8, %r15
movq %r15, %rcx
testq %rax, %rax
je 0x755f5
movq %rax, %rdx
movq %r15, %rcx
xorl %esi, %esi
cmpl %r12d, 0x20(%rdx)
setl %sil
cmovgeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x755dd
movq %r15, %rdx
cmpq %r15, %rcx
je 0x75608
cmpl %r12d, 0x20(%rcx)
cmovgq %r15, %rcx
movq %rcx, %rdx
movl 0x24(%rdx), %r12d
movq %r15, %rcx
testq %rax, %rax
je 0x7562d
movq %r15, %rcx
xorl %edx, %edx
cmpl %ebp, 0x20(%rax)
setl %dl
cmovgeq %rax, %rcx
movq 0x10(%rax,%rdx,8), %rax
testq %rax, %rax
jne 0x75617
cmpq %r15, %rcx
je 0x75639
cmpl %ebp, 0x20(%rcx)
cmovleq %rcx, %r15
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rcx # imm = 0x8E38E38E38E38E39
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x75bec
movl 0x24(%r15), %ecx
movl %ecx, 0x48(%rsp)
leaq (%r12,%r12,8), %rbx
movsd 0x38(%rax,%rbx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x78(%rsp), %rax
movl $0x1, (%rax,%r12,4)
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x509d8
movq 0x50(%rsp), %rax
leaq (%r12,%r12,2), %rcx
leaq 0x28(%rsp), %rdi
movl 0x8(%rdi), %edx
movl %edx, 0x8(%rax,%rcx,4)
movq (%rdi), %rdx
movq %rdx, (%rax,%rcx,4)
movq %r14, 0x1220af(%rip)    # 0x197768
leaq -0x2ce(%rip), %rsi      # 0x753f2
callq 0x76dc0
movq 0x10(%rsp), %rcx
movq 0x20(%rcx,%rbx,8), %rdi
cmpq %rdi, 0x28(%rcx,%rbx,8)
movabsq $-0x71c71c71c71c71c7, %r15 # imm = 0x8E38E38E38E38E39
je 0x7576c
movl $0x1, %ebp
xorl %esi, %esi
leaq 0x28(%rsp), %r14
leaq (%rsi,%rsi,4), %r8
movslq 0x4(%rdi,%r8,8), %rax
movq 0x18(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r15, %rdx
cmpq %rax, %rdx
jbe 0x75b86
leaq (%rdi,%r8,8), %rdx
movsd 0x10(%rdx), %xmm1
leaq (%rax,%rax,8), %rax
movsd 0x38(%rcx,%rax,8), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x75730
movsd %xmm0, 0x10(%rdx)
shlq $0x20, %rsi
orq %r12, %rsi
movq %r14, %rdi
callq 0x76e02
movl %ebp, %esi
movq 0x10(%rsp), %rcx
movq 0x20(%rcx,%rbx,8), %rdi
movq 0x28(%rcx,%rbx,8), %rax
subq %rdi, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rax
incl %ebp
cmpq %rsi, %rax
ja 0x756f0
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x40(%rsp), %rax
leaq 0x70(%rsp), %rdx
movq %rax, (%rdx)
callq 0x69775
movq $0x0, 0x68(%rsp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x30(%rsp), %rax
subq 0x28(%rsp), %rax
shrq $0x3, %rax
testl %eax, %eax
je 0x75a9f
leaq 0x28(%rsp), %rdi
callq 0x76eae
movq %rax, %r12
movl %r12d, %r15d
movslq %r12d, %rax
movq 0x10(%rsp), %rcx
leaq (%rax,%rax,8), %r13
leaq (%rcx,%r13,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
movb $0x1, %bpl
cmpl $0x1, %r9d
je 0x75880
cmpl $-0x1, %r9d
jne 0x75a7e
movq 0x8(%rdx), %rdx
subq %r8, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %r8 # imm = 0xCCCCCCCCCCCCCCCD
imulq %r8, %rdx
cmpq %r12, %rdx
jbe 0x75b9a
movq 0x18(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
imulq %r8, %rdx
cmpq %rbx, %rdx
jbe 0x75b97
movsd 0x10(%rsi), %xmm1
minsd 0x8(%rsp), %xmm1
leaq (%rbx,%rbx,8), %rbp
movsd 0x38(%rcx,%rbp,8), %xmm0
maxsd (%rsp), %xmm0
cmpl 0x48(%rsp), %ebx
jne 0x75926
movb $0x1, %al
movq %rax, 0x68(%rsp)
xorl %ebp, %ebp
jmp 0x75a89
movq 0x8(%rdx), %rdx
subq %r8, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x75b9a
movq %r10, %r15
movq 0x50(%rsp), %r14
leaq (%rax,%rax,2), %rax
leaq (%r14,%rax,4), %rdi
addq $0x18, %rsi
callq 0x50a30
leaq (%rbx,%rbx,2), %rcx
leaq (%r14,%rcx,4), %rdi
movq %rax, %rsi
callq 0x509e2
testb %al, %al
jne 0x75a7e
movq 0x90(%rsp), %rax
movq (%rax), %rcx
movq 0x20(%rcx,%r13,8), %rax
movq 0x28(%rcx,%r13,8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x75b9a
movsd 0x10(%rax,%r15,8), %xmm1
movsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x75a84
movapd %xmm0, %xmm1
jmp 0x75a84
movsd %xmm0, (%rsp)
movsd %xmm1, 0x8(%rsp)
movl $0x1, (%rdi,%rbx,4)
movq 0x50(%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 0x10(%rsp), %rcx
movq 0x20(%rcx,%r13,8), %rax
movq 0x28(%rcx,%r13,8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x75bab
leaq (,%r14,4), %rdi
addq 0x50(%rsp), %rdi
leaq (%rax,%r10,8), %rsi
addq $0x18, %rsi
callq 0x50a30
movq 0x50(%rsp), %rcx
movq %rax, (%rcx,%r14,4)
movl %edx, 0x8(%rcx,%r14,4)
movq 0x10(%rsp), %rcx
movq 0x20(%rcx,%rbp,8), %rdi
cmpq %rdi, 0x28(%rcx,%rbp,8)
je 0x75a5d
movl %ebx, %ebx
movl $0x1, %r14d
xorl %esi, %esi
leaq (%rsi,%rsi,4), %r8
movslq 0x4(%rdi,%r8,8), %rax
movq 0x18(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %r9 # imm = 0x8E38E38E38E38E39
imulq %r9, %rdx
cmpq %rax, %rdx
jbe 0x75b75
leaq (%rdi,%r8,8), %rdx
movsd 0x10(%rdx), %xmm1
leaq (%rax,%rax,8), %rdi
movsd 0x38(%rcx,%rdi,8), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x75a14
movsd %xmm0, 0x10(%rdx)
cmpl %r15d, %eax
je 0x75a2a
shlq $0x20, %rsi
orq %rbx, %rsi
leaq 0x28(%rsp), %rdi
callq 0x76e02
movl %r14d, %esi
movq 0x10(%rsp), %rcx
movq 0x20(%rcx,%rbp,8), %rdi
movq 0x28(%rcx,%rbp,8), %rax
subq %rdi, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rax
incl %r14d
cmpq %rsi, %rax
ja 0x759ca
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x40(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x70(%rsp), %rdx
callq 0x69775
movb $0x1, %bpl
movsd 0x8(%rsp), %xmm1
movsd (%rsp), %xmm0
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, (%rsp)
testb %bpl, %bpl
jne 0x7579c
jmp 0x75aaa
movsd 0x8(%rsp), %xmm1
movsd (%rsp), %xmm0
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, (%rsp)
je 0x75ad7
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x75afc
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x75b1e
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movsd 0xdd7aa(%rip), %xmm3    # 0x1532d0
movapd %xmm3, %xmm2
testb $0x1, 0x68(%rsp)
je 0x75b39
addsd %xmm0, %xmm0
movapd %xmm0, %xmm2
movsd %xmm2, 0x8(%rsp)
je 0x75b49
addsd %xmm1, %xmm1
movapd %xmm1, %xmm3
movsd %xmm3, (%rsp)
leaq 0x10(%rsp), %rdi
callq 0xf07c
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd9b29(%rip), %rdi     # 0x14f6a5
movq %rax, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xd9b18(%rip), %rdi     # 0x14f6a5
movq %rax, %rsi
xorl %eax, %eax
callq 0x4630
movq %rbx, %r12
leaq 0xd9b04(%rip), %rdi     # 0x14f6a5
movq %r12, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xd9af3(%rip), %rdi     # 0x14f6a5
movq %r12, %rsi
xorl %eax, %eax
callq 0x4630
movq 0x12142d(%rip), %rdi    # 0x196ff0
leaq 0xe0e4a(%rip), %rsi     # 0x156a14
movl $0x3a, %edx
callq 0x44e0
movq 0x121415(%rip), %rdi    # 0x196ff0
leaq 0xdf94c(%rip), %rsi     # 0x15552e
callq 0x4440
callq 0x4260
leaq 0xd9ab2(%rip), %rdi     # 0x14f6a5
movq %r12, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x75c22
jmp 0x75c0d
movq %rax, %rbx
jmp 0x75c56
jmp 0x75c08
movq %rax, %rbx
jmp 0x75c6d
movq %rax, %rbx
jmp 0x75c3c
jmp 0x75c22
jmp 0x75c22
jmp 0x75c22
jmp 0x75c22
jmp 0x75c22
jmp 0x75c22
jmp 0x75c22
jmp 0x75c22
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x75c3c
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x75c56
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x75c6d
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x10(%rsp), %rdi
callq 0xf07c
movq %rbx, %rdi
callq 0x4780
nop