// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1c8, %rsp            # imm = 0x1C8
movsd %xmm5, 0x10(%rsp)
movsd %xmm4, 0xf8(%rsp)
movapd %xmm3, 0x120(%rsp)
movaps %xmm2, 0xe0(%rsp)
movsd %xmm1, 0x88(%rsp)
movsd %xmm0, 0x98(%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, 0x38(%rsp)
callq *0x60(%rax)
movapd 0xe0(%rsp), %xmm2
movslq 0x18(%rbx), %rcx
movl %ecx, %eax
cltd
movl %ebp, 0x6c(%rsp)
idivl %ebp
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
minsd 0x38(%rsp), %xmm1
ucomisd 0xb5f05(%rip), %xmm2    # 0xde388
jbe 0x28493
divsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
jbe 0x28493
movapd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
mulsd 0xb6677(%rip), %xmm0    # 0xdeb18
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
leal 0x1(%rax), %edx
cmpl %eax, %ecx
cmovlel %ecx, %edx
movl %edx, 0x30(%rsp)
movq %rcx, %rdi
shlq $0x2, %rdi
testl %ecx, %ecx
movq $-0x1, %r13
cmovsq %r13, %rdi
callq 0x13030
movq %rax, 0x90(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2713c
movq %rax, 0x60(%rsp)
movslq 0x18(%rbx), %r15
movl $0x18, %ecx
movq %r15, %rax
mulq %rcx
movq %rax, %r14
cmovoq %r13, %r14
movq %r14, %rdi
callq 0x13030
movq %rax, %rbp
testq %r15, %r15
je 0x28528
shlq $0x3, %r15
leaq (%r15,%r15,2), %r15
xorl %r12d, %r12d
leaq (%r12,%rbp), %rdi
callq 0x84d7c
addq $0x18, %r12
cmpq %r12, %r15
jne 0x28516
movq %rbp, 0xa8(%rsp)
movslq 0x30(%rsp), %r15
movl $0x70, %ecx
movq %r15, %rax
mulq %rcx
movq %rax, %r14
seto %al
orq $0x8, %r14
movslq 0x18(%rbx), %rcx
testb %al, %al
cmovneq %r13, %r14
leaq (,%rcx,8), %r12
testq %rcx, %rcx
cmovsq %r13, %r12
movq %r12, %rdi
callq 0x13030
movq %rax, 0xa0(%rsp)
movq %r12, %rdi
callq 0x13030
movq %rax, 0x38(%rsp)
movq %r14, %rdi
callq 0x13030
movq %rax, %rbp
movq %r15, (%rax)
testl %r15d, %r15d
movq %rax, 0x48(%rsp)
je 0x285d2
imulq $0x70, %r15, %r13
xorl %r12d, %r12d
leaq (%r12,%rbp), %r15
addq $0x8, %r15
movq %r15, %rdi
callq 0xaaf34
leaq (%r12,%rbp), %rdi
addq $0x18, %rdi
callq 0x8386c
leaq (%r12,%rbp), %rdi
addq $0x38, %rdi
callq 0x6df44
addq $0x70, %r12
cmpq %r12, %r13
jne 0x2859f
movsd 0xb5b66(%rip), %xmm2    # 0xde140
movsd 0x98(%rsp), %xmm3
mulsd %xmm2, %xmm3
mulsd 0x88(%rsp), %xmm2
mulsd %xmm3, %xmm3
movsd 0xb6514(%rip), %xmm0    # 0xdeb10
mulsd %xmm2, %xmm2
movapd %xmm3, %xmm1
mulsd %xmm0, %xmm1
movsd 0xb5b40(%rip), %xmm4    # 0xde150
mulsd %xmm2, %xmm0
movapd %xmm4, %xmm5
divsd %xmm1, %xmm5
xorpd %xmm1, %xmm1
cmpneqsd %xmm1, %xmm3
movapd %xmm4, %xmm6
divsd %xmm0, %xmm6
cmpneqsd %xmm1, %xmm2
andpd %xmm3, %xmm5
andnpd %xmm4, %xmm3
movapd %xmm3, 0xc0(%rsp)
andpd %xmm2, %xmm6
andnpd %xmm4, %xmm2
movapd %xmm2, 0xd0(%rsp)
movslq 0x18(%rbx), %r14
testq %r14, %r14
jle 0x2868c
leaq (,%r14,4), %rdx
movq 0x90(%rsp), %rdi
xorl %esi, %esi
movapd %xmm5, 0x10(%rsp)
movapd %xmm6, 0x70(%rsp)
callq 0x132a0
movapd 0x70(%rsp), %xmm6
movapd 0x10(%rsp), %xmm5
movapd 0xc0(%rsp), %xmm0
orpd %xmm5, %xmm0
movapd %xmm0, 0xc0(%rsp)
movapd 0xd0(%rsp), %xmm0
orpd %xmm6, %xmm0
movapd %xmm0, 0xd0(%rsp)
testl %r14d, %r14d
movl 0x30(%rsp), %r13d
jle 0x286d5
shlq $0x3, %r14
movq 0x38(%rsp), %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x132a0
leaq 0x8(%rbp), %rax
movq %rax, 0x58(%rsp)
testl %r13d, %r13d
jle 0x28c93
xorps %xmm0, %xmm0
cvtsi2sdl 0x6c(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movq $0x0, 0x40(%rsp)
xorl %r12d, %r12d
callq 0xacf78
xorps %xmm1, %xmm1
cvtsi2sdl 0x18(%rbx), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movslq %eax, %r14
movq 0x90(%rsp), %rax
cmpl $0x0, (%rax,%r14,4)
jne 0x28c85
movq 0x68(%rbx), %rax
movq %r14, %r15
shlq $0x4, %r15
cmpl $0x2, 0xc(%rax,%r15)
jl 0x28c85
movl %r12d, 0x70(%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 0x138(%rsp), %r12
movq %r12, %rdi
callq 0x84d7e
leaq (%r14,%r14,2), %rax
movq 0x60(%rsp), %rcx
leaq (%rcx,%rax,8), %r14
movq %r14, %rdi
leaq 0xbda2a(%rip), %rsi     # 0xe61d0
callq 0x4d778
testl %eax, %eax
jne 0x28c80
leaq 0x100(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x838fe
cmpl $0x0, 0x18(%rbx)
jle 0x28989
movq %r14, 0x50(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ebp, %ebp
movl $0x8, %r14d
movq 0x60(%rsp), %r12
movq $0x0, 0x28(%rsp)
movq 0x68(%rbx), %rax
cmpl $0x2, 0xc(%rax,%r15)
jl 0x2896f
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 0x150(%rsp), %r13
movq %r13, %rdi
callq 0x84d7e
movq %r13, %rdi
leaq 0x100(%rsp), %rsi
callq 0x50a76
ucomisd 0x98(%rsp), %xmm0
ja 0x2896f
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
leaq 0xbd959(%rip), %rsi     # 0xe61d0
callq 0x4d778
testl %eax, %eax
jne 0x2896f
movq %r12, %rdi
movq 0x50(%rsp), %rsi
callq 0x85aae
andpd 0xb5b37(%rip), %xmm0    # 0xde3d0
xorpd %xmm2, %xmm2
movsd 0xb58ab(%rip), %xmm1    # 0xde150
ucomisd %xmm0, %xmm1
jbe 0x288b4
callq 0x13490
movapd %xmm0, %xmm2
ucomisd 0x88(%rsp), %xmm2
ja 0x2896f
movapd 0xc0(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm2, 0xb8(%rsp)
callq 0x138c0
movsd %xmm0, 0x10(%rsp)
movapd 0xd0(%rsp), %xmm0
movsd 0xb8(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
callq 0x138c0
movapd %xmm0, %xmm1
mulsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %r13
movslq %r13d, %r13
leaq (%r13,%r13,2), %rax
movq 0xa8(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
leaq 0x150(%rsp), %rsi
callq 0x850ec
movq 0xa0(%rsp), %rax
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax,%r13,8)
incl %r13d
movq %r13, 0x28(%rsp)
incq %rbp
movslq 0x18(%rbx), %rax
addq $0x18, %r12
addq $0x10, %r14
cmpq %rax, %rbp
jl 0x287f5
jmp 0x2899c
movq $0x0, 0x28(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x80(%rsp), %xmm0
ucomisd 0x8(%rsp), %xmm0
movq 0x48(%rsp), %rbp
movl 0x30(%rsp), %r13d
ja 0x28c80
leaq 0x1b0(%rsp), %r12
movq %r12, %rdi
movq 0x28(%rsp), %r13
movl %r13d, %esi
movq 0xa8(%rsp), %r14
movq %r14, %rdx
movq 0xa0(%rsp), %r15
movq %r15, %rcx
callq 0x5501d
leaq 0x150(%rsp), %rdi
movq %r12, %rsi
movl %r13d, %edx
movq %r14, %rcx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x550a7
leaq 0x180(%rsp), %r14
movq %r14, %rdi
leaq 0xbd7b9(%rip), %rsi     # 0xe61d0
callq 0x4d778
testl %eax, %eax
jne 0x28c7b
leaq 0x100(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x840d2
movslq 0x40(%rsp), %rax
imulq $0x70, %rax, %r14
movq 0x58(%rsp), %r12
leaq (%r12,%r14), %rdi
movq %rdi, 0x8(%rsp)
xorl %esi, %esi
callq 0xab174
leaq (%r12,%r14), %r15
addq $0x10, %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x85fc2
movsd 0x118(%rsp), %xmm0
movsd %xmm0, 0x18(%r15)
leaq (%r12,%r14), %rdi
addq $0x38, %rdi
leaq 0x10cf3f(%rip), %r13    # 0x1359c8
leaq 0x8(%r13), %rsi
callq 0x850ec
leaq (%r12,%r14), %r15
addq $0x50, %r15
leaq 0x20(%r13), %rsi
movq %r15, %rdi
callq 0x850ec
movq $0x0, 0x18(%r15)
cmpl $0x0, 0x18(%rbx)
jle 0x28c52
movq 0x58(%rsp), %rax
addq %r14, %rax
addq $0x30, %rax
movq %rax, 0x50(%rsp)
xorl %ebp, %ebp
movq 0x60(%rsp), %r12
xorl %r14d, %r14d
movq 0x68(%rbx), %rax
cmpl $0x2, 0xc(%rax,%rbp)
jl 0x28c3a
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 0x198(%rsp), %r13
movq %r13, %rdi
callq 0x84d7e
movq %r13, %rdi
leaq 0x100(%rsp), %rsi
callq 0x50a76
movsd %xmm0, 0x10(%rsp)
ucomisd 0x98(%rsp), %xmm0
ja 0x28c3a
movq %r12, %rdi
leaq 0xbd67c(%rip), %rsi     # 0xe61d0
callq 0x4d778
testl %eax, %eax
jne 0x28c3a
movq %r12, %rdi
leaq 0x100(%rsp), %rsi
callq 0x85aae
andpd 0xb5857(%rip), %xmm0    # 0xde3d0
xorpd %xmm2, %xmm2
movsd 0xb55cb(%rip), %xmm1    # 0xde150
ucomisd %xmm0, %xmm1
jbe 0x28b94
callq 0x13490
movapd %xmm0, %xmm2
ucomisd 0x88(%rsp), %xmm2
ja 0x28c3a
addq %rbp, %r15
movapd 0xc0(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm2, 0x28(%rsp)
callq 0x138c0
movsd %xmm0, 0x10(%rsp)
movapd 0xd0(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
callq 0x138c0
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x8(%rsp), %r13
movl 0xc(%r13), %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0xaafca
movq 0x50(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x6e9a6
movsd 0x10(%rsp), %xmm0
addsd 0x68(%r13), %xmm0
movsd %xmm0, 0x68(%r13)
movq 0x90(%rsp), %rax
incl (%rax,%r14,4)
incq %r14
movslq 0x18(%rbx), %rax
addq $0x18, %r12
addq $0x10, %rbp
cmpq %rax, %r14
jl 0x28ad3
xorl %eax, %eax
movsd 0x80(%rsp), %xmm0
movq 0x8(%rsp), %rcx
ucomisd 0x68(%rcx), %xmm0
setbe %al
movq 0x40(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x40(%rsp)
movq 0x48(%rsp), %rbp
movl 0x30(%rsp), %r13d
movl 0x70(%rsp), %r12d
incl %r12d
cmpl %r13d, %r12d
jne 0x28705
jmp 0x28c9c
movq $0x0, 0x40(%rsp)
movq 0x40(%rsp), %r14
movl %r14d, %r13d
testl %r14d, %r14d
movq 0x58(%rsp), %r12
jle 0x28cc5
leaq 0x4e4(%rip), %rcx       # 0x29199
movl $0x70, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x13970
movl $0x10, %edi
callq 0x134e0
movq %rax, 0xb0(%rsp)
movq %rax, %rdi
callq 0xaaf34
testl %r14d, %r14d
jle 0x29079
xorpd %xmm0, %xmm0
cmpltpd 0x120(%rsp), %xmm0
xorpd %xmm1, %xmm1
cmpltpd 0xe0(%rsp), %xmm1
orpd %xmm0, %xmm1
movss %xmm1, 0x80(%rsp)
xorl %eax, %eax
movq %r13, 0x28(%rsp)
movq %rax, 0x30(%rsp)
imulq $0x70, %rax, %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 0x752ae
addq %r12, %rbp
cmpl $0x0, 0xc(%rbp)
movq 0x38(%rsp), %rsi
jle 0x28f68
movq 0x10(%rsp), %rax
leaq 0x20(%rax), %rcx
movq %rcx, 0x50(%rsp)
addq $0x130, %rax            # imm = 0x130
movq %rax, 0x40(%rsp)
xorl %r13d, %r13d
movl $0x0, 0x70(%rsp)
movq (%rbp), %rax
movq (%rax,%r13,8), %rax
movq %rax, %rcx
subq 0x10(%rbx), %rcx
movq 0x68(%rbx), %rdx
shrq $0x4, %rcx
movslq %ecx, %r12
movq %r12, %rcx
shlq $0x4, %rcx
cmpl $0x2, 0xc(%rdx,%rcx)
jl 0x28f56
cmpq $0x0, (%rsi,%r12,8)
jne 0x28f56
movq 0x10(%rsp), %rcx
movq %rcx, (%rsi,%r12,8)
movq (%rax), %rcx
movq 0x8(%rax), %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 0x100(%rsp), %r15
movq %r15, %rdi
callq 0x84d7e
movq %r15, %rdi
movq %r14, %rsi
callq 0x50a76
ucomisd 0x98(%rsp), %xmm0
ja 0x28f51
movsd %xmm0, 0x8(%rsp)
leaq (%r12,%r12,2), %rax
movq 0x60(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
movq %r12, %rdi
leaq 0xbd395(%rip), %rsi     # 0xe61d0
callq 0x4d778
testl %eax, %eax
jne 0x28f51
movq %r12, %rdi
movq %r14, %rsi
callq 0x85aae
andpd 0xb5575(%rip), %xmm0    # 0xde3d0
xorpd %xmm2, %xmm2
movsd 0xb52e9(%rip), %xmm1    # 0xde150
ucomisd %xmm0, %xmm1
jbe 0x28e76
callq 0x13490
movapd %xmm0, %xmm2
ucomisd 0x88(%rsp), %xmm2
ja 0x28f51
movapd 0xc0(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm2, 0xb8(%rsp)
callq 0x138c0
movsd %xmm0, 0x8(%rsp)
movapd 0xd0(%rsp), %xmm0
movsd 0xb8(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
callq 0x138c0
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
leaq 0x150(%rsp), %r15
movq %r15, %rdi
leaq 0x100(%rsp), %rsi
callq 0x84d8e
movq %r15, %rdi
movq 0x50(%rsp), %rsi
callq 0x8569a
movsd 0x150(%rsp), %xmm0
movsd 0x158(%rsp), %xmm1
leaq 0x138(%rsp), %rdi
movq 0x40(%rsp), %r15
movq %r15, %rsi
callq 0x9923a
movsd 0x138(%rsp), %xmm0
movsd 0x140(%rsp), %xmm1
movq %r15, %rdi
movsd 0x8(%rsp), %xmm2
xorl %esi, %esi
callq 0x97bea
incl 0x70(%rsp)
movq 0x38(%rsp), %rsi
incq %r13
movslq 0xc(%rbp), %rax
cmpq %rax, %r13
jl 0x28d87
jmp 0x28f70
movl $0x0, 0x70(%rsp)
movl 0x70(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0x28fa8
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x7615e
movl $0x240, %esi            # imm = 0x240
movq %r14, %rdi
callq 0x134f0
movq 0x48(%rsp), %rbp
movq 0x58(%rsp), %r12
movq 0x28(%rsp), %r13
jmp 0x2904a
testb $0x1, 0x80(%rsp)
movq 0x48(%rsp), %rbp
movq 0x58(%rsp), %r12
movq 0x28(%rsp), %r13
je 0x29035
movq 0x10(%rsp), %r14
leaq 0x20(%r14), %rdi
callq 0x70dbe
mulsd 0x1e0(%r14), %xmm0
movapd %xmm0, %xmm1
mulsd 0xe0(%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
movapd 0x120(%rsp), %xmm0
divsd %xmm2, %xmm0
addq $0x130, %r14            # imm = 0x130
xorpd %xmm2, %xmm2
xorpd %xmm3, %xmm3
xorpd %xmm4, %xmm4
movq %r14, %rdi
movsd 0xb5b04(%rip), %xmm5    # 0xdeb20
callq 0x9a168
movq %r14, %rdi
callq 0x92bc4
ucomisd 0xb5357(%rip), %xmm0    # 0xde388
jne 0x29035
jnp 0x2905d
movq 0xb0(%rsp), %rdi
movl 0xc(%rdi), %edx
movq 0x10(%rsp), %rsi
callq 0xaafca
movq 0x30(%rsp), %rax
incq %rax
cmpq %r13, %rax
jne 0x28d18
jmp 0x29079
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x7615e
movl $0x240, %esi            # imm = 0x240
movq %r14, %rdi
callq 0x134f0
jmp 0x2904a
movq 0x90(%rsp), %rdi
callq 0x13680
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x29095
callq 0x13680
movq 0xa8(%rsp), %rdi
callq 0x13680
movq 0xa0(%rsp), %rdi
callq 0x13680
movq 0x38(%rsp), %rdi
callq 0x13680
movq (%rbp), %rax
imulq $0x70, %rax, %rcx
leaq 0x8(%rcx), %rbx
testq %rax, %rax
je 0x290f1
imulq $-0x70, %rax, %r15
leaq (%rcx,%rbp), %r14
addq $-0x68, %r14
leaq 0x30(%r14), %rdi
callq 0x6ede0
movq %r14, %rdi
callq 0xaaf9e
addq $-0x70, %r14
addq $0x70, %r15
jne 0x290d6
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x139b0
movq 0xb0(%rsp), %rax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x10, %esi
movq 0xb0(%rsp), %rdi
jmp 0x2913a
movq %rax, %rbx
jmp 0x29154
movq %rax, %rbx
movl $0x240, %esi            # imm = 0x240
movq 0x10(%rsp), %rdi
callq 0x134f0
jmp 0x29191
movq %rax, %rbx
movq %rbp, %rdi
jmp 0x29189
movq %rax, %rbx
movq %r15, %rdi
callq 0xaaf9e
testq %r12, %r12
je 0x29184
movq 0x48(%rsp), %rax
leaq (%rax,%r12), %r15
addq $-0x68, %r15
negq %r12
leaq 0x30(%r15), %rdi
callq 0x6ede0
movq %r15, %rdi
callq 0xaaf9e
addq $-0x70, %r15
addq $0x70, %r12
jne 0x29169
movq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x139b0
movq %rbx, %rdi
callq 0x138b0