// File: tomfunkhouser[P]gaps/apps/conf2conf/conf2conf.cpp
// Function: RGBDComputeSurfaceTexture(gaps::RGBDSurface*)
static int
RGBDComputeSurfaceTexture(RGBDSurface *surface)
{
  // Get/check variables
  RGBDConfiguration *configuration = surface->Configuration();
  if (!configuration) return 0;
  int width = surface->NTexels(RN_X);
  if (width == 0) return 0;
  int height = surface->NTexels(RN_Y);
  if (height == 0) return 0;

  // Allocate images for texture RGB channels (initialized with zeroes)
  RNLength world_texel_spacing = surface->WorldTexelSpacing();
  R2Box surface_bbox(0.0, 0.0, world_texel_spacing*width, world_texel_spacing*height);
  R2Grid red_channel(width, height, surface_bbox);
  red_channel.Clear(R2_GRID_UNKNOWN_VALUE);
  R2Grid green_channel(red_channel);
  R2Grid blue_channel(red_channel);

  // Allocate storage for accumulating statistics
  if (configuration->NImages() == 0) return 1;
  RNRgb *colors = new RNRgb [ configuration->NImages() ];
  if (!colors) { RNFail("Unable to allocate memory\n"); return 0; }
  RNScalar *weights = new RNScalar [ configuration->NImages() ];
  if (!weights) { RNFail("Unable to allocate memory\n"); delete [] colors; return 0; }

  // Fill the texture RGB channels
  for (int ix = 0; ix < width; ix++) {
    for (int iy = 0; iy < height; iy++) {
      // Check if (ix,iy) maps to a surface
      if (surface->mesh_face_index) {
        RNScalar face_index_value = surface->mesh_face_index->GridValue(ix, iy);
        if (face_index_value == R2_GRID_UNKNOWN_VALUE) continue;
      }

      // Get position in texture
      R2Point texture_position(ix+0.5, iy+0.5);

      // Initialize statistics
      int count = 0;
      RNScalar weight_sum = 0;
      RNRgb weighted_color_sum(0,0,0);

      // Gather sample from every image
      for (int i = 0; i < configuration->NImages(); i++) {
        // Get image
        RGBDImage *image = configuration->Image(i);

        // Get position in camera coordinates
        R3Point camera_position;
        if (!RGBDTransformTextureToCamera(texture_position, camera_position, surface, image)) continue;
        
        // Get position in image coordinates
        R2Point image_position;
        if (!RGBDTransformCameraToImage(camera_position, image_position, image)) continue;

#if 0
        // Check transformed depth
        RNScalar transformed_depth = -camera_position[2];
        if (RNIsNegativeOrZero(transformed_depth)) continue;

        // Check captured depth
        RNScalar captured_depth = image->PixelDepth(image_position);
        if (RNIsNegativeOrZero(captured_depth)) continue;

        // Check depth difference
        if (RNIsNotEqual(captured_depth, transformed_depth, 0.1 * captured_depth)) continue;
#endif
        
        // Get rgb from image
        RNScalar r = image->PixelChannelValue(image_position, RGBD_RED_CHANNEL);
        RNScalar g = image->PixelChannelValue(image_position, RGBD_GREEN_CHANNEL);
        RNScalar b = image->PixelChannelValue(image_position, RGBD_BLUE_CHANNEL);

        // Check if valid image pixel
        if (r == R2_GRID_UNKNOWN_VALUE) continue;
        if (g == R2_GRID_UNKNOWN_VALUE) continue;
        if (b == R2_GRID_UNKNOWN_VALUE) continue;

        // Get/check color
        // Don't allow purely black pixels ???
        RNRgb color(r, g, b);
        if (color == RNblack_rgb) continue;

        // Compute weight
        RNScalar weight = 1.0;
        if (texture_aggregation_weighting == 1) {
          weight = TextureScore(image, surface, image_position, texture_position, color);
          if (weight <= 0) continue;
        }
        
        // Update statistics
        weight_sum += weight;
        weighted_color_sum += weight * color;
        weights[count] = weight;
        colors[count] = color;
        count++;
      }

      // Check statistics
      if (count == 0) continue;
      if (weight_sum == 0) continue;

      // Compute color for pixel
      RNRgb color = RNblack_rgb;
      if (texture_aggregation_method == MEAN_TEXTURE_AGGREGATION) {
        // Compute weighted mean
        color = weighted_color_sum / weight_sum;
      }
      else if (texture_aggregation_method == MEDIAN_TEXTURE_AGGREGATION) {
        // Compute weighted median
        RNScalar best_dd = FLT_MAX;
        for (int i = 0; i < count; i++) {
          RNScalar dd = 0;
          for (int j = 0; j < count; j++) {
            if (i != j) {
              RNScalar dr = colors[i].R() - colors[j].R();
              RNScalar dg = colors[i].G() - colors[j].G();
              RNScalar db = colors[i].B() - colors[j].B();
              dd += weights[j] * weights[j] * (dr*dr + dg*dg + db*db);
            }
          }
          if (dd < best_dd) {
            color = colors[i];
            best_dd = dd;
          }
        }
      }
      else if (texture_aggregation_method == MODE_TEXTURE_AGGREGATION) {
        // Compute weighted mode
        RNScalar best_sum = 0;
        for (int i = 0; i < count; i++) {
          RNScalar sum = 0;
          for (int j = 0; j < count; j++) {
            if (colors[i] == colors[j]) sum += weights[j];
          }
          if (sum > best_sum) {
            color = colors[i];
            best_sum = sum;
          }
        }
      }
      else {
        RNFail("Unrecognized texture aggregation method: %d", texture_aggregation_method);
        return 0;
      }
      
      // Update the texture channels
      red_channel.SetGridValue(ix, iy, color.R());
      green_channel.SetGridValue(ix, iy, color.G());
      blue_channel.SetGridValue(ix, iy, color.B());
    }
  }

  // Delete temporary memory
  delete [] colors;
  delete [] weights;

  // Fill holes
  red_channel.FillHoles();
  green_channel.FillHoles();
  blue_channel.FillHoles();

  // Create color channels
  R2Image tmp(width, height);
  surface->CreateColorChannels(tmp);

  // Update the texture RGB channels
  surface->SetChannel(RGBD_RED_CHANNEL, red_channel);
  surface->SetChannel(RGBD_GREEN_CHANNEL, green_channel);
  surface->SetChannel(RGBD_BLUE_CHANNEL, blue_channel);

  // Write color channels
  surface->WriteColorChannels();
  
  // Return success
  return 1;
}

// Assembly:
subq $0x568, %rsp            # imm = 0x568
movq %rdi, 0x558(%rsp)
movq 0x558(%rsp), %rdi
callq 0x19fc0
movq %rax, 0x550(%rsp)
cmpq $0x0, 0x550(%rsp)
jne 0x1899f
movl $0x0, 0x564(%rsp)
jmp 0x19934
movq 0x558(%rsp), %rdi
xorl %esi, %esi
callq 0x19fd0
movl %eax, 0x54c(%rsp)
cmpl $0x0, 0x54c(%rsp)
jne 0x189cf
movl $0x0, 0x564(%rsp)
jmp 0x19934
movq 0x558(%rsp), %rdi
movl $0x1, %esi
callq 0x19fd0
movl %eax, 0x548(%rsp)
cmpl $0x0, 0x548(%rsp)
jne 0x18a02
movl $0x0, 0x564(%rsp)
jmp 0x19934
movq 0x558(%rsp), %rdi
callq 0x1a010
movsd %xmm0, 0x540(%rsp)
movsd 0x540(%rsp), %xmm3
cvtsi2sdl 0x54c(%rsp), %xmm0
movaps %xmm3, %xmm2
mulsd %xmm0, %xmm2
cvtsi2sdl 0x548(%rsp), %xmm0
mulsd %xmm0, %xmm3
leaq 0x518(%rsp), %rdi
movq %rdi, 0x108(%rsp)
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xca300
movq 0x108(%rsp), %rcx
movl 0x54c(%rsp), %esi
movl 0x548(%rsp), %edx
leaq 0x448(%rsp), %rdi
callq 0xb2080
jmp 0x18a7e
leaq 0x448(%rsp), %rdi
movsd 0x14d592(%rip), %xmm0   # 0x166020
callq 0xb5a20
jmp 0x18a95
leaq 0x368(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0xb30a0
jmp 0x18aac
leaq 0x298(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0xb30a0
jmp 0x18ac3
movq 0x550(%rsp), %rdi
callq 0x19c40
cmpl $0x0, %eax
jne 0x18b3b
movl $0x1, 0x564(%rsp)
movl $0x1, 0x294(%rsp)
jmp 0x198c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x440(%rsp)
movl %eax, 0x43c(%rsp)
jmp 0x19925
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x440(%rsp)
movl %eax, 0x43c(%rsp)
jmp 0x19918
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x440(%rsp)
movl %eax, 0x43c(%rsp)
jmp 0x1990b
movq 0x550(%rsp), %rdi
callq 0x19c40
cltq
movq %rax, 0xf0(%rsp)
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
movq %rdi, 0xf8(%rsp)
callq 0x12040
movq %rax, 0x100(%rsp)
jmp 0x18b7f
movq 0xf0(%rsp), %rax
cmpq $0x0, %rax
je 0x18bef
movq 0x100(%rsp), %rax
movq 0xf0(%rsp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0xe0(%rsp)
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0xdb180
jmp 0x18bce
movq 0xe0(%rsp), %rcx
movq 0xd8(%rsp), %rax
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, 0xe8(%rsp)
jne 0x18bb7
movq 0x100(%rsp), %rax
movq %rax, 0x288(%rsp)
cmpq $0x0, 0x288(%rsp)
jne 0x18c7c
leaq 0x14d839(%rip), %rdi    # 0x16644a
xorl %eax, %eax
callq 0xdf990
jmp 0x18c1a
movl $0x0, 0x564(%rsp)
movl $0x1, 0x294(%rsp)
jmp 0x198c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x440(%rsp)
movl %eax, 0x43c(%rsp)
jmp 0x198fe
movq 0xf8(%rsp), %rsi
movq 0x100(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x440(%rsp)
movl %eax, 0x43c(%rsp)
callq 0x12d80
jmp 0x198fe
movq 0x550(%rsp), %rdi
callq 0x19c40
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x12040
movq %rax, 0xd0(%rsp)
jmp 0x18cb0
movq 0xd0(%rsp), %rax
movq %rax, 0x280(%rsp)
cmpq $0x0, 0x280(%rsp)
jne 0x18d19
leaq 0x14d778(%rip), %rdi    # 0x16644a
xorl %eax, %eax
callq 0xdf990
jmp 0x18cdb
movq 0x288(%rsp), %rax
movq %rax, 0xc8(%rsp)
cmpq $0x0, %rax
je 0x18cfe
movq 0xc8(%rsp), %rdi
callq 0x12920
movl $0x0, 0x564(%rsp)
movl $0x1, 0x294(%rsp)
jmp 0x198c8
movl $0x0, 0x27c(%rsp)
movl 0x27c(%rsp), %eax
cmpl 0x54c(%rsp), %eax
jge 0x19766
movl $0x0, 0x278(%rsp)
movl 0x278(%rsp), %eax
cmpl 0x548(%rsp), %eax
jge 0x1974e
movq 0x558(%rsp), %rax
cmpq $0x0, 0x90(%rax)
je 0x18dc8
movq 0x558(%rsp), %rax
movq 0x90(%rax), %rdi
movl 0x27c(%rsp), %esi
movl 0x278(%rsp), %edx
callq 0x1a060
movsd %xmm0, 0xc0(%rsp)
jmp 0x18d96
movsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0x270(%rsp)
movsd 0x270(%rsp), %xmm0
movsd 0x14d267(%rip), %xmm1   # 0x166020
ucomisd %xmm1, %xmm0
jne 0x18dc6
jp 0x18dc6
jmp 0x19738
jmp 0x18dc8
cvtsi2sdl 0x27c(%rsp), %xmm0
movsd 0x14d24f(%rip), %xmm2   # 0x166028
addsd %xmm2, %xmm0
cvtsi2sdl 0x278(%rsp), %xmm1
addsd %xmm2, %xmm1
leaq 0x260(%rsp), %rdi
callq 0xcfd80
jmp 0x18df9
movl $0x0, 0x25c(%rsp)
movq $0x0, 0x250(%rsp)
leaq 0x238(%rsp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xdb1d0
jmp 0x18e28
movl $0x0, 0x234(%rsp)
movl 0x234(%rsp), %eax
movl %eax, 0xbc(%rsp)
movq 0x550(%rsp), %rdi
callq 0x19c40
movl %eax, %ecx
movl 0xbc(%rsp), %eax
cmpl %ecx, %eax
jge 0x191b0
movq 0x550(%rsp), %rdi
movl 0x234(%rsp), %esi
callq 0x19c90
movq %rax, 0xb0(%rsp)
jmp 0x18e7d
movq 0xb0(%rsp), %rax
movq %rax, 0x228(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x8a990
jmp 0x18e9c
movq 0x558(%rsp), %rdx
movq 0x228(%rsp), %rcx
leaq 0x260(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x1a7e0
movl %eax, 0xac(%rsp)
jmp 0x18eca
movl 0xac(%rsp), %eax
cmpl $0x0, %eax
jne 0x18edb
jmp 0x1919a
leaq 0x200(%rsp), %rdi
callq 0xcfd70
jmp 0x18eea
movq 0x228(%rsp), %rdx
leaq 0x210(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x1ab60
movl %eax, 0xa8(%rsp)
jmp 0x18f10
movl 0xa8(%rsp), %eax
cmpl $0x0, %eax
jne 0x18f21
jmp 0x1919a
movq 0x228(%rsp), %rdi
leaq 0x200(%rsp), %rsi
xorl %edx, %edx
callq 0x1a0a0
movsd %xmm0, 0xa0(%rsp)
jmp 0x18f43
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x1f8(%rsp)
movq 0x228(%rsp), %rdi
leaq 0x200(%rsp), %rsi
movl $0x1, %edx
callq 0x1a0a0
movsd %xmm0, 0x98(%rsp)
jmp 0x18f7a
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x1f0(%rsp)
movq 0x228(%rsp), %rdi
leaq 0x200(%rsp), %rsi
movl $0x2, %edx
callq 0x1a0a0
movsd %xmm0, 0x90(%rsp)
jmp 0x18fb1
movsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x1e8(%rsp)
movsd 0x1f8(%rsp), %xmm0
movsd 0x14d04c(%rip), %xmm1   # 0x166020
ucomisd %xmm1, %xmm0
jne 0x18fe1
jp 0x18fe1
jmp 0x1919a
movsd 0x1f0(%rsp), %xmm0
movsd 0x14d02e(%rip), %xmm1   # 0x166020
ucomisd %xmm1, %xmm0
jne 0x18fff
jp 0x18fff
jmp 0x1919a
movsd 0x1e8(%rsp), %xmm0
movsd 0x14d010(%rip), %xmm1   # 0x166020
ucomisd %xmm1, %xmm0
jne 0x1901d
jp 0x1901d
jmp 0x1919a
movsd 0x1f8(%rsp), %xmm0
movsd 0x1f0(%rsp), %xmm1
movsd 0x1e8(%rsp), %xmm2
leaq 0x1d0(%rsp), %rdi
callq 0xdb1d0
jmp 0x19047
leaq 0x19b982(%rip), %rsi    # 0x1b49d0
leaq 0x1d0(%rsp), %rdi
callq 0xdb250
movl %eax, 0x8c(%rsp)
jmp 0x19064
movl 0x8c(%rsp), %eax
cmpl $0x0, %eax
je 0x19075
jmp 0x1919a
movsd 0x14cfb3(%rip), %xmm0   # 0x166030
movsd %xmm0, 0x1c8(%rsp)
cmpl $0x1, 0x19867f(%rip)    # 0x1b170c
jne 0x190ee
movq 0x228(%rsp), %rdi
movq 0x558(%rsp), %rsi
leaq 0x200(%rsp), %rdx
leaq 0x260(%rsp), %rcx
leaq 0x1d0(%rsp), %r8
callq 0x19950
movsd %xmm0, 0x80(%rsp)
jmp 0x190c7
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x1c8(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x1c8(%rsp), %xmm0
jb 0x190ec
jmp 0x1919a
jmp 0x190ee
movsd 0x1c8(%rsp), %xmm1
movsd 0x250(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x250(%rsp)
movsd 0x1c8(%rsp), %xmm0
leaq 0x1b0(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x1a0e0
jmp 0x1912d
leaq 0x238(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0xdb390
jmp 0x19144
movsd 0x1c8(%rsp), %xmm0
movq 0x280(%rsp), %rax
movslq 0x25c(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x288(%rsp), %rax
movslq 0x25c(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0xdb350
jmp 0x19189
movl 0x25c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x25c(%rsp)
movl 0x234(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x234(%rsp)
jmp 0x18e33
cmpl $0x0, 0x25c(%rsp)
jne 0x191bf
jmp 0x19738
movsd 0x250(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x191d8
jp 0x191d8
jmp 0x19738
leaq 0x19b7f1(%rip), %rsi    # 0x1b49d0
leaq 0x198(%rsp), %rdi
callq 0xdb190
jmp 0x191ee
cmpl $0x0, 0x198e2f(%rip)    # 0x1b2024
jne 0x19233
movsd 0x250(%rsp), %xmm0
leaq 0x180(%rsp), %rdi
leaq 0x238(%rsp), %rsi
callq 0x1a120
jmp 0x19217
leaq 0x198(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0xdb350
jmp 0x1922e
jmp 0x1965e
cmpl $0x1, 0x198dea(%rip)    # 0x1b2024
jne 0x194e8
movsd 0x14cdc0(%rip), %xmm0   # 0x166008
movsd %xmm0, 0x178(%rsp)
movl $0x0, 0x174(%rsp)
movl 0x174(%rsp), %eax
cmpl 0x25c(%rsp), %eax
jge 0x194e3
xorps %xmm0, %xmm0
movsd %xmm0, 0x168(%rsp)
movl $0x0, 0x164(%rsp)
movl 0x164(%rsp), %eax
cmpl 0x25c(%rsp), %eax
jge 0x1947a
movl 0x174(%rsp), %eax
cmpl 0x164(%rsp), %eax
je 0x19462
movq 0x288(%rsp), %rax
movslq 0x174(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
callq 0x1a180
movsd %xmm0, 0x78(%rsp)
jmp 0x192d4
movq 0x288(%rsp), %rax
movslq 0x164(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
callq 0x1a180
movsd %xmm0, 0x70(%rsp)
jmp 0x192f9
movsd 0x70(%rsp), %xmm1
movsd 0x78(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x158(%rsp)
movq 0x288(%rsp), %rax
movslq 0x174(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
callq 0x1a190
movsd %xmm0, 0x68(%rsp)
jmp 0x19337
movq 0x288(%rsp), %rax
movslq 0x164(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
callq 0x1a190
movsd %xmm0, 0x60(%rsp)
jmp 0x1935c
movsd 0x60(%rsp), %xmm1
movsd 0x68(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x150(%rsp)
movq 0x288(%rsp), %rax
movslq 0x174(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
callq 0x1a1a0
movsd %xmm0, 0x58(%rsp)
jmp 0x1939a
movq 0x288(%rsp), %rax
movslq 0x164(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
callq 0x1a1a0
movsd %xmm0, 0x50(%rsp)
jmp 0x193bf
movsd 0x50(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x148(%rsp)
movq 0x280(%rsp), %rax
movslq 0x164(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x280(%rsp), %rax
movslq 0x164(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd 0x158(%rsp), %xmm1
movsd 0x158(%rsp), %xmm3
movsd 0x150(%rsp), %xmm2
mulsd 0x150(%rsp), %xmm2
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd 0x148(%rsp), %xmm2
movsd 0x148(%rsp), %xmm3
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd 0x168(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x168(%rsp)
jmp 0x19464
movl 0x164(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x164(%rsp)
jmp 0x19287
movsd 0x168(%rsp), %xmm1
movsd 0x178(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x194cb
movq 0x288(%rsp), %rax
movslq 0x174(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x198(%rsp), %rdi
callq 0xdb350
jmp 0x194b9
movsd 0x168(%rsp), %xmm0
movsd %xmm0, 0x178(%rsp)
jmp 0x194cd
movl 0x174(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x174(%rsp)
jmp 0x1925c
jmp 0x1965c
cmpl $0x2, 0x198b35(%rip)    # 0x1b2024
jne 0x19629
xorps %xmm0, %xmm0
movsd %xmm0, 0x140(%rsp)
movl $0x0, 0x13c(%rsp)
movl 0x13c(%rsp), %eax
cmpl 0x25c(%rsp), %eax
jge 0x19627
xorps %xmm0, %xmm0
movsd %xmm0, 0x130(%rsp)
movl $0x0, 0x12c(%rsp)
movl 0x12c(%rsp), %eax
cmpl 0x25c(%rsp), %eax
jge 0x195c2
movq 0x288(%rsp), %rax
movslq 0x13c(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movslq 0x12c(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rsi
callq 0xdb250
movl %eax, 0x4c(%rsp)
jmp 0x1957a
movl 0x4c(%rsp), %eax
cmpl $0x0, %eax
je 0x195aa
movq 0x280(%rsp), %rax
movslq 0x12c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd 0x130(%rsp), %xmm0
movsd %xmm0, 0x130(%rsp)
jmp 0x195ac
movl 0x12c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x12c(%rsp)
jmp 0x19537
movsd 0x130(%rsp), %xmm0
ucomisd 0x140(%rsp), %xmm0
jbe 0x1960f
movq 0x288(%rsp), %rax
movslq 0x13c(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x198(%rsp), %rdi
callq 0xdb350
jmp 0x195fd
movsd 0x130(%rsp), %xmm0
movsd %xmm0, 0x140(%rsp)
jmp 0x19611
movl 0x13c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x13c(%rsp)
jmp 0x1950c
jmp 0x1965a
movl 0x1989f5(%rip), %esi    # 0x1b2024
leaq 0x14ce2f(%rip), %rdi    # 0x166465
xorl %eax, %eax
callq 0xdf990
jmp 0x1963f
movl $0x0, 0x564(%rsp)
movl $0x1, 0x294(%rsp)
jmp 0x198c8
jmp 0x1965c
jmp 0x1965e
movl 0x27c(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0x278(%rsp), %eax
movl %eax, 0x3c(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x1a180
movsd %xmm0, 0x40(%rsp)
jmp 0x19689
movsd 0x40(%rsp), %xmm0
movl 0x3c(%rsp), %edx
movl 0x38(%rsp), %esi
leaq 0x448(%rsp), %rdi
callq 0x1a1b0
jmp 0x196a6
movl 0x27c(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x278(%rsp), %eax
movl %eax, 0x2c(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x1a190
movsd %xmm0, 0x30(%rsp)
jmp 0x196d1
movsd 0x30(%rsp), %xmm0
movl 0x2c(%rsp), %edx
movl 0x28(%rsp), %esi
leaq 0x368(%rsp), %rdi
callq 0x1a1b0
jmp 0x196ee
movl 0x27c(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x278(%rsp), %eax
movl %eax, 0x1c(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x1a1a0
movsd %xmm0, 0x20(%rsp)
jmp 0x19719
movsd 0x20(%rsp), %xmm0
movl 0x1c(%rsp), %edx
movl 0x18(%rsp), %esi
leaq 0x298(%rsp), %rdi
callq 0x1a1b0
jmp 0x19736
jmp 0x19738
movl 0x278(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x278(%rsp)
jmp 0x18d43
jmp 0x19750
movl 0x27c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x27c(%rsp)
jmp 0x18d24
movq 0x288(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x19783
movq 0x10(%rsp), %rdi
callq 0x12920
movq 0x280(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x197a0
movq 0x8(%rsp), %rdi
callq 0x12920
leaq 0x448(%rsp), %rdi
callq 0xb4960
jmp 0x197af
leaq 0x368(%rsp), %rdi
callq 0xb4960
jmp 0x197be
leaq 0x298(%rsp), %rdi
callq 0xb4960
jmp 0x197cd
movl 0x54c(%rsp), %esi
movl 0x548(%rsp), %edx
leaq 0x110(%rsp), %rdi
movl $0x3, %ecx
callq 0xd1c40
jmp 0x197ef
movq 0x558(%rsp), %rdi
movq (%rdi), %rax
movq 0xb8(%rax), %rax
leaq 0x110(%rsp), %rsi
callq *%rax
jmp 0x1980d
movq 0x558(%rsp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
xorl %esi, %esi
leaq 0x448(%rsp), %rdx
callq *%rax
jmp 0x1982a
movq 0x558(%rsp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
movl $0x1, %esi
leaq 0x368(%rsp), %rdx
callq *%rax
jmp 0x1984a
movq 0x558(%rsp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
movl $0x2, %esi
leaq 0x298(%rsp), %rdx
callq *%rax
jmp 0x1986a
movq 0x558(%rsp), %rdi
movq (%rdi), %rax
movq 0xa0(%rax), %rax
callq *%rax
jmp 0x19880
movl $0x1, 0x564(%rsp)
movl $0x1, 0x294(%rsp)
leaq 0x110(%rsp), %rdi
callq 0xd2160
jmp 0x198c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x440(%rsp)
movl %eax, 0x43c(%rsp)
leaq 0x110(%rsp), %rdi
callq 0xd2160
jmp 0x198fe
leaq 0x298(%rsp), %rdi
callq 0xb3390
leaq 0x368(%rsp), %rdi
callq 0xb3390
leaq 0x448(%rsp), %rdi
callq 0xb3390
leaq 0x518(%rsp), %rdi
callq 0x1a200
jmp 0x19934
leaq 0x298(%rsp), %rdi
callq 0xb3390
leaq 0x368(%rsp), %rdi
callq 0xb3390
leaq 0x448(%rsp), %rdi
callq 0xb3390
leaq 0x518(%rsp), %rdi
callq 0x1a200
jmp 0x19943
movl 0x564(%rsp), %eax
addq $0x568, %rsp            # imm = 0x568
retq
movq 0x440(%rsp), %rdi
callq 0x12c20