// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/networkanalysis.cc
// Function: identifyCages(ATOM_NETWORK*, VORONOI_NETWORK*, DIJKSTRA_NETWORK*, double, bool, std::basic_fstream<char, std::char_traits<char>>&, std::vector<CAGE, std::allocator<CAGE>>&)
void identifyCages(ATOM_NETWORK *atmnet, VORONOI_NETWORK *vornet, DIJKSTRA_NETWORK *dnet, double probeRadius, bool visualize, fstream &output, vector<CAGE> &cages) {
  vector<bool> nodeProcessed = vector<bool>(dnet->nodes.size(), false);
  vector<double> bestRadii   = vector<double>(dnet->nodes.size(), -1);
  unsigned int nodeIndex = 0;

  double maxRadius = 0.0;
  DELTA_POS filter(1,1,1);

  // Iterate over all nodes
  while(nodeIndex < nodeProcessed.size()){
   
    // Place starting node on stack with (0,0,0) displacement
    DELTA_POS displacement(0,0,0);
    map<int, pair<DELTA_POS, double> > visitedNodes;
    
    HEAP<pair<int, pair<DELTA_POS, double> > > heap (betterPath);
    heap.insert(pair<int, pair<DELTA_POS, double> > (nodeIndex, pair<DELTA_POS, double> (displacement, dnet->nodes[nodeIndex].max_radius)));
  
    while(heap.size() != 0){
      // Remove best remaining path
      pair<int, pair<DELTA_POS, double> > pathInfo = heap.pop();
      map<int, pair<DELTA_POS, double> >::iterator nodeInfo = visitedNodes.find(pathInfo.first);
      
      // Ending on a preprocessed node
      if(pathInfo.first == -1){
	bestRadii[nodeIndex] = pathInfo.second.second;
	break;
      }

      if(nodeInfo != visitedNodes.end()){
	if(nodeInfo->second.first.equals(pathInfo.second.first)){
	  // Circling back to previous node so terminate path
	  continue;
	}
	else {
	  // Found the optimal path through the start node
	  bestRadii[nodeIndex] = min(pathInfo.second.second, nodeInfo->second.second);
	  maxRadius = max(maxRadius, bestRadii[nodeIndex]);
	  break;
	}
      }
      else{
	visitedNodes.insert(pathInfo);
	DIJKSTRA_NODE currentNode = dnet->nodes[pathInfo.first];
	vector<CONN>::iterator connIter = currentNode.connections.begin();
	// Follow all edges leading to adjoining nodes
      
	while(connIter != currentNode.connections.end()){
	  int to = connIter->to;
	  if(nodeProcessed[to]){
	    // Know the best radii for this path because the next node has already been processed
	    // Change the path's node id to -1 to denote this
	    heap.insert(pair<int, pair<DELTA_POS, double> > (-1, pair<DELTA_POS, double> (DELTA_POS(0,0,0), min(connIter->max_radius, min(pathInfo.second.second, bestRadii[to])))));
	  }
	  else{
	    DELTA_POS newDisplacement = pathInfo.second.first + (connIter->deltaPos*filter);
	    heap.insert(pair<int, pair<DELTA_POS, double> > (to, pair<DELTA_POS, double> (newDisplacement, 
											  min(dnet->nodes[to].max_radius, min(pathInfo.second.second, connIter->max_radius)))));
	  }
	  connIter++;
	}
      }
    }
    nodeProcessed[nodeIndex] = true;
    nodeIndex++;
  }

  double CUTOFF_RATIO = 0.8; 

  // Identify nodes that satisfy cage criteria
  set<int> cageElements;
  for(unsigned int i = 0; i < vornet->nodes.size(); i++){
    double ratio = bestRadii[i]/(dnet->nodes[i].max_radius);
    if(ratio < CUTOFF_RATIO && bestRadii[i] > probeRadius) {
      cageElements.insert(i);
    }
  }
  
  // Calculate node overlaps
  vector< vector<double> > overlapFractions = calculateNodeOverlap(atmnet, vornet);

  // Cluster nodes in cages
  vector< set<int> > clusters = clusterElements(cageElements, overlapFractions, 0.1);


  //vector<CAGE> cages;
  for(unsigned int i = 0; i < clusters.size(); i++){
    cages.push_back(CAGE(clusters[i], atmnet, vornet));
  }

  if(visualize){
    output << "set num_cages " << clusters.size() << "\n";
    for(unsigned int i = 0; i < cages.size(); i++){
      cages[i].writeToVMD(i, output);
    }
  }
  else{
    vector<double> cageRadii;
    for(unsigned int i = 0; i < cages.size(); i++){
      cageRadii.push_back(cages[i].getRadius());
    }

     sort(cageRadii.begin(), cageRadii.end());
    
    vector<int> counts;
    vector<double> radii;
    double prevRad = -1, tolerance = 0.001;
    int numCageTypes = 0;
    for(unsigned int i = 0; i < cageRadii.size(); i++){
      if(abs(cageRadii[i] - prevRad) < tolerance)
	counts[numCageTypes - 1]++;
      else{
	counts.push_back(1); radii.push_back(cageRadii[i]);
	prevRad = cageRadii[i];	numCageTypes++;
      }
    }

    double totalCageAV = 0;
    output << "Note: Probe radius is subtracted from cage radius" << "\n";
    for(unsigned int i = 0; i < counts.size(); i++){
      output << counts[i] << " cage(s) of radius " << radii[i] - probeRadius << "\n";
      totalCageAV += calcSphereVolume(radii[i] - probeRadius)*counts[i];
    }
    output << "Total Cage AV: " << totalCageAV << " A^3" << "\n";
    double volumeFraction = totalCageAV/calcDeterminant(atmnet->ucVectors);
    double rho_crystal    = calcDensity(atmnet);
    double cageAVPerMass  = volumeFraction/rho_crystal;
    output << "Total Cage AV/Mass: " << cageAVPerMass << " cm^3/g" <<  "\n";
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movq %r9, 0x68(%rsp)
movq %r8, 0x108(%rsp)
movl %ecx, 0xd0(%rsp)
movsd %xmm0, 0xc8(%rsp)
movq %rdx, %r15
movq %rsi, 0x78(%rsp)
movq %rdi, %r12
movq 0x8(%rdx), %rsi
subq (%rdx), %rsi
sarq $0x3, %rsi
movabsq $-0x71c71c71c71c71c7, %r14 # imm = 0x8E38E38E38E38E39
imulq %r14, %rsi
leaq 0x130(%rsp), %rbx
movb $0x0, (%rbx)
leaq 0x1b8(%rsp), %rdi
leaq 0xd8(%rsp), %rcx
movq %rbx, %rdx
callq 0x37f36
movq 0x8(%r15), %rsi
movq %r15, 0x28(%rsp)
subq (%r15), %rsi
sarq $0x3, %rsi
imulq %r14, %rsi
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, (%rbx)
leaq 0x118(%rsp), %rdi
leaq 0x130(%rsp), %rdx
leaq 0xd8(%rsp), %rcx
callq 0x38220
leaq 0x21c(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x506b0
movq 0x1c8(%rsp), %rax
movl 0x1d0(%rsp), %ecx
subq 0x1b8(%rsp), %rax
shlq $0x3, %rax
addq %rcx, %rax
movq %r12, 0x110(%rsp)
je 0x369bf
leaq 0x230(%rsp), %r15
leaq 0xa0(%rsp), %rbx
leaq 0x80(%rsp), %r14
movq $0x0, 0x48(%rsp)
movl $0x0, 0x70(%rsp)
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x506b0
movl $0x0, 0xe0(%rsp)
xorl %eax, %eax
movq %rax, 0xe8(%rsp)
leaq 0xe0(%rsp), %r12
movq %r12, 0xf0(%rsp)
movq %r12, 0xf8(%rsp)
movq %rax, 0x100(%rsp)
leaq -0x1942(%rip), %rcx     # 0x34bf7
movq %rcx, 0xb8(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xa0(%rsp)
movq %rax, 0xb0(%rsp)
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x48(%rsp), %rcx
leaq (%rcx,%rcx,8), %rcx
movl 0x38(%rsp), %edx
movl %edx, 0x138(%rsp)
movq 0x30(%rsp), %rdx
movq %rdx, 0x130(%rsp)
movsd 0x38(%rax,%rcx,8), %xmm0
movl 0x70(%rsp), %eax
movl %eax, 0x248(%rsp)
movq 0x130(%rsp), %rax
leaq 0x250(%rsp), %rcx
movq %rax, (%rcx)
movl 0x138(%rsp), %eax
movl %eax, 0x8(%rcx)
movl 0x13c(%rsp), %eax
movl %eax, 0xc(%rcx)
movsd %xmm0, 0x260(%rsp)
movupd 0x248(%rsp), %xmm0
movupd 0x258(%rsp), %xmm1
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x38342
movq 0xa0(%rsp), %rdi
movq 0xa8(%rsp), %rax
subq %rdi, %rax
movabsq $0x1fffffffe0, %rcx     # imm = 0x1FFFFFFFE0
testq %rcx, %rax
je 0x36940
movq %r14, %rdi
movq %rbx, %rsi
callq 0x38468
movq 0xe8(%rsp), %r8
movl 0x80(%rsp), %eax
testq %r8, %r8
je 0x3666c
movq %r12, %rsi
movq %r12, %r9
movq %rsi, %rcx
movq %r8, %rdx
movl 0x20(%r8), %edi
xorl %r8d, %r8d
cmpl %eax, %edi
setl %r8b
movq %rdx, %rsi
cmovlq %rcx, %rsi
movq 0x10(%rdx,%r8,8), %r8
testq %r8, %r8
jne 0x36630
movq %r9, %r12
cmpq %r9, %rsi
je 0x3666c
cmpl %eax, %edi
cmovlq %rcx, %rdx
cmpl 0x20(%rdx), %eax
cmovlq %r9, %rsi
movq %rsi, %r12
cmpl $-0x1, %eax
je 0x3690b
leaq 0xe0(%rsp), %rax
cmpq %rax, %r12
je 0x366a8
leaq 0x28(%r12), %rdi
movq 0x88(%rsp), %rsi
movl 0x90(%rsp), %edx
callq 0x506ba
testb %al, %al
jne 0x368db
jmp 0x36916
leaq 0xd8(%rsp), %rdi
movq %r14, %rsi
callq 0x3b1ba
movq %r15, %rbp
movq %rbx, %r15
movq %r14, %rbx
movslq 0x80(%rsp), %rax
movq 0x28(%rsp), %rcx
movq (%rcx), %r12
leaq (%rax,%rax,8), %r13
leaq 0x20(%r12,%r13,8), %rsi
movupd -0x20(%rsi), %xmm0
movupd -0x10(%rsi), %xmm1
movapd %xmm0, 0x130(%rsp)
movapd %xmm1, 0x140(%rsp)
leaq 0x150(%rsp), %r14
movq %r14, %rdi
callq 0x37e9e
leaq (%r12,%r13,8), %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%r14)
movq 0x38(%rax), %rax
movq %rax, 0x18(%r14)
movq 0x150(%rsp), %r12
cmpq 0x158(%rsp), %r12
je 0x368ba
addq $0x18, %r12
movq %rbx, %r14
movq %r15, %rbx
movq %rbp, %r15
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
movslq -0x14(%r12), %r13
leal 0x3f(%r13), %eax
testq %r13, %r13
cmovnsl %r13d, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq 0x1b8(%rsp), %rax
leaq 0x3f(%rbp), %rcx
andq %r13, %rcx
xorl %edx, %edx
cmpq %rbp, %rcx
setbe %dl
movq -0x8(%rax,%rdx,8), %rax
btq %r13, %rax
jae 0x367fd
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x506b0
movq 0x118(%rsp), %rax
movsd (%rax,%r13,8), %xmm0
minsd 0x98(%rsp), %xmm0
movl 0x58(%rsp), %eax
minsd -0x8(%r12), %xmm0
movl %eax, 0x8(%r15)
movq 0x50(%rsp), %rax
movq %rax, (%r15)
movl $0xffffffff, 0x228(%rsp) # imm = 0xFFFFFFFF
movsd %xmm0, 0x240(%rsp)
movupd 0x228(%rsp), %xmm0
movupd 0x238(%rsp), %xmm1
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x38342
jmp 0x36896
movq %r12, %rdi
leaq 0x21c(%rsp), %rsi
callq 0x506ec
movq %rax, 0x50(%rsp)
movl %edx, 0x58(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x50708
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
leaq (,%r13,8), %rsi
addq %r13, %rsi
movsd -0x8(%r12), %xmm0
minsd 0x98(%rsp), %xmm0
minsd 0x38(%rcx,%rsi,8), %xmm0
movl %r13d, 0x1e0(%rsp)
movq %rax, 0x1e8(%rsp)
movl %edx, 0x1f0(%rsp)
movsd %xmm0, 0x1f8(%rsp)
movupd 0x1e0(%rsp), %xmm0
movupd 0x1f0(%rsp), %xmm1
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x38342
leaq 0x28(%r12), %rax
addq $0x10, %r12
cmpq 0x158(%rsp), %r12
movq %rax, %r12
jne 0x36746
movq 0x150(%rsp), %r12
jmp 0x368c3
movq %rbx, %r14
movq %r15, %rbx
movq %rbp, %r15
testq %r12, %r12
je 0x368db
movq 0x160(%rsp), %rsi
subq %r12, %rsi
movq %r12, %rdi
callq 0x4470
movq 0xa0(%rsp), %rdi
movq 0xa8(%rsp), %rax
subq %rdi, %rax
movabsq $0x1fffffffe0, %rcx     # imm = 0x1FFFFFFFE0
testq %rcx, %rax
leaq 0xe0(%rsp), %r12
jne 0x3660b
jmp 0x36940
movsd 0x98(%rsp), %xmm0
jmp 0x36926
movsd 0x38(%r12), %xmm0
minsd 0x98(%rsp), %xmm0
movq 0x118(%rsp), %rax
movq 0x48(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0xa0(%rsp), %rdi
movq 0x1b8(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
movl $0x1, %esi
shlq %cl, %rsi
orq %rsi, (%rax,%rdx,8)
testq %rdi, %rdi
je 0x36975
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl 0x70(%rsp), %ebp
incl %ebp
leaq 0xd8(%rsp), %rdi
callq 0x3906e
movl %ebp, 0x70(%rsp)
movl %ebp, %edx
movq 0x1c8(%rsp), %rax
movl 0x1d0(%rsp), %ecx
subq 0x1b8(%rsp), %rax
leaq (%rcx,%rax,8), %rax
movq %rdx, 0x48(%rsp)
cmpq %rdx, %rax
movq 0x110(%rsp), %r12
ja 0x364ed
leaq 0xe0(%rsp), %rax
movl $0x0, (%rax)
xorl %r15d, %r15d
movq %r15, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %r15, 0x20(%rax)
movq 0x78(%rsp), %rcx
movq 0x48(%rcx), %rax
movq 0x50(%rcx), %rcx
cmpq %rax, %rcx
je 0x36a6d
leaq 0xd8(%rsp), %rbx
leaq 0x130(%rsp), %r14
movq 0x118(%rsp), %rdx
movsd (%rdx,%r15,8), %xmm0
ucomisd 0xc8(%rsp), %xmm0
jbe 0x36a5b
movq 0x28(%rsp), %rdx
movq (%rdx), %rdx
leaq (%r15,%r15,8), %rsi
divsd 0x38(%rdx,%rsi,8), %xmm0
movsd 0x11a923(%rip), %xmm1   # 0x151358
ucomisd %xmm0, %xmm1
jbe 0x36a5b
movl %r15d, 0x130(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3b882
movq 0x78(%rsp), %rcx
movq 0x48(%rcx), %rax
movq 0x50(%rcx), %rcx
incl %r15d
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r15, %rdx
ja 0x36a02
leaq 0xa0(%rsp), %rdi
movq %r12, %rsi
movq 0x78(%rsp), %rdx
callq 0x352ce
leaq 0x268(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x11100
leaq 0x200(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xef4c
leaq 0x80(%rsp), %rdi
leaq 0x268(%rsp), %rsi
leaq 0x200(%rsp), %rdx
movsd 0x11659c(%rip), %xmm0   # 0x14d068
callq 0x355d4
leaq 0x200(%rsp), %rdi
callq 0xefe6
leaq 0x268(%rsp), %rdi
callq 0xf206
movq 0x80(%rsp), %rax
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
cmpq %rax, 0x88(%rsp)
je 0x36bc7
movl $0x1, %ebp
xorl %ecx, %ecx
leaq 0x298(%rsp), %rbx
leaq 0x130(%rsp), %r14
leaq (%rcx,%rcx,2), %rsi
shlq $0x4, %rsi
addq %rax, %rsi
movq %rbx, %rdi
callq 0x11100
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq 0x78(%rsp), %rcx
callq 0x360ae
movq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x3b92c
movq 0x178(%rsp), %rdi
testq %rdi, %rdi
je 0x36b72
movq 0x188(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x36b8f
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %r14, %rdi
callq 0xf1b6
movq %rbx, %rdi
callq 0xf206
movl %ebp, %ecx
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r15, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x36b22
cmpb $0x0, 0xd0(%rsp)
je 0x36c72
movq 0x108(%rsp), %r14
leaq 0x10(%r14), %rbx
leaq 0x11a901(%rip), %rsi    # 0x1514e9
movl $0xe, %edx
movq %rbx, %rdi
callq 0x44e0
movq 0x88(%rsp), %rsi
subq 0x80(%rsp), %rsi
sarq $0x4, %rsi
imulq %r15, %rsi
movq %rbx, %rdi
callq 0x42b0
leaq 0x11ca02(%rip), %rsi    # 0x15361e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x68(%rsp), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x370b1
xorl %edi, %edi
xorl %ebx, %ebx
shlq $0x7, %rdi
addq %rax, %rdi
movl %ebx, %esi
movq %r14, %rdx
callq 0x36244
incl %ebx
movq 0x68(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x7, %rcx
movq %rbx, %rdi
cmpq %rbx, %rcx
ja 0x36c3f
jmp 0x370b1
xorpd %xmm0, %xmm0
movapd %xmm0, 0x130(%rsp)
movq $0x0, 0x140(%rsp)
movq 0x68(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
cmpq %rax, %rcx
je 0x36e70
movl $0x1, %ebp
xorl %edx, %edx
leaq 0x130(%rsp), %rbx
leaq 0x30(%rsp), %r14
shlq $0x7, %rdx
movsd 0x78(%rax,%rdx), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x138(%rsp), %rsi
cmpq 0x140(%rsp), %rsi
je 0x36ce8
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x138(%rsp)
jmp 0x36cff
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1391c
movq 0x68(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movl %ebp, %edx
movq %rcx, %rsi
subq %rax, %rsi
sarq $0x7, %rsi
incl %ebp
cmpq %rdx, %rsi
ja 0x36cb4
movq 0x130(%rsp), %rbx
movq 0x138(%rsp), %r13
cmpq %r13, %rbx
je 0x36d64
movq %r13, %rax
subq %rbx, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3bc39
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3bd32
movq 0x130(%rsp), %rbx
movq 0x138(%rsp), %r13
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
xorl %ebp, %ebp
movq %rbp, 0x40(%rsp)
movq %rbp, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
cmpq %rbx, %r13
je 0x36e88
movsd 0x11a5cf(%rip), %xmm0   # 0x151360
movl $0x1, %r14d
leaq 0x50(%rsp), %r12
xorl %r15d, %r15d
movsd (%rbx,%r15,8), %xmm1
subsd %xmm0, %xmm1
andpd 0x1162ef(%rip), %xmm1   # 0x14d0a0
movsd 0x11628f(%rip), %xmm2   # 0x14d048
ucomisd %xmm1, %xmm2
jbe 0x36dd0
movq 0x30(%rsp), %rax
movslq %ebp, %rcx
incl -0x4(%rax,%rcx,4)
jmp 0x36e55
movl $0x1, 0xd4(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x36df8
movl $0x1, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x36e12
leaq 0x30(%rsp), %rdi
leaq 0xd4(%rsp), %rdx
callq 0x14198
movq 0x130(%rsp), %rbx
leaq (%rbx,%r15,8), %rdx
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x36e35
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x58(%rsp)
jmp 0x36e4b
movq %r12, %rdi
callq 0x1481e
movq 0x130(%rsp), %rbx
movsd (%rbx,%r15,8), %xmm0
incl %ebp
movq 0x138(%rsp), %r13
movl %r14d, %r15d
movq %r13, %rax
subq %rbx, %rax
sarq $0x3, %rax
incl %r14d
cmpq %r15, %rax
ja 0x36d9f
jmp 0x36e88
movapd %xmm0, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %rax, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movq 0x108(%rsp), %r13
addq $0x10, %r13
leaq 0x11a65d(%rip), %rsi    # 0x1514f8
movl $0x31, %edx
movq %r13, %rdi
callq 0x44e0
leaq 0x11c76f(%rip), %rsi    # 0x15361e
movl $0x1, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x36f8e
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
movl $0x1, %ebp
xorl %r12d, %r12d
leaq 0x11a645(%rip), %rbx    # 0x15152a
leaq 0x11c732(%rip), %r14    # 0x15361e
movl (%rax,%r12,4), %esi
movq %r13, %rdi
callq 0x4750
movq %rax, %r15
movl $0x13, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x44e0
movq 0x50(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
subsd 0xc8(%rsp), %xmm0
movq %r15, %rdi
callq 0x46b0
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x44e0
movq 0x50(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
subsd 0xc8(%rsp), %xmm0
callq 0x84ca6
movq 0x30(%rsp), %rax
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%r12,4), %xmm1
movq 0x38(%rsp), %rcx
mulsd %xmm1, %xmm0
movsd 0x28(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movl %ebp, %r12d
subq %rax, %rcx
sarq $0x2, %rcx
incl %ebp
cmpq %r12, %rcx
ja 0x36eec
jmp 0x36f98
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x11a59f(%rip), %rsi    # 0x15153e
movl $0xf, %edx
movq %r13, %rdi
callq 0x44e0
movq %r13, %rdi
movsd 0x28(%rsp), %xmm0
callq 0x46b0
movq %rax, %rbx
leaq 0x11a58a(%rip), %rsi    # 0x15154e
movl $0x4, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0x11c646(%rip), %rsi    # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
movq 0x110(%rsp), %rbx
leaq 0x80(%rbx), %rdi
callq 0x83b30
movsd %xmm0, 0x48(%rsp)
movq %rbx, %rdi
callq 0x3c5a8
movsd %xmm0, 0x70(%rsp)
leaq 0x11a53f(%rip), %rsi    # 0x151553
movl $0x14, %edx
movq %r13, %rdi
callq 0x44e0
movsd 0x28(%rsp), %xmm0
divsd 0x48(%rsp), %xmm0
divsd 0x70(%rsp), %xmm0
movq %r13, %rdi
callq 0x46b0
movq %rax, %rbx
leaq 0x11a523(%rip), %rsi    # 0x151568
movl $0x7, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0x11c5c5(%rip), %rsi    # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3707d
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x37094
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x370b1
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x80(%rsp), %rdi
callq 0xf5a0
leaq 0xa0(%rsp), %rdi
callq 0xefe6
leaq 0xd8(%rsp), %rdi
callq 0xf206
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0x370f5
movq 0x128(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x1b8(%rsp), %rdi
testq %rdi, %rdi
je 0x37112
movq 0x1d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x37175
jmp 0x371bc
jmp 0x371bc
movq %rax, %rbx
leaq 0x200(%rsp), %rdi
callq 0xefe6
jmp 0x37145
movq %rax, %rbx
leaq 0x268(%rsp), %rdi
callq 0xf206
jmp 0x37217
movq %rax, %rbx
jmp 0x37217
jmp 0x3717c
jmp 0x37184
movq %rax, %rbx
jmp 0x372a5
jmp 0x371bc
jmp 0x371bc
jmp 0x37191
jmp 0x371bc
jmp 0x371bc
movq %rax, %rbx
jmp 0x371ed
jmp 0x37191
movq %rax, %rbx
jmp 0x37224
movq %rax, %rbx
jmp 0x37288
jmp 0x37235
movq %rax, %rbx
jmp 0x3720a
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x38612
jmp 0x371ab
movq %rax, %rbx
leaq 0x298(%rsp), %rdi
callq 0xf206
jmp 0x3720a
jmp 0x37235
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x371d6
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x371ed
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x3720a
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x80(%rsp), %rdi
callq 0xf5a0
leaq 0xa0(%rsp), %rdi
callq 0xefe6
leaq 0xd8(%rsp), %rdi
callq 0xf206
jmp 0x37288
jmp 0x37235
movq %rax, %rbx
jmp 0x3725e
jmp 0x3723e
jmp 0x3723e
movq %rax, %rbx
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x3725e
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x3727b
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0xd8(%rsp), %rdi
callq 0x3906e
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0x372a5
movq 0x128(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x1b8(%rsp), %rdi
testq %rdi, %rdi
je 0x372c2
movq 0x1d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780