// File: /workspace/github_cpp_makefile_star2_O1/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 0x4233c
leaq 0x180(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x75880
movq %r14, 0x20(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x50ae8
testl %eax, %eax
je 0x2c683
cmpl $0x0, 0x3c(%r12)
jle 0x2c656
xorl %ecx, %ecx
leaq 0x148(%rsp), %rbx
leaq 0xd0(%rsp), %rbp
movq %r12, 0x50(%rsp)
movq 0x30(%r12), %rax
movq %rcx, 0x58(%rsp)
movq (%rax,%rcx,8), %r14
cmpl $0x0, 0x1c(%r14)
jle 0x2c63b
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 0x50ae8
testl %eax, %eax
je 0x2c611
movq (%r12), %rax
movq %r12, %rdi
callq *0xb8(%rax)
movl %eax, %ebx
callq 0x70410
cmpl %eax, %ebx
leaq 0x110(%rsp), %r14
jne 0x2c611
cmpl $0x0, 0x24(%r12)
jle 0x2c611
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 0x50ae8
testl %eax, %eax
je 0x2c5f0
movq 0x8(%rbx), %rsi
leaq 0xf8(%rsp), %rdi
callq 0x7e05e
movsd 0xf8(%rsp), %xmm1
movsd 0x108(%rsp), %xmm0
leaq 0xa8(%rsp), %rdi
callq 0x9890a
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
leaq 0x90(%rsp), %rdi
callq 0x9890a
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 0x9890a
movsd 0x90(%rsp), %xmm0
movsd 0x98(%rsp), %xmm1
movq %rsp, %rdi
movq %r15, %rsi
callq 0x907c4
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x907c4
movq %rbp, %rdi
movq %rsp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x95b26
movq %rbp, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x87b5b
movl %eax, %r14d
movq %rbp, %rdi
callq 0x96478
testl %r14d, %r14d
je 0x2c5f0
movq 0x10(%rbx), %rsi
leaq 0x90(%rsp), %rdi
callq 0x7e05e
movsd 0x90(%rsp), %xmm1
movsd 0xa0(%rsp), %xmm0
leaq 0x80(%rsp), %rdi
callq 0x9890a
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
leaq 0x28(%rsp), %rdi
callq 0x9890a
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 0x9890a
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x907c4
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x907c4
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x95b26
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
callq 0x87b5b
movl %eax, %r14d
movq %rbp, %rdi
callq 0x96478
testl %r14d, %r14d
je 0x2c5f0
movq 0x18(%rbx), %rsi
leaq 0x28(%rsp), %rdi
callq 0x7e05e
movsd 0x28(%rsp), %xmm1
movsd 0x38(%rsp), %xmm0
leaq 0x70(%rsp), %rdi
callq 0x9890a
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %rsp, %rdi
callq 0x9890a
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 0x9890a
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x907c4
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
leaq 0xb8(%rsp), %rdi
movq %r15, %rsi
callq 0x907c4
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x95b26
movq %rbp, %rdi
leaq 0x70(%rsp), %rsi
callq 0x87b5b
movl %eax, %ebx
movq %rbp, %rdi
callq 0x96478
testl %ebx, %ebx
je 0x2c5f0
movsd 0xa8(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm1
movq %rbp, %rdi
movq %r15, %rsi
callq 0x907ea
movsd 0x80(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movq %rsp, %rdi
movq %r15, %rsi
callq 0x907ea
movsd 0x70(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x907ea
movapd 0xd0(%rsp), %xmm0
movapd 0xc7b7b(%rip), %xmm1    # 0xf4100
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 0xc7ab8(%rip), %xmm0    # 0xf4098
movapd %xmm0, %xmm1
movapd %xmm0, %xmm2
xorl %r8d, %r8d
callq 0x8f61a
leaq 0x110(%rsp), %r14
movq %r14, %rdi
callq 0x766d8
incq %r13
movslq 0x24(%r12), %rax
cmpq %rax, %r13
jl 0x2c282
leaq 0x148(%rsp), %rbx
movq %rbx, %rdi
callq 0x766d8
movq 0x68(%rsp), %r13
incq %r13
movq 0x60(%rsp), %r14
movslq 0x1c(%r14), %rax
cmpq %rax, %r13
jl 0x2c21b
movq 0x58(%rsp), %rcx
incq %rcx
movq 0x50(%rsp), %r12
movslq 0x3c(%r12), %rax
cmpq %rax, %rcx
jl 0x2c1fa
cmpl $0x0, 0x2c(%r12)
jle 0x2c683
xorl %ebx, %ebx
movq 0x20(%r12), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rdx
callq 0x2c188
incq %rbx
movslq 0x2c(%r12), %rax
cmpq %rax, %rbx
jl 0x2c660
leaq 0x180(%rsp), %rdi
callq 0x766d8
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2c6a6
jmp 0x2c6a6
movq %rax, %rbx
jmp 0x2c6f7
jmp 0x2c6da
jmp 0x2c6bb
jmp 0x2c6cf
jmp 0x2c6da
jmp 0x2c6da
jmp 0x2c6bb
jmp 0x2c6da
jmp 0x2c6da
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x96478
jmp 0x2c6dd
jmp 0x2c6da
movq %rax, %rbx
jmp 0x2c6ea
jmp 0x2c6da
jmp 0x2c6da
jmp 0x2c6da
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x766d8
leaq 0x148(%rsp), %rdi
callq 0x766d8
leaq 0x180(%rsp), %rdi
callq 0x766d8
movq %rbx, %rdi
callq 0x230a0