// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/RGBD/RGBDUtil.cpp
// Function: gaps::RGBDCreateTangentChannels(gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid&, gaps::R2Grid&, gaps::R2Grid&, gaps::R2Grid&, gaps::R2Grid&, gaps::R2Grid&, gaps::R2Grid&, gaps::R2Grid&, gaps::R3Point const&, gaps::R3Vector const&, gaps::R3Vector const&, double, int, int)
int RGBDCreateTangentChannels(const R2Grid& input_depth_image, 
  const R2Grid& input_px_image, const R2Grid& input_py_image, const R2Grid& input_pz_image,
  const R2Grid& input_boundary_image,
  R2Grid& output_nx_image, R2Grid& output_ny_image, R2Grid& output_nz_image,
  R2Grid& output_tx_image, R2Grid& output_ty_image, R2Grid& output_tz_image,
  R2Grid& output_r1_image, R2Grid& output_r2_image,
  const R3Point& viewpoint, const R3Vector& towards, const R3Vector& up,
  RNLength neighborhood_world_radius, int neighborhood_pixel_radius, RNBoolean neighborhood_search)
{
  // Initialize normal images
  output_nx_image = input_depth_image; 
  output_nx_image.Clear(R2_GRID_UNKNOWN_VALUE);
  output_ny_image = output_nx_image;
  output_nz_image = output_nx_image;
  output_tx_image = output_nx_image;
  output_ty_image = output_nx_image;
  output_tz_image = output_nx_image;
  output_r1_image = output_nx_image;
  output_r2_image = output_nx_image;

  // Allocate array of neighborhood points
  int pixel_radius = neighborhood_pixel_radius * input_depth_image.XResolution() / 640.0 + 0.5;
  if (pixel_radius == 0) pixel_radius = 1;
  int neighborhood_pixel_radius_squared = pixel_radius * pixel_radius;
  RNScalar neighborhood_world_radius_squared = neighborhood_world_radius * neighborhood_world_radius;
  R3Point *neighborhood_points = new R3Point [ input_depth_image.NEntries() ];

  // Allocate search grid
  R2Grid search_grid(input_depth_image.XResolution(), input_depth_image.YResolution());
  const RNScalar *search_valuesp = search_grid.GridValues();
  search_grid.Clear(-1);

  // Fill normal images
  for (int i = 0; i < input_depth_image.XResolution(); i++) {
    for (int j = 0; j < input_depth_image.YResolution(); j++) {
      int neighborhood_npoints = 0;

      // Check depth
      RNScalar depth = input_depth_image.GridValue(i, j);
      if (RNIsNegativeOrZero(depth)) continue;

      // Get image position
      R2Point image_position(i, j);

      // Get world position
      RNScalar x = input_px_image.GridValue(i, j);
      RNScalar y = input_py_image.GridValue(i, j);
      RNScalar z = input_pz_image.GridValue(i, j);
      R3Point world_position(x, y, z);

      // Create array of neighborhood points
      if (neighborhood_search) {
        // Initialize stack
        int seed_index;
        RNArray<const RNScalar *> stack;
        search_grid.IndicesToIndex(i, j, seed_index);
        const RNScalar *seed_valuep = &search_valuesp[seed_index];
        search_grid.SetGridValue(seed_index, seed_index);
        stack.Insert(seed_valuep);

        // Depth first search, not extending beyond boundaries
        while (!stack.IsEmpty()) {
          // Pop current point off stack
          int ix, iy;
          const RNScalar *current_valuep = stack.Tail(); stack.RemoveTail();
          int current_index = current_valuep - search_valuesp;
          search_grid.IndexToIndices(current_index, ix, iy);

          // Get current info
          RNScalar current_x = input_px_image.GridValue(ix, iy);
          RNScalar current_y = input_py_image.GridValue(ix, iy);
          RNScalar current_z = input_pz_image.GridValue(ix, iy);
          R3Point current_position(current_x, current_y, current_z);
          RNScalar current_boundary_value = input_boundary_image.GridValue(ix, iy);
          int current_boundary = (int) (current_boundary_value + 0.5);
        
          // Add point to array
          neighborhood_points[neighborhood_npoints++] = current_position;

          // Add adjacent points to stack
          for (int inx = ix-1; inx <= ix+1; inx++) {
            if ((inx < 0) || (inx >= search_grid.XResolution())) continue;
            for (int iny = iy-1; iny <= iy+1; iny++) {
              if ((iny < 0) || (iny >= search_grid.YResolution())) continue;

              // Check if neighbor has already been visited
              RNScalar neighbor_value = search_grid.GridValue(inx, iny);
              if (RNIsEqual(neighbor_value, seed_index)) continue;
              search_grid.SetGridValue(inx, iny, seed_index);

              // Check neighbor depth
              RNScalar neighbor_depth = input_depth_image.GridValue(inx, iny);
              if (RNIsNegativeOrZero(neighbor_depth)) continue;

              // Check neighbor image distance
              R2Point neighbor_image_position(inx, iny);
              if (R2SquaredDistance(image_position, neighbor_image_position) > neighborhood_pixel_radius_squared) continue;
            
              // Check neighbor world distance
              RNScalar neighbor_x = input_px_image.GridValue(inx, iny);
              RNScalar neighbor_y = input_py_image.GridValue(inx, iny);
              RNScalar neighbor_z = input_pz_image.GridValue(inx, iny);
              R3Point neighbor_world_position(neighbor_x, neighbor_y, neighbor_z);
              if (neighborhood_world_radius_squared > 0) {
                if (R3SquaredDistance(world_position, neighbor_world_position) > neighborhood_world_radius_squared) continue;
              }

              // Check if neighbor is across boundary
              int neighbor_boundary = (int) (input_boundary_image.GridValue(inx, iny) + 0.5);
              if ((current_boundary == RGBD_SHADOW_BOUNDARY) && (neighbor_boundary == RGBD_SILHOUETTE_BOUNDARY)) continue;
              if ((current_boundary == RGBD_SILHOUETTE_BOUNDARY) && (neighbor_boundary == RGBD_SHADOW_BOUNDARY)) continue;
        
              // Add neighbor to search
              int neighbor_index;
              search_grid.IndicesToIndex(inx, iny, neighbor_index);
              const RNScalar *neighbor_valuep = &search_valuesp[neighbor_index];
              stack.Insert(neighbor_valuep);
            }
          }
        }
      }
      else {
        // Add neighbor points to array
        for (int inx = i-neighborhood_pixel_radius; inx <= i+neighborhood_pixel_radius; inx++) {
          if ((inx < 0) || (inx >= input_depth_image.XResolution())) continue;
          for (int iny = j-neighborhood_pixel_radius; iny <= j+neighborhood_pixel_radius; iny++) {
            if ((iny < 0) || (iny >= input_depth_image.YResolution())) continue;
            
            // Check neighbor depth
            RNScalar neighbor_depth = input_depth_image.GridValue(inx, iny);
            if (RNIsNegativeOrZero(neighbor_depth)) continue;

            // Check neighbor world position
            RNScalar neighbor_x = input_px_image.GridValue(inx, iny);
            RNScalar neighbor_y = input_py_image.GridValue(inx, iny);
            RNScalar neighbor_z = input_pz_image.GridValue(inx, iny);
            R3Point neighbor_world_position(neighbor_x, neighbor_y, neighbor_z);
            if (neighborhood_world_radius_squared > 0) {
              if (R3SquaredDistance(world_position, neighbor_world_position) > neighborhood_world_radius_squared) continue;
            }

            // Add neighbor point to array
            neighborhood_points[neighborhood_npoints++] = neighbor_world_position;
          }
        }
      }

      // Check number of neighbor points
      if (neighborhood_npoints < 3) continue;

      // Solve for normal
      RNScalar variances[3];
      R3Point centroid = R3Centroid(neighborhood_npoints, neighborhood_points);
      R3Triad triad = R3PrincipleAxes(centroid, neighborhood_npoints, neighborhood_points, NULL, variances);
      R3Vector normal = triad[2];
      R3Vector tangent = triad[0];
      
      // Flip normal to point towards camera
      R3Plane plane(world_position, normal);
      if (R3SignedDistance(plane, viewpoint) < 0) normal.Flip(); 

      // Fill normal images
      output_nx_image.SetGridValue(i, j, normal.X());
      output_ny_image.SetGridValue(i, j, normal.Y());
      output_nz_image.SetGridValue(i, j, normal.Z());

      // Fill tangent images
      output_tx_image.SetGridValue(i, j, tangent.X());
      output_ty_image.SetGridValue(i, j, tangent.Y());
      output_tz_image.SetGridValue(i, j, tangent.Z());

      // Fill radius images
      RNScalar r1 = 3 * sqrt(variances[0]);
      RNScalar r2 = 3 * sqrt(variances[1]);
      if (neighborhood_pixel_radius > 1) r1 /= neighborhood_pixel_radius;
      if (neighborhood_pixel_radius > 1) r2 /= neighborhood_pixel_radius;
      output_r1_image.SetGridValue(i, j, r1);
      output_r2_image.SetGridValue(i, j, r2);
    }
  }

  // Delete array of neighborhood points
  delete [] neighborhood_points;

  // Return success 
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movsd %xmm0, 0x18(%rsp)
movq %r9, %rbx
movq %r8, 0x98(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, %rbp
movq 0x2b8(%rsp), %r14
movq 0x2b0(%rsp), %r15
movq 0x2a8(%rsp), %r12
movq 0x2a0(%rsp), %r13
movq %r9, %rdi
movq %rbp, %rsi
callq 0x60d3c
movsd 0x9ad12(%rip), %xmm0    # 0xbd018
movq %rbx, %rdi
callq 0x62582
movq %r13, %rdi
movq %rbx, %rsi
callq 0x60d3c
movq %r12, %rdi
movq %rbx, %rsi
callq 0x60d3c
movq %r15, %rdi
movq %rbx, %rsi
callq 0x60d3c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x60d3c
movq 0x2c0(%rsp), %rdi
movq %rbx, %rsi
callq 0x60d3c
movq 0x2c8(%rsp), %rdi
movq %rbx, %rsi
callq 0x60d3c
movq 0x2d0(%rsp), %rdi
movq %rbx, 0xa0(%rsp)
movq %rbx, %rsi
callq 0x60d3c
movl 0xc0(%rbp), %eax
movl 0x2f0(%rsp), %ecx
imull %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x9be7f(%rip), %xmm0    # 0xbe210
addsd 0x9ac87(%rip), %xmm0    # 0xbd020
cvttsd2si %xmm0, %r15d
cmpl $0x1, %r15d
adcl $0x0, %r15d
movslq 0xcc(%rbp), %rbx
movl $0x18, %ecx
movq %rbx, %rax
mulq %rcx
movq $-0x1, %r14
cmovnoq %rax, %r14
movq %r14, %rdi
callq 0x11040
movq %rax, 0x10(%rsp)
testq %rbx, %rbx
je 0x223f7
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
leaq (%rax,%r12), %rdi
callq 0x4be44
addq $0x18, %r12
cmpq %r12, %rbx
jne 0x223e0
movl 0xc0(%rbp), %esi
movl 0xc4(%rbp), %edx
leaq 0x198(%rsp), %rbx
movq %rbx, %rdi
callq 0x603d0
movq 0xb8(%rbx), %rax
movq %rax, 0x70(%rsp)
movsd 0x9ac11(%rip), %xmm0    # 0xbd038
movq %rbx, %rdi
callq 0x62582
cmpl $0x0, 0xc0(%rbp)
jle 0x22daa
imull %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0xb8(%rsp)
movsd 0x18(%rsp), %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x2f0(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x90(%rsp)
leal 0x1(%rax), %ecx
movl %ecx, 0x2c(%rsp)
leal 0x1(,%rax,2), %eax
movl %eax, 0x84(%rsp)
xorl %r14d, %r14d
leaq 0x138(%rsp), %r15
cmpl $0x0, 0xc4(%rbp)
jle 0x22d96
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0xb0(%rsp)
movl %r14d, %ecx
movl 0x2f0(%rsp), %eax
subl %eax, %ecx
movl %ecx, 0x28(%rsp)
addl %r14d, %eax
movl %eax, 0x80(%rsp)
xorl %ebx, %ebx
movq %r14, 0xa8(%rsp)
movq 0xb8(%rbp), %rax
movl 0xc8(%rbp), %ecx
imull %ebx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
leaq 0xe47f1(%rip), %rdx     # 0x106ce8
movsd (%rdx), %xmm0
ucomisd (%rax,%rcx,8), %xmm0
jae 0x22d88
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
leaq 0x128(%rsp), %rdi
movsd 0xb0(%rsp), %xmm0
callq 0x6fee6
movq 0x30(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %ebx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %ebx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq 0x40(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
movq %rbx, 0x20(%rsp)
imull %ebx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
leaq 0xf0(%rsp), %rdi
callq 0x4be46
cmpl $0x0, 0x2f8(%rsp)
je 0x22955
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0x76214
movl 0x260(%rsp), %eax
imull 0x20(%rsp), %eax
addl %r14d, %eax
cltq
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x70(%rsp), %rcx
leaq (%rcx,%rax,8), %rsi
movq 0x250(%rsp), %rcx
movsd %xmm0, 0x48(%rsp)
movsd %xmm0, (%rcx,%rax,8)
movl 0x5c(%rsp), %edx
movq %rbx, %rdi
callq 0x762aa
movl 0x5c(%rsp), %eax
testl %eax, %eax
je 0x22ade
xorl %ebx, %ebx
movq 0x50(%rsp), %rcx
movslq %eax, %rsi
movq -0x8(%rcx,%rsi,8), %r14
decl %esi
leaq 0x50(%rsp), %rdi
callq 0x7641e
subq 0x70(%rsp), %r14
shrq $0x3, %r14
movl %r14d, %eax
cltd
idivl 0x260(%rsp)
movl %eax, %r14d
movl %edx, %r12d
movq 0x30(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %r14d, %ecx
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %r14d, %ecx
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq 0x40(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %r14d, %ecx
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
movq %r15, %rdi
callq 0x4be46
movq 0x98(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %r14d, %ecx
addl %r12d, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x78(%rsp)
leaq (%rbx,%rbx,2), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
movq %r15, %rsi
callq 0x4c1b4
incq %rbx
movq %rbx, 0x8(%rsp)
movsd 0x78(%rsp), %xmm0
addsd 0x9a932(%rip), %xmm0    # 0xbd020
cvttsd2si %xmm0, %eax
movl %eax, 0x8c(%rsp)
leal -0x1(%r12), %ebx
leal -0x2(%r14), %eax
movl %eax, 0x88(%rsp)
testl %ebx, %ebx
js 0x22924
cmpl 0x258(%rsp), %ebx
jge 0x22924
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x78(%rsp)
movl 0x88(%rsp), %r15d
incl %r15d
js 0x2291b
cmpl 0x25c(%rsp), %r15d
jge 0x2291b
movq 0x250(%rsp), %rax
movl 0x260(%rsp), %ecx
imull %r15d, %ecx
addl %ebx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
leaq 0xe457a(%rip), %rdx     # 0x106ce8
movsd (%rdx), %xmm1
subsd 0x48(%rsp), %xmm0
movapd %xmm1, %xmm2
xorpd 0x9a8cc(%rip), %xmm2    # 0xbd050
ucomisd %xmm2, %xmm0
jb 0x22794
ucomisd %xmm0, %xmm1
jae 0x2291b
movsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq 0xb8(%rbp), %rax
movl 0xc8(%rbp), %ecx
imull %r15d, %ecx
addl %ebx, %ecx
movslq %ecx, %rcx
leaq 0xe452c(%rip), %rdx     # 0x106ce8
movsd (%rdx), %xmm0
ucomisd (%rax,%rcx,8), %xmm0
jae 0x2291b
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
leaq 0x180(%rsp), %r13
movq %r13, %rdi
movsd 0x78(%rsp), %xmm0
callq 0x6fee6
leaq 0x128(%rsp), %rdi
movq %r13, %rsi
callq 0x5dbb7
ucomisd 0xb8(%rsp), %xmm0
ja 0x2291b
movq 0x30(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %r15d, %ecx
addl %ebx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %r15d, %ecx
addl %ebx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq 0x40(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %r15d, %ecx
addl %ebx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
leaq 0x108(%rsp), %rdi
callq 0x4be46
movsd 0x18(%rsp), %xmm0
ucomisd 0x9a78d(%rip), %xmm0    # 0xbd010
jbe 0x228a2
leaq 0xf0(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x272af
ucomisd 0x18(%rsp), %xmm0
ja 0x2291b
movl 0x8c(%rsp), %ecx
movl %ecx, %eax
xorl $0x2, %eax
xorl $0x4, %ecx
movq 0x98(%rsp), %rsi
movq 0xb8(%rsi), %rdx
movl 0xc8(%rsi), %esi
imull %r15d, %esi
addl %ebx, %esi
movslq %esi, %rsi
movsd (%rdx,%rsi,8), %xmm0
addsd 0x9a744(%rip), %xmm0    # 0xbd020
cvttsd2si %xmm0, %edx
movl %edx, %esi
xorl $0x2, %esi
xorl $0x4, %edx
orl %eax, %edx
sete %al
orl %ecx, %esi
je 0x2291b
testb %al, %al
jne 0x2291b
movl 0x260(%rsp), %eax
imull %r15d, %eax
addl %ebx, %eax
cltq
movq 0x70(%rsp), %rcx
leaq (%rcx,%rax,8), %rsi
movl 0x5c(%rsp), %edx
leaq 0x50(%rsp), %rdi
callq 0x762aa
cmpl %r14d, %r15d
jle 0x22733
leal 0x1(%rbx), %eax
cmpl %r12d, %ebx
movl %eax, %ebx
jle 0x22709
movl 0x5c(%rsp), %eax
testl %eax, %eax
leaq 0x138(%rsp), %r15
movq 0x8(%rsp), %rbx
jne 0x225fe
leaq 0x50(%rsp), %rdi
jmp 0x22aea
movq $0x0, 0x8(%rsp)
movl 0x80(%rsp), %eax
cmpl %eax, 0x28(%rsp)
jg 0x22aef
movq 0x20(%rsp), %rcx
movl %ecx, %r14d
movl 0x2f0(%rsp), %eax
subl %eax, %r14d
leal (%rcx,%rax), %r12d
movq $0x0, 0x8(%rsp)
movl 0x28(%rsp), %r15d
cmpl %r12d, %r14d
setg %al
testl %r15d, %r15d
sets %cl
cmpl 0xc0(%rbp), %r15d
setge %dl
orb %al, %cl
orb %dl, %cl
jne 0x22ace
movl 0x84(%rsp), %r13d
movl %r14d, %ebx
testl %ebx, %ebx
js 0x22ac3
cmpl 0xc4(%rbp), %ebx
jge 0x22ac3
movq 0xb8(%rbp), %rax
movl 0xc8(%rbp), %ecx
imull %ebx, %ecx
addl %r15d, %ecx
movslq %ecx, %rcx
leaq 0xe42f9(%rip), %rdx     # 0x106ce8
movsd (%rdx), %xmm0
ucomisd (%rax,%rcx,8), %xmm0
jae 0x22ac3
movq 0x30(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %ebx, %ecx
addl %r15d, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %ebx, %ecx
addl %r15d, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq 0x40(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %ebx, %ecx
addl %r15d, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
leaq 0x138(%rsp), %rdi
callq 0x4be46
movsd 0x18(%rsp), %xmm0
ucomisd 0x9a597(%rip), %xmm0    # 0xbd010
jbe 0x22a98
leaq 0xf0(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x272af
ucomisd 0x18(%rsp), %xmm0
ja 0x22ac3
movslq 0x8(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
leaq 0x138(%rsp), %rsi
callq 0x4c1b4
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
incl %ebx
decl %r13d
jne 0x229be
incl %r15d
cmpl 0x2c(%rsp), %r15d
jne 0x22993
jmp 0x22aef
movq %rbx, %rdi
movq $0x0, 0x8(%rsp)
callq 0x7627e
movq 0x8(%rsp), %r13
cmpl $0x3, %r13d
movq 0xa8(%rsp), %r14
leaq 0x138(%rsp), %r15
leaq 0x180(%rsp), %r12
jl 0x22d83
movq %r12, %rdi
movl %r13d, %esi
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x2b455
movq %r15, %rdi
movq %r12, %rsi
movl %r13d, %edx
movq %rbx, %rcx
xorl %r8d, %r8d
leaq 0x50(%rsp), %r9
callq 0x2b4df
leaq 0xc0(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x4c8ee
leaq 0xd8(%rsp), %rdi
movq %r15, %rsi
callq 0x4c8ee
leaq 0x108(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x4a9c6
leaq 0x108(%rsp), %rdi
movq 0x2d8(%rsp), %rsi
callq 0x274eb
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x22bb2
leaq 0xc0(%rsp), %rdi
callq 0x4cc6c
movsd 0xc0(%rsp), %xmm0
movq 0xa0(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
movq 0x20(%rsp), %rdx
imull %edx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0xc8(%rsp), %xmm0
movq 0x2a0(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %edx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0xd0(%rsp), %xmm0
movq 0x2a8(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %edx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0xd8(%rsp), %xmm0
movq 0x2b0(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %edx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0xe0(%rsp), %xmm0
movq 0x2b8(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %edx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0xe8(%rsp), %xmm0
movq 0x2c0(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %edx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x50(%rsp), %xmm0
ucomisd 0x9a343(%rip), %xmm0    # 0xbd010
jb 0x22cd8
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
jmp 0x22ce1
callq 0x11480
movapd %xmm0, %xmm1
mulsd 0x9b52f(%rip), %xmm1    # 0xbe218
movsd 0x58(%rsp), %xmm0
ucomisd 0x9a319(%rip), %xmm0    # 0xbd010
jb 0x22cff
sqrtsd %xmm0, %xmm0
jmp 0x22d10
movsd %xmm1, 0x48(%rsp)
callq 0x11480
movsd 0x48(%rsp), %xmm1
mulsd 0x9b500(%rip), %xmm0    # 0xbe218
movl 0x2f0(%rsp), %eax
cmpl $0x2, %eax
jl 0x22d2d
divsd 0x90(%rsp), %xmm1
jl 0x22d38
divsd 0x90(%rsp), %xmm0
movq 0x2c8(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
movq 0x20(%rsp), %rdx
imull %edx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd %xmm1, (%rax,%rcx,8)
movq 0x2d0(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull %edx, %ecx
addl %r14d, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x20(%rsp), %rbx
incl %ebx
cmpl 0xc4(%rbp), %ebx
jl 0x224da
incl %r14d
incl 0x2c(%rsp)
cmpl 0xc0(%rbp), %r14d
jl 0x22498
movq 0x10(%rsp), %rdi
callq 0x117b0
leaq 0x198(%rsp), %rdi
callq 0x60ff0
movl $0x1, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x22e04
movq %rax, %rbx
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x11ba0
jmp 0x22e27
jmp 0x22e04
jmp 0x22e04
jmp 0x22e04
jmp 0x22e04
jmp 0x22e0d
jmp 0x22e04
jmp 0x22e04
jmp 0x22e04
jmp 0x22e04
jmp 0x22e0d
jmp 0x22e0d
jmp 0x22e0d
movq %rax, %rbx
jmp 0x22e1a
jmp 0x22e0d
jmp 0x22e0d
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x7627e
leaq 0x198(%rsp), %rdi
callq 0x60ff0
movq %rbx, %rdi
callq 0x11a70