// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/apps/scninfo/scninfo.cpp
// Function: PrintReference(gaps::R3SceneReference*, int, int)
static int
PrintReference(R3SceneReference *reference, int index, int level)
{
  // Construct indent
  char indent[4096] = { '\0' };
  for (int i = 0; i < level; i++) {
    strcat(indent, "  ");
  }

  // Print reference stuff
  const R3Scene *referenced_scene = reference->ReferencedScene();
  const char *name = (referenced_scene) ? referenced_scene->Root()->Name() : NULL;
  const char *filename = (referenced_scene) ? referenced_scene->Filename() : NULL;
  printf("%sReference %d\n", indent, index);
  if (name) printf("%s  Name = %s\n", indent, name);
  if (filename) printf("%s  Filename = %s\n", indent, filename);
  printf("%s  # Materials = %d\n", indent, reference->NMaterials());
  for (int i = 0; i < reference->NMaterials(); i++) {
    R3Material *material = reference->Material(i);
    const R3Brdf *brdf = (material) ? material->Brdf() : NULL;
    const R2Texture *texture = (material) ? material->Texture() : NULL;
    RNRgb diffuse = (brdf) ? brdf->Diffuse() : RNRgb(0.5, 0.5, 0.5);
    const char *texture_name = (texture) ? texture->Name() : "None";
    printf("%s    %d (%g %g %g) %s\n", indent, i, diffuse.R(), diffuse.G(), diffuse.B(), texture_name);
  } 
  printf("\n");

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1028, %rsp           # imm = 0x1028
movl %edx, %r15d
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x20(%rsp), %r14
xorl %r12d, %r12d
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
xorl %esi, %esi
callq 0x21450
testl %r15d, %r15d
cmovgl %r15d, %r12d
subl $0x1, %r12d
jb 0x2572a
movq %r14, %rdi
callq 0x21340
movw $0x2020, 0x20(%rsp,%rax) # imm = 0x2020
movb $0x0, 0x22(%rsp,%rax)
jmp 0x2570e
movq (%rbx), %rax
testq %rax, %rax
je 0x25745
movq (%rax), %rcx
movq 0x148(%rax), %r14
movq 0x1a0(%rcx), %r15
jmp 0x2574b
xorl %r15d, %r15d
xorl %r14d, %r14d
leaq 0x9dc85(%rip), %rdi     # 0xc33d7
leaq 0x20(%rsp), %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x21080
testq %r15, %r15
je 0x2577b
leaq 0x9dc7b(%rip), %rdi     # 0xc33e7
leaq 0x20(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x21080
testq %r14, %r14
je 0x25796
leaq 0x9dc6f(%rip), %rdi     # 0xc33f6
leaq 0x20(%rsp), %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x21080
movl 0x14(%rbx), %edx
leaq 0x9dc69(%rip), %rdi     # 0xc3409
xorl %r14d, %r14d
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x21080
leaq 0x8(%rsp), %r12
leaq 0x9d9f5(%rip), %rbp     # 0xc31b0
leaq 0x9dc5d(%rip), %r13     # 0xc341f
movslq 0x14(%rbx), %rax
cmpq %rax, %r14
jge 0x25841
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x257f3
movq 0x18(%rax), %rsi
movq 0x20(%rax), %r15
testq %rsi, %rsi
je 0x257f6
addq $0x38, %rsi
movq %r12, %rdi
callq 0x7a338
jmp 0x2580c
xorl %r15d, %r15d
movq %r12, %rdi
movsd 0x9d817(%rip), %xmm0    # 0xc3018
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x7a356
movq %rbp, %rcx
testq %r15, %r15
je 0x25818
movq 0x10(%r15), %rcx
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
movl %r14d, %edx
movb $0x3, %al
callq 0x21080
incq %r14
jmp 0x257c2
pushq $0xa
popq %rdi
callq 0x21cd0
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop