// File: /workspace/github_cpp_makefile_star2_O3/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, %r14d
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x21450
testl %r14d, %r14d
jle 0x266ee
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x21350
movw $0x2020, 0x20(%rsp,%rax) # imm = 0x2020
movb $0x0, 0x22(%rsp,%rax)
decl %r14d
jne 0x266d5
movq (%rbx), %rax
testq %rax, %rax
je 0x26754
movq (%rax), %rcx
movq 0x148(%rax), %r14
movq 0x1a0(%rcx), %r15
leaq 0xb2cc1(%rip), %rdi     # 0xd93cf
leaq 0x20(%rsp), %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x21080
testq %r15, %r15
je 0x26737
leaq 0xb2cb7(%rip), %rdi     # 0xd93df
leaq 0x20(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x21080
testq %r14, %r14
je 0x26769
leaq 0xb2cab(%rip), %rdi     # 0xd93ee
leaq 0x20(%rsp), %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x21080
jmp 0x26769
leaq 0xb2c74(%rip), %rdi     # 0xd93cf
leaq 0x20(%rsp), %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x21080
movl 0x14(%rbx), %edx
leaq 0xb2c8e(%rip), %rdi     # 0xd9401
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x21080
cmpl $0x0, 0x14(%rbx)
jle 0x2681e
xorl %r14d, %r14d
leaq 0xb2a15(%rip), %rbp     # 0xd91a8
leaq 0xb2c7d(%rip), %r12     # 0xd9417
leaq 0x20(%rsp), %r13
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x267c9
movq 0x18(%rax), %rsi
movq 0x20(%rax), %r15
testq %rsi, %rsi
je 0x267cc
addq $0x38, %rsi
leaq 0x8(%rsp), %rdi
callq 0x857de
jmp 0x267e4
xorl %r15d, %r15d
leaq 0x8(%rsp), %rdi
movsd 0xb2837(%rip), %xmm0    # 0xd9010
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x857fc
movq %rbp, %rcx
testq %r15, %r15
je 0x267f0
movq 0x10(%r15), %rcx
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movb $0x3, %al
callq 0x21080
incq %r14
movslq 0x14(%rbx), %rax
cmpq %rax, %r14
jl 0x2679f
movl $0xa, %edi
callq 0x21ca0
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq