// File: tomfunkhouser[P]gaps/pkgs/R3Graphics/R3Scene.cpp
// Function: gaps::DrawNodeWithLights(gaps::R3Scene const*, gaps::R3SceneNode*, gaps::R3Affine const&, gaps::RNFlags, int, int)
static void 
DrawNodeWithLights(const R3Scene *scene, R3SceneNode *node,
  const R3Affine& parent_transformation, const R3DrawFlags draw_flags,
  int min_light = 0, int max_light = 7)
{
  // Load lights
  if ((node->NElements() > 0) || (node->NReferences() > 0)) {
    R3Box world_bbox = node->BBox();
    world_bbox.Transform(parent_transformation);
    scene->LoadLights(world_bbox, min_light, max_light);
  }
  
  // Push transformation
  R3Affine transformation = parent_transformation;
  transformation.Transform(node->Transformation());
  transformation.Push();

  // Draw elements
  for (int i = 0; i < node->NElements(); i++) {
    R3SceneElement *element = node->Element(i);
    element->Draw(draw_flags);
  }

  // Draw references
  for (int i = 0; i < node->NReferences(); i++) {
    R3SceneReference *reference = node->Reference(i);
    reference->Draw(draw_flags);
  }

  // Pop transformation
  transformation.Pop();

  // Draw children
  for (int i = 0; i < node->NChildren(); i++) {
    R3SceneNode *child = node->Child(i);
    DrawNodeWithLights(scene, child, transformation, draw_flags, min_light, max_light);
  }
}

// Assembly:
subq $0x208, %rsp            # imm = 0x208
movq %rcx, 0x200(%rsp)
movq %rdi, 0x1f8(%rsp)
movq %rsi, 0x1f0(%rsp)
movq %rdx, 0x1e8(%rsp)
movl %r8d, 0x1e4(%rsp)
movl %r9d, 0x1e0(%rsp)
movq 0x1f0(%rsp), %rdi
callq 0x2bba0
cmpl $0x0, %eax
jg 0x2e5cf
movq 0x1f0(%rsp), %rdi
callq 0x2bb40
cmpl $0x0, %eax
jle 0x2e65f
movq 0x1f0(%rsp), %rdi
callq 0x56d40
movq %rax, %rsi
leaq 0x1a8(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0xb72c0
movq 0x38(%rsp), %rdi
movq 0x1e8(%rsp), %rsi
callq 0xb9650
jmp 0x2e605
movq 0x1f8(%rsp), %rdi
movl 0x1e4(%rsp), %edx
movl 0x1e0(%rsp), %ecx
leaq 0x1a8(%rsp), %rsi
callq 0x2df40
jmp 0x2e62a
leaq 0x1a8(%rsp), %rdi
callq 0x2c1a0
jmp 0x2e65f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x2c1a0
jmp 0x2e8ae
movq 0x1e8(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0x48c80
movq 0x1f0(%rsp), %rdi
callq 0x2bae0
movq %rax, 0x30(%rsp)
jmp 0x2e688
movq 0x30(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0xc1dd0
jmp 0x2e69c
leaq 0x88(%rsp), %rdi
callq 0x66690
jmp 0x2e6ab
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x1f0(%rsp), %rdi
callq 0x2bba0
movl %eax, 0x2c(%rsp)
jmp 0x2e6d4
movl 0x28(%rsp), %eax
movl 0x2c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2e769
movq 0x1f0(%rsp), %rdi
movl 0x84(%rsp), %esi
callq 0x2bbc0
movq %rax, 0x20(%rsp)
jmp 0x2e6ff
movq 0x20(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rdi
movq 0x200(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x59950
jmp 0x2e72b
jmp 0x2e72d
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x2e6b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x88(%rsp), %rdi
callq 0xc1b00
jmp 0x2e8ae
movl $0x0, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x1f0(%rsp), %rdi
callq 0x2bb40
movl %eax, 0x1c(%rsp)
jmp 0x2e78c
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2e7eb
movq 0x1f0(%rsp), %rdi
movl 0x6c(%rsp), %esi
callq 0x2bb60
movq %rax, 0x10(%rsp)
jmp 0x2e7b0
movq 0x10(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
movq 0x200(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x5a1b0
jmp 0x2e7dc
jmp 0x2e7de
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x2e771
leaq 0x88(%rsp), %rdi
callq 0x66700
jmp 0x2e7fa
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x1f0(%rsp), %rdi
callq 0x2baf0
movl %eax, 0xc(%rsp)
jmp 0x2e81d
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2e899
movq 0x1f0(%rsp), %rdi
movl 0x54(%rsp), %esi
callq 0x2bb10
movq %rax, (%rsp)
jmp 0x2e840
movq (%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x200(%rsp), %rax
movq %rax, 0x40(%rsp)
movl 0x1e4(%rsp), %r8d
movl 0x1e0(%rsp), %r9d
movq 0x40(%rsp), %rcx
leaq 0x88(%rsp), %rdx
callq 0x2e570
jmp 0x2e887
jmp 0x2e889
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x2e802
leaq 0x88(%rsp), %rdi
callq 0xc1b00
addq $0x208, %rsp            # imm = 0x208
retq
movq 0x1a0(%rsp), %rdi
callq 0x23290
nopl (%rax,%rax)