// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkaccessibility.cc
// Function: AccessibilityClassNINF::isPointInsideAtomAndNotAccessible(Point, int)
pair <bool,bool> AccessibilityClassNINF::isPointInsideAtomAndNotAccessible(Point samplingPoint, 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 + r_probe - 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 + r_probe - 0.00000001) 
     overlaps = true;
   };

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

 inside = overlaps;

 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 < r_probe );
           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 %esi, %ebx
movq %rdi, %r12
leaq 0x260(%rsp), %r15
movb $0x0, 0x18c(%rdi)
leaq 0x60(%rsp), %rdi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
callq 0x63c46
movq 0x140(%r12), %r14
movq %r15, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
pushq $0x2
popq %rsi
movq %r15, %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 0x6fcc1
movslq 0x2c(%rsp), %rax
movl %eax, 0x168(%r12)
movups (%r15), %xmm0
movups %xmm0, 0x150(%r12)
movq 0x10(%r15), %rcx
movq %rcx, 0x160(%r12)
testl %ebx, %ebx
js 0x6f5a8
cmpb $0x0, 0x10(%r12)
je 0x6f5af
movq %r15, %r14
movq 0x8(%r12), %rcx
movq 0x308(%rcx), %rcx
cmpl %ebx, (%rcx,%rax,4)
jmp 0x6f5b4
movq %r15, %r14
xorl %ebp, %ebp
jmp 0x6f5b8
movq %r15, %r14
cmpl %ebx, %eax
setne %bpl
movq %r12, 0x38(%rsp)
movq 0x8(%r12), %rcx
imulq $0x98, %rax, %rsi
addq 0x2f0(%rcx), %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 %r14, %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
movq 0x38(%rsp), %rcx
addsd 0x138(%rcx), %xmm1
addsd 0x90e7a(%rip), %xmm1    # 0x100590
ucomisd %xmm0, %xmm1
seta %r15b
cmpb $0x0, 0x10(%rcx)
je 0x6f7ea
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movslq 0x2c(%rsp), %rdx
movq 0x308(%rcx), %rcx
movslq (%rcx,%rdx,4), %rcx
imulq $0x98, %rcx, %rsi
addq 0x2f0(%rax), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x245be
movq 0x38(%rsp), %rax
movq (%rax), %rbx
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 %rbx, %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
callq 0x3f5fe
movsd 0x118(%rsp), %xmm1
movq 0x38(%rsp), %rcx
addsd 0x138(%rcx), %xmm1
addsd 0x90db6(%rip), %xmm1    # 0x100590
ucomisd %xmm0, %xmm1
jbe 0x6f7ea
movsd %xmm0, 0x148(%rcx)
jmp 0x6f7fb
orb %bpl, %r15b
movsd %xmm0, 0x148(%rcx)
testb $0x1, %r15b
je 0x6f808
movw $0x100, %bx             # imm = 0x100
movw $0x1, %bp
jmp 0x6fc4f
movb %r15b, 0x1f(%rsp)
movq 0x8(%rcx), %rax
movslq 0x2c(%rsp), %rcx
imulq $0x98, %rcx, %rsi
addq 0x2f0(%rax), %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 %r14, %rsi
callq 0x63c56
movq 0x90(%rsp), %rax
movq %rax, 0x10(%r14)
movupd 0x80(%rsp), %xmm0
movupd %xmm0, (%r14)
movq %r14, %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 0x90(%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, 0x18c(%rax)
leaq 0x80(%rsp), %rdi
callq 0x4f970
testl %eax, %eax
je 0x6fd08
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 0x6fbe6
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 0x6fbdf
movq 0x38(%rsp), %rdx
movq 0x60(%rdx), %rcx
cltq
shlq $0x6, %rax
movsd 0x138(%rdx), %xmm0
ucomisd 0x18(%rcx,%rax), %xmm0
ja 0x6fbdf
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 0x90707(%rip), %xmm0    # 0x1002e0
jbe 0x6fc76
incl %ebp
jmp 0x6fa77
movq 0x38(%rsp), %rbx
incl 0x188(%rbx)
leaq 0x170(%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, 0x18c(%rbx)
movb 0x1f(%rsp), %bpl
movl %ebp, %ebx
leaq 0x80(%rsp), %rdi
callq 0xb3d4
movzbl %bl, %ebx
andl $0x1, %ebx
shll $0x8, %ebx
movzbl %bpl, %ebp
andl $0x1, %ebp
leaq 0xe8(%rsp), %rdi
callq 0xa808
movzwl %bp, %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
leaq 0x80(%rsp), %rdi
movl %ebp, %esi
callq 0x4f99e
movq 0x38(%rsp), %rbx
movl %eax, 0x16c(%rbx)
leaq 0x80(%rsp), %rdi
movl %ebp, %esi
callq 0x4f99e
addq $0xe0, %rbx
movslq %eax, %rsi
movq %rbx, %rdi
callq 0xaba4
testq %rdx, (%rax)
sete %bl
movb 0x1f(%rsp), %bpl
jmp 0x6fc32
movq 0xe0328(%rip), %rdi     # 0x14fff0
leaq 0x95201(%rip), %rsi     # 0x104ed0
callq 0x4480
leaq 0x928a3(%rip), %rbx     # 0x10257e
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
leaq 0x93935(%rip), %rsi     # 0x103622
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
pushq $0x1
popq %rdi
callq 0x524c
movq 0xe02e1(%rip), %rdi     # 0x14fff0
leaq 0x90da4(%rip), %rsi     # 0x100aba
callq 0x4480
leaq 0x9285c(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x90dc6(%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 0x947b4(%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 0x94786(%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 0x927c4(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x90d36(%rip), %rsi     # 0x100aff
movq %rax, %rdi
callq 0x4480
movl 0x2c(%rsp), %esi
movq %rax, %rdi
callq 0x4760
leaq 0x9279a(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x90d2d(%rip), %rsi     # 0x100b20
movq %rax, %rdi
callq 0x4480
leaq 0x9277c(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x93811(%rip), %rsi     # 0x103622
movq %rax, %rdi
callq 0x4480
leaq 0x9275e(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
jmp 0x6fd00
jmp 0x6fe4e
jmp 0x6fe4e
jmp 0x6fe4e
jmp 0x6fe4e
jmp 0x6fe43
jmp 0x6fe4e
jmp 0x6fe4e
jmp 0x6fe43
jmp 0x6fe4e
jmp 0x6fe4e
jmp 0x6fe43
movq %rax, %rbx
jmp 0x6fe5e
jmp 0x6fe4e
jmp 0x6fe4e
jmp 0x6fe4e
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xb3d4
leaq 0xe8(%rsp), %rdi
callq 0xa808
movq %rbx, %rdi
callq 0x4780
nop