// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkaccessibility.cc
// Function: AccessibilityClass::isPointInsideAtomAndNotAccessible(Point, double&, int)
pair <bool,bool> AccessibilityClass::isPointInsideAtomAndNotAccessible(Point samplingPoint, double& mindist_domod, int atomID){

 bool inside = false, overlaps = false; // flags to state if a point is inside atom, inaccessible

 needToResampleFlag = false; // since new point is tested, we clear this variable

 Point smplPoint; // temporary sampling point

 double newAtomX, newAtomY, newAtomZ;
 int minAtomID;
 bool foundCell = new_rad_con->find_voronoi_cell(samplingPoint[0], samplingPoint[1], samplingPoint[2], newAtomX, newAtomY, newAtomZ, minAtomID);
 if(!foundCell){
     cerr << "Error: Unable to find Voronoi cell for sampled point." << "\n"
          << "Exiting..." << "\n";
     exit(1);
    };

 tempMinDistAtomID = minAtomID; // store this information so it is not needed to be recomputed
 tempPoint = samplingPoint;

 // The routine first checks if the provided point is inside atoms


 // if in SA routine, check if the sampled point is within other atom
 if(atomID >= 0){
  if(highAccuracyFlag == false)
    {
    // old check from Thomas code (pre-high accuracy)
 
    // If point in Voronoi cell of different atom, probe-atom overlap occurs because of d^2-r^2 criterion.
    if(minAtomID != atomID)
      overlaps = true;

    }else{
    // new check if high accuracy is requested
    if(analyzedAtomNet.IDmapping[minAtomID] != atomID)
      overlaps = true;
    };
  }; // finishing check for SA


 ATOM curAtom = analyzedAtomNet.atoms[minAtomID];

 // Adjust sampling point so that it lies within the Voronoi cell of interest constructed previously
 smplPoint = (samplingPoint.add(Point(curAtom.x, curAtom.y, curAtom.z).subtract(Point(newAtomX, newAtomY, newAtomZ))));


 double minDist = calcEuclideanDistance(smplPoint[0], smplPoint[1], smplPoint[2], curAtom.x, curAtom.y, curAtom.z);
 if(minDist < curAtom.radius - 0.00000001) 
   overlaps = true;


 if(highAccuracyFlag)  // additional check for high accuracy calculations to check if a point is within the original atom
   {
   curAtom = orgAtomNet.atoms[analyzedAtomNet.IDmapping[minAtomID]];
   minDist = orgAtomNet.calcDistance(smplPoint[0], smplPoint[1], smplPoint[2], &curAtom);
   if(minDist < curAtom.radius - 0.00000001) 
     overlaps = true;
   };

 tempMinDist = minDist; // store temporary (to be used in AV within range function

 inside = overlaps;

 mindist_domod = minDist-curAtom.radius; // DO mod distance for probe-occupiable space

 if(inside == true) return pair<bool,bool> (inside,overlaps); // if the point is inside an atom
                                                              // terminate and return the answer



 // If the point is outside of atoms
 // The routine then checks if the point is in accessible or inaccessible volume/surface 

 curAtom = analyzedAtomNet.atoms[minAtomID];  // making sure we look at the correct atom net (hiAcc or regular)

 // Adjust sampling point so that it lies within the Voronoi cell of interest constructed previously
 samplingPoint = (samplingPoint.add(Point(curAtom.x, curAtom.y, curAtom.z).subtract(Point(newAtomX, newAtomY, newAtomZ))));

 minDist = calcEuclideanDistance(samplingPoint[0], samplingPoint[1], samplingPoint[2], curAtom.x, curAtom.y, curAtom.z);

 // If necessary, check Voronoi nodes of cell to determine accessibility of point
 if(!overlaps){
   BASIC_VCELL vcell = vorcells[minAtomID];
   Point circCenter = Point(curAtom.x, curAtom.y, curAtom.z);
   double samplingRadius = minDist;
   Point sampleRay = Point(samplingPoint[0]-curAtom.x, samplingPoint[1]-curAtom.y, samplingPoint[2]-curAtom.z);

   // Scan the nodes in the Voronoi cell to find if line can be drawn from the node to the sampling point
   bool foundNode = false;
   needToResampleFlag = false;
   if(vcell.getNumNodes() == 0){
     cerr << "Error: Voronoi cell of sampled point does not have any nodes" << "\n"
          << "Point: " << samplingPoint[0] << " " << samplingPoint[1] << " " << samplingPoint[2] << "\n"
          << "Voronoi cell is #" << minAtomID << "\n"
          << "Please contact the source code provider." << "\n"
          << "Exiting..." << "\n";
     exit(1);
   }
   for(int k = 0; k < vcell.getNumNodes(); k++){
           Point nodePoint = vcell.getNodeCoord(k);
           bool nodeInsideSphere = (calcEuclideanDistance(nodePoint[0], nodePoint[1], nodePoint[2], circCenter[0], circCenter[1], circCenter[2]) < samplingRadius);
           bool nodeInsideOtherAtom = (vornet.nodes[vcell.getNodeID(k)].rad_stat_sphere < 0.0 );
           if(!nodeInsideSphere&&!nodeInsideOtherAtom){
             Point otherRay = samplingPoint.subtract(nodePoint);
             double dotProduct = sampleRay.dot_product(otherRay);
             if(dotProduct > 0) {
               // Angle is less than 90 degrees and so the line segment intersects twice,
               // making the path not viable
             }
             else {
               // Angle is at least 90 degrees and so the line segment interesects only once, 
               // thereby representing a viable path
               foundNode = true;
               tempNodeID = vcell.getNodeID(k);
               overlaps = !accessInfo.at(vcell.getNodeID(k));
               break;
             }
           }
    }

    // Sampling failed due to lying on Voronoi cell face and numerical inaccurarcy. 
    // Record failure, resample and notify user later
    if(!foundNode){
       resampleCount++;
       resampledInfo.push_back(pair<int, Point> (minAtomID, samplingPoint));
       needToResampleFlag = true;
       };

 };

return pair<bool,bool> (inside,overlaps);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r13
leaq 0x260(%rsp), %r12
movb $0x0, 0xa3c(%rdi)
leaq 0x60(%rsp), %rdi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
callq 0x63c46
movq 0x9f0(%r13), %r14
movq %r12, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
pushq $0x2
popq %rsi
movq %r12, %rdi
callq 0x63c78
movsd (%rax), %xmm2
leaq 0x58(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0x48(%rsp), %rcx
leaq 0x2c(%rsp), %r8
movq %r14, %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
callq 0xf9584
testb %al, %al
je 0x6ef5f
movslq 0x2c(%rsp), %rax
movl %eax, 0xa18(%r13)
movups (%r12), %xmm0
movups %xmm0, 0xa00(%r13)
movq 0x10(%r12), %rcx
movq %rcx, 0xa10(%r13)
testl %ebx, %ebx
js 0x6e87d
cmpb $0x0, 0x8c0(%r13)
je 0x6e881
movq 0x768(%r13), %rcx
cmpl %ebx, (%rcx,%rax,4)
jmp 0x6e883
xorl %ebp, %ebp
jmp 0x6e887
cmpl %ebx, %eax
setne %bpl
imulq $0x98, %rax, %rsi
movq %r13, 0x38(%rsp)
addq 0x750(%r13), %rsi
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
callq 0xa75c
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm1
movsd 0x10(%rbx), %xmm2
leaq 0xc8(%rsp), %rdi
callq 0x63c46
movsd 0x58(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
leaq 0x1c8(%rsp), %rdi
callq 0x63c46
movq 0x1d8(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x1c8(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x1e0(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x63d26
movq 0x1f0(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x1e0(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x80(%rsp), %rdi
movq %r12, %rsi
callq 0x63c56
movq 0x90(%rsp), %rax
leaq 0x60(%rsp), %rdi
movq %rax, 0x10(%rdi)
movupd 0x80(%rsp), %xmm0
movapd %xmm0, (%rdi)
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x60(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x60(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm2
movsd 0xe8(%rsp), %xmm3
movsd 0xf0(%rsp), %xmm4
movsd 0xf8(%rsp), %xmm5
movsd 0x20(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
callq 0x64934
movsd 0x118(%rsp), %xmm1
movsd 0x91bbd(%rip), %xmm2    # 0x100590
addsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
seta %al
orb %bpl, %al
movq 0x38(%rsp), %rdx
cmpb $0x0, 0x8c0(%rdx)
je 0x6ea9d
movl %eax, %ebx
movslq 0x2c(%rsp), %rax
movq 0x768(%rdx), %rcx
movslq (%rcx,%rax,4), %rax
imulq $0x98, %rax, %rsi
addq 0x2f0(%rdx), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x245be
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x60(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x60(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm2
leaq 0xe8(%rsp), %rsi
movq 0x38(%rsp), %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
callq 0x3f5fe
movsd 0x118(%rsp), %xmm1
movsd 0x91b03(%rip), %xmm2    # 0x100590
addsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x6ea9b
movb $0x1, %al
jmp 0x6ea9d
movl %ebx, %eax
movq 0x38(%rsp), %rcx
movsd %xmm0, 0x9f8(%rcx)
subsd %xmm1, %xmm0
movsd %xmm0, (%r15)
movw $0x100, %bx             # imm = 0x100
movb %al, 0x1f(%rsp)
testb $0x1, %al
jne 0x6ef33
movslq 0x2c(%rsp), %rax
imulq $0x98, %rax, %rsi
addq 0x750(%rcx), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x245be
movsd 0xe8(%rsp), %xmm0
movsd 0xf0(%rsp), %xmm1
movsd 0xf8(%rsp), %xmm2
leaq 0xc8(%rsp), %rdi
callq 0x63c46
movsd 0x58(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
leaq 0x198(%rsp), %rdi
callq 0x63c46
movq 0x1a8(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x198(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x1b0(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x63d26
movq 0x1c0(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x1b0(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x80(%rsp), %rdi
movq %r12, %rsi
callq 0x63c56
movq 0x90(%rsp), %rax
movq %rax, 0x10(%r12)
movupd 0x80(%rsp), %xmm0
movupd %xmm0, (%r12)
movq %r12, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
pushq $0x1
popq %rsi
leaq 0x260(%rsp), %rdi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
pushq $0x2
popq %rsi
leaq 0x260(%rsp), %rdi
callq 0x63c78
movsd (%rax), %xmm2
movsd 0xe8(%rsp), %xmm3
movsd 0xf0(%rsp), %xmm4
movsd 0xf8(%rsp), %xmm5
movsd 0x20(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
callq 0x64934
movsd %xmm0, 0xb0(%rsp)
movslq 0x2c(%rsp), %rax
imulq $0x30, %rax, %rsi
movq 0x38(%rsp), %rax
addq 0x940(%rax), %rsi
leaq 0x80(%rsp), %rdi
callq 0xbf58
movsd 0xe8(%rsp), %xmm0
movsd 0xf0(%rsp), %xmm1
movsd 0xf8(%rsp), %xmm2
leaq 0x210(%rsp), %rdi
callq 0x63c46
leaq 0x260(%rsp), %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
subsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
pushq $0x1
popq %rsi
leaq 0x260(%rsp), %rdi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
pushq $0x2
popq %rsi
leaq 0x260(%rsp), %rdi
callq 0x63c78
movsd 0x30(%rsp), %xmm1
subsd 0x40(%rsp), %xmm1
movsd (%rax), %xmm2
subsd 0xf8(%rsp), %xmm2
leaq 0x1f8(%rsp), %rdi
movsd 0x20(%rsp), %xmm0
callq 0x63c46
movq 0x38(%rsp), %rax
movb $0x0, 0xa3c(%rax)
leaq 0x80(%rsp), %rdi
callq 0x4f970
testl %eax, %eax
je 0x6efa6
xorl %ebp, %ebp
leaq 0x80(%rsp), %r15
leaq 0xc8(%rsp), %r12
pushq $0x1
popq %r13
pushq $0x2
popq %rbx
leaq 0x210(%rsp), %r14
movq %r15, %rdi
callq 0x4f970
cmpl %eax, %ebp
jge 0x6ee91
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x4f980
movq %r12, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r12, %rdi
movl %r13d, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r12, %rdi
movl %ebx, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0xc0(%rsp)
movq %r14, %rdi
movl %r13d, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0xb8(%rsp)
movq %r14, %rdi
movl %ebx, %esi
callq 0x63c78
movsd (%rax), %xmm5
movsd 0x20(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movsd 0xc0(%rsp), %xmm3
movsd 0xb8(%rsp), %xmm4
callq 0x64934
movsd %xmm0, 0x20(%rsp)
movq %r15, %rdi
movl %ebp, %esi
callq 0x4f99e
movsd 0xb0(%rsp), %xmm0
ucomisd 0x20(%rsp), %xmm0
ja 0x6ee8a
cltq
shlq $0x6, %rax
movq 0x38(%rsp), %rcx
movq 0x910(%rcx), %rcx
xorpd %xmm0, %xmm0
ucomisd 0x18(%rcx,%rax), %xmm0
ja 0x6ee8a
movq 0xd8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xc8(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x180(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0x63d26
movq 0x190(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x180(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x63d92
ucomisd 0x91458(%rip), %xmm0    # 0x1002e0
jbe 0x6eedc
incl %ebp
jmp 0x6ed2b
movq 0x38(%rsp), %rbx
incl 0xa38(%rbx)
leaq 0xa20(%rbx), %rdi
movl 0x2c(%rsp), %eax
leaq 0xc8(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x260(%rsp), %rax
movupd (%rax), %xmm0
movupd %xmm0, 0x8(%rsi)
movq 0x10(%rax), %rax
movq %rax, 0x18(%rsi)
callq 0x37456
movb $0x1, 0xa3c(%rbx)
movb 0x1f(%rsp), %bl
jmp 0x6ef1d
leaq 0x80(%rsp), %rdi
movl %ebp, %esi
callq 0x4f99e
movq 0x38(%rsp), %rbx
movl %eax, 0xa1c(%rbx)
leaq 0x80(%rsp), %rdi
movl %ebp, %esi
callq 0x4f99e
addq $0x990, %rbx            # imm = 0x990
movslq %eax, %rsi
movq %rbx, %rdi
callq 0xaba4
testq %rdx, (%rax)
sete %bl
leaq 0x80(%rsp), %rdi
callq 0xb3d4
movzbl %bl, %ebx
andl $0x1, %ebx
shll $0x8, %ebx
leaq 0xe8(%rsp), %rdi
callq 0xa808
movzbl 0x1f(%rsp), %ecx
andl $0x1, %ecx
movzwl %bx, %eax
orl %ecx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xe108a(%rip), %rdi     # 0x14fff0
leaq 0x95f63(%rip), %rsi     # 0x104ed0
callq 0x4480
leaq 0x93605(%rip), %rbx     # 0x10257e
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
leaq 0x94697(%rip), %rsi     # 0x103622
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
pushq $0x1
popq %rdi
callq 0x524c
movq 0xe1043(%rip), %rdi     # 0x14fff0
leaq 0x91b06(%rip), %rsi     # 0x100aba
callq 0x4480
leaq 0x935be(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x91b28(%rip), %rsi     # 0x100af7
movq %rax, %rdi
callq 0x4480
movq %rax, %rbx
leaq 0x260(%rsp), %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46c0
leaq 0x95516(%rip), %rsi     # 0x104512
movq %rax, %rdi
callq 0x4480
movq %rax, %rbx
pushq $0x1
popq %rsi
leaq 0x260(%rsp), %rdi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46c0
leaq 0x954e8(%rip), %rsi     # 0x104512
movq %rax, %rdi
callq 0x4480
movq %rax, %rbx
pushq $0x2
popq %rsi
leaq 0x260(%rsp), %rdi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46c0
leaq 0x93526(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x91a98(%rip), %rsi     # 0x100aff
movq %rax, %rdi
callq 0x4480
movl 0x2c(%rsp), %esi
movq %rax, %rdi
callq 0x4760
leaq 0x934fc(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x91a8f(%rip), %rsi     # 0x100b20
movq %rax, %rdi
callq 0x4480
leaq 0x934de(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x94573(%rip), %rsi     # 0x103622
movq %rax, %rdi
callq 0x4480
leaq 0x934c0(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
jmp 0x6ef9e
jmp 0x6f0ec
jmp 0x6f0ec
jmp 0x6f0ec
jmp 0x6f0ec
jmp 0x6f0e1
jmp 0x6f0ec
jmp 0x6f0ec
jmp 0x6f0e1
jmp 0x6f0e1
jmp 0x6f0ec
jmp 0x6f0ec
movq %rax, %rbx
jmp 0x6f0fc
jmp 0x6f0ec
jmp 0x6f0ec
jmp 0x6f0ec
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xb3d4
leaq 0xe8(%rsp), %rdi
callq 0xa808
movq %rbx, %rdi
callq 0x4780
nop