// File: tomfunkhouser[P]gaps/apps/mshalign/mshalign.cpp
// Function: CreatePoints(gaps::R3Mesh*, double*, int, gaps::R3Point*, int, int)
static int
CreatePoints(R3Mesh *mesh, RNScalar *weights, int nweights, R3Point *points, int max_points, int sample_method)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Initialize return value
  int npoints = 0;

  // Check maximum number of points
  if (max_points <= 0) return 0;

  // Check sample method
  if (sample_method == 0) { 
    // Sample faces

    // Check weights
    if (nweights > 0) {
      if (weights == NULL) nweights = 0;
      else if (nweights != mesh->NFaces()) {
        RNFail("Invalid number of weights (%d) for sampling faces (%d)\n", nweights, mesh->NFaces());
        return 0;
      }
    }

    // Count total weighted area of faces
    RNArea total_area = 0.0;
    for (int i = 0; i < mesh->NFaces(); i++) {
      R3MeshFace *face = mesh->Face(i);
      RNScalar face_area = mesh->FaceArea(face);
      if (nweights > i) face_area *= weights[i];
      mesh->SetFaceValue(face, face_area);
      total_area += face_area;
    }

    // Generate points with a uniform distribution over surface area
    RNSeedRandomScalar();
    for (int i = 0; i < mesh->NFaces(); i++) {
      R3MeshFace *face = mesh->Face(i);

      // Get vertex positions
      R3MeshVertex *v0 = mesh->VertexOnFace(face, 0);
      R3MeshVertex *v1 = mesh->VertexOnFace(face, 1);
      R3MeshVertex *v2 = mesh->VertexOnFace(face, 2);
      const R3Point& p0 = mesh->VertexPosition(v0);
      const R3Point& p1 = mesh->VertexPosition(v1);
      const R3Point& p2 = mesh->VertexPosition(v2);

      // Determine number of points for face 
      RNScalar ideal_face_npoints = max_points * mesh->FaceValue(face) / total_area;
      int face_npoints = (int) ideal_face_npoints;
      RNScalar remainder = ideal_face_npoints - face_npoints;
      if (remainder > RNRandomScalar()) face_npoints++;

      // Generate random points in face
      for (int j = 0; j < face_npoints; j++) {
        RNScalar r1 = sqrt(RNRandomScalar());
        RNScalar r2 = RNRandomScalar();
        RNScalar t0 = (1.0 - r1);
        RNScalar t1 = r1 * (1.0 - r2);
        RNScalar t2 = r1 * r2;
        points[npoints++] = t0*p0 + t1*p1 + t2*p2;
        if (npoints >= max_points) break;
      }

      // Check number of points created
      if (npoints >= max_points) break;
    }
  }
  else if (sample_method == 1) {
    // Sample edges

    // Check weights
    if (nweights > 0) {
      if (weights == NULL) nweights = 0;
      else if (nweights != mesh->NEdges()) {
        RNFail("Invalid number of weights (%d) for sampling edges (%d)\n", nweights, mesh->NEdges());
        return 0;
      }
    }

    // Count total weighted length of edges
    RNLength total_length = 0.0;
    for (int i = 0; i < mesh->NEdges(); i++) {
      R3MeshEdge *edge = mesh->Edge(i);
      if ((nweights > i) && (weights[i] < min_weight)) continue;
      RNScalar edge_length = mesh->EdgeLength(edge);
      if (nweights > i) edge_length *= weights[i];
      mesh->SetEdgeValue(edge, edge_length);
      total_length += edge_length;
    }
    
    // Generate points with a uniform distribution over edge length
    RNSeedRandomScalar();
    for (int i = 0; i < mesh->NEdges(); i++) {
      R3MeshEdge *edge = mesh->Edge(i);
      if ((nweights > i) && (weights[i] < min_weight)) continue;

      // Get vertex positions
      R3MeshVertex *v0 = mesh->VertexOnEdge(edge, 0);
      R3MeshVertex *v1 = mesh->VertexOnEdge(edge, 1);
      const R3Point& p0 = mesh->VertexPosition(v0);
      const R3Point& p1 = mesh->VertexPosition(v1);

      // Determine number of points for edge 
      RNScalar ideal_edge_npoints = max_points * mesh->EdgeValue(edge) / total_length;
      int edge_npoints = (int) ideal_edge_npoints;
      RNScalar remainder = ideal_edge_npoints - edge_npoints;
      if (remainder > RNRandomScalar()) edge_npoints++;

      // Generate random points in edge
      for (int j = 0; j < edge_npoints; j++) {
        RNScalar t = RNRandomScalar();
        points[npoints++] = t*p0 + (1-t)*p1;
        if (npoints >= max_points) break;
      }

      // Check number of points created
      if (npoints >= max_points) break;
    }
  }
  else if (sample_method == 2) {
    // Sample vertices

    // Check if number of vertices is less than max_points
    if (max_points > mesh->NVertices()) {
      for (int i = 0; i < mesh->NVertices(); i++) {
        R3MeshVertex *vertex = mesh->Vertex(i);
        points[npoints++] = mesh->VertexPosition(vertex);
      }
    }
    else {
      // Check weights
      if (nweights > 0) {
        if (weights == NULL) nweights = 0;
        else if (nweights != mesh->NVertices()) {
          RNFail("Invalid number of weights (%d) for sampling vertices (%d)\n", nweights, mesh->NVertices());
          return 0;
        }
      }

      // Count total weight 
      RNScalar total_weight = 0.0;
      for (int i = 0; i < mesh->NVertices(); i++) {
        R3MeshVertex *vertex = mesh->Vertex(i);
        RNScalar vertex_weight = (nweights > i) ? weights[i] : mesh->VertexArea(vertex);
        mesh->SetVertexValue(vertex, vertex_weight);
        total_weight += vertex_weight;
      }

      // Check total weight (could be zero if there are vertices, but no weights or faces)
      if (total_weight == 0) {
        for (int i = 0; i < mesh->NVertices(); i++) {
          R3MeshVertex *vertex = mesh->Vertex(i);
          mesh->SetVertexValue(vertex, 1);
          total_weight += 1;
        }
      }

      // Generate points with probability related to vertex weights/areas
      RNSeedRandomScalar();
      for (int i = 0; i < mesh->NVertices(); i++) {
        R3MeshVertex *vertex = mesh->Vertex(i);
        const R3Point& position = mesh->VertexPosition(vertex);

        // Determine number of points for vertex
        RNScalar ideal_vertex_npoints = max_points * mesh->VertexValue(vertex) / total_weight;
        int vertex_npoints = (int) ideal_vertex_npoints;
        RNScalar remainder = ideal_vertex_npoints - vertex_npoints;
        if (remainder > RNRandomScalar()) vertex_npoints++;

        // Generate points at vertex
        for (int j = 0; j < vertex_npoints; j++) {
          points[npoints++] = position;
          if (npoints >= max_points) break;
        }

        // Check number of points created
        if (npoints >= max_points) break;
      }
    }
  }

#if 0
  if (1) {
    static int file_count = 1;
    char filename[256];
    sprintf(filename, "points%d.pts", file_count++);
    FILE *fp = fopen(filename, "wb");
    for (int i = 0; i < npoints; i++) {
      R3Point position = points[i];
      static float coordinates[6] = { 0 };
      coordinates[0] = points[i].X();
      coordinates[1] = points[i].Y();
      coordinates[2] = points[i].Z();
      fwrite(coordinates, sizeof(float), 6, fp);
    }
    fclose(fp);
  }
#endif

  // Print message
  if (print_debug) {
    printf("Created points ...\n");
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Points = %d\n", npoints);
  }

  // Return number of points actually created
  return npoints;
}

// Assembly:
subq $0x318, %rsp            # imm = 0x318
movq %rdi, 0x308(%rsp)
movq %rsi, 0x300(%rsp)
movl %edx, 0x2fc(%rsp)
movq %rcx, 0x2f0(%rsp)
movl %r8d, 0x2ec(%rsp)
movl %r9d, 0x2e8(%rsp)
leaq 0x2d8(%rsp), %rdi
callq 0xa2b30
leaq 0x2d8(%rsp), %rdi
callq 0x15df0
movl $0x0, 0x2d4(%rsp)
cmpl $0x0, 0x2ec(%rsp)
jg 0x13195
movl $0x0, 0x314(%rsp)
jmp 0x14034
cmpl $0x0, 0x2e8(%rsp)
jne 0x13693
cmpl $0x0, 0x2fc(%rsp)
jle 0x13227
cmpq $0x0, 0x300(%rsp)
jne 0x131c5
movl $0x0, 0x2fc(%rsp)
jmp 0x13225
movl 0x2fc(%rsp), %eax
movl %eax, 0x78(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e10
movl %eax, %ecx
movl 0x78(%rsp), %eax
cmpl %ecx, %eax
je 0x13223
movl 0x2fc(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e10
movl 0x74(%rsp), %esi
movl %eax, %edx
leaq 0x94262(%rip), %rdi     # 0xa746e
movb $0x0, %al
callq 0xa6d50
movl $0x0, 0x314(%rsp)
jmp 0x14034
jmp 0x13225
jmp 0x13227
xorps %xmm0, %xmm0
movsd %xmm0, 0x2c8(%rsp)
movl $0x0, 0x2c4(%rsp)
movl 0x2c4(%rsp), %eax
movl %eax, 0x70(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e10
movl %eax, %ecx
movl 0x70(%rsp), %eax
cmpl %ecx, %eax
jge 0x13324
movq 0x308(%rsp), %rdi
movl 0x2c4(%rsp), %esi
callq 0x16130
movq %rax, 0x2b8(%rsp)
movq 0x308(%rsp), %rdi
movq 0x2b8(%rsp), %rsi
callq 0x16160
movsd %xmm0, 0x2b0(%rsp)
movl 0x2fc(%rsp), %eax
cmpl 0x2c4(%rsp), %eax
jle 0x132d5
movq 0x300(%rsp), %rax
movslq 0x2c4(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
mulsd 0x2b0(%rsp), %xmm0
movsd %xmm0, 0x2b0(%rsp)
movq 0x308(%rsp), %rdi
movq 0x2b8(%rsp), %rsi
movsd 0x2b0(%rsp), %xmm0
callq 0x161d0
movsd 0x2b0(%rsp), %xmm0
addsd 0x2c8(%rsp), %xmm0
movsd %xmm0, 0x2c8(%rsp)
movl 0x2c4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c4(%rsp)
jmp 0x1323e
xorps %xmm0, %xmm0
callq 0xa64d0
movl $0x0, 0x2ac(%rsp)
movl 0x2ac(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e10
movl %eax, %ecx
movl 0x6c(%rsp), %eax
cmpl %ecx, %eax
jge 0x1368e
movq 0x308(%rsp), %rdi
movl 0x2ac(%rsp), %esi
callq 0x16130
movq %rax, 0x2a0(%rsp)
movq 0x308(%rsp), %rdi
movq 0x2a0(%rsp), %rsi
xorl %edx, %edx
callq 0x16200
movq %rax, 0x298(%rsp)
movq 0x308(%rsp), %rdi
movq 0x2a0(%rsp), %rsi
movl $0x1, %edx
callq 0x16200
movq %rax, 0x290(%rsp)
movq 0x308(%rsp), %rdi
movq 0x2a0(%rsp), %rsi
movl $0x2, %edx
callq 0x16200
movq %rax, 0x288(%rsp)
movq 0x308(%rsp), %rdi
movq 0x298(%rsp), %rsi
callq 0x16220
movq %rax, 0x280(%rsp)
movq 0x308(%rsp), %rdi
movq 0x290(%rsp), %rsi
callq 0x16220
movq %rax, 0x278(%rsp)
movq 0x308(%rsp), %rdi
movq 0x288(%rsp), %rsi
callq 0x16220
movq %rax, 0x270(%rsp)
cvtsi2sdl 0x2ec(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0x308(%rsp), %rdi
movq 0x2a0(%rsp), %rsi
callq 0x16240
movaps %xmm0, %xmm1
movsd 0x58(%rsp), %xmm0
mulsd %xmm1, %xmm0
divsd 0x2c8(%rsp), %xmm0
movsd %xmm0, 0x268(%rsp)
cvttsd2si 0x268(%rsp), %eax
movl %eax, 0x264(%rsp)
movsd 0x268(%rsp), %xmm0
cvtsi2sdl 0x264(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x258(%rsp)
movsd 0x258(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
callq 0xa6530
movaps %xmm0, %xmm1
movsd 0x60(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x134d9
movl 0x264(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x264(%rsp)
movl $0x0, 0x254(%rsp)
movl 0x254(%rsp), %eax
cmpl 0x264(%rsp), %eax
jge 0x13664
callq 0xa6530
callq 0xd2f0
movsd %xmm0, 0x248(%rsp)
callq 0xa6530
movsd %xmm0, 0x240(%rsp)
movsd 0x93ae7(%rip), %xmm0    # 0xa7008
subsd 0x248(%rsp), %xmm0
movsd %xmm0, 0x238(%rsp)
movsd 0x248(%rsp), %xmm0
movsd 0x93ac4(%rip), %xmm1    # 0xa7008
subsd 0x240(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x230(%rsp)
movsd 0x248(%rsp), %xmm0
mulsd 0x240(%rsp), %xmm0
movsd %xmm0, 0x228(%rsp)
movsd 0x238(%rsp), %xmm0
movq 0x280(%rsp), %rsi
leaq 0x1e0(%rsp), %rdi
callq 0x16260
movsd 0x230(%rsp), %xmm0
movq 0x278(%rsp), %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x16260
leaq 0x1f8(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
leaq 0x1c8(%rsp), %rdx
callq 0x7e240
movsd 0x228(%rsp), %xmm0
movq 0x270(%rsp), %rsi
leaq 0x1b0(%rsp), %rdi
callq 0x16260
leaq 0x210(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
leaq 0x1b0(%rsp), %rdx
callq 0x7e240
movq 0x2f0(%rsp), %rdi
movl 0x2d4(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x2d4(%rsp)
cltq
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0x210(%rsp), %rsi
callq 0x7d9e0
movl 0x2d4(%rsp), %eax
cmpl 0x2ec(%rsp), %eax
jl 0x1364c
jmp 0x13664
jmp 0x1364e
movl 0x254(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x254(%rsp)
jmp 0x134e4
movl 0x2d4(%rsp), %eax
cmpl 0x2ec(%rsp), %eax
jl 0x13676
jmp 0x1368e
jmp 0x13678
movl 0x2ac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2ac(%rsp)
jmp 0x13337
jmp 0x13fdf
cmpl $0x1, 0x2e8(%rsp)
jne 0x13b20
cmpl $0x0, 0x2fc(%rsp)
jle 0x13725
cmpq $0x0, 0x300(%rsp)
jne 0x136c3
movl $0x0, 0x2fc(%rsp)
jmp 0x13723
movl 0x2fc(%rsp), %eax
movl %eax, 0x54(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e30
movl %eax, %ecx
movl 0x54(%rsp), %eax
cmpl %ecx, %eax
je 0x13721
movl 0x2fc(%rsp), %eax
movl %eax, 0x50(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e30
movl 0x50(%rsp), %esi
movl %eax, %edx
leaq 0x93d9c(%rip), %rdi     # 0xa74a6
movb $0x0, %al
callq 0xa6d50
movl $0x0, 0x314(%rsp)
jmp 0x14034
jmp 0x13723
jmp 0x13725
xorps %xmm0, %xmm0
movsd %xmm0, 0x1a8(%rsp)
movl $0x0, 0x1a4(%rsp)
movl 0x1a4(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e30
movl %eax, %ecx
movl 0x4c(%rsp), %eax
cmpl %ecx, %eax
jge 0x1385a
movq 0x308(%rsp), %rdi
movl 0x1a4(%rsp), %esi
callq 0x162a0
movq %rax, 0x198(%rsp)
movl 0x2fc(%rsp), %eax
cmpl 0x1a4(%rsp), %eax
jle 0x137b6
movq 0x300(%rsp), %rax
movslq 0x1a4(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0xba46d(%rip), %xmm0    # 0xcdc18
ucomisd %xmm1, %xmm0
jbe 0x137b6
jmp 0x13844
movq 0x308(%rsp), %rdi
movq 0x198(%rsp), %rsi
callq 0x162d0
movsd %xmm0, 0x190(%rsp)
movl 0x2fc(%rsp), %eax
cmpl 0x1a4(%rsp), %eax
jle 0x1380b
movq 0x300(%rsp), %rax
movslq 0x1a4(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
mulsd 0x190(%rsp), %xmm0
movsd %xmm0, 0x190(%rsp)
movq 0x308(%rsp), %rdi
movq 0x198(%rsp), %rsi
movsd 0x190(%rsp), %xmm0
callq 0x16340
movsd 0x190(%rsp), %xmm0
addsd 0x1a8(%rsp), %xmm0
movsd %xmm0, 0x1a8(%rsp)
movl 0x1a4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a4(%rsp)
jmp 0x1373c
xorps %xmm0, %xmm0
callq 0xa64d0
movl $0x0, 0x18c(%rsp)
movl 0x18c(%rsp), %eax
movl %eax, 0x48(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e30
movl %eax, %ecx
movl 0x48(%rsp), %eax
cmpl %ecx, %eax
jge 0x13b1b
movq 0x308(%rsp), %rdi
movl 0x18c(%rsp), %esi
callq 0x162a0
movq %rax, 0x180(%rsp)
movl 0x2fc(%rsp), %eax
cmpl 0x18c(%rsp), %eax
jle 0x138e7
movq 0x300(%rsp), %rax
movslq 0x18c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0xba33c(%rip), %xmm0    # 0xcdc18
ucomisd %xmm1, %xmm0
jbe 0x138e7
jmp 0x13b05
movq 0x308(%rsp), %rdi
movq 0x180(%rsp), %rsi
xorl %edx, %edx
callq 0x16370
movq %rax, 0x178(%rsp)
movq 0x308(%rsp), %rdi
movq 0x180(%rsp), %rsi
movl $0x1, %edx
callq 0x16370
movq %rax, 0x170(%rsp)
movq 0x308(%rsp), %rdi
movq 0x178(%rsp), %rsi
callq 0x16220
movq %rax, 0x168(%rsp)
movq 0x308(%rsp), %rdi
movq 0x170(%rsp), %rsi
callq 0x16220
movq %rax, 0x160(%rsp)
cvtsi2sdl 0x2ec(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x308(%rsp), %rdi
movq 0x180(%rsp), %rsi
callq 0x16390
movaps %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
mulsd %xmm1, %xmm0
divsd 0x1a8(%rsp), %xmm0
movsd %xmm0, 0x158(%rsp)
cvttsd2si 0x158(%rsp), %eax
movl %eax, 0x154(%rsp)
movsd 0x158(%rsp), %xmm0
cvtsi2sdl 0x154(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x148(%rsp)
movsd 0x148(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
callq 0xa6530
movaps %xmm0, %xmm1
movsd 0x40(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13a08
movl 0x154(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x154(%rsp)
movl $0x0, 0x144(%rsp)
movl 0x144(%rsp), %eax
cmpl 0x154(%rsp), %eax
jge 0x13af1
callq 0xa6530
movsd %xmm0, 0x138(%rsp)
movsd 0x138(%rsp), %xmm0
movq 0x168(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0x16260
movsd 0x935ad(%rip), %xmm0    # 0xa7008
subsd 0x138(%rsp), %xmm0
movq 0x160(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
callq 0x16260
leaq 0x120(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
callq 0x7e240
movq 0x2f0(%rsp), %rdi
movl 0x2d4(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x2d4(%rsp)
cltq
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0x120(%rsp), %rsi
callq 0x7d9e0
movl 0x2d4(%rsp), %eax
cmpl 0x2ec(%rsp), %eax
jl 0x13ad9
jmp 0x13af1
jmp 0x13adb
movl 0x144(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x144(%rsp)
jmp 0x13a13
movl 0x2d4(%rsp), %eax
cmpl 0x2ec(%rsp), %eax
jl 0x13b03
jmp 0x13b1b
jmp 0x13b05
movl 0x18c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18c(%rsp)
jmp 0x1386d
jmp 0x13fdd
cmpl $0x2, 0x2e8(%rsp)
jne 0x13fdb
movl 0x2ec(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e50
movl %eax, %ecx
movl 0x34(%rsp), %eax
cmpl %ecx, %eax
jle 0x13bf9
movl $0x0, 0xec(%rsp)
movl 0xec(%rsp), %eax
movl %eax, 0x30(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e50
movl %eax, %ecx
movl 0x30(%rsp), %eax
cmpl %ecx, %eax
jge 0x13bf4
movq 0x308(%rsp), %rdi
movl 0xec(%rsp), %esi
callq 0x163b0
movq %rax, 0xe0(%rsp)
movq 0x308(%rsp), %rdi
movq 0xe0(%rsp), %rsi
callq 0x16220
movq %rax, %rsi
movq 0x2f0(%rsp), %rdi
movl 0x2d4(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x2d4(%rsp)
cltq
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x7d9e0
movl 0xec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xec(%rsp)
jmp 0x13b5f
jmp 0x13fd9
cmpl $0x0, 0x2fc(%rsp)
jle 0x13c7d
cmpq $0x0, 0x300(%rsp)
jne 0x13c1b
movl $0x0, 0x2fc(%rsp)
jmp 0x13c7b
movl 0x2fc(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e50
movl %eax, %ecx
movl 0x2c(%rsp), %eax
cmpl %ecx, %eax
je 0x13c79
movl 0x2fc(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e50
movl 0x28(%rsp), %esi
movl %eax, %edx
leaq 0x9387c(%rip), %rdi     # 0xa74de
movb $0x0, %al
callq 0xa6d50
movl $0x0, 0x314(%rsp)
jmp 0x14034
jmp 0x13c7b
jmp 0x13c7d
xorps %xmm0, %xmm0
movsd %xmm0, 0xd8(%rsp)
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e50
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jge 0x13d7c
movq 0x308(%rsp), %rdi
movl 0xd4(%rsp), %esi
callq 0x163b0
movq %rax, 0xc8(%rsp)
movl 0x2fc(%rsp), %eax
cmpl 0xd4(%rsp), %eax
jle 0x13d03
movq 0x300(%rsp), %rax
movslq 0xd4(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x18(%rsp)
jmp 0x13d1e
movq 0x308(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0x3a340
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0xc0(%rsp)
movq 0x308(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movsd 0xc0(%rsp), %xmm0
callq 0x163e0
movsd 0xc0(%rsp), %xmm0
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x13c94
movsd 0xd8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x13e30
jp 0x13e30
movl $0x0, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e50
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0x13e2e
movq 0x308(%rsp), %rdi
movl 0xbc(%rsp), %esi
callq 0x163b0
movq %rax, 0xb0(%rsp)
movq 0x308(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movsd 0x9320f(%rip), %xmm0    # 0xa7008
callq 0x163e0
movsd 0x93202(%rip), %xmm0    # 0xa7008
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x13da3
jmp 0x13e30
xorps %xmm0, %xmm0
callq 0xa64d0
movl $0x0, 0xac(%rsp)
movl 0xac(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x308(%rsp), %rdi
callq 0x15e50
movl %eax, %ecx
movl 0x10(%rsp), %eax
cmpl %ecx, %eax
jge 0x13fd7
movq 0x308(%rsp), %rdi
movl 0xac(%rsp), %esi
callq 0x163b0
movq %rax, 0xa0(%rsp)
movq 0x308(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x16220
movq %rax, 0x98(%rsp)
cvtsi2sdl 0x2ec(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x308(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x16410
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
divsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x90(%rsp)
cvttsd2si 0x90(%rsp), %eax
movl %eax, 0x8c(%rsp)
movsd 0x90(%rsp), %xmm0
cvtsi2sdl 0x8c(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0xa6530
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13f46
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
movl $0x0, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jge 0x13fad
movq 0x98(%rsp), %rsi
movq 0x2f0(%rsp), %rdi
movl 0x2d4(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x2d4(%rsp)
cltq
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x7d9e0
movl 0x2d4(%rsp), %eax
cmpl 0x2ec(%rsp), %eax
jl 0x13f9e
jmp 0x13fad
jmp 0x13fa0
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x13f4e
movl 0x2d4(%rsp), %eax
cmpl 0x2ec(%rsp), %eax
jl 0x13fbf
jmp 0x13fd7
jmp 0x13fc1
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x13e43
jmp 0x13fd9
jmp 0x13fdb
jmp 0x13fdd
jmp 0x13fdf
cmpl $0x0, 0xb9c2e(%rip)     # 0xcdc14
je 0x14026
leaq 0x9352a(%rip), %rdi     # 0xa7519
movb $0x0, %al
callq 0xd070
leaq 0x2d8(%rsp), %rdi
callq 0xa2bf0
leaq 0x93209(%rip), %rdi     # 0xa7213
movb $0x1, %al
callq 0xd070
movl 0x2d4(%rsp), %esi
leaq 0x9350e(%rip), %rdi     # 0xa752d
movb $0x0, %al
callq 0xd070
movl 0x2d4(%rsp), %eax
movl %eax, 0x314(%rsp)
movl 0x314(%rsp), %eax
addq $0x318, %rsp            # imm = 0x318
retq
nopw %cs:(%rax,%rax)