// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelUtils.cpp
// Function: gaps::CreatePlanarGrids(gaps::R3SurfelPointGraph*, double, double, double, double, int, double, double)
RNArray<R3PlanarGrid *> *
CreatePlanarGrids(R3SurfelPointGraph *graph, 
  RNLength max_offplane_distance, RNAngle max_normal_angle,
  RNArea min_area, RNScalar min_density, int min_points,
  RNLength grid_spacing, RNScalar accuracy_factor)
{
  // Get convenient variables
  RNLength offplane_distance_sigma = 0.5 * max_offplane_distance;
  RNLength offplane_distance_sigma_squared = offplane_distance_sigma * offplane_distance_sigma;
  RNScalar offplane_distance_factor = (offplane_distance_sigma_squared != 0) ? 1.0 / (-2.0 * offplane_distance_sigma_squared) : 1;
  RNLength normal_angle_sigma = 0.5 * max_normal_angle;
  RNAngle normal_angle_sigma_squared = normal_angle_sigma * normal_angle_sigma;
  RNScalar normal_angle_factor = (normal_angle_sigma_squared != 0) ? 1.0 / (-2.0 * normal_angle_sigma_squared) : 1;

  // Determine number of samples
  if (min_points <= 1) min_points = 1;
  RNScalar max_grids = graph->NPoints();
  RNScalar bbox_volume = graph->BBox().Volume();
  if ((min_points > 0) && (graph->NPoints() / min_points < max_grids)) max_grids = graph->NPoints() / min_points;
  if ((min_area > 0) && (bbox_volume / min_area < max_grids)) max_grids = bbox_volume / min_area;
  int nsamples = (int) (accuracy_factor * 10.0 * max_grids) + 1;
  if (nsamples > graph->NPoints()) nsamples = graph->NPoints();

  // Create temporary data
  int *point_marks = new int [ graph->NPoints() ];
  R3Vector *point_normals = CreateNormals(graph, FALSE);
  R3Point *point_positions = new R3Point [ graph->NPoints() ];
  RNScalar *point_weights = new RNScalar [ graph->NPoints() ];
  R3PlanarGrid **point_grids = new R3PlanarGrid * [ graph->NPoints() ];
  SurfelPlanarGridData *grid_datas = new SurfelPlanarGridData [ nsamples ];
  for (int i = 0; i < graph->NPoints(); i++) point_marks[i] = 0;
  for (int i = 0; i < graph->NPoints(); i++) point_grids[i] = NULL;

  // Generate grid data
  int grid_data_count = 0;
  for (int iter = 0; iter < nsamples; iter++) {
    // Compute plane 
    int seed_index = (int) (RNRandomScalar() * graph->NPoints());
    if (point_marks[seed_index]) continue;
    if (graph->NNeighbors(seed_index) < 2) continue;
    R3SurfelPoint *seed = graph->Point(seed_index);
    R3Point seed_position = seed->Position();
    const R3Vector& seed_normal = point_normals[seed_index];
    if (R3Contains(seed_normal, R3zero_vector)) continue;
    R3Plane plane(seed_position, seed_normal);

    // Find positions of points near plane
    int point_count = 0;
    RNScalar total_weight = 0;
    for (int i = 0; i < graph->NPoints(); i++) {
      R3SurfelPoint *point = graph->Point(i);
      if (graph->NNeighbors(seed_index) < 2) continue;
      R3Point position = point->Position();
      RNScalar offplane_distance = R3Distance(plane, position);
      if (offplane_distance > max_offplane_distance) continue;
      const R3Vector& normal = point_normals[i];
      if (R3Contains(normal, R3zero_vector)) continue;
      RNScalar dot = fabs(normal.Dot(seed_normal));
      RNAngle normal_angle = (dot < 1) ? acos(dot) : 0;
      if (normal_angle > max_normal_angle) continue;
      RNScalar weight = 1;
      weight *= exp(offplane_distance_factor * offplane_distance * offplane_distance);
      weight *= exp(normal_angle_factor * normal_angle * normal_angle);
      total_weight += weight;
      point_positions[point_count] = position;
      point_weights[point_count] = weight;
      point_count++;
    }

    // Check number of points
    if (total_weight < min_points) continue;

    // Re-compute plane to fit points
    R3Point centroid = R3Centroid(point_count, point_positions, point_weights);
    R3Triad triad = R3PrincipleAxes(centroid, point_count, point_positions, point_weights);
    if (R3Contains(triad[2], R3zero_vector)) continue;
    plane.Reset(centroid, triad[2]);

    // Fill grid data
    SurfelPlanarGridData *grid_data = &grid_datas[grid_data_count];
    grid_data->points.Empty();
    grid_data->plane = plane;
    grid_data->bbox = R3null_box;
    grid_data->weight = 0;
    for (int i = 0; i < graph->NPoints(); i++) {
      R3SurfelPoint *point = graph->Point(i);
      int point_index = graph->PointIndex(point);
      if (graph->NNeighbors(point_index) < 2) continue;
      R3Point position = point->Position();
      RNScalar offplane_distance = R3Distance(plane, position);
      if (offplane_distance > max_offplane_distance) continue;
      const R3Vector& normal = point_normals[i];
      if (R3Contains(normal, R3zero_vector)) continue;
      RNScalar dot = fabs(normal.Dot(plane.Normal()));
      RNAngle normal_angle = (dot < 1) ? acos(dot) : 0;
      if (normal_angle > max_normal_angle) continue;
      RNScalar weight = 1;
      weight *= exp(offplane_distance_factor * offplane_distance * offplane_distance);
      weight *= exp(normal_angle_factor * normal_angle * normal_angle);
      grid_data->points.Insert(point);
      grid_data->bbox.Union(position);
      grid_data->weight += weight;
      point_marks[point_index]++;
    }

    // Check grid
    if (grid_data->weight < min_points) continue;

    // Add grid data
    grid_data_count++;
  }

  ////////////////////

  // Sort grid data
  if (grid_data_count > 0) {
    qsort(grid_datas, grid_data_count, sizeof(SurfelPlanarGridData), CompareSurfelPlanarGridDatas);
  }

  ////////////////////

  // Create array of grids
  RNArray<R3PlanarGrid *> *grids = new RNArray<R3PlanarGrid *>();
  if (!grids) {
    RNFail("Unable to allocate array of grids\n");
    return NULL;
  }

  // Create grids
  for (int i = 0; i < grid_data_count; i++) {
    int point_count = 0;
    SurfelPlanarGridData *grid_data = &grid_datas[i];
    R3PlanarGrid *grid = new R3PlanarGrid(grid_data->plane, grid_data->bbox, grid_spacing);
    for (int j = 0; j < grid_data->points.NEntries(); j++) {
      R3SurfelPoint *point = grid_data->points.Kth(j);
      int point_index = graph->PointIndex(point);
      if (graph->NNeighbors(point_index) < 2) continue;
      if (point_grids[point_index]) continue;
      point_grids[point_index] = grid;
      R3Point position = point->Position();
      RNScalar offplane_distance = R3Distance(grid_data->plane, position);
      if (offplane_distance > max_offplane_distance) continue;
      const R3Vector& normal = point_normals[point_index];
      if (R3Contains(normal, R3zero_vector)) continue;
      RNScalar dot = fabs(normal.Dot(grid_data->plane.Normal()));
      RNAngle normal_angle = (dot < 1) ? acos(dot) : 0;
      if (normal_angle > max_normal_angle) continue;
      RNScalar weight = 1;
      weight *= exp(offplane_distance_factor * offplane_distance * offplane_distance);
      weight *= exp(normal_angle_factor * normal_angle * normal_angle);
      grid->RasterizeWorldPoint(position, weight);
      point_count++;
    }

    // Check grid support
    if ((min_points > 0) && (point_count < min_points)) {
      delete grid;
      continue;
    }

    // Mask low-density areas and small-connected components
    if ((min_density > 0) || (min_area > 0)) {
      RNLength gridcell_per_meter = grid->WorldToGridScaleFactor();
      RNScalar min_grid_density = min_density / (gridcell_per_meter * gridcell_per_meter);
      RNScalar min_grid_area = min_area * gridcell_per_meter * gridcell_per_meter;
      grid->ConnectedComponentFilter(min_grid_density, min_grid_area, 0, 0, 0, R2_GRID_KEEP_VALUE);
      if (grid->Sum() == 0) { delete grid; continue; }
    }

    // Insert grid
    grids->Insert(grid);
  }

  ////////////////////

  // Delete temporary data
  delete [] point_marks;
  delete [] point_normals;
  delete [] point_positions;
  delete [] point_weights;
  delete [] point_grids;
  delete [] grid_datas;

  // Return grids
  return grids;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movsd %xmm5, 0x10(%rsp)
movsd %xmm4, 0xf8(%rsp)
movapd %xmm3, 0x100(%rsp)
movaps %xmm2, 0xc0(%rsp)
movsd %xmm1, 0x70(%rsp)
movsd %xmm0, 0x78(%rsp)
movq %rdi, %rbx
cmpl $0x2, %esi
movl $0x1, %ebp
cmovgel %esi, %ebp
addq $0x20, %rdi
movq 0x20(%rbx), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0x18(%rbx), %xmm0
movsd %xmm0, 0x28(%rsp)
callq *0x60(%rax)
movapd 0xc0(%rsp), %xmm2
movslq 0x18(%rbx), %rcx
movl %ecx, %eax
cltd
movl %ebp, 0x5c(%rsp)
idivl %ebp
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
minsd 0x28(%rsp), %xmm1
ucomisd 0xb5265(%rip), %xmm2    # 0xdd388
jbe 0x28133
divsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
jbe 0x28133
movapd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
mulsd 0xb59df(%rip), %xmm0    # 0xddb20
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
leal 0x1(%rax), %edx
cmpl %eax, %ecx
cmovlel %ecx, %edx
movl %edx, 0x10(%rsp)
movq %rcx, %rdi
shlq $0x2, %rdi
testl %ecx, %ecx
movq $-0x1, %rbp
cmovsq %rbp, %rdi
callq 0x13030
movq %rax, 0x38(%rsp)
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x26e3b
movq %rax, 0x40(%rsp)
movslq 0x18(%rbx), %r15
movl $0x18, %ecx
movq %r15, %rax
mulq %rcx
movq %rax, %r14
cmovoq %rbp, %r14
movq %r14, %rdi
callq 0x13030
movq %rax, 0x50(%rsp)
testq %r15, %r15
je 0x281ed
shlq $0x3, %r15
leaq (%r15,%r15,2), %r15
xorl %r12d, %r12d
movq 0x50(%rsp), %rax
leaq (%rax,%r12), %rdi
callq 0x83dc0
addq $0x18, %r12
cmpq %r12, %r15
jne 0x281b8
movl 0x18(%rbx), %r13d
movslq %r13d, %rax
leaq (,%rax,8), %rcx
testl %eax, %eax
movq $-0x1, %r12
cmovnsq %rcx, %r12
jmp 0x281f0
xorl %r12d, %r12d
movslq 0x10(%rsp), %r15
movl $0x70, %ecx
movq %r15, %rax
mulq %rcx
movq %rax, %r14
seto %al
orq $0x8, %r14
testb %al, %al
cmovneq %rbp, %r14
movq %r12, %rdi
callq 0x13030
movq %rax, 0x88(%rsp)
movq %r12, %rdi
callq 0x13030
movq %rax, 0x28(%rsp)
movq %r14, %rdi
callq 0x13030
movq %rax, %rbp
movq %r15, (%rax)
testl %r15d, %r15d
movq %rax, 0x80(%rsp)
je 0x28286
imulq $0x70, %r15, %r13
xorl %r12d, %r12d
leaq (%r12,%rbp), %r15
addq $0x8, %r15
movq %r15, %rdi
callq 0xa9ca8
leaq (%r12,%rbp), %rdi
addq $0x18, %rdi
callq 0x828b0
leaq (%r12,%rbp), %rdi
addq $0x38, %rdi
callq 0x6d310
addq $0x70, %r12
cmpq %r12, %r13
jne 0x2824f
movl 0x18(%rbx), %r13d
movsd 0xb4eaa(%rip), %xmm3    # 0xdd138
movsd 0x78(%rsp), %xmm4
mulsd %xmm3, %xmm4
mulsd 0x70(%rsp), %xmm3
mulsd %xmm4, %xmm4
movsd 0xb586e(%rip), %xmm0    # 0xddb18
mulsd %xmm3, %xmm3
movapd %xmm4, %xmm1
mulsd %xmm0, %xmm1
movsd 0xb4e8a(%rip), %xmm5    # 0xdd148
mulsd %xmm3, %xmm0
movapd %xmm5, %xmm2
divsd %xmm1, %xmm2
xorpd %xmm6, %xmm6
cmpneqsd %xmm6, %xmm4
movapd %xmm5, %xmm1
divsd %xmm0, %xmm1
cmpneqsd %xmm6, %xmm3
andpd %xmm4, %xmm2
andnpd %xmm5, %xmm4
orpd %xmm2, %xmm4
movapd %xmm4, 0xd0(%rsp)
andpd %xmm3, %xmm1
andnpd %xmm5, %xmm3
orpd %xmm1, %xmm3
movapd %xmm3, 0xe0(%rsp)
testl %r13d, %r13d
jle 0x28339
movl %r13d, %r14d
leaq (,%r14,4), %rdx
movq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0x132a0
shlq $0x3, %r14
movq 0x28(%rsp), %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x132a0
leaq 0x8(%rbp), %r12
cmpl $0x0, 0x10(%rsp)
movq %r12, 0x68(%rsp)
jle 0x2891a
xorps %xmm0, %xmm0
cvtsi2sdl 0x5c(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq $0x0, 0x30(%rsp)
xorl %r12d, %r12d
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %rbp
callq 0xaba84
xorps %xmm1, %xmm1
cvtsi2sdl 0x18(%rbx), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movslq %eax, %r14
cmpl $0x0, (%rbp,%r14,4)
jne 0x288e1
movq 0x68(%rbx), %rax
movq %r14, %r15
shlq $0x4, %r15
cmpl $0x2, 0xc(%rax,%r15)
jl 0x288e1
movl %r12d, 0xc(%rsp)
movq 0x10(%rbx), %rax
movq (%rax,%r15), %rcx
movq 0x8(%rax,%r15), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
addsd 0x10(%rcx), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rax), %xmm1
addsd 0x18(%rcx), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rax), %xmm2
addsd 0x20(%rcx), %xmm2
leaq 0x118(%rsp), %r12
movq %r12, %rdi
callq 0x83dc2
leaq (%r14,%r14,2), %rax
leaq (,%rax,8), %r14
addq %r13, %r14
movq %r14, %rdi
leaq 0xbcdaa(%rip), %rsi     # 0xe51b8
callq 0x4cfd8
testl %eax, %eax
jne 0x288dc
leaq 0xa0(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x82942
movl 0x18(%rbx), %eax
testl %eax, %eax
jle 0x285e5
movq %r14, 0x48(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %ebp, %ebp
movl $0x8, %r14d
movq 0x40(%rsp), %r12
movq $0x0, 0x18(%rsp)
movq 0x68(%rbx), %rcx
cmpl $0x2, 0xc(%rcx,%r15)
jl 0x285cc
movq 0x10(%rbx), %rax
movq -0x8(%rax,%r14), %rcx
movq (%rax,%r14), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
addsd 0x10(%rcx), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rax), %xmm1
addsd 0x18(%rcx), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rax), %xmm2
addsd 0x20(%rcx), %xmm2
leaq 0x130(%rsp), %r13
movq %r13, %rdi
callq 0x83dc2
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x500ce
ucomisd 0x78(%rsp), %xmm0
ja 0x285c9
movsd %xmm0, (%rsp)
movq %r12, %rdi
leaq 0xbccdc(%rip), %rsi     # 0xe51b8
callq 0x4cfd8
testl %eax, %eax
jne 0x285c9
movq %r12, %rdi
movq 0x48(%rsp), %rsi
callq 0x84ae2
andpd 0xb4ed2(%rip), %xmm0    # 0xdd3d0
xorpd %xmm2, %xmm2
movsd 0xb4c3e(%rip), %xmm1    # 0xdd148
ucomisd %xmm0, %xmm1
jbe 0x28519
callq 0x13490
movapd %xmm0, %xmm2
ucomisd 0x70(%rsp), %xmm2
ja 0x285c9
movapd 0xd0(%rsp), %xmm0
movsd (%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm2, 0x90(%rsp)
callq 0x138c0
movsd %xmm0, (%rsp)
movapd 0xe0(%rsp), %xmm0
movsd 0x90(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
callq 0x138c0
movapd %xmm0, %xmm1
mulsd (%rsp), %xmm1
movsd %xmm1, (%rsp)
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x18(%rsp), %r13
movslq %r13d, %r13
leaq (%r13,%r13,2), %rax
movq 0x50(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
leaq 0x130(%rsp), %rsi
callq 0x8412a
movq 0x88(%rsp), %rax
movsd (%rsp), %xmm0
movsd %xmm0, (%rax,%r13,8)
incl %r13d
movq %r13, 0x18(%rsp)
movl 0x18(%rbx), %eax
incq %rbp
movslq %eax, %rcx
addq $0x18, %r12
addq $0x10, %r14
cmpq %rcx, %rbp
jl 0x2845e
jmp 0x285f8
movq $0x0, 0x18(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x60(%rsp), %xmm0
ucomisd 0x20(%rsp), %xmm0
jbe 0x28615
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %rbp
jmp 0x288dc
leaq 0x190(%rsp), %r12
movq %r12, %rdi
movq 0x18(%rsp), %r13
movl %r13d, %esi
movq 0x50(%rsp), %r14
movq %r14, %rdx
movq 0x88(%rsp), %r15
movq %r15, %rcx
callq 0x545c1
leaq 0x130(%rsp), %rdi
movq %r12, %rsi
movl %r13d, %edx
movq %r14, %rcx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x5464b
leaq 0x160(%rsp), %r14
movq %r14, %rdi
leaq 0xbcb4a(%rip), %rsi     # 0xe51b8
callq 0x4cfd8
testl %eax, %eax
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %rbp
jne 0x288dc
movq %r12, %rsi
leaq 0xa0(%rsp), %rdi
movq %r14, %rdx
callq 0x83114
movslq 0x30(%rsp), %rax
imulq $0x70, %rax, %r14
movq 0x68(%rsp), %r15
leaq (%r15,%r14), %rdi
movq %rdi, 0x20(%rsp)
xorl %esi, %esi
callq 0xa9f08
leaq (%r15,%r14), %r12
addq $0x10, %r12
movq %r12, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x84fe2
movsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0x18(%r12)
leaq (%r15,%r14), %rdi
addq $0x38, %rdi
leaq 0x10c2db(%rip), %r12    # 0x1349c8
leaq 0x8(%r12), %rsi
callq 0x8412a
leaq (%r15,%r14), %rdi
addq $0x50, %rdi
leaq 0x20(%r12), %rsi
movq %rdi, %r12
callq 0x8412a
movq $0x0, 0x18(%r12)
movl 0x18(%rbx), %eax
testl %eax, %eax
jle 0x288bd
leaq (%r15,%r14), %rcx
addq $0x30, %rcx
movq %rcx, 0x48(%rsp)
movq %r13, %r12
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x68(%rbx), %rcx
cmpl $0x2, 0xc(%rcx,%rbp)
jl 0x28890
movq 0x10(%rbx), %r15
movq (%r15,%rbp), %rax
movq 0x8(%r15,%rbp), %rcx
xorps %xmm0, %xmm0
cvtss2sd (%rcx), %xmm0
addsd 0x10(%rax), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rcx), %xmm1
addsd 0x18(%rax), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rcx), %xmm2
addsd 0x20(%rax), %xmm2
leaq 0x178(%rsp), %r13
movq %r13, %rdi
callq 0x83dc2
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x500ce
movsd %xmm0, (%rsp)
ucomisd 0x78(%rsp), %xmm0
ja 0x2888d
movq %r12, %rdi
leaq 0xbca06(%rip), %rsi     # 0xe51b8
callq 0x4cfd8
testl %eax, %eax
jne 0x2888d
movq %r12, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x84ae2
andpd 0xb4bf9(%rip), %xmm0    # 0xdd3d0
xorpd %xmm2, %xmm2
movsd 0xb4965(%rip), %xmm1    # 0xdd148
ucomisd %xmm0, %xmm1
jbe 0x287f2
callq 0x13490
movapd %xmm0, %xmm2
ucomisd 0x70(%rsp), %xmm2
ja 0x2888d
addq %rbp, %r15
movapd 0xd0(%rsp), %xmm0
movsd (%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm2, 0x18(%rsp)
callq 0x138c0
movsd %xmm0, (%rsp)
movapd 0xe0(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
callq 0x138c0
mulsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x20(%rsp), %r13
movl 0xc(%r13), %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0xa9d3e
movq 0x48(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x6dd46
movsd (%rsp), %xmm0
addsd 0x68(%r13), %xmm0
movsd %xmm0, 0x68(%r13)
movq 0x38(%rsp), %rax
incl (%rax,%r14,4)
movl 0x18(%rbx), %eax
incq %r14
movslq %eax, %rcx
addq $0x18, %r12
addq $0x10, %rbp
cmpq %rcx, %r14
jl 0x28735
movq 0x20(%rsp), %rax
movsd 0x68(%rax), %xmm0
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %rbp
jmp 0x288c1
xorpd %xmm0, %xmm0
xorl %eax, %eax
movsd 0x60(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setbe %al
movq 0x30(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x30(%rsp)
movl 0xc(%rsp), %r12d
incl %r12d
cmpl 0x10(%rsp), %r12d
jne 0x28372
movq 0x30(%rsp), %r14
testl %r14d, %r14d
jle 0x28921
movl %r14d, %esi
leaq 0x4b6(%rip), %rcx       # 0x28db9
movl $0x70, %edx
movq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x13970
movb $0x1, %bpl
jmp 0x28928
xorl %ebp, %ebp
xorl %r14d, %r14d
jmp 0x28928
xorl %ebp, %ebp
movq 0x68(%rsp), %r12
movl $0x10, %edi
callq 0x134e0
movq %rax, 0x30(%rsp)
movq %rax, %rdi
callq 0xa9ca8
testb %bpl, %bpl
je 0x28c95
xorpd %xmm0, %xmm0
cmpltpd 0x100(%rsp), %xmm0
xorpd %xmm1, %xmm1
cmpltpd 0xc0(%rsp), %xmm1
orpd %xmm0, %xmm1
movss %xmm1, 0x9c(%rsp)
movl %r14d, %eax
movq %rax, 0x90(%rsp)
xorl %r13d, %r13d
imulq $0x70, %r13, %rbp
movl $0x240, %edi            # imm = 0x240
callq 0x134e0
leaq (%r12,%rbp), %r14
addq $0x10, %r14
leaq 0x30(%r12,%rbp), %rdx
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r14, %rsi
movsd 0xf8(%rsp), %xmm0
callq 0x7459a
addq %r12, %rbp
movl 0xc(%rbp), %eax
testl %eax, %eax
movq 0x28(%rsp), %rdi
jle 0x28bd3
movq %r13, 0x20(%rsp)
movq 0x10(%rsp), %rcx
leaq 0x20(%rcx), %rdx
movq %rdx, 0x48(%rsp)
addq $0x130, %rcx            # imm = 0x130
movq %rcx, 0x18(%rsp)
xorl %r13d, %r13d
movl $0x0, 0xc(%rsp)
movq (%rbp), %rcx
movq (%rcx,%r13,8), %rcx
movq %rcx, %rdx
subq 0x10(%rbx), %rdx
movq 0x68(%rbx), %rsi
shrq $0x4, %rdx
movslq %edx, %r12
movq %r12, %rdx
shlq $0x4, %rdx
cmpl $0x2, 0xc(%rsi,%rdx)
jl 0x28bb0
cmpq $0x0, (%rdi,%r12,8)
jne 0x28bb0
movq 0x10(%rsp), %rax
movq %rax, (%rdi,%r12,8)
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
xorps %xmm0, %xmm0
cvtss2sd (%rcx), %xmm0
addsd 0x10(%rax), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rcx), %xmm1
addsd 0x18(%rax), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rcx), %xmm2
addsd 0x20(%rax), %xmm2
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
callq 0x83dc2
movq %r15, %rdi
movq %r14, %rsi
callq 0x500ce
ucomisd 0x78(%rsp), %xmm0
ja 0x28ba8
movsd %xmm0, (%rsp)
leaq (%r12,%r12,2), %rax
movq 0x40(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
movq %r12, %rdi
leaq 0xbc718(%rip), %rsi     # 0xe51b8
callq 0x4cfd8
testl %eax, %eax
jne 0x28ba8
movq %r12, %rdi
movq %r14, %rsi
callq 0x84ae2
andpd 0xb4910(%rip), %xmm0    # 0xdd3d0
xorpd %xmm2, %xmm2
movsd 0xb467c(%rip), %xmm1    # 0xdd148
ucomisd %xmm0, %xmm1
jbe 0x28adb
callq 0x13490
movapd %xmm0, %xmm2
ucomisd 0x70(%rsp), %xmm2
ja 0x28ba8
movapd 0xd0(%rsp), %xmm0
movsd (%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm2, 0x60(%rsp)
callq 0x138c0
movsd %xmm0, (%rsp)
movapd 0xe0(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
callq 0x138c0
movsd (%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
leaq 0x130(%rsp), %r15
movq %r15, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x83dd2
movq %r15, %rdi
movq 0x48(%rsp), %rsi
callq 0x846d8
movsd 0x130(%rsp), %xmm0
movsd 0x138(%rsp), %xmm1
leaq 0x118(%rsp), %rdi
movq 0x18(%rsp), %r15
movq %r15, %rsi
callq 0x97ff6
movsd 0x118(%rsp), %xmm0
movsd 0x120(%rsp), %xmm1
movq %r15, %rdi
movsd (%rsp), %xmm2
xorl %esi, %esi
callq 0x969e4
incl 0xc(%rsp)
movq 0x28(%rsp), %rdi
movl 0xc(%rbp), %eax
incq %r13
movslq %eax, %rcx
cmpq %rcx, %r13
jl 0x289f0
movl 0xc(%rsp), %eax
cmpl 0x5c(%rsp), %eax
movq 0x68(%rsp), %r12
movq 0x20(%rsp), %r13
jge 0x28bf2
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x7544a
movl $0x240, %esi            # imm = 0x240
movq %r14, %rdi
callq 0x134f0
jmp 0x28c84
testb $0x1, 0x9c(%rsp)
je 0x28c72
movq 0x48(%rsp), %rdi
callq 0x70152
movq 0x10(%rsp), %rax
mulsd 0x1e0(%rax), %xmm0
movapd %xmm0, %xmm1
mulsd 0xc0(%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
movapd 0x100(%rsp), %xmm0
divsd %xmm2, %xmm0
xorpd %xmm2, %xmm2
xorpd %xmm3, %xmm3
xorpd %xmm4, %xmm4
movq 0x18(%rsp), %r14
movq %r14, %rdi
movsd 0xb4ed3(%rip), %xmm5    # 0xddb28
callq 0x98f14
movq %r14, %rdi
callq 0x91a6e
ucomisd 0xb471e(%rip), %xmm0    # 0xdd388
jne 0x28c72
jnp 0x28bd3
movq 0x30(%rsp), %rdi
movl 0xc(%rdi), %edx
movq 0x10(%rsp), %rsi
callq 0xa9d3e
incq %r13
cmpq 0x90(%rsp), %r13
jne 0x2897f
movq 0x38(%rsp), %rdi
callq 0x13680
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
movq 0x80(%rsp), %r12
je 0x28cb6
callq 0x13680
movq 0x50(%rsp), %rdi
callq 0x13680
movq 0x88(%rsp), %rdi
callq 0x13680
movq 0x28(%rsp), %rdi
callq 0x13680
movq (%r12), %rax
imulq $0x70, %rax, %rcx
leaq 0x8(%rcx), %rbx
testq %rax, %rax
je 0x28d0f
imulq $-0x70, %rax, %r15
leaq (%rcx,%r12), %r14
addq $-0x68, %r14
leaq 0x30(%r14), %rdi
callq 0x6e174
movq %r14, %rdi
callq 0xa9d12
addq $-0x70, %r14
addq $0x70, %r15
jne 0x28cf4
movq %r12, %rdi
movq %rbx, %rsi
callq 0x139b0
movq 0x30(%rsp), %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x10, %esi
movq 0x30(%rsp), %rdi
jmp 0x28d4d
movq %rax, %rbx
movl $0x240, %esi            # imm = 0x240
movq 0x10(%rsp), %rdi
callq 0x134f0
jmp 0x28db1
movq %rax, %rbx
jmp 0x28d6e
movq %rax, %rbx
movq 0x50(%rsp), %rdi
jmp 0x28da9
movq %rax, %rbx
movq %r15, %rdi
callq 0xa9d12
testq %r12, %r12
je 0x28da1
movq 0x80(%rsp), %rax
leaq (%rax,%r12), %r15
addq $-0x68, %r15
negq %r12
leaq 0x30(%r15), %rdi
callq 0x6e174
movq %r15, %rdi
callq 0xa9d12
addq $-0x70, %r15
addq $0x70, %r12
jne 0x28d86
movq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0x139b0
movq %rbx, %rdi
callq 0x138b0