// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
cmpb $0x0, 0xb1d(%rdi)
je 0x479b8
movl %esi, %ebp
movq %rdi, %rbx
movsd %xmm0, 0x50(%rsp)
movsd %xmm0, 0xd40(%rdi)
movq 0x990(%rdi), %r14
movl $0x3b4ca6f5, %edi       # imm = 0x3B4CA6F5
callq 0x4410
movq 0xd60(%rbx), %rax
cmpq %rax, 0xd68(%rbx)
je 0x470c6
movq %rax, 0xd68(%rbx)
movq 0xd78(%rbx), %rax
cmpq %rax, 0xd80(%rbx)
je 0x470dd
movq %rax, 0xd80(%rbx)
movq 0xd90(%rbx), %rax
cmpq %rax, 0xd98(%rbx)
je 0x470f4
movq %rax, 0xd98(%rbx)
movq 0xda8(%rbx), %rax
cmpq %rax, 0xdb0(%rbx)
je 0x4710b
movq %rax, 0xdb0(%rbx)
movl $0x0, 0xd48(%rbx)
leaq 0xdc0(%rbx), %rdi
xorpd %xmm0, %xmm0
movupd %xmm0, 0xd50(%rbx)
movq 0xdc0(%rbx), %rax
cmpq %rax, 0xdc8(%rbx)
je 0x4713f
movq %rax, 0xdc8(%rbx)
movslq 0xa68(%rbx), %rsi
leaq 0x70(%rsp), %rdx
movq $0x0, (%rdx)
callq 0x48ca6
leaq 0xdd8(%rbx), %rdi
movq 0xdd8(%rbx), %rax
cmpq %rax, 0xde0(%rbx)
je 0x47175
movq %rax, 0xde0(%rbx)
movslq 0xa6c(%rbx), %rsi
leaq 0x70(%rsp), %rdx
movq $0x0, (%rdx)
callq 0x48ca6
movq 0xdf0(%rbx), %rax
cmpq %rax, 0xdf8(%rbx)
je 0x471a4
movq %rax, 0xdf8(%rbx)
cmpl $0x0, 0x110(%r14)
jle 0x478ca
leaq 0x990(%rbx), %r15
leaq 0xd60(%rbx), %rax
movq %rax, 0x100(%rsp)
leaq 0xd78(%rbx), %rax
movq %rax, 0xf0(%rsp)
leaq 0xd90(%rbx), %rax
movq %rax, 0xf8(%rsp)
leaq 0xda8(%rbx), %rax
movq %rax, 0xe8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0xe0(%rsp)
leaq 0xdf0(%rbx), %rax
movq %rax, 0xd8(%rsp)
leaq 0xa0(%rsp), %rcx
xorl %r12d, %r12d
movq %rbx, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movslq 0xa68(%rbx), %rsi
xorl %r12d, %r12d
movl %r12d, 0x88(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x88(%rsp), %r13
movq %r13, %rdx
movq %rcx, %rbp
callq 0x3864a
movslq 0xa6c(%rbx), %rsi
movl %r12d, 0xa0(%rsp)
movq %r13, %rdi
movq %rbp, %rdx
leaq 0x108(%rsp), %rcx
callq 0x3864a
movq 0x2f0(%r14), %rax
movq 0x2f8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x79435e50d79435e5, %rcx # imm = 0x86BCA1AF286BCA1B
imulq %rcx, %rdx
movq 0x20(%rsp), %rsi
cmpq %rsi, %rdx
movsd 0x50(%rsp), %xmm4
jbe 0x479e5
imulq $0x98, %rsi, %r13
movsd 0x30(%rax,%r13), %xmm0
addsd %xmm4, %xmm0
mulsd %xmm0, %xmm0
mulsd 0x10a366(%rip), %xmm0   # 0x151630
mulsd 0xe0(%rsp), %xmm0
cvttsd2si %xmm0, %ecx
addl %ecx, 0xd48(%rbx)
movl %ecx, 0x44(%rsp)
testl %ecx, %ecx
jle 0x4770c
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
xorl %ebx, %ebx
callq 0x4150
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x10a2e7(%rip), %xmm0   # 0x1515f0
addsd %xmm0, %xmm0
mulsd 0x10a2fb(%rip), %xmm0   # 0x151610
movsd %xmm0, 0x30(%rsp)
callq 0x4150
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x10a2e9(%rip), %xmm0   # 0x151618
addsd %xmm0, %xmm0
addsd 0x105d1d(%rip), %xmm0   # 0x14d058
movsd %xmm0, 0x48(%rsp)
callq 0x4400
movsd %xmm0, 0x58(%rsp)
callq 0x4100
movsd %xmm0, 0x28(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x4800
mulsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x58(%rsp), %xmm0
callq 0x4100
movsd %xmm0, 0x58(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x4100
movsd 0x58(%rsp), %xmm1
mulsd %xmm0, %xmm1
movq 0x2f0(%r14), %rax
movsd 0x30(%rax,%r13), %xmm2
addsd 0x50(%rsp), %xmm2
movsd 0x28(%rsp), %xmm0
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
mulsd 0x48(%rsp), %xmm2
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x52eec
movq %r12, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movq 0x2f0(%r14), %rax
addsd 0x18(%rax,%r13), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r12, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movq 0x2f0(%r14), %rax
addsd 0x20(%rax,%r13), %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r12, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm2
movq 0x2f0(%r14), %rax
addsd 0x28(%rax,%r13), %xmm2
leaq 0x108(%rsp), %rdi
movq %r14, %rsi
movsd 0x30(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd %xmm2, 0x28(%rsp)
callq 0x52d94
movq 0x118(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x108(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq 0x20(%rsp), %rsi
callq 0x95c96
movl %eax, %r12d
movq %r15, %rdi
callq 0x48a72
movl %eax, %ebp
movq %r15, %rdi
callq 0x48a72
orb %r12b, %al
testb $0x1, %al
jne 0x476c2
leaq 0x120(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
callq 0x83f68
movq 0x130(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x120(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0xc0(%rsp), %rdi
movq %r14, %rsi
callq 0x53a92
btl $0x8, %r12d
jb 0x47526
movq 0x18(%rsp), %rcx
movq 0xd68(%rcx), %rsi
cmpq 0xd70(%rcx), %rsi
je 0x47565
movq 0xd0(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0xc0(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0xd68(%rcx)
jmp 0x4757a
movq 0x18(%rsp), %rcx
movq 0xd98(%rcx), %rsi
cmpq 0xda0(%rcx), %rsi
je 0x475e9
movq 0xd0(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0xc0(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0xd98(%rcx)
jmp 0x475fe
movq 0x100(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x2fec4
movq %r15, %rdi
callq 0x48aea
movq %rax, 0x38(%rsp)
movabsq $-0x100000001, %rcx     # imm = 0xFFFFFFFEFFFFFFFF
cmpq %rcx, %rax
jbe 0x475a2
movq 0x70(%rsp), %rcx
cltq
incl (%rcx,%rax,4)
jmp 0x475ba
movl $0x3f, %edx
movq 0x14da12(%rip), %rdi    # 0x194fc0
leaq 0x10a1d9(%rip), %rsi    # 0x15178e
callq 0x44e0
movq 0x18(%rsp), %rcx
movq 0xd80(%rcx), %rsi
cmpq 0xd88(%rcx), %rsi
je 0x47661
movl 0x38(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xd80(%rcx)
jmp 0x47673
movq 0xf8(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x2fec4
movq %r15, %rdi
callq 0x48aea
movq %rax, 0x38(%rsp)
cmpl $-0x1, %eax
jne 0x47621
sarq $0x20, %rax
movq 0x88(%rsp), %rcx
incl (%rcx,%rax,4)
jmp 0x47639
movl $0x3d, %edx
movq 0x14d993(%rip), %rdi    # 0x194fc0
leaq 0x10a11c(%rip), %rsi    # 0x151750
callq 0x44e0
movq 0x18(%rsp), %rcx
movq 0xdb0(%rcx), %rsi
cmpq 0xdb8(%rcx), %rsi
je 0x4768e
movl 0x3c(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xdb0(%rcx)
jmp 0x476a0
movq 0xf0(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xf864
movdqa 0x60(%rsp), %xmm1
movd %xmm1, %eax
incl %eax
movd %eax, %xmm0
movss %xmm0, %xmm1            # xmm1 = xmm0[0],xmm1[1,2,3]
movaps %xmm1, 0x60(%rsp)
jmp 0x476c2
movq 0xe8(%rsp), %rdi
leaq 0x3c(%rsp), %rdx
callq 0xf864
movdqa 0x60(%rsp), %xmm1
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
movd %xmm0, %eax
incl %eax
movd %eax, %xmm0
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
shufps $0xe2, %xmm1, %xmm0     # xmm0 = xmm0[2,0],xmm1[2,3]
movaps %xmm0, 0x60(%rsp)
movzbl %bpl, %eax
negl %eax
addl %eax, %ebx
incl %ebx
cmpl 0x44(%rsp), %ebx
jl 0x472f5
movq 0x2f0(%r14), %rax
movq 0x2f8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x79435e50d79435e5, %rcx # imm = 0x86BCA1AF286BCA1B
imulq %rcx, %rdx
cvtdq2pd 0x60(%rsp), %xmm2
movq 0x18(%rsp), %rbx
movsd 0x50(%rsp), %xmm4
jmp 0x47710
xorpd %xmm2, %xmm2
cmpq 0x20(%rsp), %rdx
jbe 0x479f3
xorps %xmm0, %xmm0
cvtsi2sdl 0x44(%rsp), %xmm0
movq 0xdc8(%rbx), %rcx
movq 0xdc0(%rbx), %rdx
movapd %xmm0, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
divpd %xmm1, %xmm2
leaq 0x30(%rax,%r13), %rax
movsd (%rax), %xmm1
addsd %xmm4, %xmm1
mulsd %xmm1, %xmm1
mulpd 0x109ef9(%rip), %xmm2   # 0x151650
mulpd 0x109f01(%rip), %xmm2   # 0x151660
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm2, %xmm1
movupd 0xd50(%rbx), %xmm2
addpd %xmm1, %xmm2
movupd %xmm2, 0xd50(%rbx)
subq %rdx, %rcx
movsd 0x109e8a(%rip), %xmm5   # 0x151610
movsd 0x109e92(%rip), %xmm6   # 0x151620
je 0x477d4
sarq $0x3, %rcx
movq 0x70(%rsp), %rsi
xorl %edi, %edi
xorps %xmm2, %xmm2
cvtsi2sdl (%rsi,%rdi,4), %xmm2
divsd %xmm0, %xmm2
mulsd %xmm6, %xmm2
mulsd %xmm5, %xmm2
movsd (%rax), %xmm3
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm2, %xmm3
addsd (%rdx,%rdi,8), %xmm3
movsd %xmm3, (%rdx,%rdi,8)
incq %rdi
movl %edi, %r8d
cmpq %r8, %rcx
ja 0x4779b
movq 0xdd8(%rbx), %rcx
movq 0xde0(%rbx), %rdx
subq %rcx, %rdx
movq 0x20(%rsp), %r12
je 0x47833
sarq $0x3, %rdx
movq 0x88(%rsp), %rsi
xorl %edi, %edi
xorps %xmm2, %xmm2
cvtsi2sdl (%rsi,%rdi,4), %xmm2
divsd %xmm0, %xmm2
mulsd %xmm6, %xmm2
mulsd %xmm5, %xmm2
movsd (%rax), %xmm3
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm2, %xmm3
addsd (%rcx,%rdi,8), %xmm3
movsd %xmm3, (%rcx,%rdi,8)
incq %rdi
movl %edi, %r8d
cmpq %r8, %rdx
ja 0x477fa
movapd %xmm1, 0xa0(%rsp)
movq 0xdf8(%rbx), %rsi
cmpq 0xe00(%rbx), %rsi
je 0x47863
movapd 0xa0(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0xdf8(%rbx)
jmp 0x47878
movq 0xd8(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x49446
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x47895
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x478af
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incq %r12
movslq 0x110(%r14), %rax
cmpq %rax, %r12
leaq 0xa0(%rsp), %rcx
jl 0x47224
leaq 0xd50(%rbx), %r12
movq 0x14d6e8(%rip), %r14    # 0x194fc0
leaq 0x10a792(%rip), %rsi    # 0x152071
movl $0x21, %edx
movq %r14, %rdi
callq 0x44e0
movl 0xd48(%rbx), %esi
movq %r14, %rdi
callq 0x4750
leaq 0x10bd1d(%rip), %rsi    # 0x15361e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movl 0xb18(%rbx), %ebp
testl %ebp, %ebp
je 0x479b0
movq 0x14d6cd(%rip), %r15    # 0x194ff0
leaq 0x10bcf4(%rip), %r14    # 0x15361e
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x44e0
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x44e0
leaq 0x109e7d(%rip), %rsi    # 0x1517ce
movl $0x13, %edx
movq %r15, %rdi
callq 0x44e0
movq %r15, %rdi
movl %ebp, %esi
callq 0x4750
movq %rax, %r15
leaq 0x109e70(%rip), %rsi    # 0x1517e2
movl $0xf, %edx
movq %rax, %rdi
callq 0x44e0
movl 0xd48(%rbx), %esi
movq %r15, %rdi
callq 0x4750
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x44e0
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x44e0
movsd (%r12), %xmm0
jmp 0x479d3
movq 0x14d631(%rip), %rdi    # 0x194ff0
leaq 0x10a0b2(%rip), %rsi    # 0x151a78
movl $0x4e, %edx
callq 0x44e0
xorps %xmm0, %xmm0
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x105d09(%rip), %rdi    # 0x14d6f5
xorl %eax, %eax
callq 0x4630
leaq 0x105cfb(%rip), %rdi    # 0x14d6f5
movq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x47a23
jmp 0x47a23
movq %rax, %rbx
jmp 0x47a43
jmp 0x47a23
jmp 0x47a23
jmp 0x47a23
jmp 0x47a23
jmp 0x47a23
jmp 0x47a23
jmp 0x47a23
jmp 0x47a23
jmp 0x47a23
jmp 0x47a23
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x47a43
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x47a5d
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780