// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/feature.cc
// Function: FEATURE::calculateSurfaceArea_OLD(ATOM_NETWORK*, std::vector<DIJKSTRA_NODE, std::allocator<DIJKSTRA_NODE>>*, std::vector<int, std::allocator<int>>*, int, char*, int)
double FEATURE::calculateSurfaceArea_OLD(ATOM_NETWORK *uc,vector<DIJKSTRA_NODE> *ChanNodeList,vector <int> *featnodemap,int curr_f,char *name,int fid){
 
  long int i,j,k,counter=0;  
  double volume;
  int step;
  double r_tr; // threshold for r
  XYZ max,min;
  XYZ box;
  XYZ pt;

  vector <double> SA_holo;  // stores hologram for each feature
  vector <double> SA_holo_otherf; // as above but excluding surface that is covered by other segments

  srand(randSeed2);
  SPHERE sph,sph2;
  vector <SPHERE> object; // a vector of spheres that define object (segemnt/feature/channel)

  vector <SPHERE> other_object; // vectors of spheres corresponding to other segments

    // Draw the components located in each unit cell
    for(unsigned int i = 0; i < unitCells.size(); i++){
      vector<int> nodeIDs = ucNodes.at(i);
      DELTA_POS disp = unitCells.at(i);
      
      // Iterate over all nodes in the unit cell
      for(unsigned int j = 0; j < nodeIDs.size(); j++){
	DIJKSTRA_NODE curNode = nodes.at(nodeIDs.at(j));
	
	// Find node coordinates

        if(dimensionality<1) 
           { // if feature is not a channel, use reconstrcted feature
	   sph.x = curNode.x + v_a.x*disp.x + v_b.x*disp.y + v_c.x*disp.z;
	   sph.y = curNode.y + v_a.y*disp.x + v_b.y*disp.y + v_c.y*disp.z;
	   sph.z = curNode.z + v_a.z*disp.x + v_b.z*disp.y + v_c.z*disp.z;
           } else {
           sph.x = nodes.at(nodeIDs.at(j)).x;sph.y = nodes.at(nodeIDs.at(j)).y;sph.z = nodes.at(nodeIDs.at(j)).z;
//           cout << "draw sphere { " << sph.x << "  " << sph.y << "  " << sph.z << " } radius 0.1 " << "\n"; 
           };

	sph.r = SPHERE_SCALE*curNode.max_radius;

        object.push_back(sph);

        if(object.size()==1)
          { // first sphere added
          min.x=sph.x-sph.r;max.x=sph.x+sph.r;
          min.y=sph.y-sph.r;max.y=sph.y+sph.r;
          min.z=sph.z-sph.r;max.z=sph.z+sph.r;
          }else
          {
          if(min.x>(sph.x-sph.r)) min.x=sph.x-sph.r;
          if(max.x<(sph.x+sph.r)) max.x=sph.x+sph.r;
          if(min.y>(sph.y-sph.r)) min.y=sph.y-sph.r;
          if(max.y<(sph.y+sph.r)) max.y=sph.y+sph.r;
          if(min.z>(sph.z-sph.r)) min.z=sph.z-sph.r;
          if(max.z<(sph.z+sph.r)) max.z=sph.z+sph.r;
          };
		
      }
    } // end of analysis of object



// Create a list of spheres that overlap with the current feature
/*
 for(j=0;j<(int)ChanNodeList->size();j++)
    {
    int count=0;
    int count2=0;
    Point node;
    node.x=ChanNodeList->at(j).x; node.y=ChanNodeList->at(j).y; node.z=ChanNodeList->at(j).z;
    node=uc->shiftXYZInUC(node);

    for(int i = 0; i < (int)object.size(); i++){
       Point p;
       p.x=object[i].x;p.y=object[i].y;p.z=object[i].z;
       Point p_shifted=uc->shiftXYZInUC(p);

       double dist = uc->calcDistanceXYZ(p.x,p.y,p.z,node.x,node.y,node.z);
       if(dist<0.01&&fabs(ChanNodeList->at(j).max_radius*SPHERE_SCALE-object[i].r)<0.01) 
          {
          count++; break;
          };

       if(dist<ChanNodeList->at(j).max_radius*SPHERE_SCALE+object[i].r)
         {
         count2++;
         };

       };

    if(count==0) // if node is not a part of the current feature
      {
      if(count2>0) {
        //origDNet->nodes[j] is an sphere overlapping with the current feature
        sph2.r=ChanNodeList->at(j).max_radius*SPHERE_SCALE;
        sph2.x=node.x; sph2.y=node.y; sph2.z=node.z;
        other_object.push_back(sph2);
        };
      };

    };
*/

// New version of code to find overlapping nodes

vector <int> conn_feat;

 for(j=0;j<(int)ChanNodeList->size();j++)
    {
    if(featnodemap->at(j)==curr_f)
      {
      for(i=0;i<(int)(ChanNodeList->at(j).connections.size());i++)      
         {
         if(featnodemap->at(ChanNodeList->at(j).connections.at(i).to)!=curr_f)
            {
            int flag=0;
            for(k=0;k<(int)conn_feat.size();k++)
               {
               if(conn_feat[k]==featnodemap->at(ChanNodeList->at(j).connections.at(i).to)) flag=1;
               };
            if(flag==0) conn_feat.push_back(featnodemap->at(ChanNodeList->at(j).connections.at(i).to));
            };
         };
      };
    }

for(i=0;i<(int)conn_feat.size();i++)
 for(j=0;j<(int)ChanNodeList->size();j++)
    {
    if(featnodemap->at(j)==i)
       {
       Point node;
       node[0]=ChanNodeList->at(j).x; node[1]=ChanNodeList->at(j).y; node[2]=ChanNodeList->at(j).z;
       node=uc->shiftXYZInUC(node);

       sph2.r=ChanNodeList->at(j).max_radius*SPHERE_SCALE;
       sph2.x=node[0]; sph2.y=node[1]; sph2.z=node[2];
       other_object.push_back(sph2);

       };
    };



cout << "Outside spheres list contain " << other_object.size() << " spheres (of " << ChanNodeList->size() << " nodes)." << "\n";


//

  box.x=max.x-min.x;
  box.y=max.y-min.y;
  box.z=max.z-min.z;
 
  volume=box.x*box.y*box.z;

//  cout << "Segment Box volume= " << volume << "\n"; 

// Now MC integration of surface

//int pos_origDNet;

SA_holo.resize(NBINS_SA_HOLO,0);
SA_holo_otherf.resize(NBINS_SA_HOLO,0);

for(step=0;step<NBINS_SA_HOLO;step++) // loop over all bins for surface area holograms
   {
   r_tr=(double)step*SA_HOLO_STEP;

   counter=0;

   for(j=0;j<(int)object.size();j++)
      {
      if(object[j].r>r_tr) { counter++;break;}; // at least one sphere larger than r_tr, sampling makes sense
      };


   if(counter>0)
     { // sampling makes sense

//     double totalSA = 0;
//     int sampleCount = 0;

     // Sample around each of the object's spheres
     for(int i = 0; i < (int)object.size(); i++){


        // now go to sampling

//        cout << "Object " << i << "\n"; cout.flush();

        int count = 0;
        int count_otherf=0;

        if(object[i].r-r_tr>0)
        for(int j = 0; j < N_MC_SA_SAMPLE; j++){

        bool overlap=false;
        bool overlap_otherf=false; // overlap with other features

        // Randomly sample point on a sphere of radius 1
        double theta = (rand()*1.0/RAND_MAX)*2*PI;
        double cosphi = 1.0 - (rand()*1.0/RAND_MAX)*2.0;
        double phi = acos(cosphi);

        // Convert spherical coordinates to xyz coordinates
        double xpoint = sin(phi)*cos(theta); //Don't need abs(sin(phi)) becase phi is from 0 to pi
        double ypoint = sin(phi)*sin(theta);
        double zpoint = cosphi;	
      
        // Scale the point to lie on a radius of r_probe + r_atom#i
        xpoint *= (object[i].r-r_tr);
        ypoint *= (object[i].r-r_tr);
        zpoint *= (object[i].r-r_tr);

        // move the point to the segment

        pt.x=object[i].x+xpoint;
        pt.y=object[i].y+ypoint;
        pt.z=object[i].z+zpoint;


        if(dimensionality<1)
          { // if the feature is not a channel, just check overlap with other spheres

          for(k=0;k<(int)object.size();k++)
             {
             if(k!=i)
                {
                if(calcEuclideanDistance(pt.x,pt.y,pt.z,object[k].x,object[k].y,object[k].z)<(object[k].r-r_tr)- 0.00001)
                   {
                   overlap=true; break;
                   };
                };
             };

          if(overlap==false) count++;


          //otherlap with other segments

         if(overlap==false)
         for(int jj=0;jj<(int)other_object.size();jj++)
            {
            Point p;
            p[0]=pt.x;p[1]=pt.y;p[2]=pt.z;
            Point p_shifted=uc->shiftXYZInUC(p);

            double dist = uc->calcDistanceXYZ(p[0],p[1],p[2],other_object[jj].x,other_object[jj].y,other_object[jj].z);

            if(dist<other_object[jj].r) {
                 overlap_otherf=true; break;
                 };

           };

 
          if(overlap_otherf==false) count_otherf++;

          }else{
          // sample points in case of channels, have to use pbc here

          // Convert (x,y,z) coordinates to ones relative to the unit cell vectors
          Point abc_coords = uc->xyz_to_abc(pt.x, pt.y, pt.z);

          abc_coords=uc->shiftABCInUC(abc_coords);
/*
          if(abc_coords.x<0||abc_coords.x>=1||abc_coords.y<0||abc_coords.y>=1||abc_coords.z<0||abc_coords.z>=1)
             {
             overlap=true;           
             };
*/
          if(overlap!=true)
            {
            for(k=0;k<(int)object.size();k++)
               {
               if(k!=i)
                  {
                  Point new_abc=uc->xyz_to_abc(object[k].x, object[k].y, object[k].z);
                  double centerDist = uc->calcDistanceABC(new_abc[0],new_abc[1],new_abc[2],abc_coords[0],abc_coords[1],abc_coords[2]);
                  if(centerDist < (object[k].r-r_tr) - 0.00001){
                     overlap=true; break;
                     };
                  };
               };

            };
          if(overlap==false) count++;

         // check otherlap with other segments
  
         if(overlap==false)
         for(int jk=0;jk<(int)other_object.size();jk++)
            {
            Point p;
            p[0]=pt.x;p[1]=pt.y;p[2]=pt.z;
            Point p_shifted=uc->shiftXYZInUC(p);

            double dist = uc->calcDistanceXYZ(p[0],p[1],p[2],other_object[jk].x,other_object[jk].y,other_object[jk].z);

            if(dist<other_object[jk].r) {
                 overlap_otherf=true; break;
                 };

           };
          

          if(overlap_otherf == false) 
	    count_otherf++;

          }; // end if, for channels (dim>0)

     
       }; // ends for(int j = 0; j < N_MC_SA_SAMPLE; j++){

//     cout << " count= " << count << "    cont_otherf= " << count_otherf << "\n";

     SA_holo[step]+= ((double)count/(double)N_MC_SA_SAMPLE)* 4.0 * PI * pow(object[i].r-r_tr,2);
     SA_holo_otherf[step]+= ((double)count_otherf/(double)N_MC_SA_SAMPLE)* 4.0 * PI * pow(object[i].r-r_tr,2);
     }; // ends for(int i = 0; i < (int)object.size() 

     }else   // from if(counter>0)
     {
     // surface area is 0
     SA_holo[step]=0;
     }; // ends  if(counter>0)

   }; // ends for(step=0;step<NBINS_SA_HOLO;step++)


cout << "##SA_holo:  " << name << "  Feature=  " << fid << "   ";
for(i=0;i<NBINS_SA_HOLO;i++)
   {
   cout << SA_holo[i] << "   ";
   };

cout << " Other:  ";
for(i=0;i<NBINS_SA_HOLO;i++)
   {
   cout << SA_holo_otherf[i] << "   ";
   };

cout << "\n";

//volume=volume*((double)(N_MC_SAMPLE-counter))/(double)N_MC_SAMPLE;

return SA_holo[0];


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %r9, 0x1d0(%rsp)
movl %r8d, %r15d
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x110(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x6402e
leaq 0xf0(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x6402e
leaq 0x250(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x6402e
leaq 0xd0(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x6402e
xorpd %xmm0, %xmm0
movapd %xmm0, 0x160(%rsp)
andq $0x0, 0x170(%rsp)
movapd %xmm0, 0x190(%rsp)
andq $0x0, 0x1a0(%rsp)
movl $0x3b4ca6f5, %edi       # imm = 0x3B4CA6F5
callq 0x4460
leaq 0xa0(%rsp), %r13
andq $0x0, 0x10(%r13)
andq $0x0, 0x90(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r13)
movapd %xmm0, 0x80(%rsp)
leaq 0x90(%r14), %rax
movq %rax, 0x1d8(%rsp)
leaq 0xa8(%r14), %rax
movq %rax, 0x60(%rsp)
movq %r14, 0x68(%rsp)
addq $0x60, %r14
xorl %esi, %esi
leaq 0x40(%rsp), %rbp
movl %esi, %esi
movq 0x68(%rsp), %rcx
movq 0x98(%rcx), %rax
subq 0x90(%rcx), %rax
cqto
pushq $0xc
popq %rcx
idivq %rcx
cmpq %rsi, %rax
jbe 0x5e335
movq 0x60(%rsp), %rdi
movq %rsi, 0x28(%rsp)
callq 0x4bbec
movq %rbp, %rdi
movq %rax, %rsi
callq 0xa6ce
movq 0x1d8(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x576b6
cvtsi2sdl (%rax), %xmm0
cvtsi2sdl 0x4(%rax), %xmm1
cvtsi2sdl 0x8(%rax), %xmm2
movapd %xmm2, 0x150(%rsp)
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
movapd %xmm2, 0xc0(%rsp)
movapd %xmm1, 0x30(%rsp)
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd %xmm1, 0x1c0(%rsp)
movapd %xmm0, 0x70(%rsp)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm0, 0x1b0(%rsp)
xorl %r12d, %r12d
movl %r12d, %r12d
movq 0x48(%rsp), %rax
subq 0x40(%rsp), %rax
sarq $0x2, %rax
cmpq %r12, %rax
jbe 0x5e321
movq %rbp, %rdi
movq %r12, %rsi
callq 0xac00
movslq (%rax), %rsi
movq %r14, %rdi
callq 0xabe2
leaq 0x1e0(%rsp), %rdi
movq %rax, %rsi
callq 0x29ebe
movq 0x68(%rsp), %rax
cmpl $0x0, 0x108(%rax)
jle 0x5e10d
movq %rbp, %rdi
movq %r12, %rsi
callq 0xac00
movslq (%rax), %rsi
movq %r14, %rdi
callq 0xabe2
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x130(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0xac00
movslq (%rax), %rsi
movq %r14, %rdi
callq 0xabe2
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x138(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0xac00
movslq (%rax), %rsi
movq %r14, %rdi
callq 0xabe2
movsd 0x18(%rax), %xmm0
jmp 0x5e19c
movupd 0x1e8(%rsp), %xmm0
movupd 0xc0(%rax), %xmm1
mulpd 0x1b0(%rsp), %xmm1
addpd %xmm0, %xmm1
movupd 0xd8(%rax), %xmm0
mulpd 0x1c0(%rsp), %xmm0
addpd %xmm1, %xmm0
movupd 0xf0(%rax), %xmm1
mulpd 0xc0(%rsp), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x130(%rsp)
movsd 0xd0(%rax), %xmm0
mulsd 0x70(%rsp), %xmm0
addsd 0x1f8(%rsp), %xmm0
movsd 0xe8(%rax), %xmm1
mulsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x100(%rax), %xmm0
mulsd 0x150(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x140(%rsp)
movsd 0x218(%rsp), %xmm0
mulsd 0xa2f8a(%rip), %xmm0    # 0x101140
movsd %xmm0, 0x148(%rsp)
movq %r13, %rdi
leaq 0x130(%rsp), %rsi
callq 0x37192
movq 0xa8(%rsp), %rax
subq 0xa0(%rsp), %rax
cmpq $0x20, %rax
jne 0x5e240
movsd 0x148(%rsp), %xmm0
movapd 0x130(%rsp), %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movapd %xmm1, %xmm3
subpd %xmm2, %xmm3
movapd %xmm3, 0xf0(%rsp)
addpd %xmm1, %xmm2
movapd %xmm2, 0x110(%rsp)
movsd 0x140(%rsp), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
movsd %xmm2, 0x100(%rsp)
addsd %xmm1, %xmm0
jmp 0x5e303
movsd 0xf0(%rsp), %xmm3
movsd 0x130(%rsp), %xmm1
movsd 0x148(%rsp), %xmm0
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
jbe 0x5e272
movsd %xmm2, 0xf0(%rsp)
addsd %xmm0, %xmm1
ucomisd 0x110(%rsp), %xmm1
jbe 0x5e28a
movsd %xmm1, 0x110(%rsp)
movsd 0xf8(%rsp), %xmm3
movsd 0x138(%rsp), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
jbe 0x5e2b3
movsd %xmm2, 0xf8(%rsp)
addsd %xmm0, %xmm1
ucomisd 0x118(%rsp), %xmm1
jbe 0x5e2cb
movsd %xmm1, 0x118(%rsp)
movsd 0x100(%rsp), %xmm3
movsd 0x140(%rsp), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
jbe 0x5e2f4
movsd %xmm2, 0x100(%rsp)
addsd %xmm1, %xmm0
ucomisd 0x120(%rsp), %xmm0
jbe 0x5e30c
movsd %xmm0, 0x120(%rsp)
leaq 0x200(%rsp), %rdi
callq 0xaf14
incl %r12d
jmp 0x5e057
movq %rbp, %rdi
callq 0xb290
movq 0x28(%rsp), %rsi
incl %esi
jmp 0x5dfb8
xorpd %xmm0, %xmm0
leaq 0x1e0(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
xorl %r12d, %r12d
pushq $0x1
popq %r14
movq %rbx, 0x70(%rsp)
movl %r15d, 0xb8(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rsi
movq %rsi, %rax
subq %rcx, %rax
cqto
pushq $0x48
popq %rdi
idivq %rdi
cltq
cmpq %rax, %r12
jge 0x5e4b3
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0xac00
cmpl %r15d, (%rax)
jne 0x5e4ab
xorl %ebp, %ebp
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xabe2
movq 0x28(%rax), %rcx
subq 0x20(%rax), %rcx
movq %rcx, %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cltq
cmpq %rax, %rbp
jge 0x5e4ab
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xabe2
addq $0x20, %rax
movq %rax, %rdi
movq %rbp, %rsi
callq 0x29efa
movslq 0x4(%rax), %rsi
movq 0x20(%rsp), %rdi
callq 0xac00
cmpl %r15d, (%rax)
je 0x5e4a3
xorl %r15d, %r15d
xorl %ebx, %ebx
movq 0x1e0(%rsp), %rax
movq 0x1e8(%rsp), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbx
jge 0x5e457
movl (%rax,%rbx,4), %r13d
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xabe2
addq $0x20, %rax
movq %rax, %rdi
movq %rbp, %rsi
callq 0x29efa
movslq 0x4(%rax), %rsi
movq 0x20(%rsp), %rdi
callq 0xac00
cmpl (%rax), %r13d
cmovel %r14d, %r15d
incq %rbx
jmp 0x5e3fe
testl %r15d, %r15d
movq 0x70(%rsp), %rbx
movl 0xb8(%rsp), %r15d
jne 0x5e4a3
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xabe2
addq $0x20, %rax
movq %rax, %rdi
movq %rbp, %rsi
callq 0x29efa
movslq 0x4(%rax), %rsi
movq 0x20(%rsp), %rdi
callq 0xac00
leaq 0x1e0(%rsp), %rdi
movq %rax, %rsi
callq 0x9434
incq %rbp
jmp 0x5e39b
incq %r12
jmp 0x5e35e
xorl %ebp, %ebp
leaq 0x40(%rsp), %r14
pushq $0x2
popq %r13
pushq $0x48
popq %r15
movq 0x1e8(%rsp), %rax
subq 0x1e0(%rsp), %rax
shrq $0x2, %rax
cltq
cmpq %rax, %rbp
jge 0x5e689
xorl %r12d, %r12d
movq %rsi, %rax
subq %rcx, %rax
cqto
idivq %r15
cltq
cmpq %rax, %r12
jge 0x5e681
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0xac00
movslq (%rax), %rax
cmpq %rax, %rbp
jne 0x5e66d
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %r14, %rdi
callq 0x63c46
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xabe2
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x63c78
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xabe2
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xabe2
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r14, %rdi
movl %r13d, %esi
callq 0x63c78
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x40(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x178(%rsp), %rdi
movq %rbx, %rsi
callq 0x3f9c2
movq 0x188(%rsp), %rax
movq %rax, 0x50(%rsp)
movupd 0x178(%rsp), %xmm0
movapd %xmm0, 0x40(%rsp)
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xabe2
movsd 0x38(%rax), %xmm0
mulsd 0xa2b38(%rip), %xmm0    # 0x101140
movsd %xmm0, 0x248(%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x230(%rsp)
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x238(%rsp)
movq %r14, %rdi
movl %r13d, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x240(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x230(%rsp), %rsi
callq 0x37192
incq %r12
movq 0x18(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rsi
jmp 0x5e4e4
incq %rbp
jmp 0x5e4c2
movq 0xf1930(%rip), %rdi     # 0x14ffc0
leaq 0xa5800(%rip), %rsi     # 0x103e97
callq 0x4480
movq 0x88(%rsp), %rsi
subq 0x80(%rsp), %rsi
sarq $0x5, %rsi
movq %rax, %rdi
callq 0x42e0
leaq 0xa57f6(%rip), %rsi     # 0x103eb5
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
idivq %r15
movq %rax, %rsi
callq 0x42e0
leaq 0xa57d9(%rip), %rsi     # 0x103ec3
movq %rax, %rdi
callq 0x4480
leaq 0xa3e85(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
movapd 0x110(%rsp), %xmm0
subpd 0xf0(%rsp), %xmm0
movapd %xmm0, 0x250(%rsp)
movsd 0x120(%rsp), %xmm0
subsd 0x100(%rsp), %xmm0
movsd %xmm0, 0x260(%rsp)
leaq 0x40(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x160(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x3713c
movq 0x68(%rsp), %rbp
leaq 0x40(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x190(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x3713c
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x5, %rdx
movslq %edx, %rdx
xorl %esi, %esi
testq %rdx, %rdx
cmovleq %rsi, %rdx
shlq $0x5, %rdx
addq $0x20, %rdx
xorpd %xmm0, %xmm0
leaq 0x20(%rsi), %rdi
cmpq %rdi, %rdx
je 0x5eee4
movsd 0x18(%rax,%rsi), %xmm1
ucomisd %xmm0, %xmm1
movq %rdi, %rsi
jbe 0x5e7a0
xorl %r12d, %r12d
leaq 0x40(%rsp), %rbx
leaq 0x178(%rsp), %r14
xorl %r13d, %r13d
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x5, %rdx
movslq %edx, %rdx
cmpq %rdx, %r13
jge 0x5eef0
movq %r13, %rsi
shlq $0x5, %rsi
movsd 0x18(%rax,%rsi), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
xorpd %xmm0, %xmm0
jbe 0x5ee72
movq %rsi, 0xb8(%rsp)
movl $0x0, 0x60(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
movq %r13, 0x28(%rsp)
cmpl $0x1f4, %ecx            # imm = 0x1F4
je 0x5ee4a
movl %ecx, 0x1b0(%rsp)
movl %eax, 0x1c0(%rsp)
callq 0x4170
cvtsi2sd %eax, %xmm0
divsd 0xa1d38(%rip), %xmm0    # 0x100580
addsd %xmm0, %xmm0
mulsd 0xa1d5c(%rip), %xmm0    # 0x1005b0
movsd %xmm0, 0x18(%rsp)
callq 0x4170
cvtsi2sd %eax, %xmm0
divsd 0xa1d4d(%rip), %xmm0    # 0x1005b8
addsd %xmm0, %xmm0
addsd 0x9d7e1(%rip), %xmm0    # 0xfc058
movsd %xmm0, 0x20(%rsp)
callq 0x4450
movsd %xmm0, 0xc0(%rsp)
callq 0x4110
movapd %xmm0, 0x30(%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x47e0
movaps %xmm0, 0x150(%rsp)
movsd 0xc0(%rsp), %xmm0
callq 0x4110
movaps %xmm0, 0xc0(%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x4110
movsd 0x20(%rsp), %xmm2
movq 0xa0(%rsp), %rax
movq 0xb8(%rsp), %rcx
movsd 0x18(%rax,%rcx), %xmm1
mulsd %xmm1, %xmm2
movapd 0x30(%rsp), %xmm3
unpcklpd 0xc0(%rsp), %xmm3       # xmm3 = xmm3[0],mem[0]
movapd 0x150(%rsp), %xmm4
unpcklpd %xmm0, %xmm4            # xmm4 = xmm4[0],xmm0[0]
mulpd %xmm3, %xmm4
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm4, %xmm1
movupd (%rax,%rcx), %xmm0
addpd %xmm1, %xmm0
movapd %xmm0, 0xd0(%rsp)
addsd 0x10(%rax,%rcx), %xmm2
movsd %xmm2, 0xe0(%rsp)
cmpl $0x0, 0x108(%rbp)
jle 0x5ec38
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movq %rbx, %rdi
movq 0x70(%rsp), %r15
movq %r15, %rsi
callq 0x3f1ce
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x40(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x3f94a
movq 0x188(%rsp), %rax
movq %rax, 0x50(%rsp)
movupd 0x178(%rsp), %xmm0
movapd %xmm0, 0x40(%rsp)
movq 0xa0(%rsp), %rax
xorl %r15d, %r15d
xorl %ebp, %ebp
movq 0xa8(%rsp), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jge 0x5eabd
cmpq %r15, %r12
je 0x5eab1
movsd (%rax,%r15), %xmm0
movsd 0x8(%rax,%r15), %xmm1
movsd 0x10(%rax,%r15), %xmm2
movq %r14, %rdi
movq 0x70(%rsp), %rsi
callq 0x3f1ce
movq %r14, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r14, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x150(%rsp)
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0xc0(%rsp)
movq %rbx, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm5
movq 0x70(%rsp), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x150(%rsp), %xmm3
movsd 0xc0(%rsp), %xmm4
callq 0x3f440
movq 0xa0(%rsp), %rax
movsd 0x18(%rax,%r15), %xmm1
addsd 0xa5131(%rip), %xmm1    # 0x103bd8
ucomisd %xmm0, %xmm1
ja 0x5ee1f
incq %rbp
addq $0x20, %r15
jmp 0x5e9a1
setge %al
movzbl %al, %eax
addl %eax, 0x60(%rsp)
movq 0x80(%rsp), %rax
pushq $-0x1
popq %rbp
xorl %r15d, %r15d
movq 0x88(%rsp), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
movslq %ecx, %r13
incq %rbp
cmpq %r13, %rbp
jge 0x5ec26
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %r14, %rdi
callq 0x63c46
movsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x63c78
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r14, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x188(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x178(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x270(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x3f9c2
movq %r14, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r14, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm2
movq 0x80(%rsp), %rax
movsd (%rax,%r15), %xmm3
movsd 0x8(%rax,%r15), %xmm4
movsd 0x10(%rax,%r15), %xmm5
movq 0x70(%rsp), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x3f636
movq 0x80(%rsp), %rax
movsd 0x18(%rax,%r15), %xmm1
addq $0x20, %r15
ucomisd %xmm0, %xmm1
jbe 0x5ead5
xorl %eax, %eax
cmpq %r13, %rbp
setge %al
movq 0x28(%rsp), %r13
jmp 0x5ee22
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0xa8(%rsp), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jge 0x5ecb8
cmpq %r15, %r12
je 0x5ecaf
movsd 0xd0(%rsp), %xmm0
movsd 0xd8(%rsp), %xmm1
movsd 0xe0(%rsp), %xmm2
movsd (%rax,%r15), %xmm3
movsd 0x8(%rax,%r15), %xmm4
movsd 0x10(%rax,%r15), %xmm5
callq 0x64934
movq 0xa0(%rsp), %rax
movsd 0x18(%rax,%r15), %xmm1
addsd 0xa4f33(%rip), %xmm1    # 0x103bd8
ucomisd %xmm0, %xmm1
ja 0x5ee29
incq %r13
addq $0x20, %r15
jmp 0x5ec3e
incl 0x60(%rsp)
movq 0x80(%rsp), %rax
pushq $-0x1
popq %rbp
xorl %r15d, %r15d
movq 0x88(%rsp), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
movslq %ecx, %r13
incq %rbp
cmpq %r13, %rbp
jge 0x5ee10
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %rbx, %rdi
callq 0x63c46
movsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x63c78
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x40(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %r14, %rdi
movq 0x70(%rsp), %rsi
callq 0x3f9c2
movq %rbx, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm2
movq 0x80(%rsp), %rax
movsd (%rax,%r15), %xmm3
movsd 0x8(%rax,%r15), %xmm4
movsd 0x10(%rax,%r15), %xmm5
movq 0x70(%rsp), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x3f636
movq 0x80(%rsp), %rax
movsd 0x18(%rax,%r15), %xmm1
addq $0x20, %r15
ucomisd %xmm0, %xmm1
jbe 0x5ecca
xorl %eax, %eax
cmpq %r13, %rbp
setge %al
movq 0x68(%rsp), %rbp
jmp 0x5ee2c
pushq $0x1
popq %rax
movq 0x68(%rsp), %rbp
jmp 0x5ee31
pushq $0x1
popq %rax
movq 0x28(%rsp), %r13
movl 0x1c0(%rsp), %ecx
addl %eax, %ecx
movl %ecx, %eax
movl 0x1b0(%rsp), %ecx
incl %ecx
jmp 0x5e81d
cvtsi2sdl 0x60(%rsp), %xmm2
cvtsi2sd %eax, %xmm0
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq 0xb8(%rsp), %rsi
movsd 0x18(%rax,%rsi), %xmm1
movsd 0xa4d66(%rip), %xmm4    # 0x103be0
divsd %xmm4, %xmm2
movsd 0xa1722(%rip), %xmm5    # 0x1005a8
mulsd %xmm5, %xmm2
movsd 0xa171e(%rip), %xmm3    # 0x1005b0
mulsd %xmm3, %xmm2
mulsd %xmm1, %xmm1
mulsd %xmm2, %xmm1
movq 0x160(%rsp), %rdx
addsd (%rdx), %xmm1
movsd %xmm1, (%rdx)
divsd %xmm4, %xmm0
mulsd %xmm5, %xmm0
mulsd %xmm3, %xmm0
movsd 0x18(%rax,%rsi), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm1
movq 0x190(%rsp), %rdx
addsd (%rdx), %xmm1
movsd %xmm1, (%rdx)
incq %r13
addq $0x20, %r12
jmp 0x5e7cf
movq 0x160(%rsp), %rax
andq $0x0, (%rax)
movq 0xf10c9(%rip), %rdi     # 0x14ffc0
leaq 0xa4fce(%rip), %rsi     # 0x103ecc
callq 0x4480
movq %rax, %rdi
movq 0x1d0(%rsp), %rsi
callq 0x4480
leaq 0xa4fbf(%rip), %rsi     # 0x103ed9
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movl 0x2c0(%rsp), %esi
callq 0x4760
leaq 0x9d596(%rip), %rsi     # 0xfc4ce
movq %rax, %rdi
callq 0x4480
movq 0x160(%rsp), %rax
movsd (%rax), %xmm0
movq 0xf106d(%rip), %rdi     # 0x14ffc0
callq 0x46c0
leaq 0x9d56f(%rip), %rsi     # 0xfc4ce
movq %rax, %rdi
callq 0x4480
movq 0xf1052(%rip), %rdi     # 0x14ffc0
leaq 0xa4f71(%rip), %rsi     # 0x103ee6
callq 0x4480
movq 0x190(%rsp), %rax
movsd (%rax), %xmm0
movq 0xf1033(%rip), %rdi     # 0x14ffc0
callq 0x46c0
leaq 0x9d535(%rip), %rsi     # 0xfc4ce
movq %rax, %rdi
callq 0x4480
movq 0xf1018(%rip), %rdi     # 0x14ffc0
leaq 0xa35cf(%rip), %rsi     # 0x10257e
callq 0x4480
leaq 0x160(%rsp), %rbx
movq (%rbx), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0xb290
leaq 0x80(%rsp), %rdi
callq 0x3796e
leaq 0xa0(%rsp), %rdi
callq 0x3796e
leaq 0x190(%rsp), %rdi
callq 0xb25c
movq %rbx, %rdi
callq 0xb25c
movsd 0x18(%rsp), %xmm0
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
jmp 0x5f040
movq %rax, %rbx
jmp 0x5f078
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
movq %rax, %rbx
jmp 0x5f059
jmp 0x5f068
jmp 0x5f068
movq %rax, %rbx
leaq 0x200(%rsp), %rdi
callq 0xaf14
leaq 0x40(%rsp), %rdi
jmp 0x5f073
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
jmp 0x5f068
movq %rax, %rbx
leaq 0x1e0(%rsp), %rdi
callq 0xb290
leaq 0x80(%rsp), %rdi
callq 0x3796e
leaq 0xa0(%rsp), %rdi
callq 0x3796e
leaq 0x190(%rsp), %rdi
callq 0xb25c
leaq 0x160(%rsp), %rdi
callq 0xb25c
movq %rbx, %rdi
callq 0x4780