// File: tomfunkhouser[P]gaps/pkgs/R3Utils/R3Segmentation.cpp
// Function: gaps::R3SegmentationCluster::Affinity(gaps::R3SegmentationCluster*) const
RNScalar R3SegmentationCluster::
Affinity(R3SegmentationCluster *cluster) const
{
  // Get convenient variables
  R3Segmentation *segmentation = cluster->segmentation;
  double max_pair_color_difference = (segmentation) ? segmentation->max_pair_color_difference : 0;
  double max_pair_timestamp_difference = (segmentation) ? segmentation->max_pair_timestamp_difference : 0;
  double max_pair_category_difference = (segmentation) ? segmentation->max_pair_category_difference : 0;
  double max_pair_centroid_distance = (segmentation) ? segmentation->max_pair_centroid_distance : 0;
  double max_pair_primitive_distance = (segmentation) ? segmentation->max_pair_primitive_distance : 0;
  double max_pair_normal_angle = (segmentation) ? segmentation->max_pair_normal_angle : 0;
  RNBoolean equalize_cluster_sizes = (segmentation) ? segmentation->equalize_cluster_sizes : FALSE;
  RNBoolean balance_cluster_sizes = (segmentation) ? segmentation->balance_cluster_sizes : FALSE;
  RNBoolean favor_convex_clusters = (segmentation) ? segmentation->favor_convex_clusters : FALSE;
  RNBoolean scale_tolerances_with_depth = (segmentation) ? segmentation->scale_tolerances_with_depth : FALSE;

  // Initialize affinity
  RNScalar affinity = 1;

  // Check color difference
  if (max_pair_color_difference > 0) {
    RNLength color_difference = 0;
    color_difference += fabs(color.R() - cluster->color.R());
    color_difference += fabs(color.G() - cluster->color.G());
    color_difference += fabs(color.B() - cluster->color.B());
    RNScalar color_difference_affinity = exp(color_difference * color_difference / (-2.0 * 0.25 * max_pair_color_difference * max_pair_color_difference));
    affinity *= color_difference_affinity;
    assert(affinity >= 0);
  }

  // Check timestamp difference
  if (max_pair_timestamp_difference > 0) {
    RNLength timestamp_difference = fabs(timestamp - cluster->timestamp);
    if (timestamp_difference > 0) {
      RNScalar timestamp_difference_affinity = exp(timestamp_difference * timestamp_difference / (-2.0 *  max_pair_timestamp_difference * max_pair_timestamp_difference));
      affinity *= timestamp_difference_affinity;
      assert(affinity >= 0);
    }
  }

  // Check category difference
  if (max_pair_category_difference > 0) {
    if (category_identifier != cluster->category_identifier) {
      RNScalar min_category_confidence = (category_confidence <  cluster->category_confidence) ? category_confidence : cluster->category_confidence;
      RNScalar category_difference_affinity = exp(min_category_confidence * min_category_confidence / (-2.0 * max_pair_category_difference * max_pair_category_difference));
      affinity *= category_difference_affinity;
    }
  }

  // Compute centroid distance
  if (max_pair_centroid_distance > 0) {
    RNLength centroid_distance = R3Distance(primitive.centroid, cluster->primitive.centroid);
    RNScalar centroid_distance_affinity = exp(centroid_distance * centroid_distance / (-2.0 * 0.25 * max_pair_centroid_distance * max_pair_centroid_distance));
    affinity *= centroid_distance_affinity;
    assert(affinity >= 0);
  }

  // Compute primitive distances
  if (max_pair_primitive_distance > 0) {
    // Compute point0-primitive1 distance
    RNLength primitive0_distance = primitive.Distance(cluster->primitive.centroid);
    if (seed_point && (seed_point->depth > 0) && scale_tolerances_with_depth) primitive0_distance  /= seed_point->depth;
    RNScalar primitive0_distance_affinity = exp(primitive0_distance * primitive0_distance / (-2.0 * 0.25 * max_pair_primitive_distance * max_pair_primitive_distance));
    affinity *= primitive0_distance_affinity;
    assert(affinity >= 0);

    // Compute point1-primitive0 distance
    RNLength primitive1_distance = cluster->primitive.Distance(primitive.centroid);
    if (seed_point && (seed_point->depth > 0) && scale_tolerances_with_depth) primitive1_distance  /= seed_point->depth;
    RNScalar primitive1_distance_affinity = exp(primitive1_distance * primitive1_distance / (-2.0 * 0.25 * max_pair_primitive_distance * max_pair_primitive_distance));
    affinity *= primitive1_distance_affinity;
    assert(affinity >= 0);
  }

  // Compute normal angle
  if (max_pair_normal_angle > 0) {
    if ((primitive.primitive_type == R3_SEGMENTATION_LINE_PRIMITIVE_TYPE) &&
      (cluster->primitive.primitive_type == R3_SEGMENTATION_LINE_PRIMITIVE_TYPE)) {
      RNScalar dot = fabs(primitive.line.Vector().Dot(cluster->primitive.line.Vector()));
      RNAngle normal_angle = (dot < 1) ? acos(dot) : 0;
      if (seed_point && (seed_point->depth > 0) && scale_tolerances_with_depth) normal_angle  /= seed_point->depth;
      RNScalar normal_angle_affinity = exp(normal_angle * normal_angle / (-2.0 * 0.25 * max_pair_normal_angle * max_pair_normal_angle));
      affinity *= normal_angle_affinity;
      assert(affinity >= 0);
    }
    else if ((primitive.primitive_type == R3_SEGMENTATION_PLANE_PRIMITIVE_TYPE) &&
      (cluster->primitive.primitive_type == R3_SEGMENTATION_LINE_PRIMITIVE_TYPE)) {
      RNScalar dot = fabs(primitive.plane.Normal().Dot(cluster->primitive.line.Vector()));
      RNAngle normal_angle = (dot < 1) ? RN_PI_OVER_TWO - acos(dot) : RN_PI_OVER_TWO;
      if (seed_point && (seed_point->depth > 0) && scale_tolerances_with_depth) normal_angle  /= seed_point->depth;
      RNScalar normal_angle_affinity = exp(normal_angle * normal_angle / (-2.0 * 0.25 * max_pair_normal_angle * max_pair_normal_angle));
      affinity *= normal_angle_affinity;
      assert(affinity >= 0);
    }
    else if ((primitive.primitive_type == R3_SEGMENTATION_LINE_PRIMITIVE_TYPE) &&
      (cluster->primitive.primitive_type == R3_SEGMENTATION_PLANE_PRIMITIVE_TYPE)) {
      RNScalar dot = fabs(primitive.line.Vector().Dot(cluster->primitive.plane.Normal()));
      RNAngle normal_angle = (dot < 1) ? RN_PI_OVER_TWO - acos(dot) : RN_PI_OVER_TWO;
      if (seed_point && (seed_point->depth > 0) && scale_tolerances_with_depth) normal_angle  /= seed_point->depth;
      RNScalar normal_angle_affinity = exp(normal_angle * normal_angle / (-2.0 * 0.25 * max_pair_normal_angle * max_pair_normal_angle));
      affinity *= normal_angle_affinity;
      assert(affinity >= 0);
    }
    else if ((primitive.primitive_type == R3_SEGMENTATION_PLANE_PRIMITIVE_TYPE) &&
      (cluster->primitive.primitive_type == R3_SEGMENTATION_PLANE_PRIMITIVE_TYPE)) {
      RNScalar dot = primitive.plane.Normal().Dot(cluster->primitive.plane.Normal());
      RNAngle normal_angle = (dot > -1) ? ((dot < 1) ? acos(dot) : 0) : RN_PI;
      if (seed_point && (seed_point->depth > 0) && scale_tolerances_with_depth) normal_angle  /= seed_point->depth;
      RNScalar normal_angle_affinity = exp(normal_angle * normal_angle / (-2.0 * 0.25 * max_pair_normal_angle * max_pair_normal_angle));
      affinity *= normal_angle_affinity;
      assert(affinity >= 0);
    }
  }

  // Compute fraction of points in smallest cluster
  if (equalize_cluster_sizes) {
    int segmentation_npoints = (segmentation) ? segmentation->points.NEntries() : 0;
    int segmentation_nclusters = (segmentation) ? segmentation->clusters.NEntries() : 0;
    if ((segmentation_npoints > 0) && (segmentation_nclusters > 0)) {
      int smaller_npoints = (points.NEntries() < cluster->points.NEntries()) ? points.NEntries() : cluster->points.NEntries();
      if (smaller_npoints == 0) return 0;
      RNScalar avg_points_per_cluster = (RNScalar) segmentation_npoints / (RNScalar) segmentation_nclusters;
      RNScalar balance_affinity =  avg_points_per_cluster / smaller_npoints;
      affinity *= balance_affinity;
      assert(affinity >= 0);
    }
  }
  
  // Compute relative sizes of clusters
  if (balance_cluster_sizes) {
    RNScalar balance_affinity = 1.0;
    if (points.NEntries() == 0) return 0;
    if (cluster->points.NEntries() == 0) return 0;
    if (points.NEntries() < cluster->points.NEntries()) balance_affinity = (RNScalar) points.NEntries() / (RNScalar) cluster->points.NEntries();
    else balance_affinity = (RNScalar) cluster->points.NEntries() / (RNScalar) points.NEntries();
    affinity *= balance_affinity;
    assert(affinity >= 0);
  }
  
  // Compute fraction of points in smallest cluster
  if (favor_convex_clusters) {
    RNScalar convexity_affinity = MergedConvexity(this, cluster);
    affinity *= convexity_affinity;
    assert(affinity >= 0);
  }
  
  // Just checking
  assert(affinity >= 0);

  // Return affinity
  return affinity;
}

// Assembly:
subq $0x248, %rsp            # imm = 0x248
movq %rdi, 0x238(%rsp)
movq %rsi, 0x230(%rsp)
movq 0x238(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0x230(%rsp), %rax
movq 0x130(%rax), %rax
movq %rax, 0x228(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x40a34
movq 0x228(%rsp), %rax
movsd 0x98(%rax), %xmm0
movsd %xmm0, 0xe0(%rsp)
jmp 0x40a42
xorps %xmm0, %xmm0
movsd %xmm0, 0xe0(%rsp)
jmp 0x40a42
movsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x220(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x40a7a
movq 0x228(%rsp), %rax
movsd 0xa0(%rax), %xmm0
movsd %xmm0, 0xd8(%rsp)
jmp 0x40a88
xorps %xmm0, %xmm0
movsd %xmm0, 0xd8(%rsp)
jmp 0x40a88
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x218(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x40ac0
movq 0x228(%rsp), %rax
movsd 0xa8(%rax), %xmm0
movsd %xmm0, 0xd0(%rsp)
jmp 0x40ace
xorps %xmm0, %xmm0
movsd %xmm0, 0xd0(%rsp)
jmp 0x40ace
movsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0x210(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x40b06
movq 0x228(%rsp), %rax
movsd 0x80(%rax), %xmm0
movsd %xmm0, 0xc8(%rsp)
jmp 0x40b14
xorps %xmm0, %xmm0
movsd %xmm0, 0xc8(%rsp)
jmp 0x40b14
movsd 0xc8(%rsp), %xmm0
movsd %xmm0, 0x208(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x40b4c
movq 0x228(%rsp), %rax
movsd 0x88(%rax), %xmm0
movsd %xmm0, 0xc0(%rsp)
jmp 0x40b5a
xorps %xmm0, %xmm0
movsd %xmm0, 0xc0(%rsp)
jmp 0x40b5a
movsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0x200(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x40b92
movq 0x228(%rsp), %rax
movsd 0x90(%rax), %xmm0
movsd %xmm0, 0xb8(%rsp)
jmp 0x40ba0
xorps %xmm0, %xmm0
movsd %xmm0, 0xb8(%rsp)
jmp 0x40ba0
movsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0x1f8(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x40bd4
movq 0x228(%rsp), %rax
movl 0xc0(%rax), %eax
movl %eax, 0xb4(%rsp)
jmp 0x40bdf
xorl %eax, %eax
movl %eax, 0xb4(%rsp)
jmp 0x40bdf
movl 0xb4(%rsp), %eax
movl %eax, 0x1f4(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x40c0f
movq 0x228(%rsp), %rax
movl 0xc4(%rax), %eax
movl %eax, 0xb0(%rsp)
jmp 0x40c1a
xorl %eax, %eax
movl %eax, 0xb0(%rsp)
jmp 0x40c1a
movl 0xb0(%rsp), %eax
movl %eax, 0x1f0(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x40c4a
movq 0x228(%rsp), %rax
movl 0xc8(%rax), %eax
movl %eax, 0xac(%rsp)
jmp 0x40c55
xorl %eax, %eax
movl %eax, 0xac(%rsp)
jmp 0x40c55
movl 0xac(%rsp), %eax
movl %eax, 0x1ec(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x40c85
movq 0x228(%rsp), %rax
movl 0xcc(%rax), %eax
movl %eax, 0xa8(%rsp)
jmp 0x40c90
xorl %eax, %eax
movl %eax, 0xa8(%rsp)
jmp 0x40c90
movl 0xa8(%rsp), %eax
movl %eax, 0x1e8(%rsp)
movsd 0x1bc37a(%rip), %xmm0   # 0x1fd020
movsd %xmm0, 0x1e0(%rsp)
movsd 0x220(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x40e44
movq 0xe8(%rsp), %rdi
xorps %xmm0, %xmm0
movsd %xmm0, 0x1d8(%rsp)
addq $0xf0, %rdi
callq 0x1f700
movsd %xmm0, 0x90(%rsp)
movq 0x230(%rsp), %rdi
addq $0xf0, %rdi
callq 0x1f700
movq 0xe8(%rsp), %rdi
movaps %xmm0, %xmm1
movsd 0x90(%rsp), %xmm0
subsd %xmm1, %xmm0
movaps 0x1bc34f(%rip), %xmm1   # 0x1fd070
pand %xmm1, %xmm0
addsd 0x1d8(%rsp), %xmm0
movsd %xmm0, 0x1d8(%rsp)
addq $0xf0, %rdi
callq 0x1f710
movsd %xmm0, 0x98(%rsp)
movq 0x230(%rsp), %rdi
addq $0xf0, %rdi
callq 0x1f710
movq 0xe8(%rsp), %rdi
movaps %xmm0, %xmm1
movsd 0x98(%rsp), %xmm0
subsd %xmm1, %xmm0
movaps 0x1bc2f1(%rip), %xmm1   # 0x1fd070
pand %xmm1, %xmm0
addsd 0x1d8(%rsp), %xmm0
movsd %xmm0, 0x1d8(%rsp)
addq $0xf0, %rdi
callq 0x1f720
movsd %xmm0, 0xa0(%rsp)
movq 0x230(%rsp), %rdi
addq $0xf0, %rdi
callq 0x1f720
movaps %xmm0, %xmm1
movsd 0xa0(%rsp), %xmm0
subsd %xmm1, %xmm0
movaps 0x1bc29b(%rip), %xmm1   # 0x1fd070
pand %xmm1, %xmm0
addsd 0x1d8(%rsp), %xmm0
movsd %xmm0, 0x1d8(%rsp)
movsd 0x1d8(%rsp), %xmm0
mulsd 0x1d8(%rsp), %xmm0
movsd 0x1bc7eb(%rip), %xmm1   # 0x1fd5f0
mulsd 0x220(%rsp), %xmm1
mulsd 0x220(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x16ce0
movsd %xmm0, 0x1d0(%rsp)
movsd 0x1d0(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
movsd 0x218(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x40efb
movq 0xe8(%rsp), %rax
movsd 0x108(%rax), %xmm0
movq 0x230(%rsp), %rax
subsd 0x108(%rax), %xmm0
movaps 0x1bc1ef(%rip), %xmm1   # 0x1fd070
pand %xmm1, %xmm0
movsd %xmm0, 0x1c8(%rsp)
movsd 0x1c8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x40ef9
movsd 0x1c8(%rsp), %xmm0
mulsd 0x1c8(%rsp), %xmm0
movsd 0x1bd1f6(%rip), %xmm1   # 0x1fe0b0
mulsd 0x218(%rsp), %xmm1
mulsd 0x218(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x16ce0
movsd %xmm0, 0x1c0(%rsp)
movsd 0x1c0(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x40efb
movsd 0x210(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x40ffa
movq 0xe8(%rsp), %rax
movl 0x110(%rax), %eax
movq 0x230(%rsp), %rcx
cmpl 0x110(%rcx), %eax
je 0x40ff8
movq 0xe8(%rsp), %rax
movsd 0x118(%rax), %xmm1
movq 0x230(%rsp), %rax
movsd 0x118(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x40f74
movq 0xe8(%rsp), %rax
movsd 0x118(%rax), %xmm0
movsd %xmm0, 0x88(%rsp)
jmp 0x40f8d
movq 0x230(%rsp), %rax
movsd 0x118(%rax), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x1b8(%rsp)
movsd 0x1b8(%rsp), %xmm0
mulsd 0x1b8(%rsp), %xmm0
movsd 0x1bd0f7(%rip), %xmm1   # 0x1fe0b0
mulsd 0x210(%rsp), %xmm1
mulsd 0x210(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x16ce0
movsd %xmm0, 0x1b0(%rsp)
movsd 0x1b0(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x40ffa
movsd 0x208(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x41097
movq 0xe8(%rsp), %rdi
addq $0x40, %rdi
addq $0x40, %rdi
movq 0x230(%rsp), %rsi
addq $0x40, %rsi
addq $0x40, %rsi
callq 0xc0550
movsd %xmm0, 0x1a8(%rsp)
movsd 0x1a8(%rsp), %xmm0
mulsd 0x1a8(%rsp), %xmm0
movsd 0x1bc598(%rip), %xmm1   # 0x1fd5f0
mulsd 0x208(%rsp), %xmm1
mulsd 0x208(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x16ce0
movsd %xmm0, 0x1a0(%rsp)
movsd 0x1a0(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
movsd 0x200(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4125d
movq 0xe8(%rsp), %rdi
addq $0x40, %rdi
movq 0x230(%rsp), %rsi
addq $0x40, %rsi
addq $0x40, %rsi
callq 0x3cac0
movq 0xe8(%rsp), %rax
movsd %xmm0, 0x198(%rsp)
cmpq $0x0, (%rax)
je 0x4112c
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4112c
cmpl $0x0, 0x1e8(%rsp)
je 0x4112c
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm1
movsd 0x198(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x198(%rsp)
movsd 0x198(%rsp), %xmm0
mulsd 0x198(%rsp), %xmm0
movsd 0x1bc4aa(%rip), %xmm1   # 0x1fd5f0
mulsd 0x200(%rsp), %xmm1
mulsd 0x200(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x16ce0
movq 0xe8(%rsp), %rsi
movsd %xmm0, 0x190(%rsp)
movsd 0x190(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
movq 0x230(%rsp), %rdi
addq $0x40, %rdi
addq $0x40, %rsi
addq $0x40, %rsi
callq 0x3cac0
movq 0xe8(%rsp), %rax
movsd %xmm0, 0x188(%rsp)
cmpq $0x0, (%rax)
je 0x41204
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x41204
cmpl $0x0, 0x1e8(%rsp)
je 0x41204
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm1
movsd 0x188(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x188(%rsp)
movsd 0x188(%rsp), %xmm0
mulsd 0x188(%rsp), %xmm0
movsd 0x1bc3d2(%rip), %xmm1   # 0x1fd5f0
mulsd 0x200(%rsp), %xmm1
mulsd 0x200(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x16ce0
movsd %xmm0, 0x180(%rsp)
movsd 0x180(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
movsd 0x1f8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x418a3
movq 0xe8(%rsp), %rax
cmpl $0x2, 0x40(%rax)
jne 0x413e3
movq 0x230(%rsp), %rax
cmpl $0x2, 0x40(%rax)
jne 0x413e3
movq 0xe8(%rsp), %rdi
addq $0x40, %rdi
addq $0x58, %rdi
callq 0x47560
movq %rax, 0x80(%rsp)
movq 0x230(%rsp), %rdi
addq $0x40, %rdi
addq $0x58, %rdi
callq 0x47560
movq 0x80(%rsp), %rdi
movq %rax, %rsi
callq 0x12c4c0
movaps 0x1bbd90(%rip), %xmm1   # 0x1fd070
pand %xmm1, %xmm0
movsd %xmm0, 0x178(%rsp)
movsd 0x1bbd2b(%rip), %xmm0   # 0x1fd020
ucomisd 0x178(%rsp), %xmm0
jbe 0x41316
movsd 0x178(%rsp), %xmm0
callq 0x166c0
movsd %xmm0, 0x78(%rsp)
jmp 0x41321
xorps %xmm0, %xmm0
movsd %xmm0, 0x78(%rsp)
jmp 0x41321
movq 0xe8(%rsp), %rax
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x170(%rsp)
cmpq $0x0, (%rax)
je 0x41385
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x41385
cmpl $0x0, 0x1e8(%rsp)
je 0x41385
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm1
movsd 0x170(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x170(%rsp)
movsd 0x170(%rsp), %xmm0
mulsd 0x170(%rsp), %xmm0
movsd 0x1bc251(%rip), %xmm1   # 0x1fd5f0
mulsd 0x1f8(%rsp), %xmm1
mulsd 0x1f8(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x16ce0
movsd %xmm0, 0x168(%rsp)
movsd 0x168(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x418a1
movq 0xe8(%rsp), %rax
cmpl $0x3, 0x40(%rax)
jne 0x41574
movq 0x230(%rsp), %rax
cmpl $0x2, 0x40(%rax)
jne 0x41574
movq 0xe8(%rsp), %rdi
addq $0x40, %rdi
addq $0x88, %rdi
callq 0x2dca0
movq %rax, 0x70(%rsp)
movq 0x230(%rsp), %rdi
addq $0x40, %rdi
addq $0x58, %rdi
callq 0x47560
movq 0x70(%rsp), %rdi
movq %rax, %rsi
callq 0x12c4c0
movaps 0x1bbc23(%rip), %xmm1   # 0x1fd070
pand %xmm1, %xmm0
movsd %xmm0, 0x160(%rsp)
movsd 0x1bbbbe(%rip), %xmm0   # 0x1fd020
ucomisd 0x160(%rsp), %xmm0
jbe 0x414a1
leaq 0x1c22dc(%rip), %rax    # 0x203750
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x160(%rsp), %xmm0
callq 0x166c0
movaps %xmm0, %xmm1
movsd 0x60(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
jmp 0x414b2
leaq 0x1c22a8(%rip), %rax    # 0x203750
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0xe8(%rsp), %rax
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x158(%rsp)
cmpq $0x0, (%rax)
je 0x41516
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x41516
cmpl $0x0, 0x1e8(%rsp)
je 0x41516
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm1
movsd 0x158(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x158(%rsp)
movsd 0x158(%rsp), %xmm0
mulsd 0x158(%rsp), %xmm0
movsd 0x1bc0c0(%rip), %xmm1   # 0x1fd5f0
mulsd 0x1f8(%rsp), %xmm1
mulsd 0x1f8(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x16ce0
movsd %xmm0, 0x150(%rsp)
movsd 0x150(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x4189f
movq 0xe8(%rsp), %rax
cmpl $0x2, 0x40(%rax)
jne 0x41705
movq 0x230(%rsp), %rax
cmpl $0x3, 0x40(%rax)
jne 0x41705
movq 0xe8(%rsp), %rdi
addq $0x40, %rdi
addq $0x58, %rdi
callq 0x47560
movq %rax, 0x58(%rsp)
movq 0x230(%rsp), %rdi
addq $0x40, %rdi
addq $0x88, %rdi
callq 0x2dca0
movq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x12c4c0
movaps 0x1bba92(%rip), %xmm1   # 0x1fd070
pand %xmm1, %xmm0
movsd %xmm0, 0x148(%rsp)
movsd 0x1bba2d(%rip), %xmm0   # 0x1fd020
ucomisd 0x148(%rsp), %xmm0
jbe 0x41632
leaq 0x1c214b(%rip), %rax    # 0x203750
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x148(%rsp), %xmm0
callq 0x166c0
movaps %xmm0, %xmm1
movsd 0x48(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
jmp 0x41643
leaq 0x1c2117(%rip), %rax    # 0x203750
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0xe8(%rsp), %rax
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x140(%rsp)
cmpq $0x0, (%rax)
je 0x416a7
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x416a7
cmpl $0x0, 0x1e8(%rsp)
je 0x416a7
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm1
movsd 0x140(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x140(%rsp)
movsd 0x140(%rsp), %xmm0
mulsd 0x140(%rsp), %xmm0
movsd 0x1bbf2f(%rip), %xmm1   # 0x1fd5f0
mulsd 0x1f8(%rsp), %xmm1
mulsd 0x1f8(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x16ce0
movsd %xmm0, 0x138(%rsp)
movsd 0x138(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x4189d
movq 0xe8(%rsp), %rax
cmpl $0x3, 0x40(%rax)
jne 0x4189b
movq 0x230(%rsp), %rax
cmpl $0x3, 0x40(%rax)
jne 0x4189b
movq 0xe8(%rsp), %rdi
addq $0x40, %rdi
addq $0x88, %rdi
callq 0x2dca0
movq %rax, 0x40(%rsp)
movq 0x230(%rsp), %rdi
addq $0x40, %rdi
addq $0x88, %rdi
callq 0x2dca0
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x12c4c0
movsd %xmm0, 0x130(%rsp)
movsd 0x130(%rsp), %xmm0
movsd 0x1bc923(%rip), %xmm1   # 0x1fe0a8
ucomisd %xmm1, %xmm0
jbe 0x417cd
movsd 0x1bb88d(%rip), %xmm0   # 0x1fd020
ucomisd 0x130(%rsp), %xmm0
jbe 0x417b4
movsd 0x130(%rsp), %xmm0
callq 0x166c0
movsd %xmm0, 0x38(%rsp)
jmp 0x417bf
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
jmp 0x417bf
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
jmp 0x417de
leaq 0x1c1f6c(%rip), %rax    # 0x203740
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xe8(%rsp), %rax
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x128(%rsp)
cmpq $0x0, (%rax)
je 0x41842
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x41842
cmpl $0x0, 0x1e8(%rsp)
je 0x41842
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm1
movsd 0x128(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x128(%rsp)
movsd 0x128(%rsp), %xmm0
mulsd 0x128(%rsp), %xmm0
movsd 0x1bbd94(%rip), %xmm1   # 0x1fd5f0
mulsd 0x1f8(%rsp), %xmm1
mulsd 0x1f8(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x16ce0
movsd %xmm0, 0x120(%rsp)
movsd 0x120(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x4189d
jmp 0x4189f
jmp 0x418a1
jmp 0x418a3
cmpl $0x0, 0x1f4(%rsp)
je 0x41a10
cmpq $0x0, 0x228(%rsp)
je 0x418cf
movq 0x228(%rsp), %rdi
callq 0x1ecf0
movl %eax, 0x2c(%rsp)
jmp 0x418d7
xorl %eax, %eax
movl %eax, 0x2c(%rsp)
jmp 0x418d7
movl 0x2c(%rsp), %eax
movl %eax, 0x11c(%rsp)
cmpq $0x0, 0x228(%rsp)
je 0x41904
movq 0x228(%rsp), %rdi
addq $0x18, %rdi
callq 0x1ecf0
movl %eax, 0x28(%rsp)
jmp 0x4190c
xorl %eax, %eax
movl %eax, 0x28(%rsp)
jmp 0x4190c
movl 0x28(%rsp), %eax
movl %eax, 0x118(%rsp)
cmpl $0x0, 0x11c(%rsp)
jle 0x41a0e
cmpl $0x0, 0x118(%rsp)
jle 0x41a0e
movq 0xe8(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
movl %eax, 0x24(%rsp)
movq 0x230(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jge 0x4197a
movq 0xe8(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
movl %eax, 0x20(%rsp)
jmp 0x4198f
movq 0x230(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x114(%rsp)
cmpl $0x0, 0x114(%rsp)
jne 0x419b5
xorps %xmm0, %xmm0
movsd %xmm0, 0x240(%rsp)
jmp 0x41ba5
cvtsi2sdl 0x11c(%rsp), %xmm0
cvtsi2sdl 0x118(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x108(%rsp)
movsd 0x108(%rsp), %xmm0
cvtsi2sdl 0x114(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x100(%rsp)
movsd 0x100(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x41a10
cmpl $0x0, 0x1f0(%rsp)
je 0x41b50
movq 0xe8(%rsp), %rdi
movsd 0x1bb5f2(%rip), %xmm0   # 0x1fd020
movsd %xmm0, 0xf8(%rsp)
addq $0x8, %rdi
callq 0x1ecf0
cmpl $0x0, %eax
jne 0x41a56
xorps %xmm0, %xmm0
movsd %xmm0, 0x240(%rsp)
jmp 0x41ba5
movq 0x230(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
cmpl $0x0, %eax
jne 0x41a7d
xorps %xmm0, %xmm0
movsd %xmm0, 0x240(%rsp)
jmp 0x41ba5
movq 0xe8(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
movl %eax, 0x1c(%rsp)
movq 0x230(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jge 0x41af2
movq 0xe8(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x230(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
movsd 0x10(%rsp), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xf8(%rsp)
jmp 0x41b35
movq 0x230(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
movq 0xe8(%rsp), %rdi
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
addq $0x8, %rdi
callq 0x1ecf0
movsd 0x8(%rsp), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xf8(%rsp)
movsd 0xf8(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
cmpl $0x0, 0x1ec(%rsp)
je 0x41b93
movq 0xe8(%rsp), %rdi
movq 0x230(%rsp), %rsi
callq 0x41bc0
movsd %xmm0, 0xf0(%rsp)
movsd 0xf0(%rsp), %xmm0
mulsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
movsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x240(%rsp)
movsd 0x240(%rsp), %xmm0
addq $0x248, %rsp            # imm = 0x248
retq
nopw %cs:(%rax,%rax)