// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelImage.cpp
// Function: gaps::R3SurfelImage::RenderImage(gaps::R2Image*, gaps::R2Grid*, gaps::R2Grid*, gaps::R2Grid*, gaps::R2Grid*, gaps::R2Grid*, gaps::R2Grid*, gaps::R2Grid*, gaps::R2Grid*, gaps::R2Grid*) const
int R3SurfelImage::
RenderImage(R2Image *color_image,
  R2Grid *depth_image, R2Grid *height_image,
  R2Grid *xnormal_image, R2Grid *ynormal_image, R2Grid *znormal_image,
  R2Grid *label_image, R2Grid *object_image,
  R2Grid *node_image, R2Grid *block_image) const
{
  // Only for scans now
  R3SurfelScan *scan = Scan();
  if (!scan) return 0;
  R3SurfelNode *node = scan->Node();
  if (!node) return 0;
  
  // Initialize images
  R2Grid tmp_image(ImageWidth(), ImageHeight());
  tmp_image.Clear(R2_GRID_UNKNOWN_VALUE);
  if (color_image) *color_image = R2Image(ImageWidth(), ImageHeight());
  if (depth_image) *depth_image = tmp_image;
  if (height_image) *height_image = tmp_image;
  if (xnormal_image) *xnormal_image = tmp_image;
  if (ynormal_image) *ynormal_image = tmp_image;
  if (znormal_image) *znormal_image = tmp_image;
  if (label_image) *label_image = tmp_image;
  if (object_image) *object_image = tmp_image;
  if (node_image) *node_image = tmp_image;
  if (block_image) *block_image = tmp_image;

  // Check stuff
  if (!scene || !scene->Tree()) return 0;

  // Visit leaf nodes
  RNArray<const R3SurfelNode *> stack;
  stack.Insert(node);
  while (!stack.IsEmpty()) {
    const R3SurfelNode *decendent = stack.Tail();
    stack.RemoveTail();
    if (decendent->NParts() > 0) {
      // Visit decendent nodes
      for (int i = 0; i < decendent->NParts(); i++) {
        R3SurfelNode *part = decendent->Part(i);
        stack.Insert(part);
      }
    }
    else {
      // Render all blocks of leaf node
      for (int i = 0; i < decendent->NBlocks(); i++) {
        R3SurfelBlock *block = decendent->Block(i);
        R3SurfelNode *node = (block) ? block->Node() : NULL;
        R3SurfelObject *object = (node) ? node->Object(TRUE) : NULL;
        R3SurfelLabel *label = (object) ? object->CurrentLabel() : NULL;

        // Read block
        scene->Tree()->Database()->ReadBlock(block);

        // Render block
        for (int j = 0; j < block->NSurfels(); j++) {
          const R3Surfel *surfel = block->Surfel(j);

          // Get image position
          R2Point image_position = TransformFromWorldToImage(block->SurfelPosition(j));
          if (!ContainsImagePosition(image_position)) continue;
          int ix = (int) (image_position.X() + 0.5);
          int iy = (int) (image_position.Y() + 0.5);

          // Fill pixel at image index
          if (color_image) color_image->SetPixelRGB(ix, iy, block->SurfelColor(j));
          if (depth_image) depth_image->SetGridValue(ix, iy, (block->SurfelPosition(j) - Viewpoint()).Dot(Towards()));
          if (height_image) height_image->SetGridValue(ix, iy, block->SurfelPosition(j).Z() - Viewpoint().Z());
          if (xnormal_image) xnormal_image->SetGridValue(ix, iy, surfel->NX());
          if (ynormal_image) ynormal_image->SetGridValue(ix, iy, surfel->NY());
          if (znormal_image) znormal_image->SetGridValue(ix, iy, surfel->NZ());
          if (block_image) block_image->SetGridValue(ix, iy, block->DatabaseIndex());
          if (node_image && node) node_image->SetGridValue(ix, iy, node->TreeIndex());
          if (object_image && object) object_image->SetGridValue(ix, iy, object->SceneIndex());
          if (label_image && label) label_image->SetGridValue(ix, iy, label->SceneIndex());
        }

        // Release block
        scene->Tree()->Database()->ReleaseBlock(block);
      }
    }
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rcx, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x18(%rdi), %rax
xorl %r14d, %r14d
testq %rax, %rax
je 0x3df18
movq 0x18(%rax), %rbx
testq %rbx, %rbx
je 0x3df18
movq %r9, %r15
movq %r8, %r12
movq 0x18(%rsp), %rax
movl 0x98(%rax), %esi
movl 0x9c(%rax), %edx
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
callq 0x90cb8
movsd 0xa0b97(%rip), %xmm0    # 0xde2a0
movq %r14, %rdi
callq 0x92e38
cmpq $0x0, 0x40(%rsp)
je 0x3d752
movq 0x18(%rsp), %rax
movl 0x98(%rax), %esi
movl 0x9c(%rax), %edx
leaq 0x60(%rsp), %rdi
movl $0x3, %ecx
callq 0xa30f6
leaq 0x60(%rsp), %rsi
movq 0x40(%rsp), %rdi
callq 0xa33ee
leaq 0x60(%rsp), %rdi
callq 0xa3350
cmpq $0x0, 0x38(%rsp)
je 0x3d76c
leaq 0xb8(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x9162a
cmpq $0x0, 0x30(%rsp)
je 0x3d786
leaq 0xb8(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0x9162a
testq %r12, %r12
je 0x3d79b
leaq 0xb8(%rsp), %rsi
movq %r12, %rdi
callq 0x9162a
testq %r15, %r15
je 0x3d7b0
leaq 0xb8(%rsp), %rsi
movq %r15, %rdi
callq 0x9162a
movq 0x1f0(%rsp), %rdi
testq %rdi, %rdi
je 0x3d7ca
leaq 0xb8(%rsp), %rsi
callq 0x9162a
cmpq $0x0, 0x1f8(%rsp)
je 0x3d7ea
leaq 0xb8(%rsp), %rsi
movq 0x1f8(%rsp), %rdi
callq 0x9162a
cmpq $0x0, 0x200(%rsp)
je 0x3d80a
leaq 0xb8(%rsp), %rsi
movq 0x200(%rsp), %rdi
callq 0x9162a
cmpq $0x0, 0x208(%rsp)
je 0x3d82a
leaq 0xb8(%rsp), %rsi
movq 0x208(%rsp), %rdi
callq 0x9162a
movq 0x210(%rsp), %rdi
testq %rdi, %rdi
je 0x3d844
leaq 0xb8(%rsp), %rsi
callq 0x9162a
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
xorl %r14d, %r14d
testq %rax, %rax
je 0x3df0b
cmpq $0x0, 0x8(%rax)
je 0x3df0b
leaq 0x48(%rsp), %rdi
callq 0xa9ca8
movq %r12, 0x90(%rsp)
movq %r15, 0x98(%rsp)
leaq 0x48(%rsp), %rdi
movl 0xc(%rdi), %edx
movq %rbx, %rsi
callq 0xa9d3e
movl 0x54(%rsp), %eax
testl %eax, %eax
je 0x3defb
movq 0x18(%rsp), %rcx
leaq 0x30(%rcx), %rdx
movq %rdx, 0x80(%rsp)
addq $0x78, %rcx
movq %rcx, 0x78(%rsp)
leaq 0x48(%rsp), %r14
leaq 0x60(%rsp), %r13
leaq 0x188(%rsp), %r12
movq 0x48(%rsp), %rcx
movslq %eax, %rsi
movq -0x8(%rcx,%rsi,8), %r15
decl %esi
movq %r14, %rdi
callq 0xa9ec8
cmpl $0x0, 0x3c(%r15)
jle 0x3d913
xorl %ebx, %ebx
movq 0x30(%r15), %rax
movq (%rax,%rbx,8), %rsi
movl 0x54(%rsp), %edx
movq %r14, %rdi
callq 0xa9d3e
incq %rbx
movslq 0x3c(%r15), %rax
cmpq %rax, %rbx
jl 0x3d8e6
movl 0x54(%rsp), %eax
testl %eax, %eax
jne 0x3d8c6
jmp 0x3defb
cmpl $0x0, 0x4c(%r15)
jle 0x3d906
xorl %ebp, %ebp
movq %r15, 0x88(%rsp)
movq 0x40(%r15), %rax
movq (%rax,%rbp,8), %r14
testq %r14, %r14
je 0x3d973
movq 0xb8(%r14), %rbx
testq %rbx, %rbx
je 0x3d973
movq %rbx, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x376f4
movq %rbx, 0x58(%rsp)
testq %rax, %rax
je 0x3dee8
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x17872
movq %rax, 0x20(%rsp)
movb $0x1, %bl
movb $0x1, %r15b
jmp 0x3d993
xorl %ebx, %ebx
movq $0x0, 0x28(%rsp)
movq $0x0, 0x58(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x20(%rsp)
movl 0xb4(%r14), %eax
testl %eax, %eax
jne 0x3d9cd
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rdi
movq (%rdi), %rax
movq 0x8(%rdi), %rdx
movl 0x28(%rdi), %ecx
movq %r14, %rsi
callq *0x88(%rax)
testl %eax, %eax
je 0x3d9d6
movl 0xb4(%r14), %eax
incl %eax
movl %eax, 0xb4(%r14)
movq %rbp, 0xa0(%rsp)
cmpl $0x0, 0x8(%r14)
jle 0x3de49
cmpq $0x0, 0x208(%rsp)
setne %cl
cmpq $0x0, 0x200(%rsp)
setne %dl
cmpq $0x0, 0x1f8(%rsp)
setne %al
andb %r15b, %cl
movb %cl, 0x17(%rsp)
andb %bl, %dl
movb %dl, 0x16(%rsp)
cmpq $0x0, 0x20(%rsp)
setne %cl
andb %al, %cl
movb %cl, 0x15(%rsp)
xorl %ebx, %ebx
xorl %r15d, %r15d
movq (%r14), %rbp
xorps %xmm0, %xmm0
cvtss2sd (%rbp,%rbx), %xmm0
addsd 0x10(%r14), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rbp,%rbx), %xmm1
addsd 0x18(%r14), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rbp,%rbx), %xmm2
addsd 0x20(%r14), %xmm2
movq %r13, %rdi
callq 0x83dc2
leaq 0xa8(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r13, %rdx
callq 0x3ce12
movsd 0xa8(%rsp), %xmm0
movsd 0xa0c5c(%rip), %xmm1    # 0xde6e8
ucomisd %xmm0, %xmm1
ja 0x3de35
movsd 0xb0(%rsp), %xmm1
movsd 0xa0c41(%rip), %xmm2    # 0xde6e8
ucomisd %xmm1, %xmm2
ja 0x3de35
movq 0x18(%rsp), %rax
xorps %xmm2, %xmm2
cvtsi2sdl 0x98(%rax), %xmm2
addsd 0xa0c27(%rip), %xmm2    # 0xde6f0
ucomisd %xmm2, %xmm0
jae 0x3de35
movq 0x18(%rsp), %rax
xorps %xmm2, %xmm2
cvtsi2sdl 0x9c(%rax), %xmm2
addsd 0xa0c05(%rip), %xmm2    # 0xde6f0
ucomisd %xmm2, %xmm1
jae 0x3de35
movsd 0x9f63b(%rip), %xmm2    # 0xdd138
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x10(%rsp)
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0xc(%rsp)
cmpq $0x0, 0x40(%rsp)
je 0x3db75
movq (%r14), %rax
movzbl 0x2c(%rax,%rbx), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x9f83c(%rip), %xmm3    # 0xdd370
mulsd %xmm3, %xmm0
movzbl 0x2d(%rax,%rbx), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm3, %xmm1
movzbl 0x2e(%rax,%rbx), %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
mulsd %xmm3, %xmm2
movq %r13, %rdi
callq 0xa9b1c
movq 0x40(%rsp), %rdi
movl 0x10(%rsp), %esi
movl 0xc(%rsp), %edx
movq %r13, %rcx
callq 0xa34a6
cmpq $0x0, 0x38(%rsp)
je 0x3dc15
movq (%r14), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%rbx), %xmm0
addsd 0x10(%r14), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rax,%rbx), %xmm1
addsd 0x18(%r14), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rax,%rbx), %xmm2
addsd 0x20(%r14), %xmm2
leaq 0x1a0(%rsp), %r13
movq %r13, %rdi
callq 0x83dc2
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
movq 0x80(%rsp), %rdx
callq 0x8401e
movq %r12, %rdi
movq 0x78(%rsp), %rsi
callq 0x85490
leaq 0x60(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x84ae2
movq 0x38(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull 0xc(%rsp), %ecx
addl 0x10(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
cmpq $0x0, 0x30(%rsp)
je 0x3dc87
movq (%r14), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%rbx), %xmm0
addsd 0x10(%r14), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rax,%rbx), %xmm1
addsd 0x18(%r14), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rax,%rbx), %xmm2
addsd 0x20(%r14), %xmm2
movq %r13, %rdi
callq 0x83dc2
movsd 0x70(%rsp), %xmm0
movq 0x18(%rsp), %rax
subsd 0x40(%rax), %xmm0
movq 0x30(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull 0xc(%rsp), %ecx
addl 0x10(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x90(%rsp), %rcx
testq %rcx, %rcx
je 0x3dcca
movswl 0x10(%rbp,%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
mulss 0x9f758(%rip), %xmm0    # 0xdd400
cvtss2sd %xmm0, %xmm0
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull 0xc(%rsp), %ecx
addl 0x10(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x98(%rsp), %rcx
testq %rcx, %rcx
je 0x3dd0d
movswl 0x12(%rbp,%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
mulss 0x9f715(%rip), %xmm0    # 0xdd400
cvtss2sd %xmm0, %xmm0
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull 0xc(%rsp), %ecx
addl 0x10(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x1f0(%rsp), %rcx
testq %rcx, %rcx
je 0x3dd50
movswl 0x14(%rbp,%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
mulss 0x9f6d2(%rip), %xmm0    # 0xdd400
cvtss2sd %xmm0, %xmm0
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull 0xc(%rsp), %ecx
addl 0x10(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x210(%rsp), %rcx
testq %rcx, %rcx
je 0x3dd87
xorps %xmm0, %xmm0
cvtsi2sdl 0xa0(%r14), %xmm0
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull 0xc(%rsp), %ecx
addl 0x10(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
cmpb $0x0, 0x17(%rsp)
je 0x3ddc1
movq 0x58(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0x20(%rax), %xmm0
movq 0x208(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull 0xc(%rsp), %ecx
addl 0x10(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
cmpb $0x0, 0x16(%rsp)
je 0x3ddfb
movq 0x28(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0x10(%rax), %xmm0
movq 0x200(%rsp), %rcx
movq 0xb8(%rcx), %rax
movl 0xc8(%rcx), %ecx
imull 0xc(%rsp), %ecx
addl 0x10(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
cmpb $0x0, 0x15(%rsp)
je 0x3de35
movq 0x20(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0x10(%rax), %xmm0
movq 0x1f8(%rsp), %rax
movl 0xc(%rsp), %ecx
imull 0xc8(%rax), %ecx
movq 0xb8(%rax), %rax
addl 0x10(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
incq %r15
movslq 0x8(%r14), %rax
addq $0x30, %rbx
cmpq %rax, %r15
jl 0x3da2e
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %r15
movl 0xb4(%r14), %eax
cmpl $0x1, %eax
movq 0xa0(%rsp), %rbp
jne 0x3de90
movq (%r15), %rax
movq 0x8(%r15), %rdx
movl 0x28(%r15), %ecx
movq %r15, %rdi
movq %r14, %rsi
callq *0x90(%rax)
testl %eax, %eax
je 0x3dec6
movl 0xb4(%r14), %eax
decl %eax
movl %eax, 0xb4(%r14)
jne 0x3dec6
testb $0x2, 0x89(%r14)
je 0x3dec6
movq (%r15), %rax
movq %r15, %rdi
movq %r14, %rsi
callq *0x18(%rax)
movq %r14, %rdi
callq 0x2ca06
movl $0xc8, %esi
movq %r14, %rdi
callq 0x134f0
incq %rbp
movq 0x88(%rsp), %r15
movslq 0x4c(%r15), %rax
cmpq %rax, %rbp
leaq 0x48(%rsp), %r14
jl 0x3d924
jmp 0x3d906
movb $0x1, %r15b
xorl %ebx, %ebx
movq $0x0, 0x28(%rsp)
jmp 0x3d98a
leaq 0x48(%rsp), %rdi
callq 0xa9d12
movl $0x1, %r14d
leaq 0xb8(%rsp), %rdi
callq 0x918ec
movl %r14d, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3df57
jmp 0x3df42
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xa3350
jmp 0x3df64
jmp 0x3df42
movq %rax, %rbx
jmp 0x3df64
jmp 0x3df57
jmp 0x3df57
jmp 0x3df57
jmp 0x3df57
jmp 0x3df57
jmp 0x3df57
jmp 0x3df57
jmp 0x3df57
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xa9d12
leaq 0xb8(%rsp), %rdi
callq 0x918ec
movq %rbx, %rdi
callq 0x138b0
nopl (%rax)