// File: /workspace/github_cpp_makefile_star2_O1/Luthaf[P]zeopp/psd.cc
// Function: NEWcalcPoreSizeDistr(MATERIAL*, std::ostream&)
void NEWcalcPoreSizeDistr(MATERIAL *Mat, ostream &output){

/* PSD debug section (old code that is not used */
  bool PSDDEBUG = false; // this flag enables execution of old parts of PSD output
                         // that can be used for debuging  

  string pointsFile, nodeAndRadiiFile;
  if(PSDDEBUG == true) { pointsFile = "DEBUG_PSDpointsfile"; nodeAndRadiiFile = "DEBUG_PSDnodeAndRadiiFile"; };
  ofstream outfile;
  if (!pointsFile.empty()) outfile.open(pointsFile.data());
  ofstream nodeAndRadii;
  if (!nodeAndRadiiFile.empty()) nodeAndRadii.open(nodeAndRadiiFile.data());

//The following data structures are used to PSDDEBUG

//List of sample points and radius of sphere that contains sample point for visualization in Visit
  vector <pair <Point, double> > axsPoint_and_radiiOfNodeSphere;
  vector <pair <Point, double> > axsPoint_and_radiiOfGhostSphere;
//List of node coordinates and radii for visualization
  vector <int> nodeIDs;
  vector <pair <Point, double> > coord_and_radiiOfNodeSphere;
  vector <pair <Point, double> > coord_and_radiiOfGhostSphere;
	vector <double> distanceBetweenNodeSpheres;
	vector <double> distanceBetweenGhostSpheres;

/* end PSD debug */


/* PSD codes assumes that AV run was executed and AV data structures in MATERIALS class are filled with data */

  int count = Mat->AVcount; // number of AV samples that turned accessible
  int incount = 0; // count number of points inside Voronoi nodes
  int outcount = 0; 

  cout << "PSD calculation for " << count << " points(" << Mat->AVaxsPoints.size() << ").\n"; 

  double pointParticleRadius; // used to be set to = Mat->AVprobeRadius; 

           // After vivid discussions with Rich, we concluded that the ghost particle radius
           // should be set to the smallest radius in the system
           // this gives the correct voronoi network, but the distance from the vericies of the ghost cell to the particle are not correct
           // representation of the pore diamter
  for(int i=0; i<Mat->accessAnalysis.analyzedAtomNet->atoms.size(); i++)
     {
     if(i == 0) pointParticleRadius = Mat->accessAnalysis.analyzedAtomNet->atoms.at(i).radius;
     else
     if(Mat->accessAnalysis.analyzedAtomNet->atoms.at(i).radius < pointParticleRadius) pointParticleRadius = Mat->accessAnalysis.analyzedAtomNet->atoms.at(i).radius;
     };
  cout << "Radius of ghost cell particle = " << pointParticleRadius << "\n";




//Below are functions that go beyond accessible volume calcluation. Each accessible point is analyzed to find the largest encapsulating sphere

//Determine whether sample point is inside/outside node sphere
  for (int a=0; a<Mat->AVaxsPoints.size(); a++){
    Point samplePt = Mat->accessAnalysis.analyzedAtomNet->abc_to_xyz(Mat->AVaxsPoints.at(a));
    Point maxNodeCoord = Point (0, 0, 0);
    double maxRadius = 0;
    for (int b=0; b<Mat->accessAnalysis.vornet.nodes.size(); b++)
      {
      bool access = Mat->accessAnalysis.accessInfo.at(b);
      if (access){
        Point nodePt = Point(Mat->accessAnalysis.vornet.nodes.at(b).x, Mat->accessAnalysis.vornet.nodes.at(b).y, Mat->accessAnalysis.vornet.nodes.at(b).z);
        double radius = Mat->accessAnalysis.vornet.nodes.at(b).rad_stat_sphere;
         //double radius = Mat->accessAnalysis.vornet.nodes.at(b).rad_stat_sphere + Mat->AVprobeRadius;
                        // commented out in non-inflated version
        double sampToNode = Mat->accessAnalysis.analyzedAtomNet->calcDistanceXYZ(samplePt[0], samplePt[1], samplePt[2], nodePt[0], nodePt[1], nodePt[2]);
        bool inSphere = (sampToNode <= radius); 
        //if point is inside more than one sphere, chooses largest sphere (i.e. largest radius)
        if (inSphere){
          maxRadius = max(radius, maxRadius);
          //If query zpsd, this stores the largest node sphere and its coordinate for visualization in Visit (only for PSD DEBUG)
          if (radius==maxRadius){
             maxNodeCoord = nodePt; 
             }
        } // ends if(inSphere)
      }
     }
    if (maxRadius==0) outcount++; 
    if (maxRadius!=0) incount++;



//Generate new "ghost" Voronoi cell

    // ghost cell particle radius (pointParticleRadius) is now set to the radius of the 
    // smallest atom (before the main PSD loop)

    voronoicell v(*(Mat->accessAnalysis.new_rad_con));
    Mat->accessAnalysis.new_rad_con->compute_ghost_cell(v, samplePt[0], samplePt[1], samplePt[2], pointParticleRadius);
    vector<double> vertexCoords;
    v.vertices(vertexCoords);

    vector <Point> pointVertexCoords;
    for (int a=0; a<vertexCoords.size(); a= a+3){
      Point vertexPoint = Point(vertexCoords.at(a), vertexCoords.at(a+1), vertexCoords.at(a+2));
      pointVertexCoords.push_back(vertexPoint);
    }

    double maxDistFromCtoV = 0;
    Point maxGhostCoord = Point (0, 0, 0);
//Calculate distance from center of cell to vertices
   for (int b=0; b<pointVertexCoords.size(); b++){
      Point vertexGlobalCoord = Point((samplePt[0]+pointVertexCoords.at(b)[0]), (samplePt[1]+pointVertexCoords.at(b)[1]), (samplePt[2]+pointVertexCoords.at(b)[2]));
      double calcDistFromCtoV = calcEuclideanDistance(pointVertexCoords.at(b)[0], pointVertexCoords.at(b)[1], pointVertexCoords.at(b)[2], 0.0, 0.0, 0.0) - pointParticleRadius;
      maxDistFromCtoV = max(maxDistFromCtoV, calcDistFromCtoV);
//If query zpsd, this stores the largest ghost sphere and its coordinate for visualization in Visit (only for PSDDEBUG)
      if (calcDistFromCtoV==maxDistFromCtoV){
         maxGhostCoord = vertexGlobalCoord;
         }
    }

//Compares node radius to biggest ghost radius and stores the larger of the two values accordingly
    double origNodeRadius = maxRadius;
    double ghostRadius = maxDistFromCtoV;  
    bool compareRadii = (origNodeRadius >= ghostRadius); 
    if (compareRadii) {
      Mat->AVaxsPointsPSD.push_back(2.0*origNodeRadius); 
      if (PSDDEBUG){
      axsPoint_and_radiiOfNodeSphere.push_back(pair<Point, double>(samplePt, origNodeRadius));
      checkDuplicates((Mat->accessAnalysis.analyzedAtomNet), &(Mat->accessAnalysis.vornet), nodeIDs, coord_and_radiiOfNodeSphere, maxNodeCoord, origNodeRadius);
      }
    }
    if (!compareRadii) {
      Mat->AVaxsPointsPSD.push_back(2.0*ghostRadius);
      if (PSDDEBUG){
        axsPoint_and_radiiOfGhostSphere.push_back(pair<Point, double>(samplePt, ghostRadius));
        coord_and_radiiOfGhostSphere.push_back(pair <Point, double> (maxGhostCoord, maxDistFromCtoV));
      }
    }
  }

  double volumeFraction = count*1.0/Mat->AVnumSamples;
  double nodeVolFraction = incount*1.0/Mat->AVnumSamples;
  double outFraction = outcount*1.0/Mat->AVnumSamples;


  Histogram(output, BINSTEP, MAXBINS, (Mat->AVaxsPointsPSD), count, nodeVolFraction, outFraction, Mat->AVnumSamples);

  printf("Pore size distribution calculated.\n\n");

  if (PSDDEBUG) {
    printFileCoords_Radii(outfile, axsPoint_and_radiiOfNodeSphere, axsPoint_and_radiiOfGhostSphere, distanceBetweenNodeSpheres, distanceBetweenGhostSpheres, false, -1, -1);
    printf("Points file generated.\n\n");
    printFileCoords_Radii(nodeAndRadii, coord_and_radiiOfNodeSphere, coord_and_radiiOfGhostSphere, distanceBetweenNodeSpheres, distanceBetweenGhostSpheres, false, -1, -1);
    printf("Radii file generated.\n");
    }


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x658, %rsp            # imm = 0x658
movq %rsi, %r15
movq %rdi, %r14
leaq 0x108(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xe8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x458(%rsp), %r12
movq %r12, %rdi
callq 0x4720
cmpq $0x0, 0x100(%rsp)
je 0x8cf7d
movq 0xf8(%rsp), %rsi
leaq 0x458(%rsp), %rdi
movl $0x10, %edx
callq 0x4070
leaq 0x258(%rsp), %rbp
movq %rbp, %rdi
callq 0x4720
cmpq $0x0, 0xe0(%rsp)
je 0x8cfb2
movq 0xd8(%rsp), %rsi
leaq 0x258(%rsp), %rdi
movl $0x10, %edx
callq 0x4070
movl 0xc7c(%r14), %eax
movl %eax, 0x60(%rsp)
movq 0x109ffc(%rip), %rdi    # 0x196fc0
leaq 0xca985(%rip), %rsi     # 0x157950
movl $0x14, %edx
callq 0x44e0
movq 0x109fe4(%rip), %rdi    # 0x196fc0
movl 0x60(%rsp), %esi
callq 0x4750
movq %rax, %rbx
leaq 0xca976(%rip), %rsi     # 0x157965
movl $0x8, %edx
movq %rax, %rdi
callq 0x44e0
movq 0xc98(%r14), %rsi
subq 0xc90(%r14), %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r13, %rsi
movq %rbx, %rdi
callq 0x42b0
leaq 0xd2a99(%rip), %rsi     # 0x15fac4
movl $0x3, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x998(%r14), %rcx
movq 0x2f0(%rcx), %rax
movq 0x2f8(%rcx), %rdx
subq %rax, %rdx
je 0x8d09d
sarq $0x3, %rdx
movabsq $-0x79435e50d79435e5, %rcx # imm = 0x86BCA1AF286BCA1B
imulq %rdx, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
addq $0x30, %rax
xorl %edx, %edx
movsd (%rax), %xmm0
testq %rdx, %rdx
je 0x8d087
movsd 0x50(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8d08d
movsd %xmm0, 0x50(%rsp)
incq %rdx
addq $0x98, %rax
cmpq %rdx, %rcx
jne 0x8d072
jmp 0x8d09d
movq 0x109f1c(%rip), %rdi    # 0x196fc0
leaq 0xca8c3(%rip), %rsi     # 0x15796e
movl $0x20, %edx
callq 0x44e0
movq 0x109f04(%rip), %rdi    # 0x196fc0
movsd 0x50(%rsp), %xmm0
callq 0x46b0
leaq 0xc8460(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movq 0xc90(%r14), %rax
cmpq %rax, 0xc98(%r14)
je 0x8d9a0
movq %r15, 0x118(%rsp)
leaq 0xa70(%r14), %rcx
movq %rcx, 0x128(%rsp)
leaq 0xd20(%r14), %rcx
movq %rcx, 0xd0(%rsp)
xorl %edx, %edx
leaq 0x240(%rsp), %rbp
xorl %r12d, %r12d
movl $0x0, 0x64(%rsp)
movq 0x998(%r14), %rsi
movq %rdx, 0x120(%rsp)
leaq (%rdx,%rdx,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x10(%rsp)
movupd (%rax,%rcx,8), %xmm0
movupd %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x52144
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0x140(%rsp), %rdi
callq 0x85436
movl %r12d, 0x94(%rsp)
movq 0x9f8(%r14), %rax
cmpq 0x9f0(%r14), %rax
je 0x8d357
xorpd %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x128(%rsp), %rdi
movq %r15, %rsi
callq 0xedb6
testq %rdx, (%rax)
je 0x8d333
movq 0x9f0(%r14), %rax
movq 0x9f8(%r14), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r15, %rdx
jbe 0x8daf2
movsd (%rax,%r12), %xmm0
movsd 0x8(%rax,%r12), %xmm1
movsd 0x10(%rax,%r12), %xmm2
leaq 0x158(%rsp), %rdi
callq 0x85436
movq 0x9f0(%r14), %rax
movq 0x9f8(%r14), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r15, %rdx
jbe 0x8dae1
movsd 0x18(%rax,%r12), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x998(%r14), %rbx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rbp, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%rsp)
movq %rbp, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x88(%rsp)
leaq 0x158(%rsp), %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x138(%rsp)
leaq 0x158(%rsp), %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x130(%rsp)
leaq 0x158(%rsp), %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm5
movq %rbx, %rdi
movsd 0x28(%rsp), %xmm0
movsd 0x68(%rsp), %xmm1
movsd 0x88(%rsp), %xmm2
movsd 0x138(%rsp), %xmm3
movsd 0x130(%rsp), %xmm4
callq 0x5394a
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x8d333
movsd 0x58(%rsp), %xmm0
maxsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
ucomisd %xmm0, %xmm1
jne 0x8d333
jp 0x8d333
movq 0x168(%rsp), %rax
movq %rax, 0x150(%rsp)
movupd 0x158(%rsp), %xmm0
movapd %xmm0, 0x140(%rsp)
movq 0x9f8(%r14), %rax
subq 0x9f0(%r14), %rax
incq %r15
sarq $0x6, %rax
addq $0x40, %r12
cmpq %r15, %rax
ja 0x8d19e
jmp 0x8d361
xorpd %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0xad0(%r14), %rax
movsd 0x178(%rax), %xmm0
leaq 0x158(%rsp), %rdi
callq 0x122cd0
leaq 0x10993c(%rip), %rax    # 0x196cc0
movq %rax, 0x158(%rsp)
movq 0xad0(%r14), %r15
movq %rbp, %rdi
xorl %esi, %esi
callq 0x85478
movl 0x94(%rsp), %r12d
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbp, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rbp, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd 0x20(%rsp), %xmm1
movsd %xmm1, 0x70(%rsp)
movsd 0x28(%rsp), %xmm1
movsd %xmm1, 0x30(%rsp)
movsd %xmm0, 0xb0(%rsp)
movq %r15, %rdi
leaq 0x98(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0xb0(%rsp), %r8
callq 0x14a16c
movslq 0x98(%rsp), %rcx
movq 0x1a8(%r15), %rdx
movq 0x1b0(%r15), %rax
movq (%rdx,%rcx,8), %rdx
movslq (%rax,%rcx,4), %rsi
leal 0x1(%rsi), %edi
movl %edi, (%rax,%rcx,4)
shlq $0x5, %rsi
movsd 0x1d8(%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x70(%rsp), %xmm0
movsd %xmm0, (%rdx,%rsi)
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x8(%rdx,%rsi)
movsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0x10(%rdx,%rsi)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x18(%rdx,%rsi)
ucomisd 0x1d8(%r15), %xmm0
jbe 0x8d49d
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x1d8(%r15)
movslq 0x98(%rsp), %r8
movl (%rax,%r8,4), %ecx
movl 0x128(%r15), %edi
movl 0x190(%r15), %esi
imull %edi, %esi
movl %r8d, %eax
cltd
idivl %esi
movl %eax, %esi
movl %edx, %eax
cltd
idivl %edi
movl %edx, %r9d
decl %ecx
leaq 0x1f8(%r15), %rdi
movl %esi, (%rsp)
leaq 0x158(%rsp), %rsi
movl %r8d, %edx
movl %r9d, %r8d
movl %eax, %r9d
callq 0x142f28
movq 0x1b0(%r15), %rax
movslq 0x98(%rsp), %rcx
decl (%rax,%rcx,4)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x1d8(%r15)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x1266f8
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rdx
subq %rax, %rdx
leaq 0x30(%rsp), %r15
je 0x8d5ff
sarq $0x3, %rdx
movl $0x1, %ebx
cmpq %rbx, %rdx
jbe 0x8dad0
leaq 0x1(%rbx), %rsi
cmpq %rsi, %rdx
jbe 0x8dad3
movsd -0x8(%rax,%rbx,8), %xmm0
movsd (%rax,%rbx,8), %xmm1
movsd 0x8(%rax,%rbx,8), %xmm2
leaq 0xb0(%rsp), %rdi
callq 0x85436
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x8d5ca
movq 0xc0(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0xb0(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x38(%rsp)
jmp 0x8d5da
movq %r15, %rdi
leaq 0xb0(%rsp), %rdx
callq 0x3012c
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
leaq 0x3(%rbx), %rcx
addq $0x2, %rbx
cmpq %rbx, %rdx
movq %rcx, %rbx
ja 0x8d569
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0xb0(%rsp), %rdi
callq 0x85436
movq 0x38(%rsp), %rax
cmpq 0x30(%rsp), %rax
je 0x8d854
xorpd %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
xorl %ebx, %ebx
xorl %r15d, %r15d
movq %rbp, %rdi
xorl %esi, %esi
callq 0x85478
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r15, %rdx
jbe 0x8daae
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
addq %rbx, %rdi
xorl %esi, %esi
callq 0x85478
movsd 0x20(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbp, %rdi
movl $0x1, %esi
callq 0x85478
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r15, %rdx
jbe 0x8daae
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
addq %rbx, %rdi
movl $0x1, %esi
callq 0x85478
movsd 0x28(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rbp, %rdi
movl $0x2, %esi
callq 0x85478
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r15, %rdx
jbe 0x8daae
movsd (%rax), %xmm0
movsd %xmm0, 0x88(%rsp)
addq %rbx, %rdi
movl $0x2, %esi
callq 0x85478
movsd 0x28(%rsp), %xmm1
movsd 0x88(%rsp), %xmm2
addsd (%rax), %xmm2
leaq 0x98(%rsp), %rdi
movsd 0x20(%rsp), %xmm0
callq 0x85436
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r15, %rdx
jbe 0x8dabf
addq %rbx, %rdi
xorl %esi, %esi
callq 0x85478
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r15, %rdx
jbe 0x8dabf
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
addq %rbx, %rdi
movl $0x1, %esi
callq 0x85478
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r15, %rdx
jbe 0x8dabf
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
addq %rbx, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm2
xorps %xmm3, %xmm3
xorps %xmm4, %xmm4
xorps %xmm5, %xmm5
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x868fa
subsd 0x50(%rsp), %xmm0
movapd %xmm0, %xmm1
maxsd 0x68(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jne 0x8d82a
jp 0x8d82a
movq 0xa8(%rsp), %rax
movq %rax, 0xc0(%rsp)
movupd 0x98(%rsp), %xmm0
movapd %xmm0, 0xb0(%rsp)
incq %r15
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
sarq $0x3, %rax
imulq %r13, %rax
addq $0x18, %rbx
movsd %xmm1, 0x68(%rsp)
cmpq %r15, %rax
ja 0x8d637
jmp 0x8d858
xorpd %xmm1, %xmm1
movsd 0x58(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jae 0x8d887
addsd %xmm1, %xmm1
movsd %xmm1, 0x98(%rsp)
movq 0xd28(%r14), %rsi
cmpq 0xd30(%r14), %rsi
je 0x8d8b5
movsd %xmm1, (%rsi)
jmp 0x8d8a8
addsd %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
movq 0xd28(%r14), %rsi
cmpq 0xd30(%r14), %rsi
je 0x8d8cc
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0xd28(%r14)
jmp 0x8d8e1
movq 0xd0(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x139c2
jmp 0x8d8e1
movq 0xd0(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x139c2
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8d8f8
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8d912
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd 0x58(%rsp), %xmm2
movapd %xmm2, %xmm0
xorpd %xmm1, %xmm1
cmpeqsd %xmm1, %xmm0
movq %xmm0, %rax
subl %eax, 0x64(%rsp)
cmpneqsd %xmm1, %xmm2
movq %xmm2, %rax
subl %eax, %r12d
leaq 0x158(%rsp), %rdi
callq 0x122f4a
movq 0x120(%rsp), %rdx
incq %rdx
movq 0xc90(%r14), %rax
movq 0xc98(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r13, %rcx
cmpq %rdx, %rcx
ja 0x8d12a
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
xorps %xmm2, %xmm2
cvtsi2sdl 0x64(%rsp), %xmm2
leaq 0x458(%rsp), %r12
movq 0x118(%rsp), %r15
leaq 0x258(%rsp), %rbp
jmp 0x8d9a8
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
movl 0xc78(%r14), %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
divsd %xmm0, %xmm1
divsd %xmm0, %xmm2
addq $0xd20, %r14            # imm = 0xD20
movsd 0xc680a(%rip), %xmm0    # 0x1541d8
movq %r15, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
movq %r14, %rdx
movl 0x60(%rsp), %ecx
callq 0x8c643
leaq 0xca149(%rip), %rdi     # 0x157b32
callq 0x4660
movq 0x1095ab(%rip), %rax    # 0x196fa0
movq (%rax), %rbx
movq 0x18(%rax), %r14
leaq 0x260(%rsp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, 0x258(%rsp,%rax)
callq 0x4390
movl $0xf8, %r15d
addq %r15, %rbp
movq %rbp, %rdi
callq 0x41a0
leaq 0x460(%rsp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, 0x458(%rsp,%rax)
callq 0x4390
addq %r15, %r12
movq %r12, %rdi
callq 0x41a0
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x8da77
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x8da9c
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x4470
addq $0x658, %rsp            # imm = 0x658
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc1bf0(%rip), %rdi     # 0x14f6a5
movq %r15, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xc1bdf(%rip), %rdi     # 0x14f6a5
movq %r15, %rsi
xorl %eax, %eax
callq 0x4630
movq %rbx, %rsi
leaq 0xc1bcb(%rip), %rdi     # 0x14f6a5
xorl %eax, %eax
callq 0x4630
leaq 0xc1bbd(%rip), %rdi     # 0x14f6a5
movq %r15, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xc1bac(%rip), %rdi     # 0x14f6a5
movq %r15, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x8db45
jmp 0x8db09
jmp 0x8db45
movq %rax, %rbx
jmp 0x8dbc3
movq %rax, %rbx
jmp 0x8dbfb
jmp 0x8db45
jmp 0x8db4a
jmp 0x8db4a
jmp 0x8db45
jmp 0x8db4a
movq %rax, %rbx
jmp 0x8db64
jmp 0x8db45
jmp 0x8db45
jmp 0x8db45
movq %rax, %rbx
jmp 0x8db7e
jmp 0x8db45
jmp 0x8db45
jmp 0x8db45
jmp 0x8db45
jmp 0x8db4a
jmp 0x8db4a
jmp 0x8db4a
jmp 0x8db4a
jmp 0x8db4a
movq %rax, %rbx
jmp 0x8db8b
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8db64
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8db7e
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x158(%rsp), %rdi
callq 0x122f4a
movq 0x10940e(%rip), %rax    # 0x196fa0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x260(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x258(%rsp,%rcx)
callq 0x4390
leaq 0x350(%rsp), %rdi
callq 0x41a0
movq 0x1093d6(%rip), %rax    # 0x196fa0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x460(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x458(%rsp,%rcx)
callq 0x4390
leaq 0x550(%rsp), %rdi
callq 0x41a0
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x8dc20
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x8dc45
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780