// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/apps/scnview/scnview.cpp
// Function: DrawNormals(gaps::R3Scene*, gaps::R3SceneNode*)
static void 
DrawNormals(R3Scene *scene, R3SceneNode *node)
{
  // Push transformation
  node->Transformation().Push();

  // Draw children normals
  for (int i = 0; i < node->NChildren(); i++) {
    R3SceneNode *child = node->Child(i);
    DrawNormals(scene, child);
  }

  // Draw reference normals
  for (int i = 0; i < node->NReferences(); i++) {
    R3SceneReference *reference = node->Reference(i);
    R3Scene *referenced_scene = reference->ReferencedScene();
    DrawNormals(referenced_scene, referenced_scene->Root());
  }

  // Draw element normals
  RNGrfxBegin(RN_GRFX_LINES);
  double r = 0.01 * scene->BBox().DiagonalRadius();
  for (int i = 0; i < node->NElements(); i++) {
    R3SceneElement *element = node->Element(i);
    for (int j = 0; j < element->NShapes(); j++) {
      R3Shape *shape = element->Shape(j);
      if (shape->ClassID() == R3TriangleArray::CLASS_ID()) {
        R3TriangleArray *triangles = (R3TriangleArray *) shape;
        for (int k = 0; k < triangles->NTriangles(); k++) {
          R3Triangle *triangle = triangles->Triangle(k);
          // R3LoadPoint(triangle->Centroid());
          // R3LoadPoint(triangle->Centroid() + r * triangle->Normal());
          for (int v = 0; v < 3; v++) {
            R3TriangleVertex *vertex = triangle->Vertex(v);
            if (!vertex->HasNormal()) continue;
            R3LoadPoint(vertex->Position());
            R3LoadPoint(vertex->Position() + r * vertex->Normal());
          }
        }
      }
    }
  }
  RNGrfxEnd();
  
  // Pop transformation
  node->Transformation().Pop();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x58(%rsi), %rdi
movq 0x58(%rsi), %rax
movq %rdi, (%rsp)
callq *0xb0(%rax)
xorl %ebx, %ebx
movslq 0x2c(%r14), %rax
cmpq %rax, %rbx
jge 0x25491
movq 0x20(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0x2544b
incq %rbx
jmp 0x25473
xorl %ebx, %ebx
movslq 0x4c(%r14), %rax
cmpq %rax, %rbx
jge 0x254b4
movq 0x40(%r14), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rdi
movq (%rdi), %rsi
callq 0x2544b
incq %rbx
jmp 0x25493
movq %r14, 0x8(%rsp)
pushq $0x1
popq %rdi
callq 0x21190
movq %r15, %rdi
callq 0x27352
movq %rax, %rdi
callq 0x2735a
mulsd 0x9fb47(%rip), %xmm0    # 0xc5020
movsd %xmm0, 0x30(%rsp)
xorl %edx, %edx
leaq 0x38(%rsp), %r15
leaq 0x50(%rsp), %r12
movq 0x8(%rsp), %rcx
movslq 0x3c(%rcx), %rax
cmpq %rax, %rdx
jge 0x255cc
movq 0x30(%rcx), %rax
movq %rdx, 0x10(%rsp)
movq (%rax,%rdx,8), %rcx
xorl %edx, %edx
movq %rcx, 0x18(%rsp)
movslq 0x1c(%rcx), %rax
cmpq %rax, %rdx
jge 0x255bf
movq 0x10(%rcx), %rax
movq %rdx, 0x20(%rsp)
movq (%rax,%rdx,8), %r14
movq (%r14), %rax
movq %r14, %rdi
callq *0xb8(%rax)
movl %eax, %ebp
callq 0x5f048
cmpl %eax, %ebp
jne 0x255ad
xorl %ebx, %ebx
movq %r14, 0x28(%rsp)
movslq 0x24(%r14), %rax
cmpq %rax, %rbx
jge 0x255ad
movq 0x18(%r14), %rax
movq (%rax,%rbx,8), %r14
pushq $0x1
popq %r13
cmpq $0x4, %r13
je 0x255a3
movq (%r14,%r13,8), %rbp
testb $0x1, 0x59(%rbp)
je 0x2559e
movq %rbp, %rdi
callq 0x211b0
leaq 0x18(%rbp), %rsi
movq %r15, %rdi
movsd 0x30(%rsp), %xmm0
callq 0x6c72a
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x6bb3b
movq %r12, %rdi
callq 0x211b0
incq %r13
jmp 0x2555e
incq %rbx
movq 0x28(%rsp), %r14
jmp 0x25549
movq 0x20(%rsp), %rdx
incq %rdx
movq 0x18(%rsp), %rcx
jmp 0x25511
movq 0x10(%rsp), %rdx
incq %rdx
jmp 0x254eb
callq 0x21c60
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0xb8(%rax)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq