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

  // Print material
  const char *name = material->Name();
  const R3Brdf *brdf = material->Brdf();
  const char *brdf_name = (brdf) ? brdf->Name() : NULL;
  const R2Texture *texture = material->Texture();
  const char *texture_name = (texture) ? texture->Name() : NULL;
  const RNRgb& diffuse = (brdf) ? brdf->Diffuse() : RNblack_rgb;
  printf("%sMaterial %d\n", indent, index);
  if (name) printf("%s  Name = %s\n", indent, name);
  if (texture) printf("%s  Texture index = %d\n", indent, texture->SceneIndex());
  if (texture_name) printf("%s  Texture name = %s\n", indent, texture_name);
  if (brdf) printf("%s  Brdf index = %d\n", indent, brdf->SceneIndex());
  if (brdf_name) printf("%s  Brdf name = %s\n", indent, brdf_name);
  printf("%s  Brdf diffuse = %g %g %g\n", indent, diffuse.R(), diffuse.G(), diffuse.B());
  printf("\n");

  // Return success
  return 1;
}

// Assembly:
subq $0x1098, %rsp           # imm = 0x1098
movq %rdi, 0x1090(%rsp)
movl %esi, 0x108c(%rsp)
movl %edx, 0x1088(%rsp)
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x224b0
movl $0x0, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
cmpl 0x1088(%rsp), %eax
jge 0x28fa7
leaq 0x80(%rsp), %rdi
leaq 0x1668cc(%rip), %rsi    # 0x18f861
callq 0x23230
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x28f79
movq 0x1090(%rsp), %rdi
callq 0x2ade0
movq %rax, 0x70(%rsp)
movq 0x1090(%rsp), %rdi
callq 0x2ab30
movq %rax, 0x68(%rsp)
cmpq $0x0, 0x68(%rsp)
je 0x28fe4
movq 0x68(%rsp), %rdi
callq 0x2ac40
movq %rax, 0x40(%rsp)
jmp 0x28fed
xorl %eax, %eax
movq %rax, 0x40(%rsp)
jmp 0x28fed
movq 0x40(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x1090(%rsp), %rdi
callq 0x2ab40
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x29022
movq 0x58(%rsp), %rdi
callq 0x2ab60
movq %rax, 0x38(%rsp)
jmp 0x2902b
xorl %eax, %eax
movq %rax, 0x38(%rsp)
jmp 0x2902b
movq 0x38(%rsp), %rax
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x68(%rsp)
je 0x2904e
movq 0x68(%rsp), %rdi
callq 0x2ab50
movq %rax, 0x30(%rsp)
jmp 0x2905c
leaq 0x1d4903(%rip), %rax    # 0x1fd958
movq %rax, 0x30(%rsp)
jmp 0x2905c
movq 0x30(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x80(%rsp), %rsi
movl 0x108c(%rsp), %edx
leaq 0x16354c(%rip), %rdi    # 0x18c5c8
movb $0x0, %al
callq 0x22090
cmpq $0x0, 0x70(%rsp)
je 0x290a6
leaq 0x80(%rsp), %rsi
movq 0x70(%rsp), %rdx
leaq 0x1633ab(%rip), %rdi    # 0x18c44a
movb $0x0, %al
callq 0x22090
cmpq $0x0, 0x58(%rsp)
je 0x290da
leaq 0x80(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x58(%rsp), %rdi
callq 0x2adc0
movq 0x28(%rsp), %rsi
movl %eax, %edx
leaq 0x163504(%rip), %rdi    # 0x18c5d7
movb $0x0, %al
callq 0x22090
cmpq $0x0, 0x50(%rsp)
je 0x290fd
leaq 0x80(%rsp), %rsi
movq 0x50(%rsp), %rdx
leaq 0x1634f9(%rip), %rdi    # 0x18c5ef
movb $0x0, %al
callq 0x22090
cmpq $0x0, 0x68(%rsp)
je 0x29131
leaq 0x80(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x68(%rsp), %rdi
callq 0x2adf0
movq 0x20(%rsp), %rsi
movl %eax, %edx
leaq 0x1634dc(%rip), %rdi    # 0x18c606
movb $0x0, %al
callq 0x22090
cmpq $0x0, 0x60(%rsp)
je 0x29154
leaq 0x80(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x1634ce(%rip), %rdi    # 0x18c61b
movb $0x0, %al
callq 0x22090
leaq 0x80(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rdi
callq 0x2ab70
movsd %xmm0, 0x18(%rsp)
movq 0x48(%rsp), %rdi
callq 0x2ab80
movsd %xmm0, 0x10(%rsp)
movq 0x48(%rsp), %rdi
callq 0x2ab90
movq 0x8(%rsp), %rsi
movsd 0x10(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x18(%rsp), %xmm0
leaq 0x163489(%rip), %rdi    # 0x18c62f
movb $0x3, %al
callq 0x22090
leaq 0x16a54e(%rip), %rdi    # 0x193702
movb $0x0, %al
callq 0x22090
movl $0x1, %eax
addq $0x1098, %rsp           # imm = 0x1098
retq
nopl (%rax,%rax)