// File: Luthaf[P]zeopp/area_and_volume.cc
// Function: NEWcalcASA(MATERIAL*, double, int)
double NEWcalcASA(MATERIAL *Mat, double r_probe, int sampleDensity){
//numSamplesiATOM_NETWORK *hiaccatmnet, ATOM_NETWORK *orgatmnet, bool highAccuracy, double r_probe_chan, double r_probe, double rho_crystal, int numSamples, bool excludePockets, ostream &output, char *filename, bool visualize, bool VisITflag, bool LiverpoolFlag, bool ExtendedOutputFlag){


  // Inital checks
  if(!(Mat->accessAnalysis.alreadySegmentedFlag))
      {
      cerr << "Cannot run calcAV without prior accessibility analysis.\nExiting with return 0\n";
      return 0;
      }

  // Setting parameters
  Mat->ASAprobeRadius = r_probe;

  // Setting pointer to the original atom network (not one modified by -ha)
  ATOM_NETWORK *atmnet; // pointed to the analyzed (original atomsnet)
  atmnet = Mat->accessAnalysis.orgAtomNet;


  // commenting out removeOverlappedNodes() but not really sure it affects results. This function 
  // modifies the voronoi network so, if executed, may have effect on other functions, e.g. ones
  // triggered by -vol
  // accessAnalysis.removeOverlappedNodes();

  srand(randSeed);

  bool excludePockets = true; // this is default (in old version, without voro-stuff it was used)

  int numSamples; // number of samples per atom


  // inits of ASA data structures in MATERIALS class
  Mat->ASAaxsPoints.clear(); // List of accessible points to be visualized in ZeoVis/VISIT
  Mat->ASAaxsPointsChannelIDs.clear();  // corresponding channel IDs
  Mat->ASAinaxsPoints.clear(); // List of inaccessible points to be visualized in ZeoVis/VISIT
  Mat->ASAinaxsPointsPocketIDs.clear(); // corresponding pocket IDs
  Mat->ASAtotal = 0;
  Mat->ASAtotal_inaxs = 0;
  Mat->ASAnumSamples = 0;

  Mat->ASA_inChannel.clear(); Mat->ASA_inChannel.resize(Mat->accessAnalysis.n_channels,0);
  Mat->ASA_inPocket.clear(); Mat->ASA_inPocket.resize(Mat->accessAnalysis.n_pockets,0);

  //vectors that store SA contributions per atom (a pair of accessible and inaccessible)
  Mat->ASAhistogramSAperAtom.clear();


  // Sample around each of the network's atoms
  for(int i = 0; i < atmnet->numAtoms; i++){
    int count = 0;
    int count_inaxs = 0;
    // MC statistics can be collected w.r.t to identified channels and inaccessible pockets
    vector<int> count_inChannel(Mat->accessAnalysis.n_channels,0);
    vector<int> count_inPocket(Mat->accessAnalysis.n_pockets,0);

    // calculate number of samples per atom (from sample density)
    numSamples = (int)((4.0 * PI * pow((atmnet->atoms.at(i).radius + r_probe),2)) * sampleDensity);
    Mat->ASAnumSamples +=numSamples;

    for(int j = 0; j < numSamples; j++){
      bool overlaps = false;
      bool inside = false;

      // 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 *= (atmnet->atoms[i].radius + r_probe);
      ypoint *= (atmnet->atoms[i].radius + r_probe);
      zpoint *= (atmnet->atoms[i].radius + r_probe);

      // Convert (x,y,z) coordinates to ones relative to the unit cell vectors
      Point abc_coords = atmnet->xyz_to_abc(xpoint, ypoint, zpoint);

      // Transform coords relative to the atom center into ones relative to the unit cell vectors
      double newAPoint = abc_coords[0] + atmnet->atoms[i].a_coord;
      double newBPoint = abc_coords[1] + atmnet->atoms[i].b_coord;
      double newCPoint = abc_coords[2] + atmnet->atoms[i].c_coord;

      Point samplingPoint = atmnet->abc_to_xyz(newAPoint, newBPoint, newCPoint);


      // Calling accessibility object to determine accessibility of the point (this replaced a big chunk of code by Thomas)
      pair<bool,bool> answer = (Mat->accessAnalysis.isSPointInsideAtomAndNotAccessible(samplingPoint, i));
      inside = answer.first; overlaps = answer.second;
      if(Mat->accessAnalysis.needToResample() == true) j--; // the sampled point could not be analyzed in isSPointInsideAtomAndNotAccessible() function, resampling needed

      if(inside == false && excludePockets == false) overlaps = false; // if ignore inacceible pockets, treat the point as accessible (unless inside atom)


      // Store sampled points that did not overlap within atom for later visualization
      if(Mat->accessAnalysis.needToResample() == false && !inside) {
	Point abcCoords = Point(newAPoint, newBPoint, newCPoint);
//	Point coords = atmnet->abc_to_xyz(atmnet->shiftABCInUC(abcCoords)); // to be removed, new function stores fractional coordinates
        Point coords = atmnet->shiftABCInUC(abcCoords);
	if(overlaps)
          {
          count_inaxs++;
	  Mat->ASAinaxsPoints.push_back(coords);
          pair <int,int> CoP = Mat->accessAnalysis.lastChannelOrPocket();
          if(CoP.first!=-1)
            {
            cout << "Error: CoP.first!=-1 in pocket, consult source code provider\n";
            } else {
            count_inPocket[CoP.second]++;
            };
          Mat->ASAinaxsPointsPocketIDs.push_back(CoP.second);
          }
	else
          {
	  Mat->ASAaxsPoints.push_back(coords);
          count++;
          pair <int,int> CoP = Mat->accessAnalysis.lastChannelOrPocket();
          if(CoP.second!=-1)
            {
            cout << "Error: CoP.second!=-1 in channel, consult source code provider\n";
            } else {
            count_inChannel[CoP.first]++;
            };
          Mat->ASAaxsPointsChannelIDs.push_back(CoP.first);
          };
      }

//      if(accessAnalysis.needToResample() == false && !overlaps)
//        count++;
    }
   
    // SA per atom (in accessible space and in inaccessible pockets)
    double SAperAtom = (1.0*count)/numSamples * 4.0 * PI * pow((atmnet->atoms.at(i).radius + r_probe),2);
    double SAperAtom_inaxs = (1.0*count_inaxs)/numSamples * 4.0 * PI * pow((atmnet->atoms.at(i).radius + r_probe),2);

    //Increment total surface area by fraction of atom that is accessible
    Mat->ASAtotal += SAperAtom;
    //and inaccessible
    Mat->ASAtotal_inaxs += SAperAtom_inaxs;

    // SA per channel and pocket
    for(unsigned int m = 0; m < Mat->ASA_inChannel.size(); m++)
      {
      Mat->ASA_inChannel[m] += (1.0*count_inChannel[m])/numSamples * 4.0 * PI * pow((atmnet->atoms.at(i).radius + r_probe),2);
      };
    for(unsigned int m = 0; m < Mat->ASA_inPocket.size(); m++)
      {
      Mat->ASA_inPocket[m] += (1.0*count_inPocket[m])/numSamples * 4.0 * PI * pow((atmnet->atoms.at(i).radius + r_probe),2);
      };

    Mat->ASAhistogramSAperAtom.push_back(pair <double,double> (SAperAtom,SAperAtom_inaxs));

  } // ends the main ASA sampling loop (over atoms)

  // Write the necessary commands to the output stream
  // necessary to visualize the sampling

  /* Now moved to a different function */
  /*
  if(visualize){
    if(VisITflag == false)
      {
      reportPoints(output, axsPoints, inaxsPoints);
      }
    else{
      if(LiverpoolFlag == false)
        {
        //report points in std. VisIt format
        reportPointsVisIT(output, axsPoints, inaxsPoints);
        }
      else{
      //report points in Liverpool format
      vector<Point> LiverpoolAxsPoints = vector<Point> ();
      vector<Point> LiverpoolInaxsPoints = vector<Point> ();
      for(unsigned i = 0; i < axsPoints.size(); i++)
         {
         LiverpoolAxsPoints.push_back(atmnet->xyz_to_abc(axsPoints[i]));
         };
      for(unsigned j = 0; j < inaxsPoints.size(); j++)
         {
         LiverpoolInaxsPoints.push_back(atmnet->xyz_to_abc(inaxsPoints[j]));
         };
//      reportPointsVisIT(output, LiverpoolAxsPoints, LiverpoolInaxsPoints);
      reportPointsVisIT(output, LiverpoolAxsPoints, axsPointsChannelIDs, LiverpoolInaxsPoints, inaxsPointsPocketIDs);
      };
      };
    //reportResampledPoints(output, resampledInfo);
  }

  */ // ends writing vis files

  cout << "Total number of ASA MC samples = " << Mat->ASAnumSamples << "\n";
    
    // Warn user if points were resampled
  int resampleCount =  Mat->accessAnalysis.getResampleCount();
  if(resampleCount != 0){
    cerr << "\n" << "\n"
  	 << "Warning: Resampled " << resampleCount << " points out of " << Mat->ASAnumSamples
	 << "\n" << "\n"; 
  }
  return Mat->ASAtotal;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rdi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movq -0x10(%rbp), %rax
testb $0x1, 0xb1d(%rax)
jne 0x82534
movq 0x1f0ad5(%rip), %rdi    # 0x272ff0
leaq 0x174526(%rip), %rsi    # 0x1f6a48
callq 0x5540
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x832b2
movsd -0x18(%rbp), %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, 0xd40(%rax)
movq -0x10(%rbp), %rax
movq 0x990(%rax), %rax
movq %rax, -0x28(%rbp)
movl $0x3b4ca6f5, %edi       # imm = 0x3B4CA6F5
callq 0x5510
movb $0x1, -0x29(%rbp)
movq -0x10(%rbp), %rdi
addq $0xd60, %rdi            # imm = 0xD60
callq 0x84ae0
movq -0x10(%rbp), %rdi
addq $0xd78, %rdi            # imm = 0xD78
callq 0x163b0
movq -0x10(%rbp), %rdi
addq $0xd90, %rdi            # imm = 0xD90
callq 0x84ae0
movq -0x10(%rbp), %rdi
addq $0xda8, %rdi            # imm = 0xDA8
callq 0x163b0
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0xd50(%rax)
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0xd58(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xd48(%rax)
movq -0x10(%rbp), %rdi
addq $0xdc0, %rdi            # imm = 0xDC0
callq 0x851f0
movq -0x10(%rbp), %rdi
addq $0xdc0, %rdi            # imm = 0xDC0
movq -0x10(%rbp), %rax
movslq 0xa68(%rax), %rsi
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x38(%rbp), %rdx
callq 0x85210
movq -0x10(%rbp), %rdi
addq $0xdd8, %rdi            # imm = 0xDD8
callq 0x851f0
movq -0x10(%rbp), %rdi
addq $0xdd8, %rdi            # imm = 0xDD8
movq -0x10(%rbp), %rax
movslq 0xa6c(%rax), %rsi
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0x40(%rbp), %rdx
callq 0x85210
movq -0x10(%rbp), %rdi
addq $0xdf0, %rdi            # imm = 0xDF0
callq 0x852c0
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x110(%rcx), %eax
jge 0x831d0
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movslq 0xa68(%rax), %rax
movq %rax, -0x1e0(%rbp)
movl $0x0, -0x6c(%rbp)
leaq -0x6d(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x10960
movq -0x1e0(%rbp), %rsi
movq -0x1d8(%rbp), %rcx
leaq -0x68(%rbp), %rdi
leaq -0x6c(%rbp), %rdx
callq 0x65a70
jmp 0x826ba
leaq -0x6d(%rbp), %rdi
callq 0x13030
movq -0x10(%rbp), %rax
movslq 0xa6c(%rax), %rax
movq %rax, -0x1f0(%rbp)
movl $0x0, -0x9c(%rbp)
leaq -0x9d(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x10960
movq -0x1f0(%rbp), %rsi
movq -0x1e8(%rbp), %rcx
leaq -0x98(%rbp), %rdi
leaq -0x9c(%rbp), %rdx
callq 0x65a70
jmp 0x82715
leaq -0x9d(%rbp), %rdi
callq 0x13030
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xf090
movq %rax, -0x1f8(%rbp)
jmp 0x8273e
movq -0x1f8(%rbp), %rax
movsd 0x30(%rax), %xmm0
movsd -0x18(%rbp), %xmm1
addsd %xmm1, %xmm0
movl $0x2, %edi
callq 0x850c0
movsd %xmm0, -0x200(%rbp)
jmp 0x82767
movsd -0x200(%rbp), %xmm1
movsd 0x173ec1(%rip), %xmm0   # 0x1f6638
mulsd %xmm1, %xmm0
cvtsi2sdl -0x1c(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0xd48(%rax), %ecx
movl %ecx, 0xd48(%rax)
movl $0x0, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x82dee
movb $0x0, -0xa5(%rbp)
movb $0x0, -0xa6(%rbp)
callq 0x5190
cvtsi2sd %eax, %xmm0
movsd 0x173e32(%rip), %xmm1   # 0x1f6608
movsd %xmm1, -0x218(%rbp)
divsd %xmm1, %xmm0
addsd %xmm0, %xmm0
movsd 0x173e42(%rip), %xmm1   # 0x1f6630
mulsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
callq 0x5190
movsd -0x218(%rbp), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm0, %xmm1
addsd %xmm1, %xmm1
movsd 0x16f835(%rip), %xmm0   # 0x1f2050
subsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0xb8(%rbp), %xmm0
callq 0x54f0
movsd %xmm0, -0xc0(%rbp)
movsd -0xc0(%rbp), %xmm0
callq 0x5140
movsd %xmm0, -0x210(%rbp)
movsd -0xb0(%rbp), %xmm0
callq 0x5970
movaps %xmm0, %xmm1
movsd -0x210(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0xc0(%rbp), %xmm0
callq 0x5140
movsd %xmm0, -0x208(%rbp)
movsd -0xb0(%rbp), %xmm0
callq 0x5140
movaps %xmm0, %xmm1
movsd -0x208(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xfcc0
movsd 0x30(%rax), %xmm1
movsd -0x18(%rbp), %xmm0
addsd %xmm0, %xmm1
movsd -0xc8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xfcc0
movsd 0x30(%rax), %xmm1
movsd -0x18(%rbp), %xmm0
addsd %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xfcc0
movsd 0x30(%rax), %xmm1
movsd -0x18(%rbp), %xmm0
addsd %xmm0, %xmm1
movsd -0xd8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0x28(%rbp), %rsi
movsd -0xc8(%rbp), %xmm0
movsd -0xd0(%rbp), %xmm1
movsd -0xd8(%rbp), %xmm2
leaq -0xf0(%rbp), %rdi
callq 0x97360
jmp 0x8298a
leaq -0xf0(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x220(%rbp)
jmp 0x829a1
movq -0x220(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x230(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xfcc0
movsd -0x230(%rbp), %xmm0
movsd 0x18(%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
leaq -0xf0(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x228(%rbp)
jmp 0x829fb
movq -0x228(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x240(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xfcc0
movsd -0x240(%rbp), %xmm0
movsd 0x20(%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
leaq -0xf0(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x238(%rbp)
jmp 0x82a55
movq -0x238(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x248(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xfcc0
movsd -0x248(%rbp), %xmm0
movsd 0x28(%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x108(%rbp)
movq -0x28(%rbp), %rsi
movsd -0xf8(%rbp), %xmm0
movsd -0x100(%rbp), %xmm1
movsd -0x108(%rbp), %xmm2
leaq -0x120(%rbp), %rdi
callq 0x97170
jmp 0x82abf
movq -0x10(%rbp), %rdi
addq $0x990, %rdi            # imm = 0x990
movq -0x110(%rbp), %rax
movq %rax, -0x130(%rbp)
movups -0x120(%rbp), %xmm0
movaps %xmm0, -0x140(%rbp)
movl -0x44(%rbp), %esi
movq -0x130(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movaps -0x140(%rbp), %xmm0
movups %xmm0, (%rax)
callq 0xffe10
movw %ax, -0x24a(%rbp)
jmp 0x82b0f
movw -0x24a(%rbp), %ax
movw %ax, -0x122(%rbp)
movb -0x122(%rbp), %al
andb $0x1, %al
movb %al, -0xa6(%rbp)
movb -0x121(%rbp), %al
andb $0x1, %al
movb %al, -0xa5(%rbp)
movq -0x10(%rbp), %rdi
addq $0x990, %rdi            # imm = 0x990
callq 0x84bb0
movb %al, -0x24b(%rbp)
jmp 0x82b51
movb -0x24b(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x82bc6
movl -0xa4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x82bc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x6d(%rbp), %rdi
callq 0x13030
jmp 0x832c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x9d(%rbp), %rdi
callq 0x13030
jmp 0x831c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xec80
jmp 0x831c2
movb -0xa6(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x82bea
movb -0x29(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x82bea
movb $0x0, -0xa5(%rbp)
movq -0x10(%rbp), %rdi
addq $0x990, %rdi            # imm = 0x990
callq 0x84bb0
movb %al, -0x24c(%rbp)
jmp 0x82c02
movb -0x24c(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x82dd8
testb $0x1, -0xa6(%rbp)
jne 0x82dd8
movsd -0xf8(%rbp), %xmm0
movsd -0x100(%rbp), %xmm1
movsd -0x108(%rbp), %xmm2
leaq -0x158(%rbp), %rdi
callq 0xe9c70
jmp 0x82c49
movq -0x28(%rbp), %rsi
movq -0x148(%rbp), %rax
movq %rax, -0x180(%rbp)
movups -0x158(%rbp), %xmm0
movaps %xmm0, -0x190(%rbp)
movq -0x180(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movaps -0x190(%rbp), %xmm0
movups %xmm0, (%rax)
leaq -0x170(%rbp), %rdi
callq 0x97e90
jmp 0x82c8f
testb $0x1, -0xa5(%rbp)
je 0x82d3c
movl -0x4c(%rbp), %eax
incl %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
addq $0xd90, %rdi            # imm = 0xD90
leaq -0x170(%rbp), %rsi
callq 0x59bf0
jmp 0x82cbd
movq -0x10(%rbp), %rdi
addq $0x990, %rdi            # imm = 0x990
callq 0x84c20
movq %rax, -0x258(%rbp)
jmp 0x82cd6
movq -0x258(%rbp), %rax
movq %rax, -0x198(%rbp)
cmpl $-0x1, -0x198(%rbp)
je 0x82d04
movq 0x1f02cc(%rip), %rdi    # 0x272fc0
leaq 0x173a25(%rip), %rsi    # 0x1f6720
callq 0x5540
jmp 0x82d02
jmp 0x82d1e
movslq -0x194(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0xed60
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
addq $0xda8, %rdi            # imm = 0xDA8
leaq -0x194(%rbp), %rsi
callq 0xd1b0
jmp 0x82d37
jmp 0x82dd6
movq -0x10(%rbp), %rdi
addq $0xd60, %rdi            # imm = 0xD60
leaq -0x170(%rbp), %rsi
callq 0x59bf0
jmp 0x82d55
movl -0x48(%rbp), %eax
incl %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
addq $0x990, %rdi            # imm = 0x990
callq 0x84c20
movq %rax, -0x260(%rbp)
jmp 0x82d76
movq -0x260(%rbp), %rax
movq %rax, -0x1a0(%rbp)
cmpl $-0x1, -0x19c(%rbp)
je 0x82da4
movq 0x1f022c(%rip), %rdi    # 0x272fc0
leaq 0x1739c3(%rip), %rsi    # 0x1f675e
callq 0x5540
jmp 0x82da2
jmp 0x82dbb
movslq -0x1a0(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0xed60
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
addq $0xd78, %rdi            # imm = 0xD78
leaq -0x1a0(%rbp), %rsi
callq 0xd1b0
jmp 0x82dd4
jmp 0x82dd6
jmp 0x82dd8
jmp 0x82dda
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x827a8
cvtsi2sdl -0x48(%rbp), %xmm0
cvtsi2sdl -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x173824(%rip), %xmm1   # 0x1f6628
mulsd %xmm1, %xmm0
movsd 0x173820(%rip), %xmm1   # 0x1f6630
mulsd %xmm1, %xmm0
movsd %xmm0, -0x270(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xf090
movq %rax, -0x268(%rbp)
jmp 0x82e39
movq -0x268(%rbp), %rax
movsd 0x30(%rax), %xmm0
movsd -0x18(%rbp), %xmm1
addsd %xmm1, %xmm0
movl $0x2, %edi
callq 0x850c0
movsd %xmm0, -0x278(%rbp)
jmp 0x82e62
movsd -0x278(%rbp), %xmm1
movsd -0x270(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x1a8(%rbp)
cvtsi2sdl -0x4c(%rbp), %xmm0
cvtsi2sdl -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x173794(%rip), %xmm1   # 0x1f6628
mulsd %xmm1, %xmm0
movsd 0x173790(%rip), %xmm1   # 0x1f6630
mulsd %xmm1, %xmm0
movsd %xmm0, -0x288(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xf090
movq %rax, -0x280(%rbp)
jmp 0x82ec9
movq -0x280(%rbp), %rax
movsd 0x30(%rax), %xmm0
movsd -0x18(%rbp), %xmm1
addsd %xmm1, %xmm0
movl $0x2, %edi
callq 0x850c0
movsd %xmm0, -0x290(%rbp)
jmp 0x82ef2
movsd -0x290(%rbp), %xmm1
movsd -0x288(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x1b0(%rbp)
movsd -0x1a8(%rbp), %xmm0
movq -0x10(%rbp), %rax
addsd 0xd50(%rax), %xmm0
movsd %xmm0, 0xd50(%rax)
movsd -0x1b0(%rbp), %xmm0
movq -0x10(%rbp), %rax
addsd 0xd58(%rax), %xmm0
movsd %xmm0, 0xd58(%rax)
movl $0x0, -0x1b4(%rbp)
movl -0x1b4(%rbp), %eax
movq %rax, -0x298(%rbp)
movq -0x10(%rbp), %rdi
addq $0xdc0, %rdi            # imm = 0xDC0
callq 0xf990
movq %rax, %rcx
movq -0x298(%rbp), %rax
cmpq %rcx, %rax
jae 0x83050
movl -0x1b4(%rbp), %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
callq 0xed60
cvtsi2sdl (%rax), %xmm0
cvtsi2sdl -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x173682(%rip), %xmm1   # 0x1f6628
mulsd %xmm1, %xmm0
movsd 0x17367e(%rip), %xmm1   # 0x1f6630
mulsd %xmm1, %xmm0
movsd %xmm0, -0x2a8(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xf090
movq %rax, -0x2a0(%rbp)
jmp 0x82fdb
movq -0x2a0(%rbp), %rax
movsd 0x30(%rax), %xmm0
movsd -0x18(%rbp), %xmm1
addsd %xmm1, %xmm0
movl $0x2, %edi
callq 0x850c0
movsd %xmm0, -0x2b0(%rbp)
jmp 0x83004
movq -0x10(%rbp), %rdi
addq $0xdc0, %rdi            # imm = 0xDC0
movl -0x1b4(%rbp), %eax
movl %eax, %esi
callq 0xedb0
movsd -0x2a8(%rbp), %xmm0
movsd -0x2b0(%rbp), %xmm2
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl -0x1b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b4(%rbp)
jmp 0x82f50
movl $0x0, -0x1b8(%rbp)
movl -0x1b8(%rbp), %eax
movq %rax, -0x2b8(%rbp)
movq -0x10(%rbp), %rdi
addq $0xdd8, %rdi            # imm = 0xDD8
callq 0xf990
movq %rax, %rcx
movq -0x2b8(%rbp), %rax
cmpq %rcx, %rax
jae 0x8315d
movl -0x1b8(%rbp), %eax
movl %eax, %esi
leaq -0x98(%rbp), %rdi
callq 0xed60
cvtsi2sdl (%rax), %xmm0
cvtsi2sdl -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x173575(%rip), %xmm1   # 0x1f6628
mulsd %xmm1, %xmm0
movsd 0x173571(%rip), %xmm1   # 0x1f6630
mulsd %xmm1, %xmm0
movsd %xmm0, -0x2c8(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x44(%rbp), %rsi
callq 0xf090
movq %rax, -0x2c0(%rbp)
jmp 0x830e8
movq -0x2c0(%rbp), %rax
movsd 0x30(%rax), %xmm0
movsd -0x18(%rbp), %xmm1
addsd %xmm1, %xmm0
movl $0x2, %edi
callq 0x850c0
movsd %xmm0, -0x2d0(%rbp)
jmp 0x83111
movq -0x10(%rbp), %rdi
addq $0xdd8, %rdi            # imm = 0xDD8
movl -0x1b8(%rbp), %eax
movl %eax, %esi
callq 0xedb0
movsd -0x2c8(%rbp), %xmm0
movsd -0x2d0(%rbp), %xmm2
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl -0x1b8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b8(%rbp)
jmp 0x8305a
movq -0x10(%rbp), %rax
addq $0xdf0, %rax            # imm = 0xDF0
movq %rax, -0x2d8(%rbp)
leaq -0x1c8(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x1b0(%rbp), %rdx
callq 0x85120
jmp 0x8318a
movq -0x2d8(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x850f0
jmp 0x8319f
leaq -0x98(%rbp), %rdi
callq 0xec80
leaq -0x68(%rbp), %rdi
callq 0xec80
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x82653
leaq -0x68(%rbp), %rdi
callq 0xec80
jmp 0x832c0
movq 0x1efde9(%rip), %rdi    # 0x272fc0
leaq 0x173e8f(%rip), %rsi    # 0x1f706d
callq 0x5540
movq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0xd48(%rax), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x176426(%rip), %rsi    # 0x1f9625
callq 0x5540
movq -0x10(%rbp), %rdi
addq $0x990, %rdi            # imm = 0x990
callq 0x84db0
movl %eax, -0x1cc(%rbp)
cmpl $0x0, -0x1cc(%rbp)
je 0x832a1
movq 0x1efdc6(%rip), %rdi    # 0x272ff0
leaq 0x1763f4(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, %rdi
leaq 0x1763e5(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, %rdi
leaq 0x17354f(%rip), %rsi    # 0x1f679e
callq 0x5540
movq %rax, %rdi
movl -0x1cc(%rbp), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x173546(%rip), %rsi    # 0x1f67b2
callq 0x5540
movq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0xd48(%rax), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x176398(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, %rdi
leaq 0x176389(%rip), %rsi    # 0x1f9625
callq 0x5540
movq -0x10(%rbp), %rax
movsd 0xd50(%rax), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x58f0
nopl (%rax)