// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Graphics/R3Scene.cpp
// Function: gaps::R3Scene::ReadObbFile(char const*, gaps::R3SceneNode*)
int R3Scene::
ReadObbFile(const char *filename, R3SceneNode *parent_node)
{
  // Get/check parent node
  if (!parent_node) parent_node = root;

  // Open file
  FILE *fp;
  if (!(fp = fopen(filename, "r"))) {
    RNFail("Unable to open file %s", filename);
    return 0;
  }

  // Read file
  char buffer[4096];
  int line_number = 0;
  while (fgets(buffer, 4096, fp)) {
    // Check line
    line_number++;
    char *bufferp = buffer;
    while (*bufferp && isspace(*bufferp)) bufferp++;
    if (!bufferp) continue;
    if (*bufferp == '#') continue;

    // Parse line
    char cmd[1024], name[1024];
    int category, instance, originator;
    double center[3], axis0[3], axis1[3], radii[3], confidence;
    if (sscanf(bufferp, "%s%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%d%d%lf%d%s", cmd,
      &center[0], &center[1], &center[2],
      &axis0[0], &axis0[1], &axis0[2],
      &axis1[0], &axis1[1], &axis1[2],
      &radii[0], &radii[1], &radii[2],
      &category, &instance,
      &confidence, &originator,
      name) != (unsigned int) 18) {
      RNFail("Error parsing line %d of %s\n", line_number, filename);
      return 0;
    }

    // Check cmd
    if (strcmp(cmd, "OBB")) {
      RNFail("Unrecognized command at line %d in %s\n", line_number, filename);
      return 0;
    }

    // Create node
    R3SceneNode *node = new R3SceneNode(this);
    parent_node->InsertChild(node);

    // Set node name
    char node_name[2048];
    sprintf(node_name, "%s_%03d", name, (int) (1000*confidence));
    node->SetName(node_name);

    // Create color based on category
    double r = (1 + (category % 7)) / 7.0;
    double g = 1.0 - (1 + (category % 17)) / 17.0;
    double b = (1 + (category % 31)) / 31.0;
    R3Brdf *brdf = new R3Brdf(RNRgb(r, g, b));
    InsertBrdf(brdf);
    R3Material *material = new R3Material(brdf);
    InsertMaterial(material);

    // Create element
    R3SceneElement *element = new R3SceneElement();
    element->SetMaterial(material);
    node->InsertElement(element);

    // Create shape 
    R3OrientedBox *obb = new R3OrientedBox(R3Point(center),
      R3Vector(axis0), R3Vector(axis1),
      radii[0], radii[1], radii[2]);
    R3Sphere *nose = new R3Sphere(
      R3Point(center) + radii[0] * R3Vector(axis0), 0.02 * radii[0]);
    element->InsertShape(obb);
    element->InsertShape(nose);
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2158, %rsp           # imm = 0x2158
movq %rsi, %r15
movq %rdi, %r12
movq %rdx, 0x20(%rsp)
testq %rdx, %rdx
jne 0x2d94c
movq (%r12), %rax
movq %rax, 0x20(%rsp)
leaq 0xb56f0(%rip), %rsi     # 0xe3043
movq %r15, %rdi
callq 0x21ac0
testq %rax, %rax
je 0x2de37
movq %rax, %r13
leaq 0x950(%rsp), %rbx
movq %rbx, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %rax, %rdx
callq 0x21f40
testq %rax, %rax
je 0x2de28
leaq 0x38(%r12), %rax
movq %rax, 0x68(%rsp)
leaq 0x28(%r12), %rax
movq %rax, 0x60(%rsp)
leaq 0x138(%rsp), %r14
movl $0x0, 0xc(%rsp)
movq %r12, 0x28(%rsp)
movq %r15, 0x50(%rsp)
movq %r13, 0x58(%rsp)
incl 0xc(%rsp)
movb 0x950(%rsp), %bpl
testb %bpl, %bpl
je 0x2d9fe
leaq 0x950(%rsp), %rbx
movsbl %bpl, %edi
callq 0x210b0
testl %eax, %eax
je 0x2d9ef
movb 0x1(%rbx), %bpl
incq %rbx
testb %bpl, %bpl
jne 0x2d9d4
jmp 0x2d9fe
movl $0x2, %eax
cmpb $0x23, %bpl
je 0x2de03
movq %rbx, %rdi
leaq 0xaf6af(%rip), %rsi     # 0xdd0b7
leaq 0x550(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
leaq 0xb8(%rsp), %r8
leaq 0xc0(%rsp), %r9
xorl %eax, %eax
leaq 0x150(%rsp), %r10
pushq %r10
leaq 0x90(%rsp), %r10
pushq %r10
leaq 0x90(%rsp), %r10
pushq %r10
leaq 0xa4(%rsp), %r10
pushq %r10
leaq 0x3c(%rsp), %r10
pushq %r10
leaq 0x68(%rsp), %r10
pushq %r10
leaq 0x68(%rsp), %r10
pushq %r10
leaq 0x68(%rsp), %r10
pushq %r10
leaq 0x120(%rsp), %r10
pushq %r10
leaq 0x120(%rsp), %r10
pushq %r10
leaq 0x120(%rsp), %r10
pushq %r10
leaq 0xf8(%rsp), %r10
pushq %r10
leaq 0xf8(%rsp), %r10
pushq %r10
leaq 0xf8(%rsp), %r10
pushq %r10
callq 0x21890
addq $0x70, %rsp
cmpl $0x12, %eax
jne 0x2dde0
cmpl $0x42424f, 0x550(%rsp) # imm = 0x42424F
jne 0x2dde9
movl $0x1b0, %edi            # imm = 0x1B0
callq 0x218c0
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
callq 0x3bab8
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x3ce8e
movsd 0x80(%rsp), %xmm0
mulsd 0xae9dd(%rip), %xmm0    # 0xdc4e0
cvttsd2si %xmm0, %ecx
leaq 0x1950(%rsp), %rbx
movq %rbx, %rdi
leaq 0xaf5f7(%rip), %rsi     # 0xdd110
leaq 0x150(%rsp), %rdx
xorl %eax, %eax
callq 0x21140
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3d0ca
movslq 0x1c(%rsp), %rax
imulq $-0x6db6db6d, %rax, %rcx # imm = 0x92492493
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x2, %ecx
addl %edx, %ecx
leal (,%rcx,8), %edx
subl %edx, %ecx
addl %eax, %ecx
incl %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
divsd 0xae97d(%rip), %xmm0    # 0xdc4e8
movsd %xmm0, 0x10(%rsp)
imulq $0x78787879, %rax, %rcx # imm = 0x78787879
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
sarl $0x3, %ecx
addl %edx, %ecx
movl %ecx, %edx
shll $0x4, %edx
addl %ecx, %edx
negl %edx
leal (%rax,%rdx), %ecx
incl %ecx
cvtsi2sd %ecx, %xmm1
divsd 0xae94e(%rip), %xmm1    # 0xdc4f0
movsd 0xae46e(%rip), %xmm0    # 0xdc018
addsd %xmm0, %xmm1
movsd %xmm1, 0x78(%rsp)
imulq $-0x7bdef7bd, %rax, %rcx # imm = 0x84210843
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x4, %ecx
addl %edx, %ecx
movl %ecx, %edx
shll $0x5, %edx
subl %edx, %ecx
addl %ecx, %eax
incl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0xae913(%rip), %xmm0    # 0xdc4f8
movsd %xmm0, 0x70(%rsp)
movl $0xb8, %edi
callq 0x218c0
movq %rax, %rbx
leaq 0xf0(%rsp), %r15
movq %r15, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
movsd 0x70(%rsp), %xmm2
callq 0x88530
xorpd %xmm0, %xmm0
movq %rbx, %rdi
movq %r15, %rsi
movsd 0xae3ec(%rip), %xmm1    # 0xdc018
movaps %xmm1, %xmm2
xorl %edx, %edx
callq 0x44488
movq 0x28(%rsp), %r13
movq %r13, 0x8(%rbx)
movl 0x44(%r13), %edx
movl %edx, 0x10(%rbx)
movq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x88752
movl $0x30, %edi
callq 0x218c0
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x440f8
movq %r13, (%r15)
movl 0x34(%r13), %edx
movl %edx, 0x8(%r15)
movq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x88752
movl $0x60, %edi
callq 0x218c0
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x3d9c4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3dc66
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3ceca
movl $0x80, %edi
callq 0x218c0
movq %rax, %rbp
leaq 0xf0(%rsp), %r15
movq %r15, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x762e8
movq 0x58(%rsp), %r13
leaq 0x108(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x76de4
movq %r14, %rdi
leaq 0xd0(%rsp), %rsi
callq 0x76de4
movq %r14, %r12
leaq 0x108(%rsp), %r14
movsd 0x30(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movq %rbp, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x6c790
movl $0x28, %edi
callq 0x218c0
movq %rax, %r15
movq %r14, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x762e8
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x76de4
movq %r12, %r14
movq %r12, %rdi
leaq 0x120(%rsp), %rsi
movsd 0x10(%rsp), %xmm0
callq 0x77722
leaq 0xf0(%rsp), %rdi
leaq 0x108(%rsp), %rsi
movq %r14, %rdx
callq 0x76605
movsd 0x30(%rsp), %xmm0
mulsd 0xae754(%rip), %xmm0    # 0xdc500
movq %r15, %rdi
leaq 0xf0(%rsp), %rsi
callq 0x6b536
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3dc6c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3dc6c
xorl %eax, %eax
movq 0x50(%rsp), %r15
movq 0x28(%rsp), %r12
jmp 0x2de03
leaq 0xaf2a9(%rip), %rdi     # 0xdd090
jmp 0x2ddf0
leaq 0xaf2f9(%rip), %rdi     # 0xdd0e9
movl 0xc(%rsp), %esi
movq %r15, %rdx
xorl %eax, %eax
callq 0x8b53a
movl $0x1, %eax
testb $0x1, %al
jne 0x2de4c
leaq 0x950(%rsp), %rbx
movq %rbx, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r13, %rdx
callq 0x21f40
testq %rax, %rax
jne 0x2d9bb
movq %r13, %rdi
callq 0x218b0
movl $0x1, %ebx
jmp 0x2de4e
leaq 0xae808(%rip), %rdi     # 0xdc646
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0x8b53a
jmp 0x2de4e
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x2158, %rsp           # imm = 0x2158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2dea0
jmp 0x2de93
jmp 0x2de93
movq %rax, %r14
movl $0x60, %esi
jmp 0x2de8e
movq %rax, %r14
movl $0x30, %esi
jmp 0x2dea8
movq %rax, %r14
movl $0x1b0, %esi            # imm = 0x1B0
jmp 0x2de9b
movq %rax, %r14
movl $0xb8, %esi
movq %rbx, %rdi
jmp 0x2deab
movq %rax, %r14
movl $0x80, %esi
movq %rbp, %rdi
jmp 0x2deab
movq %rax, %r14
movl $0x28, %esi
movq %r15, %rdi
callq 0x218e0
movq %r14, %rdi
callq 0x220d0