// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/area_and_volume.cc
// Function: calcASA(ATOM_NETWORK*, ATOM_NETWORK*, bool, double, double, double, int, bool, std::ostream&, char*, bool, bool, bool, bool)
double calcASA(ATOM_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){

  ATOM_NETWORK *atmnet; // pointed to the analyzed (original atomsnet)

  if(highAccuracy) atmnet=orgatmnet; else atmnet = hiaccatmnet; // this ensures that the loops below loop over original atoms
                                                                // and not "high-acuracy" clusters, which are used only for
                                                                // voronoi decomposition

  // Create an object that handles analysis of accessibility of sampled points
  AccessibilityClass accessAnalysis;
  if(highAccuracy) accessAnalysis.setupAndFindChannels(hiaccatmnet, orgatmnet, highAccuracy, r_probe_chan, r_probe);
    else accessAnalysis.setupAndFindChannels(hiaccatmnet, hiaccatmnet, highAccuracy, r_probe_chan, r_probe);

  accessAnalysis.removeOverlappedNodes();

  srand(randSeed);

  vector<Point> axsPoints   = vector<Point> (); // List of accessible points to be visualized in ZeoVis
  vector<int> axsPointsChannelIDs;  // corresponding channel IDs
  vector<Point> inaxsPoints = vector<Point> (); // List of inaccessible points to be visualized in ZeoVis
  vector<int> inaxsPointsPocketIDs; // corresponding pocket IDs
  double totalSA = 0;
  double totalSA_inaxs = 0;

  vector<double> totalSA_inChannel(accessAnalysis.n_channels,0);
  vector<double> totalSA_inPocket(accessAnalysis.n_pockets,0);

  //vectors that store SA contributions per atom (a pair of accessible and inaccessible)
  vector< pair <double,double> > histogramSAperAtom;

  // 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(accessAnalysis.n_channels,0);
    vector<int> count_inPocket(accessAnalysis.n_pockets,0);

    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 = (accessAnalysis.isSPointInsideAtomAndNotAccessible(samplingPoint, i));
      inside = answer.first; overlaps = answer.second;
      if(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(accessAnalysis.needToResample() == false && !inside) {
	Point abcCoords = Point(newAPoint, newBPoint, newCPoint);
	Point coords = atmnet->abc_to_xyz(atmnet->shiftABCInUC(abcCoords));
	if(overlaps)
          {
          count_inaxs++;
	  inaxsPoints.push_back(coords);
          pair <int,int> CoP = accessAnalysis.lastChannelOrPocket();
          if(CoP.first!=-1)
            {
            cout << "Error: CoP.first!=-1 in pocket, consult source code provider\n";
            } else {
            count_inPocket[CoP.second]++;
            };
          inaxsPointsPocketIDs.push_back(CoP.second);
          }
	else
          {
	  axsPoints.push_back(coords);
          count++;
          pair <int,int> CoP = accessAnalysis.lastChannelOrPocket();
          if(CoP.second!=-1)
            {
            cout << "Error: CoP.second!=-1 in channel, consult source code provider\n";
            } else {
            count_inChannel[CoP.first]++;
            };
          axsPointsChannelIDs.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
    totalSA += SAperAtom;
    //and inaccessible
    totalSA_inaxs += SAperAtom_inaxs;

    // SA per channel and pocket
    for(unsigned int m = 0; m < totalSA_inChannel.size(); m++)
      {
      totalSA_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 < totalSA_inPocket.size(); m++)
      {
      totalSA_inPocket[m] += (1.0*count_inPocket[m])/numSamples * 4.0 * PI * pow((atmnet->atoms.at(i).radius + r_probe),2);
      };

    histogramSAperAtom.push_back(pair <double,double> (SAperAtom,SAperAtom_inaxs));

  }

  // Write the necessary commands to the output stream
  // necessary to visualize the sampling
  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);
  }


  double ucVolume    = calcDeterminant(atmnet->ucVectors);   
  double saPerVolume = (totalSA/ucVolume)*pow(10.0,4.0); // Units of m^2/cm^3
  double saPerMass   = saPerVolume/rho_crystal;          // Units of m^2/g

  double saPerVolume_inaxs = (totalSA_inaxs/ucVolume)*pow(10.0,4.0); // Units of m^2/cm^3
  double saPerMass_inaxs   = saPerVolume_inaxs/rho_crystal;          // Units of m^2/g

  if(!visualize){
//    output << newAtomNet.name << " ";
    output << "@ " << filename << " ";
    output << "Unitcell_volume: " << ucVolume << "   Density: " << rho_crystal << "   ";
    output << "ASA_A^2: " << totalSA << " "
	   << "ASA_m^2/cm^3: " << saPerVolume << " "
	   << "ASA_m^2/g: " << saPerMass << " "
           << "NASA_A^2: " << totalSA_inaxs << " "
           << "NASA_m^2/cm^3: " << saPerVolume_inaxs << " "
           << "NASA_m^2/g: " << saPerMass_inaxs << "\n";
  }

  // Surface composition histogram
  if(!visualize&&ExtendedOutputFlag){
    double metalFrac = 0, metalFrac_inaxs = 0;

    for(int i = 0; i < atmnet->numAtoms; i++)
       {
       if(isMetal(atmnet->atoms[i].type) == true) 
         {
         metalFrac+= histogramSAperAtom.at(i).first;
         metalFrac_inaxs += histogramSAperAtom.at(i).second;
         };
       };

    metalFrac = metalFrac / totalSA;
    if(totalSA == 0) metalFrac=0;
    metalFrac_inaxs = metalFrac_inaxs / totalSA_inaxs;
    if(totalSA_inaxs == 0) metalFrac_inaxs =0;

    output << "# " << filename << " Metal fraction in ASA and NASA: " << metalFrac << "   " << metalFrac_inaxs << "\n";
  };

  // extended output
  if(!visualize){
    output << "Number_of_channels: " << totalSA_inChannel.size()  << " Channel_surface_area_A^2: ";
    for(unsigned int i = 0; i < totalSA_inChannel.size(); i++)
      {
      output << totalSA_inChannel[i] << "  ";
      };
    output << "\nNumber_of_pockets: " << totalSA_inPocket.size()  << " Pocket_surface_area_A^2: ";
    for(unsigned int i = 0; i < totalSA_inPocket.size(); i++)
      {
      output << totalSA_inPocket[i] << "  ";
      };
    output << "\n";
    };

    
    // Warn user if points were resampled
  int resampleCount =  accessAnalysis.getResampleCount();
  if(resampleCount != 0){
    cerr << "\n" << "\n"
  	 << "Warning: Resampled " << resampleCount << " points out of " << atmnet->numAtoms*numSamples 
	 << "\n" << "\n"; 
  }
  accessAnalysis.deconstruct();
  return totalSA;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd48, %rsp            # imm = 0xD48
movq %r9, 0xa0(%rsp)
movl %r8d, 0xc4(%rsp)
movl %ecx, 0x54(%rsp)
movsd %xmm2, 0xa8(%rsp)
movsd %xmm1, 0x40(%rsp)
movsd %xmm0, 0x30(%rsp)
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
testl %edx, %edx
cmoveq %rdi, %r14
leaq 0x308(%rsp), %r12
movq %r12, %rdi
callq 0x36c02
movq %r12, %rdi
movq %r15, %rsi
movq %r14, 0x20(%rsp)
movq %r14, %rdx
movl %ebx, %ecx
movsd 0x30(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
callq 0x6e3ac
leaq 0x308(%rsp), %rdi
callq 0x6e72e
movl $0x3b4ca6f5, %edi       # imm = 0x3B4CA6F5
callq 0x4460
xorpd %xmm0, %xmm0
movapd %xmm0, 0x130(%rsp)
andq $0x0, 0x140(%rsp)
movapd %xmm0, 0x1b0(%rsp)
andq $0x0, 0x1c0(%rsp)
movapd %xmm0, 0x110(%rsp)
andq $0x0, 0x120(%rsp)
movapd %xmm0, 0x190(%rsp)
andq $0x0, 0x1a0(%rsp)
movslq 0xc90(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0xf8(%rsp), %rdi
leaq 0x170(%rsp), %rcx
callq 0x2a2b4
movslq 0xc94(%rsp), %rsi
leaq 0x170(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0xc8(%rsp), %rdi
leaq 0xe0(%rsp), %rcx
callq 0x2a2b4
xorpd %xmm0, %xmm0
leaq 0x170(%rsp), %rax
andq $0x0, 0x10(%rax)
movapd %xmm0, (%rax)
movq 0x20(%rsp), %rax
leaq 0x2f0(%rax), %r13
cvtsi2sdl 0x54(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
xorl %r12d, %r12d
leaq 0xe0(%rsp), %r14
movsd %xmm0, 0x58(%rsp)
movq %r13, 0x148(%rsp)
movq 0x20(%rsp), %rax
movslq 0x110(%rax), %rax
cmpq %rax, %r12
jge 0x34f85
movslq 0xc90(%rsp), %rsi
andl $0x0, 0x80(%rsp)
movq %r14, %rdi
leaq 0x80(%rsp), %rbx
movq %rbx, %rdx
leaq 0x158(%rsp), %r14
movq %r14, %rcx
callq 0x2a44a
movslq 0xc94(%rsp), %rsi
andl $0x0, 0x158(%rsp)
movq %rbx, %rdi
movq %r14, %rdx
leaq 0x288(%rsp), %rcx
callq 0x2a44a
xorl %r13d, %r13d
imulq $0x98, %r12, %rbx
movl $0x0, 0x70(%rsp)
movl $0x0, 0x74(%rsp)
movq %rbx, 0x150(%rsp)
cmpl 0x54(%rsp), %r13d
jge 0x34d67
callq 0x4170
cvtsi2sd %eax, %xmm0
divsd 0xcbb60(%rip), %xmm0    # 0x100580
addsd %xmm0, %xmm0
mulsd 0xcbb84(%rip), %xmm0    # 0x1005b0
movsd %xmm0, 0x30(%rsp)
callq 0x4170
cvtsi2sd %eax, %xmm0
divsd 0xcbb75(%rip), %xmm0    # 0x1005b8
addsd %xmm0, %xmm0
addsd 0xc7609(%rip), %xmm0    # 0xfc058
movsd %xmm0, 0x28(%rsp)
callq 0x4450
movsd %xmm0, 0xb0(%rsp)
callq 0x4110
movsd %xmm0, 0x68(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x47e0
mulsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0xb0(%rsp), %xmm0
callq 0x4110
movsd %xmm0, 0xb0(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x4110
movsd 0xb0(%rsp), %xmm1
mulsd %xmm0, %xmm1
movq 0x20(%rsp), %rsi
movq 0x2f0(%rsi), %rax
movsd 0x30(%rax,%rbx), %xmm2
addsd 0x40(%rsp), %xmm2
movsd 0x68(%rsp), %xmm0
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
mulsd 0x28(%rsp), %xmm2
leaq 0x158(%rsp), %r15
movq %r15, %rdi
callq 0x3f1ce
movq %r15, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movq 0x148(%rsp), %rbx
movq (%rbx), %rax
movq 0x150(%rsp), %r14
addsd 0x18(%rax,%r14), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r15, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movq (%rbx), %rax
addsd 0x20(%rax,%r14), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r15, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm2
movq 0x20(%rsp), %rsi
movq 0x2f0(%rsi), %rax
addsd 0x28(%rax,%r14), %xmm2
leaq 0x288(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd %xmm2, 0x68(%rsp)
callq 0x3f0e6
movq 0x298(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x288(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %r12, %rsi
leaq 0x308(%rsp), %r12
movq %r12, %rdi
movq %rsi, %r14
callq 0x6f142
movl %eax, %ebx
movq %r12, %rdi
callq 0x36d64
movl %eax, %ebp
movl %ebx, %eax
shrl $0x8, %eax
andl $0x1, %eax
movl 0xc4(%rsp), %ecx
andb %al, %cl
testb $0x1, %bl
movzbl %cl, %r15d
cmovnel %eax, %r15d
movq %r12, %rdi
callq 0x36d64
orb %bl, %al
testb $0x1, %al
je 0x34bed
movq %r14, %r12
jmp 0x34d4e
leaq 0x2d0(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x68(%rsp), %xmm2
callq 0x63c46
leaq 0x308(%rsp), %rbx
movq %r14, %r12
movq 0x2e0(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x2d0(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x2a0(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x3f94a
movq 0x2b0(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x2a0(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x2b8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x3e536
testb %r15b, %r15b
je 0x34cb1
leaq 0x110(%rsp), %rdi
leaq 0x2b8(%rsp), %rsi
callq 0x2468e
movq %rbx, %rdi
callq 0x36da8
movq %rax, 0xb8(%rsp)
cmpl $-0x1, %eax
jne 0x34cf4
sarq $0x20, %rax
movq 0x80(%rsp), %rcx
incl (%rcx,%rax,4)
jmp 0x34d07
leaq 0x130(%rsp), %rdi
leaq 0x2b8(%rsp), %rsi
callq 0x2468e
movq %rbx, %rdi
callq 0x36da8
movq %rax, 0xb8(%rsp)
movabsq $-0x100000001, %rcx     # imm = 0xFFFFFFFEFFFFFFFF
cmpq %rcx, %rax
jbe 0x34d22
movq 0xe0(%rsp), %rcx
cltq
incl (%rcx,%rax,4)
jmp 0x34d35
movq 0x11b2c5(%rip), %rdi    # 0x14ffc0
leaq 0xcb9be(%rip), %rsi     # 0x1006c0
callq 0x4480
leaq 0x190(%rsp), %rdi
leaq 0xbc(%rsp), %rsi
callq 0x9434
incl 0x70(%rsp)
jmp 0x34d4e
movq 0x11b297(%rip), %rdi    # 0x14ffc0
leaq 0xcb9ce(%rip), %rsi     # 0x1006fe
callq 0x4480
leaq 0x1b0(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x9434
incl 0x74(%rsp)
movzbl %bpl, %eax
negl %eax
addl %eax, %r13d
incl %r13d
movq 0x150(%rsp), %rbx
jmp 0x34a04
movq 0x148(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xa73a
cvtsi2sdl 0x74(%rsp), %xmm1
divsd 0x78(%rsp), %xmm1
movsd 0xcb81a(%rip), %xmm0    # 0x1005a8
mulsd %xmm0, %xmm1
movsd 0xcb816(%rip), %xmm0    # 0x1005b0
mulsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movsd 0x30(%rax), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0xa73a
leaq 0xe0(%rsp), %r14
movsd 0x28(%rsp), %xmm1
mulsd %xmm1, %xmm1
cvtsi2sdl 0x70(%rsp), %xmm0
movsd 0x30(%rsp), %xmm2
mulsd %xmm1, %xmm2
divsd 0x78(%rsp), %xmm0
mulsd 0xcb7b8(%rip), %xmm0    # 0x1005a8
mulsd 0xcb7b8(%rip), %xmm0    # 0x1005b0
movsd 0x30(%rax), %xmm1
addsd 0x40(%rsp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm1
movsd 0x58(%rsp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x60(%rsp), %xmm0
movsd %xmm1, 0x28(%rsp)
addsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
xorl %ecx, %ecx
movq 0xf8(%rsp), %rax
movapd %xmm2, %xmm0
movsd %xmm2, 0x30(%rsp)
movl %ecx, %ebx
movq 0x100(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
jbe 0x34ebb
movq 0xe0(%rsp), %rax
movl (%rax,%rbx,4), %ebp
movq %r13, %rdi
movq %r12, %rsi
callq 0xa73a
cvtsi2sd %ebp, %xmm0
divsd 0x78(%rsp), %xmm0
mulsd 0xcb725(%rip), %xmm0    # 0x1005a8
mulsd 0xcb725(%rip), %xmm0    # 0x1005b0
movsd 0x30(%rax), %xmm1
addsd 0x40(%rsp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm1
movq 0xf8(%rsp), %rax
addsd (%rax,%rbx,8), %xmm1
movsd %xmm1, (%rax,%rbx,8)
leal 0x1(%rbx), %ecx
movsd 0x30(%rsp), %xmm0
jmp 0x34e45
xorl %ecx, %ecx
movq 0xc8(%rsp), %rax
movl %ecx, %ebx
movq 0xd0(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
jbe 0x34f3b
movq 0x80(%rsp), %rax
movl (%rax,%rbx,4), %ebp
movq %r13, %rdi
movq %r12, %rsi
callq 0xa73a
cvtsi2sd %ebp, %xmm0
divsd 0x78(%rsp), %xmm0
mulsd 0xcb6a5(%rip), %xmm0    # 0x1005a8
mulsd 0xcb6a5(%rip), %xmm0    # 0x1005b0
movsd 0x30(%rax), %xmm1
addsd 0x40(%rsp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm1
movq 0xc8(%rsp), %rax
addsd (%rax,%rbx,8), %xmm1
movsd %xmm1, (%rax,%rbx,8)
leal 0x1(%rbx), %ecx
movsd 0x30(%rsp), %xmm0
jmp 0x34ec5
movsd %xmm0, 0x158(%rsp)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x160(%rsp)
leaq 0x170(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x375ec
leaq 0x80(%rsp), %rdi
callq 0xb290
movq %r14, %rdi
callq 0xb290
incq %r12
jmp 0x3497c
movb 0xd88(%rsp), %bl
testb %bl, %bl
movq 0xa0(%rsp), %r15
je 0x35240
cmpb $0x0, 0xd90(%rsp)
je 0x35047
cmpb $0x0, 0xd98(%rsp)
je 0x350a3
xorpd %xmm0, %xmm0
leaq 0xe0(%rsp), %rbx
andq $0x0, 0x10(%rbx)
movapd %xmm0, (%rbx)
andq $0x0, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
xorl %r12d, %r12d
pushq $0x18
popq %r14
leaq 0x158(%rsp), %r15
movl %r12d, %r12d
movq 0x130(%rsp), %rcx
movq 0x138(%rsp), %rax
subq %rcx, %rax
cqto
idivq %r14
cmpq %r12, %rax
jbe 0x350ff
imulq $0x18, %r12, %rax
movq 0x10(%rcx,%rax), %rdx
movq %rdx, 0x10(%rsp)
movupd (%rcx,%rax), %xmm0
movupd %xmm0, (%rsp)
movq %r15, %rdi
movq 0x20(%rsp), %rsi
callq 0x3e4c8
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2468e
incl %r12d
jmp 0x34fee
leaq 0x270(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0xa66e
leaq 0x258(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0xa66e
leaq 0x270(%rsp), %rsi
leaq 0x258(%rsp), %rdx
movq %r15, %rdi
callq 0x2e1f5
leaq 0x258(%rsp), %rdi
callq 0xb83e
leaq 0x270(%rsp), %rdi
jmp 0x3523b
leaq 0x240(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0xa66e
leaq 0x228(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0xa66e
leaq 0x240(%rsp), %rsi
leaq 0x228(%rsp), %rdx
movq %r15, %rdi
callq 0x2e5b9
leaq 0x228(%rsp), %rdi
callq 0xb83e
leaq 0x240(%rsp), %rdi
jmp 0x3523b
xorl %r12d, %r12d
leaq 0x158(%rsp), %rbx
leaq 0x80(%rsp), %r15
movl %r12d, %r12d
movq 0x110(%rsp), %rcx
movq 0x118(%rsp), %rax
subq %rcx, %rax
cqto
idivq %r14
cmpq %r12, %rax
jbe 0x35167
imulq $0x18, %r12, %rax
movq 0x10(%rcx,%rax), %rdx
movq %rdx, 0x10(%rsp)
movupd (%rcx,%rax), %xmm0
movupd %xmm0, (%rsp)
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x3e4c8
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2468e
incl %r12d
jmp 0x35112
leaq 0x210(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0xa66e
leaq 0x1f8(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0xa6ce
movq 0xa0(%rsp), %r15
movb 0xd88(%rsp), %bl
leaq 0x1e0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xa66e
leaq 0x1c8(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0xa6ce
leaq 0x210(%rsp), %rsi
leaq 0x1f8(%rsp), %rdx
leaq 0x1e0(%rsp), %rcx
leaq 0x1c8(%rsp), %r8
movq %r15, %rdi
callq 0x2e77d
leaq 0x1c8(%rsp), %rdi
callq 0xb290
leaq 0x1e0(%rsp), %rdi
callq 0xb83e
leaq 0x1f8(%rsp), %rdi
callq 0xb290
leaq 0x210(%rsp), %rdi
callq 0xb83e
leaq 0x80(%rsp), %rdi
callq 0xb83e
leaq 0xe0(%rsp), %rdi
callq 0xb83e
movq 0x20(%rsp), %rax
leaq 0x80(%rax), %rdi
callq 0x63835
movsd %xmm0, 0x40(%rsp)
testb %bl, %bl
jne 0x35687
leaq 0xce9d7(%rip), %rsi     # 0x103c3d
movq %r15, %rdi
callq 0x4480
movq %rax, %rdi
movq 0xd80(%rsp), %rsi
callq 0x4480
leaq 0xcf28d(%rip), %rsi     # 0x104512
movq %rax, %rdi
callq 0x4480
leaq 0xcb58e(%rip), %rsi     # 0x100822
movq %r15, %rdi
callq 0x4480
movq %rax, %rdi
movsd 0x40(%rsp), %xmm0
callq 0x46c0
leaq 0xcb583(%rip), %rsi     # 0x100834
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movsd 0xa8(%rsp), %xmm0
callq 0x46c0
leaq 0xc71fd(%rip), %rsi     # 0xfc4ce
movq %rax, %rdi
callq 0x4480
leaq 0xcbc7e(%rip), %rsi     # 0x100f5e
movq %r15, %rdi
callq 0x4480
movq %rax, %rdi
movsd 0x58(%rsp), %xmm0
callq 0x46c0
leaq 0xcf215(%rip), %rsi     # 0x104512
movq %rax, %rdi
callq 0x4480
leaq 0xcbc5d(%rip), %rsi     # 0x100f69
movq %rax, %rdi
callq 0x4480
movsd 0x58(%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
mulsd 0xcb278(%rip), %xmm0    # 0x1005a0
movq %rax, %rdi
movsd %xmm0, 0x30(%rsp)
callq 0x46c0
leaq 0xcf1d5(%rip), %rsi     # 0x104512
movq %rax, %rdi
callq 0x4480
leaq 0xcbc2d(%rip), %rsi     # 0x100f79
movq %rax, %rdi
callq 0x4480
movsd 0x30(%rsp), %xmm0
divsd 0xa8(%rsp), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xcf1a0(%rip), %rsi     # 0x104512
movq %rax, %rdi
callq 0x4480
leaq 0xcbbdc(%rip), %rsi     # 0x100f5d
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movsd 0x60(%rsp), %xmm0
callq 0x46c0
leaq 0xcf174(%rip), %rsi     # 0x104512
movq %rax, %rdi
callq 0x4480
leaq 0xcbbbb(%rip), %rsi     # 0x100f68
movq %rax, %rdi
callq 0x4480
movsd 0x60(%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
mulsd 0xcb1d7(%rip), %xmm0    # 0x1005a0
movq %rax, %rdi
movsd %xmm0, 0x40(%rsp)
callq 0x46c0
leaq 0xcf134(%rip), %rsi     # 0x104512
movq %rax, %rdi
callq 0x4480
leaq 0xcbb8b(%rip), %rsi     # 0x100f78
movq %rax, %rdi
callq 0x4480
movsd 0x40(%rsp), %xmm0
divsd 0xa8(%rsp), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xcd16b(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
cmpb $0x0, 0xda0(%rsp)
je 0x35576
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
pushq $0x40
popq %r14
xorl %ebx, %ebx
leaq 0x2e8(%rsp), %r15
leaq 0x170(%rsp), %r12
movapd %xmm0, 0x30(%rsp)
movq 0x20(%rsp), %rax
movslq 0x110(%rax), %rax
cmpq %rax, %rbx
jge 0x354d8
movq (%r13), %rsi
addq %r14, %rsi
movq %r15, %rdi
callq 0x45d0
movq %r15, %rdi
callq 0x1b62f
movl %eax, %ebp
movq %r15, %rdi
callq 0x4210
testb %bpl, %bpl
je 0x354c9
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3711a
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3711a
movapd 0x40(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
movapd %xmm0, 0x40(%rsp)
movapd 0x30(%rsp), %xmm0
addsd 0x8(%rax), %xmm0
movapd %xmm0, 0x30(%rsp)
incq %rbx
addq $0x98, %r14
jmp 0x3544f
leaq 0xcbaa6(%rip), %rsi     # 0x100f85
movq 0xa0(%rsp), %r15
movq %r15, %rdi
callq 0x4480
movq %rax, %rdi
movq 0xd80(%rsp), %rsi
callq 0x4480
leaq 0xcba82(%rip), %rsi     # 0x100f88
movq %rax, %rdi
callq 0x4480
movsd 0x58(%rsp), %xmm0
movapd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
cmpeqsd %xmm2, %xmm0
andnpd %xmm1, %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xc6f94(%rip), %rsi     # 0xfc4ce
movq %rax, %rdi
callq 0x4480
movsd 0x60(%rsp), %xmm2
movapd 0x30(%rsp), %xmm1
divsd %xmm2, %xmm1
xorpd %xmm0, %xmm0
cmpeqsd %xmm2, %xmm0
andnpd %xmm1, %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xcd010(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xcb2f8(%rip), %rsi     # 0x100875
movq %r15, %rdi
callq 0x4480
movq 0x100(%rsp), %rsi
subq 0xf8(%rsp), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x42e0
leaq 0xcba02(%rip), %rsi     # 0x100faa
movq %rax, %rdi
callq 0x4480
xorl %r14d, %r14d
leaq 0xc6f15(%rip), %rbx     # 0xfc4cf
movl %r14d, %r14d
movq 0xf8(%rsp), %rax
movq 0x100(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jbe 0x355f7
movsd (%rax,%r14,8), %xmm0
movq %r15, %rdi
callq 0x46c0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
incl %r14d
jmp 0x355ba
leaq 0xcb2a2(%rip), %rsi     # 0x1008a0
movq %r15, %rdi
callq 0x4480
movq 0xd0(%rsp), %rsi
subq 0xc8(%rsp), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x42e0
leaq 0xcb99d(%rip), %rsi     # 0x100fc6
movq %rax, %rdi
callq 0x4480
xorl %r14d, %r14d
leaq 0xc6e94(%rip), %rbx     # 0xfc4cf
movl %r14d, %r14d
movq 0xc8(%rsp), %rax
movq 0xd0(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jbe 0x35678
movsd (%rax,%r14,8), %xmm0
movq %r15, %rdi
callq 0x46c0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
incl %r14d
jmp 0x3563b
leaq 0xcceff(%rip), %rsi     # 0x10257e
movq %r15, %rdi
callq 0x4480
movl 0xd40(%rsp), %ebx
testl %ebx, %ebx
je 0x35716
movq 0x11a953(%rip), %rdi    # 0x14fff0
leaq 0xcceda(%rip), %rsi     # 0x10257e
callq 0x4480
leaq 0xccece(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xcb07f(%rip), %rsi     # 0x10073e
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movl %ebx, %esi
callq 0x4760
leaq 0xcb07a(%rip), %rsi     # 0x100752
movq %rax, %rdi
callq 0x4480
movl 0x54(%rsp), %esi
movq 0x20(%rsp), %rcx
imull 0x110(%rcx), %esi
movq %rax, %rdi
callq 0x4760
leaq 0xcce7f(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xcce70(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x308(%rsp), %rbx
movq %rbx, %rdi
callq 0x36e7a
leaq 0x170(%rsp), %rdi
callq 0x371ec
leaq 0xc8(%rsp), %rdi
callq 0xb25c
leaq 0xf8(%rsp), %rdi
callq 0xb25c
leaq 0x190(%rsp), %rdi
callq 0xb290
leaq 0x110(%rsp), %rdi
callq 0xb83e
leaq 0x1b0(%rsp), %rdi
callq 0xb290
leaq 0x130(%rsp), %rdi
callq 0xb83e
movq %rbx, %rdi
callq 0x36e9e
movsd 0x58(%rsp), %xmm0
addq $0xd48, %rsp            # imm = 0xD48
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
callq 0xb290
jmp 0x357b6
movq %rax, %rbx
leaq 0x1e0(%rsp), %rdi
callq 0xb83e
jmp 0x357c8
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0xb290
jmp 0x357da
movq %rax, %rbx
leaq 0x210(%rsp), %rdi
callq 0xb83e
jmp 0x35860
jmp 0x3585d
movq %rax, %rbx
leaq 0x228(%rsp), %rdi
callq 0xb83e
jmp 0x35800
movq %rax, %rbx
leaq 0x240(%rsp), %rdi
jmp 0x35875
movq %rax, %rbx
leaq 0x258(%rsp), %rdi
callq 0xb83e
jmp 0x3581f
movq %rax, %rbx
leaq 0x270(%rsp), %rdi
jmp 0x35875
jmp 0x3588f
jmp 0x3588f
movq %rax, %rbx
jmp 0x358e1
movq %rax, %rbx
jmp 0x358ee
jmp 0x3588f
movq %rax, %rbx
jmp 0x35922
jmp 0x3588f
movq %rax, %rbx
leaq 0x2e8(%rsp), %rdi
callq 0x4210
jmp 0x358c7
jmp 0x3585d
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xb83e
leaq 0xe0(%rsp), %rdi
callq 0xb83e
jmp 0x358c7
jmp 0x3588f
jmp 0x3588f
jmp 0x358aa
jmp 0x358aa
jmp 0x358aa
jmp 0x3588f
jmp 0x3588f
movq %rax, %rbx
jmp 0x358ba
movq %rax, %rbx
jmp 0x358c7
jmp 0x358aa
jmp 0x358aa
jmp 0x358aa
jmp 0x358aa
jmp 0x358aa
jmp 0x358aa
jmp 0x358aa
jmp 0x358aa
jmp 0x358aa
jmp 0x358aa
jmp 0x358aa
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xb290
leaq 0xe0(%rsp), %rdi
callq 0xb290
leaq 0x170(%rsp), %rdi
callq 0x371ec
leaq 0xc8(%rsp), %rdi
callq 0xb25c
leaq 0xf8(%rsp), %rdi
callq 0xb25c
leaq 0x190(%rsp), %rdi
callq 0xb290
leaq 0x110(%rsp), %rdi
callq 0xb83e
leaq 0x1b0(%rsp), %rdi
callq 0xb290
leaq 0x130(%rsp), %rdi
callq 0xb83e
leaq 0x308(%rsp), %rdi
callq 0x36e9e
movq %rbx, %rdi
callq 0x4780