// File: /workspace/github_cpp_makefile_star2_O3/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)
cmpl $0x0, 0x2c(%r14)
jle 0x261fa
xorl %ebx, %ebx
movq 0x20(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0x261af
incq %rbx
movslq 0x2c(%r14), %rax
cmpq %rax, %rbx
jl 0x261de
cmpl $0x0, 0x4c(%r14)
jle 0x26222
xorl %ebx, %ebx
movq 0x40(%r14), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rdi
movq (%rdi), %rsi
callq 0x261af
incq %rbx
movslq 0x4c(%r14), %rax
cmpq %rax, %rbx
jl 0x26203
movl $0x1, %edi
callq 0x21190
movq (%r15), %rdi
callq 0x3c478
movq %rax, %rdi
callq 0x6d330
movl 0x3c(%r14), %eax
testl %eax, %eax
jle 0x26358
mulsd 0xb3dd0(%rip), %xmm0    # 0xda020
mulsd 0xb3dd0(%rip), %xmm0    # 0xda028
movsd %xmm0, 0x30(%rsp)
xorl %edx, %edx
leaq 0x38(%rsp), %r15
leaq 0x50(%rsp), %r12
movq %r14, 0x8(%rsp)
movq 0x30(%r14), %rcx
movq (%rcx,%rdx,8), %rcx
cmpl $0x0, 0x1c(%rcx)
jle 0x26349
movq %rdx, 0x10(%rsp)
xorl %edx, %edx
movq %rcx, 0x18(%rsp)
movq 0x10(%rcx), %rax
movq %rdx, 0x20(%rsp)
movq (%rax,%rdx,8), %rbx
movq (%rbx), %rax
movq %rbx, %rdi
callq *0xb8(%rax)
movl %eax, %ebp
callq 0x678ec
cmpl %eax, %ebp
jne 0x26321
cmpl $0x0, 0x24(%rbx)
jle 0x26321
xorl %r14d, %r14d
movq %rbx, 0x28(%rsp)
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rbx
movl $0x1, %r13d
movq (%rbx,%r13,8), %rbp
testb $0x1, 0x59(%rbp)
je 0x26307
movq %rbp, %rdi
callq 0x211b0
leaq 0x18(%rbp), %rsi
movq %r15, %rdi
movsd 0x30(%rsp), %xmm0
callq 0x767fa
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x7570f
movq %r12, %rdi
callq 0x211b0
incq %r13
cmpq $0x4, %r13
jne 0x262cd
incq %r14
movq 0x28(%rsp), %rbx
movslq 0x24(%rbx), %rax
cmpq %rax, %r14
jl 0x262bf
movq 0x20(%rsp), %rdx
incq %rdx
movq 0x18(%rsp), %rcx
movslq 0x1c(%rcx), %rax
cmpq %rax, %rdx
jl 0x2628d
movq 0x8(%rsp), %r14
movl 0x3c(%r14), %eax
movq 0x10(%rsp), %rdx
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
jl 0x2626f
callq 0x21c50
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