// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/apps/scn2cam/scn2cam.cpp
// Function: RasterizeIntoZXGrid(gaps::R2Grid&, gaps::R3SceneNode*, gaps::R3Box const&)
static void
RasterizeIntoZXGrid(R2Grid& grid, R3SceneNode *node,
  const R3Box& world_bbox)
{
  // Check bounding box
  R3Box node_bbox = node->BBox();
  if (!R3Intersects(world_bbox, node_bbox)) return;
  
  // Rasterize elements into grid
  for (int j = 0; j < node->NElements(); j++) {
    R3SceneElement *element = node->Element(j);
    for (int k = 0; k < element->NShapes(); k++) {
      R3Shape *shape = element->Shape(k);
      R3Box shape_bbox = shape->BBox();
      if (!R3Intersects(world_bbox, shape_bbox)) continue;
      if (shape->ClassID() == R3TriangleArray::CLASS_ID()) {
        R3TriangleArray *triangles = (R3TriangleArray *) shape;
        for (int m = 0; m < triangles->NTriangles(); m++) {
          R3Triangle *triangle = triangles->Triangle(m);
          R3Box triangle_bbox = triangle->BBox();
          if (!R3Intersects(world_bbox, triangle_bbox)) continue;
          R3TriangleVertex *v0 = triangle->V0();
          R3Point vp0 = v0->Position();
          R2Point p0(vp0.Z(), vp0.X());
          if (!R2Contains(grid.WorldBox(), p0)) continue;
          R3TriangleVertex *v1 = triangle->V1();
          R3Point vp1 = v1->Position();
          R2Point p1(vp1.Z(), vp1.X());
          if (!R2Contains(grid.WorldBox(), p1)) continue;
          R3TriangleVertex *v2 = triangle->V2();
          R3Point vp2 = v2->Position();
          R2Point p2(vp2.Z(), vp2.X());
          if (!R2Contains(grid.WorldBox(), p2)) continue;
          grid.RasterizeWorldTriangle(p0, p1, p2, 1.0);
        }
      }
    }
  }

  // Rasterize children into grid
  for (int j = 0; j < node->NChildren(); j++) {
    R3SceneNode *child = node->Child(j);
    RasterizeIntoZXGrid(grid, child, world_bbox);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movq %rsi, %rdi
callq 0x41d4c
leaq 0x180(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x74908
movq %r14, 0x20(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x50204
testl %eax, %eax
je 0x2c5fc
movl 0x3c(%r12), %eax
testl %eax, %eax
jle 0x2c5cf
xorl %edx, %edx
leaq 0x148(%rsp), %rbx
leaq 0xd0(%rsp), %rbp
movq %r12, 0x50(%rsp)
movq 0x30(%r12), %rcx
movq (%rcx,%rdx,8), %r14
cmpl $0x0, 0x1c(%r14)
jle 0x2c5c0
movq %rdx, 0x58(%rsp)
xorl %r13d, %r13d
movq %r14, 0x60(%rsp)
movq 0x10(%r14), %rax
movq (%rax,%r13,8), %r12
movq (%r12), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x88(%rax)
movq %r13, 0x68(%rsp)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x50204
testl %eax, %eax
je 0x2c587
movq (%r12), %rax
movq %r12, %rdi
callq *0xb8(%rax)
movl %eax, %ebx
callq 0x6f518
cmpl %eax, %ebx
leaq 0x110(%rsp), %r14
jne 0x2c587
cmpl $0x0, 0x24(%r12)
jle 0x2c587
xorl %r13d, %r13d
movq 0x18(%r12), %rax
movq (%rax,%r13,8), %rbx
movq (%rbx), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0x88(%rax)
movq 0x20(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x50204
testl %eax, %eax
je 0x2c566
movq 0x8(%rbx), %rsi
leaq 0xf8(%rsp), %rdi
callq 0x7d006
movsd 0xf8(%rsp), %xmm1
movsd 0x108(%rsp), %xmm0
leaq 0xa8(%rsp), %rdi
callq 0x9774a
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
leaq 0x90(%rsp), %rdi
callq 0x9774a
movl 0xc0(%r15), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl 0xc4(%r15), %eax
decl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
leaq 0x28(%rsp), %rdi
callq 0x9774a
movsd 0x90(%rsp), %xmm0
movsd 0x98(%rsp), %xmm1
movq %rsp, %rdi
movq %r15, %rsi
callq 0x8f59c
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x8f59c
movq %rbp, %rdi
movq %rsp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x9496e
movq %rbp, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x86a74
movl %eax, %r14d
movq %rbp, %rdi
callq 0x952b8
testl %r14d, %r14d
je 0x2c566
movq 0x10(%rbx), %rsi
leaq 0x90(%rsp), %rdi
callq 0x7d006
movsd 0x90(%rsp), %xmm1
movsd 0xa0(%rsp), %xmm0
leaq 0x80(%rsp), %rdi
callq 0x9774a
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
leaq 0x28(%rsp), %rdi
callq 0x9774a
movl 0xc0(%r15), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl 0xc4(%r15), %eax
decl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movq %rsp, %rdi
callq 0x9774a
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x8f59c
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x8f59c
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x9496e
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
callq 0x86a74
movl %eax, %r14d
movq %rbp, %rdi
callq 0x952b8
testl %r14d, %r14d
je 0x2c566
movq 0x18(%rbx), %rsi
leaq 0x28(%rsp), %rdi
callq 0x7d006
movsd 0x28(%rsp), %xmm1
movsd 0x38(%rsp), %xmm0
leaq 0x70(%rsp), %rdi
callq 0x9774a
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %rsp, %rdi
callq 0x9774a
movl 0xc0(%r15), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl 0xc4(%r15), %eax
decl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
leaq 0x10(%rsp), %rdi
callq 0x9774a
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x8f59c
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
leaq 0xb8(%rsp), %rdi
movq %r15, %rsi
callq 0x8f59c
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x9496e
movq %rbp, %rdi
leaq 0x70(%rsp), %rsi
callq 0x86a74
movl %eax, %ebx
movq %rbp, %rdi
callq 0x952b8
testl %ebx, %ebx
je 0x2c566
movsd 0xa8(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm1
movq %rbp, %rdi
movq %r15, %rsi
callq 0x8f5c2
movsd 0x80(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movq %rsp, %rdi
movq %r15, %rsi
callq 0x8f5c2
movsd 0x70(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x8f5c2
movapd 0xd0(%rsp), %xmm0
movapd 0xc5c05(%rip), %xmm1    # 0xf2100
addpd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0x40(%rsp)
movapd (%rsp), %xmm0
addpd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0xb8(%rsp)
movapd 0x10(%rsp), %xmm0
addpd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0xc8(%rsp)
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
leaq 0xc8(%rsp), %rcx
movsd 0xc5b42(%rip), %xmm0    # 0xf2098
movapd %xmm0, %xmm1
movapd %xmm0, %xmm2
xorl %r8d, %r8d
callq 0x8e45e
leaq 0x110(%rsp), %r14
movq %r14, %rdi
callq 0x75728
incq %r13
movslq 0x24(%r12), %rax
cmpq %rax, %r13
jl 0x2c1f8
leaq 0x148(%rsp), %rbx
movq %rbx, %rdi
callq 0x75728
movq 0x68(%rsp), %r13
incq %r13
movq 0x60(%rsp), %r14
movslq 0x1c(%r14), %rax
cmpq %rax, %r13
jl 0x2c191
movq 0x50(%rsp), %r12
movl 0x3c(%r12), %eax
movq 0x58(%rsp), %rdx
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
jl 0x2c170
cmpl $0x0, 0x2c(%r12)
jle 0x2c5fc
xorl %ebx, %ebx
movq 0x20(%r12), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rdx
callq 0x2c0fd
incq %rbx
movslq 0x2c(%r12), %rax
cmpq %rax, %rbx
jl 0x2c5d9
leaq 0x180(%rsp), %rdi
callq 0x75728
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2c61f
jmp 0x2c61f
movq %rax, %rbx
jmp 0x2c670
jmp 0x2c653
jmp 0x2c634
jmp 0x2c648
jmp 0x2c653
jmp 0x2c653
jmp 0x2c634
jmp 0x2c653
jmp 0x2c653
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x952b8
jmp 0x2c656
jmp 0x2c653
movq %rax, %rbx
jmp 0x2c663
jmp 0x2c653
jmp 0x2c653
jmp 0x2c653
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x75728
leaq 0x148(%rsp), %rdi
callq 0x75728
leaq 0x180(%rsp), %rdi
callq 0x75728
movq %rbx, %rdi
callq 0x23090