// File: tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::UpdateWorkingSet(gaps::R3Viewer const&)
void R3SurfelViewer::
UpdateWorkingSet(const R3Viewer& view)
{
  // Just checking
  if (!scene) return;
  R3SurfelTree *tree = scene->Tree();
  if (!tree) return;
 
  // Get convenient variables
  R3Point eye = view.Camera().Origin();
  R3Vector towards = view.Camera().Towards();
  R2Box viewport_box = view.Viewport().BBox();
  if (viewport_box.Area() == 0) return;

  // Allocate temporary memory
  int xres = viewport_box.XLength();
  int yres = int (xres * (double) viewport_box.YLength() / (double) viewport_box.XLength());
  int *visible_marks = new int [ tree->NNodes() ];
  int *resident_marks = new int [ tree->NNodes() ];
  int *item_buffer = new int [ xres * yres ];
  RNScalar *depth_buffer = new RNScalar [ xres * yres ];
  RNScalar *viewpoint_distance_buffer = new RNScalar [ xres * yres ];
  for (int i = 0; i < tree->NNodes(); i++) { resident_marks[i] = visible_marks[i] = 0; }
  for (int i = 0; i < resident_nodes.NNodes(); i++) resident_marks[resident_nodes.Node(i)->TreeIndex()] = 1;

  // Create viewer
  R3Viewer tmp_viewer(view);
  tmp_viewer.ResizeViewport(0, 0, xres, yres);

  RNBoolean done = FALSE;
  const int max_iterations = 8;
  for (int iteration = 0; iteration < max_iterations; iteration++) {
    // Check if done
    if (done) break;
    done = TRUE;

    // Initialize buffers
    for (int i = 0; i < xres * yres; i++) {
      item_buffer[i] = -1;
      depth_buffer[i] = FLT_MAX;
      viewpoint_distance_buffer[i] = FLT_MAX;
    }
    for (int i = 0; i < tree->NNodes(); i++) {
      visible_marks[i] = 0;
    }

    // Render surfels into item buffer
    for (int i = 0; i < resident_nodes.NNodes(); i++) {
      R3SurfelNode *node = resident_nodes.Node(i);
      for (int j = 0; j < node->NBlocks(); j++) {
        R3SurfelBlock *block = node->Block(j);
        const R3Point& block_origin = block->PositionOrigin();
        for (int k = 0; k < block->NSurfels(); k++) {
          const R3Surfel *surfel = block->Surfel(k);
          double wx = surfel->X() + block_origin.X();
          double wy = surfel->Y() + block_origin.Y();
          double wz = surfel->Z() + block_origin.Z();
          R3Point wp(wx, wy, wz);
          RNScalar depth = towards.Dot(wp - eye);
          if (depth <= 0) continue; 
          R2Point vp = tmp_viewer.ViewportPoint(wp);
          if (vp == R2infinite_point) continue; 
          int vx = (int) (vp.X() + 0.5);
          if ((vx < 0) || (vx >= xres)) continue; 
          int vy = (int) (vp.Y() + 0.5);
          if ((vy < 0) || (vy >= yres)) continue; 
          int index = xres*vy + vx;
          if (RNIsGreater(depth, depth_buffer[index])) continue;
          RNLength viewpoint_distance = (node->Scan()) ? R3Distance(tmp_viewer.Camera().Origin(), node->Scan()->Viewpoint()) : RN_INFINITY;
          if (RNIsEqual(depth, depth_buffer[index], 1E-3) && RNIsGreater(viewpoint_distance, viewpoint_distance_buffer[index])) continue;
          item_buffer[index] = node->TreeIndex();
          depth_buffer[index] = depth;
          viewpoint_distance_buffer[index] = viewpoint_distance;
        }
      }
    }

    // Mark visible nodes
    for (int i = 0; i < xres * yres; i++) {
      int node_index = item_buffer[i];
      if (node_index < 0) continue;
      if (visible_marks[node_index] == 0) {
        visible_marks[node_index] = 1;
      }
    }

    // Remove invisible nodes from working set
    for (int i = 0; i < resident_nodes.NNodes(); i++) {
      R3SurfelNode *node = resident_nodes.Node(i);
      assert(resident_marks[node->TreeIndex()]);
      if (visible_marks[node->TreeIndex()] == 1) continue;
      resident_marks[node->TreeIndex()] = 0;
      RemoveFromWorkingSet(node);
    }
    
    // Add parts of visible nodes to working set
    for (int i = 0; i < xres * yres; i++) {
      int node_index = item_buffer[i];
      if (node_index < 0) continue;
      assert(depth_buffer[i] < FLT_MAX);
      assert(visible_marks[node_index] == 1);
      if (resident_marks[node_index] == 0) continue;
      R3SurfelNode *node = tree->Node(node_index);
      if (node->NParts() == 0) continue;
      resident_marks[node_index] = 0;
      RemoveFromWorkingSet(node);
      for (int j = 0; j < node->NParts(); j++) {
        R3SurfelNode *part = node->Part(j);
        resident_marks[part->TreeIndex()] = 1;
        InsertIntoWorkingSet(part);
        done = FALSE;
      }
    }

    if (done) break;
  }

  // Delete temporary memory
  delete [] visible_marks;
  delete [] resident_marks;
  delete [] item_buffer;
  delete [] depth_buffer;
  delete [] viewpoint_distance_buffer;

  // Invalidate VBO buffers
  InvalidateVBO();
}

// Assembly:
subq $0x478, %rsp            # imm = 0x478
movq %rdi, 0x470(%rsp)
movq %rsi, 0x468(%rsp)
movq 0x470(%rsp), %rax
movq %rax, 0x218(%rsp)
cmpq $0x0, 0x8(%rax)
jne 0x392d3
jmp 0x3a3f5
movq 0x218(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x2f020
movq %rax, 0x460(%rsp)
cmpq $0x0, 0x460(%rsp)
jne 0x392fc
jmp 0x3a3f5
movq 0x468(%rsp), %rdi
callq 0x2f6d0
movq %rax, %rdi
callq 0x2ee60
movq %rax, %rsi
leaq 0x448(%rsp), %rdi
callq 0x162300
movq 0x468(%rsp), %rdi
callq 0x2f6d0
movq %rax, %rsi
leaq 0x430(%rsp), %rdi
callq 0x2eea0
movq 0x468(%rsp), %rdi
callq 0x3def0
movq %rax, %rsi
leaq 0x408(%rsp), %rdi
movq %rdi, 0x208(%rsp)
callq 0x3ec80
movq 0x208(%rsp), %rdi
callq 0x18fbf0
movsd %xmm0, 0x210(%rsp)
jmp 0x3937b
movsd 0x210(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x393b8
jp 0x393b8
movl $0x1, 0x3f8(%rsp)
jmp 0x3a3e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x400(%rsp)
movl %eax, 0x3fc(%rsp)
jmp 0x3a3fd
leaq 0x408(%rsp), %rdi
callq 0x3ecd0
movsd %xmm0, 0x200(%rsp)
jmp 0x393d0
movsd 0x200(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x3f4(%rsp)
cvtsi2sdl 0x3f4(%rsp), %xmm0
movsd %xmm0, 0x1f0(%rsp)
leaq 0x408(%rsp), %rdi
callq 0x3ecf0
movsd %xmm0, 0x1f8(%rsp)
jmp 0x3940e
movsd 0x1f8(%rsp), %xmm1
movsd 0x1f0(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x1e0(%rsp)
leaq 0x408(%rsp), %rdi
callq 0x3ecd0
movsd %xmm0, 0x1e8(%rsp)
jmp 0x39445
movsd 0x1e8(%rsp), %xmm1
movsd 0x1e0(%rsp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x3f0(%rsp)
movq 0x460(%rsp), %rdi
callq 0x2f030
movl %eax, 0x1dc(%rsp)
jmp 0x3947c
movl 0x1dc(%rsp), %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x28040
movq %rax, 0x1d0(%rsp)
jmp 0x394aa
movq 0x1d0(%rsp), %rax
movq %rax, 0x3e8(%rsp)
movq 0x460(%rsp), %rdi
callq 0x2f030
movl %eax, 0x1cc(%rsp)
jmp 0x394d0
movl 0x1cc(%rsp), %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x28040
movq %rax, 0x1c0(%rsp)
jmp 0x394fe
movq 0x1c0(%rsp), %rax
movq %rax, 0x3e0(%rsp)
movl 0x3f4(%rsp), %eax
movl 0x3f0(%rsp), %ecx
imull %ecx, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x28040
movq %rax, 0x1b8(%rsp)
jmp 0x39546
movq 0x1b8(%rsp), %rax
movq %rax, 0x3d8(%rsp)
movl 0x3f4(%rsp), %eax
movl 0x3f0(%rsp), %ecx
imull %ecx, %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x28040
movq %rax, 0x1b0(%rsp)
jmp 0x3958e
movq 0x1b0(%rsp), %rax
movq %rax, 0x3d0(%rsp)
movl 0x3f4(%rsp), %eax
movl 0x3f0(%rsp), %ecx
imull %ecx, %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x28040
movq %rax, 0x1a8(%rsp)
jmp 0x395d6
movq 0x1a8(%rsp), %rax
movq %rax, 0x3c8(%rsp)
movl $0x0, 0x3c4(%rsp)
movl 0x3c4(%rsp), %eax
movl %eax, 0x1a0(%rsp)
movq 0x460(%rsp), %rdi
callq 0x2f030
movl %eax, 0x1a4(%rsp)
jmp 0x39615
movl 0x1a0(%rsp), %eax
movl 0x1a4(%rsp), %ecx
cmpl %ecx, %eax
jge 0x39668
movq 0x3e8(%rsp), %rax
movslq 0x3c4(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x3e0(%rsp), %rax
movslq 0x3c4(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x3c4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c4(%rsp)
jmp 0x395f1
movl $0x0, 0x3c0(%rsp)
movq 0x218(%rsp), %rdi
movl 0x3c0(%rsp), %eax
movl %eax, 0x198(%rsp)
addq $0x10, %rdi
callq 0x3df90
movl %eax, 0x19c(%rsp)
jmp 0x3969b
movl 0x198(%rsp), %eax
movl 0x19c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x39724
movq 0x218(%rsp), %rdi
movq 0x3e0(%rsp), %rax
movq %rax, 0x188(%rsp)
addq $0x10, %rdi
movl 0x3c0(%rsp), %esi
callq 0x3dfb0
movq %rax, 0x190(%rsp)
jmp 0x396df
movq 0x190(%rsp), %rdi
callq 0x3d5c0
movl %eax, 0x184(%rsp)
jmp 0x396f5
movq 0x188(%rsp), %rax
movl 0x184(%rsp), %ecx
movslq %ecx, %rcx
movl $0x1, (%rax,%rcx,4)
movl 0x3c0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c0(%rsp)
jmp 0x39673
movq 0x468(%rsp), %rsi
leaq 0x318(%rsp), %rdi
callq 0xcd3b0
jmp 0x3973b
movl 0x3f4(%rsp), %ecx
movl 0x3f0(%rsp), %r8d
leaq 0x318(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xcd740
jmp 0x3975d
movl $0x0, 0x314(%rsp)
movl $0x8, 0x310(%rsp)
movl $0x0, 0x30c(%rsp)
cmpl $0x8, 0x30c(%rsp)
jge 0x3a32b
cmpl $0x0, 0x314(%rsp)
je 0x397c1
jmp 0x3a32b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x400(%rsp)
movl %eax, 0x3fc(%rsp)
leaq 0x318(%rsp), %rdi
callq 0xcd500
jmp 0x3a3fd
movl $0x1, 0x314(%rsp)
movl $0x0, 0x308(%rsp)
movl 0x308(%rsp), %eax
movl 0x3f4(%rsp), %ecx
imull 0x3f0(%rsp), %ecx
cmpl %ecx, %eax
jge 0x39855
movq 0x3d8(%rsp), %rax
movslq 0x308(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movq 0x3d0(%rsp), %rax
movslq 0x308(%rsp), %rcx
movsd 0x207cb0(%rip), %xmm0   # 0x2414d0
movsd %xmm0, (%rax,%rcx,8)
movq 0x3c8(%rsp), %rax
movslq 0x308(%rsp), %rcx
movsd 0x207c93(%rip), %xmm0   # 0x2414d0
movsd %xmm0, (%rax,%rcx,8)
movl 0x308(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x308(%rsp)
jmp 0x397d7
movl $0x0, 0x304(%rsp)
movl 0x304(%rsp), %eax
movl %eax, 0x17c(%rsp)
movq 0x460(%rsp), %rdi
callq 0x2f030
movl %eax, 0x180(%rsp)
jmp 0x39884
movl 0x17c(%rsp), %eax
movl 0x180(%rsp), %ecx
cmpl %ecx, %eax
jge 0x398c0
movq 0x3e8(%rsp), %rax
movslq 0x304(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x304(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x304(%rsp)
jmp 0x39860
movl $0x0, 0x300(%rsp)
movq 0x218(%rsp), %rdi
movl 0x300(%rsp), %eax
movl %eax, 0x174(%rsp)
addq $0x10, %rdi
callq 0x3df90
movl %eax, 0x178(%rsp)
jmp 0x398f3
movl 0x174(%rsp), %eax
movl 0x178(%rsp), %ecx
cmpl %ecx, %eax
jge 0x39f89
movq 0x218(%rsp), %rdi
addq $0x10, %rdi
movl 0x300(%rsp), %esi
callq 0x3dfb0
movq %rax, 0x168(%rsp)
jmp 0x3992b
movq 0x168(%rsp), %rax
movq %rax, 0x2f8(%rsp)
movl $0x0, 0x2f4(%rsp)
movl 0x2f4(%rsp), %eax
movl %eax, 0x160(%rsp)
movq 0x2f8(%rsp), %rdi
callq 0x2f200
movl %eax, 0x164(%rsp)
jmp 0x3996a
movl 0x160(%rsp), %eax
movl 0x164(%rsp), %ecx
cmpl %ecx, %eax
jge 0x39f71
movq 0x2f8(%rsp), %rdi
movl 0x2f4(%rsp), %esi
callq 0x2f280
movq %rax, 0x158(%rsp)
jmp 0x3999e
movq 0x158(%rsp), %rax
movq %rax, 0x2e8(%rsp)
movq 0x2e8(%rsp), %rdi
callq 0x3d6b0
movq %rax, 0x150(%rsp)
jmp 0x399c5
movq 0x150(%rsp), %rax
movq %rax, 0x2e0(%rsp)
movl $0x0, 0x2dc(%rsp)
movl 0x2dc(%rsp), %eax
movl %eax, 0x148(%rsp)
movq 0x2e8(%rsp), %rdi
callq 0x2f2b0
movl %eax, 0x14c(%rsp)
jmp 0x39a04
movl 0x148(%rsp), %eax
movl 0x14c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x39f59
movq 0x2e8(%rsp), %rdi
movl 0x2dc(%rsp), %esi
callq 0x3e050
movq %rax, 0x140(%rsp)
jmp 0x39a38
movq 0x140(%rsp), %rax
movq %rax, 0x2d0(%rsp)
movq 0x2d0(%rsp), %rdi
callq 0x3e0c0
movss %xmm0, 0x13c(%rsp)
jmp 0x39a60
movss 0x13c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x128(%rsp)
movq 0x2e0(%rsp), %rdi
callq 0x2ee70
movsd %xmm0, 0x130(%rsp)
jmp 0x39a8e
movsd 0x130(%rsp), %xmm1
movsd 0x128(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x2c8(%rsp)
movq 0x2d0(%rsp), %rdi
callq 0x3e0d0
movss %xmm0, 0x124(%rsp)
jmp 0x39ac5
movss 0x124(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x110(%rsp)
movq 0x2e0(%rsp), %rdi
callq 0x2ee80
movsd %xmm0, 0x118(%rsp)
jmp 0x39af3
movsd 0x118(%rsp), %xmm1
movsd 0x110(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x2c0(%rsp)
movq 0x2d0(%rsp), %rdi
callq 0x3d6c0
movss %xmm0, 0x10c(%rsp)
jmp 0x39b2a
movss 0x10c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xf8(%rsp)
movq 0x2e0(%rsp), %rdi
callq 0x2ee90
movsd %xmm0, 0x100(%rsp)
jmp 0x39b58
movsd 0x100(%rsp), %xmm1
movsd 0xf8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x2b8(%rsp)
movsd 0x2c8(%rsp), %xmm0
movsd 0x2c0(%rsp), %xmm1
movsd 0x2b8(%rsp), %xmm2
leaq 0x2a0(%rsp), %rdi
callq 0x1622c0
jmp 0x39ba1
leaq 0x280(%rsp), %rdi
leaq 0x2a0(%rsp), %rsi
leaq 0x448(%rsp), %rdx
callq 0x162620
jmp 0x39bc0
leaq 0x430(%rsp), %rdi
leaq 0x280(%rsp), %rsi
callq 0x163a30
movsd %xmm0, 0xf0(%rsp)
jmp 0x39be0
movsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0x298(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x298(%rsp), %xmm0
jb 0x39c05
jmp 0x39f43
leaq 0x270(%rsp), %rdi
leaq 0x318(%rsp), %rsi
leaq 0x2a0(%rsp), %rdx
callq 0xcf070
jmp 0x39c24
leaq 0x69cc9d(%rip), %rsi    # 0x6d68c8
leaq 0x270(%rsp), %rdi
callq 0x195420
movl %eax, 0xec(%rsp)
jmp 0x39c41
movl 0xec(%rsp), %eax
cmpl $0x0, %eax
je 0x39c52
jmp 0x39f43
leaq 0x270(%rsp), %rdi
callq 0x3dc80
movsd %xmm0, 0xe0(%rsp)
jmp 0x39c6a
movsd 0xe0(%rsp), %xmm0
movsd 0x2073bd(%rip), %xmm1   # 0x241038
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x26c(%rsp)
cmpl $0x0, 0x26c(%rsp)
jl 0x39ca4
movl 0x26c(%rsp), %eax
cmpl 0x3f4(%rsp), %eax
jl 0x39ca9
jmp 0x39f43
leaq 0x270(%rsp), %rdi
callq 0x3dcb0
movsd %xmm0, 0xd8(%rsp)
jmp 0x39cc1
movsd 0xd8(%rsp), %xmm0
movsd 0x207366(%rip), %xmm1   # 0x241038
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x268(%rsp)
cmpl $0x0, 0x268(%rsp)
jl 0x39cfb
movl 0x268(%rsp), %eax
cmpl 0x3f0(%rsp), %eax
jl 0x39d00
jmp 0x39f43
movl 0x3f4(%rsp), %eax
movl 0x268(%rsp), %ecx
imull %ecx, %eax
movl 0x26c(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x264(%rsp)
movsd 0x298(%rsp), %xmm0
movq 0x3d0(%rsp), %rax
movslq 0x264(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
leaq 0x292e02(%rip), %rax    # 0x2ccb48
movsd (%rax), %xmm2
callq 0x3ed10
movl %eax, 0xd4(%rsp)
jmp 0x39d58
movl 0xd4(%rsp), %eax
cmpl $0x0, %eax
je 0x39d69
jmp 0x39f43
movq 0x2f8(%rsp), %rdi
movl $0x1, %esi
callq 0x590e0
movq %rax, 0xc8(%rsp)
jmp 0x39d85
movq 0xc8(%rsp), %rax
cmpq $0x0, %rax
je 0x39e2c
leaq 0x318(%rsp), %rdi
callq 0x2f6d0
movq %rax, 0xc0(%rsp)
jmp 0x39dae
movq 0xc0(%rsp), %rdi
callq 0x2ee60
movq %rax, 0xb8(%rsp)
jmp 0x39dc5
movq 0x2f8(%rsp), %rdi
movl $0x1, %esi
callq 0x590e0
movq %rax, 0xb0(%rsp)
jmp 0x39de1
movq 0xb0(%rsp), %rdi
callq 0x3e270
movq %rax, 0xa8(%rsp)
jmp 0x39df8
movq 0xa8(%rsp), %rsi
movq 0xb8(%rsp), %rdi
callq 0xf0ed0
movsd %xmm0, 0xa0(%rsp)
jmp 0x39e18
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
jmp 0x39e40
leaq 0x292d25(%rip), %rax    # 0x2ccb58
movsd (%rax), %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x258(%rsp)
movsd 0x298(%rsp), %xmm0
movq 0x3d0(%rsp), %rax
movslq 0x264(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x207738(%rip), %xmm2   # 0x2415b0
callq 0x3ed40
movl %eax, 0x94(%rsp)
jmp 0x39e86
movl 0x94(%rsp), %eax
cmpl $0x0, %eax
je 0x39ed7
movsd 0x258(%rsp), %xmm0
movq 0x3c8(%rsp), %rax
movslq 0x264(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
leaq 0x292c91(%rip), %rax    # 0x2ccb48
movsd (%rax), %xmm2
callq 0x3ed10
movl %eax, 0x90(%rsp)
jmp 0x39ec9
movl 0x90(%rsp), %eax
cmpl $0x0, %eax
je 0x39ed7
jmp 0x39f43
movq 0x2f8(%rsp), %rdi
callq 0x3d5c0
movl %eax, 0x8c(%rsp)
jmp 0x39eed
movl 0x8c(%rsp), %edx
movq 0x3d8(%rsp), %rax
movslq 0x264(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movsd 0x298(%rsp), %xmm0
movq 0x3d0(%rsp), %rax
movslq 0x264(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x258(%rsp), %xmm0
movq 0x3c8(%rsp), %rax
movslq 0x264(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x2dc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2dc(%rsp)
jmp 0x399e0
jmp 0x39f5b
movl 0x2f4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2f4(%rsp)
jmp 0x39946
jmp 0x39f73
movl 0x300(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x300(%rsp)
jmp 0x398cb
movl $0x0, 0x254(%rsp)
movl 0x254(%rsp), %eax
movl 0x3f4(%rsp), %ecx
imull 0x3f0(%rsp), %ecx
cmpl %ecx, %eax
jge 0x3a019
movq 0x3d8(%rsp), %rax
movslq 0x254(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x250(%rsp)
cmpl $0x0, 0x250(%rsp)
jge 0x39fd4
jmp 0x3a003
movq 0x3e8(%rsp), %rax
movslq 0x250(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x3a001
movq 0x3e8(%rsp), %rax
movslq 0x250(%rsp), %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x3a003
movl 0x254(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x254(%rsp)
jmp 0x39f94
movl $0x0, 0x24c(%rsp)
movq 0x218(%rsp), %rdi
movl 0x24c(%rsp), %eax
movl %eax, 0x84(%rsp)
addq $0x10, %rdi
callq 0x3df90
movl %eax, 0x88(%rsp)
jmp 0x3a04c
movl 0x84(%rsp), %eax
movl 0x88(%rsp), %ecx
cmpl %ecx, %eax
jge 0x3a12d
movq 0x218(%rsp), %rdi
addq $0x10, %rdi
movl 0x24c(%rsp), %esi
callq 0x3dfb0
movq %rax, 0x78(%rsp)
jmp 0x3a081
movq 0x78(%rsp), %rax
movq %rax, 0x240(%rsp)
movq 0x3e8(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x240(%rsp), %rdi
callq 0x3d5c0
movl %eax, 0x74(%rsp)
jmp 0x3a0ae
movq 0x68(%rsp), %rax
movl 0x74(%rsp), %ecx
movslq %ecx, %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0x3a0c2
jmp 0x3a117
movq 0x3e0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x240(%rsp), %rdi
callq 0x3d5c0
movl %eax, 0x64(%rsp)
jmp 0x3a0e2
movq 0x218(%rsp), %rdi
movq 0x58(%rsp), %rax
movl 0x64(%rsp), %ecx
movslq %ecx, %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x240(%rsp), %rsi
movq (%rdi), %rax
movq 0x330(%rax), %rax
xorl %edx, %edx
callq *%rax
jmp 0x3a115
jmp 0x3a117
movl 0x24c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24c(%rsp)
jmp 0x3a024
movl $0x0, 0x23c(%rsp)
movl 0x23c(%rsp), %eax
movl 0x3f4(%rsp), %ecx
imull 0x3f0(%rsp), %ecx
cmpl %ecx, %eax
jge 0x3a307
movq 0x3d8(%rsp), %rax
movslq 0x23c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x238(%rsp)
cmpl $0x0, 0x238(%rsp)
jge 0x3a17f
jmp 0x3a2f1
movq 0x3e0(%rsp), %rax
movslq 0x238(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x3a19a
jmp 0x3a2f1
movq 0x460(%rsp), %rdi
movl 0x238(%rsp), %esi
callq 0x2f1d0
movq %rax, 0x50(%rsp)
jmp 0x3a1b5
movq 0x50(%rsp), %rax
movq %rax, 0x230(%rsp)
movq 0x230(%rsp), %rdi
callq 0x2f260
movl %eax, 0x4c(%rsp)
jmp 0x3a1d5
movl 0x4c(%rsp), %eax
cmpl $0x0, %eax
jne 0x3a1e3
jmp 0x3a2f1
movq 0x218(%rsp), %rdi
movq 0x3e0(%rsp), %rax
movslq 0x238(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x230(%rsp), %rsi
movq (%rdi), %rax
movq 0x330(%rax), %rax
xorl %edx, %edx
callq *%rax
jmp 0x3a21a
movl $0x0, 0x22c(%rsp)
movl 0x22c(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0x230(%rsp), %rdi
callq 0x2f260
movl %eax, 0x48(%rsp)
jmp 0x3a243
movl 0x44(%rsp), %eax
movl 0x48(%rsp), %ecx
cmpl %ecx, %eax
jge 0x3a2ef
movq 0x230(%rsp), %rdi
movl 0x22c(%rsp), %esi
callq 0x3eba0
movq %rax, 0x38(%rsp)
jmp 0x3a26e
movq 0x38(%rsp), %rax
movq %rax, 0x220(%rsp)
movq 0x3e0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x220(%rsp), %rdi
callq 0x3d5c0
movl %eax, 0x34(%rsp)
jmp 0x3a29b
movq 0x218(%rsp), %rdi
movq 0x28(%rsp), %rax
movl 0x34(%rsp), %ecx
movslq %ecx, %rcx
movl $0x1, (%rax,%rcx,4)
movq 0x220(%rsp), %rsi
movq (%rdi), %rax
movq 0x328(%rax), %rax
xorl %edx, %edx
callq *%rax
jmp 0x3a2ce
movl $0x0, 0x314(%rsp)
movl 0x22c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x22c(%rsp)
jmp 0x3a225
jmp 0x3a2f1
movl 0x23c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x23c(%rsp)
jmp 0x3a138
cmpl $0x0, 0x314(%rsp)
je 0x3a313
jmp 0x3a32b
jmp 0x3a315
movl 0x30c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30c(%rsp)
jmp 0x3977e
movq 0x3e8(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, %rax
je 0x3a348
movq 0x20(%rsp), %rdi
callq 0x28e00
movq 0x3e0(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x3a365
movq 0x18(%rsp), %rdi
callq 0x28e00
movq 0x3d8(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x3a382
movq 0x10(%rsp), %rdi
callq 0x28e00
movq 0x3d0(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x3a39f
movq 0x8(%rsp), %rdi
callq 0x28e00
movq 0x3c8(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x3a3ba
movq (%rsp), %rdi
callq 0x28e00
movq 0x218(%rsp), %rdi
movq (%rdi), %rax
movq 0x378(%rax), %rax
callq *%rax
jmp 0x3a3d0
leaq 0x318(%rsp), %rdi
callq 0xcd500
movl $0x0, 0x3f8(%rsp)
leaq 0x408(%rsp), %rdi
callq 0x3de80
addq $0x478, %rsp            # imm = 0x478
retq
leaq 0x408(%rsp), %rdi
callq 0x3de80
movq 0x400(%rsp), %rdi
callq 0x292e0
nopw (%rax,%rax)