// File: /workspace/github_cpp_makefile_star2_O1/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 0x26745
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x21350
movw $0x2020, 0x20(%rsp,%rax) # imm = 0x2020
movb $0x0, 0x22(%rsp,%rax)
decl %r14d
jne 0x2672c
movq (%rbx), %rax
testq %rax, %rax
je 0x26759
movq (%rax), %rcx
movq 0x1a0(%rcx), %r15
jmp 0x2675c
xorl %r15d, %r15d
testq %rax, %rax
je 0x2676a
movq 0x148(%rax), %r14
jmp 0x2676d
xorl %r14d, %r14d
leaq 0xb4c5b(%rip), %rdi     # 0xdb3cf
leaq 0x20(%rsp), %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x21080
testq %r15, %r15
je 0x2679d
leaq 0xb4c51(%rip), %rdi     # 0xdb3df
leaq 0x20(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x21080
testq %r14, %r14
je 0x267b8
leaq 0xb4c45(%rip), %rdi     # 0xdb3ee
leaq 0x20(%rsp), %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x21080
movl 0x14(%rbx), %edx
leaq 0xb4c3f(%rip), %rdi     # 0xdb401
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x21080
cmpl $0x0, 0x14(%rbx)
jle 0x2687c
xorl %r14d, %r14d
leaq 0xb49c6(%rip), %rbp     # 0xdb1a8
leaq 0xb4c2e(%rip), %r12     # 0xdb417
leaq 0x20(%rsp), %r13
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x26801
movq 0x18(%rax), %rsi
jmp 0x26803
xorl %esi, %esi
testq %rax, %rax
je 0x2680e
movq 0x20(%rax), %r15
jmp 0x26811
xorl %r15d, %r15d
testq %rsi, %rsi
je 0x26826
addq $0x38, %rsi
leaq 0x8(%rsp), %rdi
callq 0x8693a
jmp 0x2683e
leaq 0x8(%rsp), %rdi
movsd 0xb47dd(%rip), %xmm0    # 0xdb010
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x86958
movq %rbp, %rcx
testq %r15, %r15
je 0x2684a
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 0x267ee
movl $0xa, %edi
callq 0x21cb0
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq