// File: /workspace/github_cpp_makefile_star2_O3/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 $0x2138, %rsp           # imm = 0x2138
movq %rsi, %r14
movq %rdi, %rbx
movq %rdx, 0x18(%rsp)
testq %rdx, %rdx
jne 0x2d783
movq (%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0xb38f9(%rip), %rsi     # 0xe1083
movq %r14, %rdi
callq 0x21ab0
testq %rax, %rax
je 0x2dc2d
movq %rax, %r13
movq %rbx, 0x8(%rsp)
movq %r14, 0x40(%rsp)
leaq 0x930(%rsp), %rbp
movq %rbp, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %rax, %rdx
callq 0x21f30
testq %rax, %rax
je 0x2dc1e
movq 0x8(%rsp), %rcx
leaq 0x38(%rcx), %rax
movq %rax, 0x58(%rsp)
leaq 0x28(%rcx), %rax
movq %rax, 0x50(%rsp)
leaq 0xd0(%rsp), %rbx
xorl %r15d, %r15d
movq %r13, 0x48(%rsp)
incl %r15d
movb 0x930(%rsp), %r12b
movq %rbp, %r14
testb %r12b, %r12b
je 0x2d82b
movq %rbp, %r14
movsbl %r12b, %edi
callq 0x210b0
testl %eax, %eax
je 0x2d821
movb 0x1(%r14), %r12b
incq %r14
testb %r12b, %r12b
jne 0x2d806
jmp 0x2d82b
cmpb $0x23, %r12b
je 0x2dc05
movq %r14, %rdi
leaq 0xad892(%rip), %rsi     # 0xdb0c7
leaq 0x530(%rsp), %rdx
movq %rbx, %rcx
leaq 0xd8(%rsp), %r8
leaq 0xe0(%rsp), %r9
xorl %eax, %eax
leaq 0x130(%rsp), %r10
pushq %r10
leaq 0x80(%rsp), %r10
pushq %r10
leaq 0x80(%rsp), %r10
pushq %r10
leaq 0x94(%rsp), %r10
pushq %r10
leaq 0x34(%rsp), %r10
pushq %r10
leaq 0x58(%rsp), %r10
pushq %r10
leaq 0x58(%rsp), %r10
pushq %r10
leaq 0x58(%rsp), %r10
pushq %r10
leaq 0xf0(%rsp), %r10
pushq %r10
leaq 0xf0(%rsp), %r10
pushq %r10
leaq 0xf0(%rsp), %r10
pushq %r10
leaq 0xe8(%rsp), %r10
pushq %r10
leaq 0xe8(%rsp), %r10
pushq %r10
leaq 0xe8(%rsp), %r10
pushq %r10
callq 0x21890
addq $0x70, %rsp
cmpl $0x12, %eax
jne 0x2dc42
cmpl $0x42424f, 0x530(%rsp) # imm = 0x42424F
jne 0x2dc4e
movl %r15d, 0x10(%rsp)
movl $0x1b0, %edi            # imm = 0x1B0
callq 0x218c0
movq %rax, %r12
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x3b560
movq %rbx, %r15
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x3c97e
movsd 0x70(%rsp), %xmm0
mulsd 0xacbae(%rip), %xmm0    # 0xda4e0
cvttsd2si %xmm0, %ecx
leaq 0x1930(%rsp), %rbx
movq %rbx, %rdi
leaq 0xad7d8(%rip), %rsi     # 0xdb120
leaq 0x130(%rsp), %rdx
xorl %eax, %eax
callq 0x21140
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3cc1a
movslq 0x14(%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 0xacb4e(%rip), %xmm0    # 0xda4e8
movsd %xmm0, (%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 0xacb20(%rip), %xmm1    # 0xda4f0
movsd 0xac640(%rip), %xmm0    # 0xda018
addsd %xmm0, %xmm1
movsd %xmm1, 0x68(%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 0xacae5(%rip), %xmm0    # 0xda4f8
movsd %xmm0, 0x60(%rsp)
movl $0xb8, %edi
callq 0x218c0
movq %rax, %r14
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
movsd (%rsp), %xmm0
movsd 0x68(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
callq 0x87400
xorpd %xmm0, %xmm0
movq %r14, %rdi
movq %rbx, %rsi
movsd 0xac5bf(%rip), %xmm1    # 0xda018
movaps %xmm1, %xmm2
xorl %edx, %edx
callq 0x43ea4
movq 0x8(%rsp), %rbx
movq %rbx, 0x8(%r14)
movl 0x44(%rbx), %edx
movl %edx, 0x10(%r14)
movq 0x58(%rsp), %rdi
movq %r14, %rsi
callq 0x87622
movl $0x30, %edi
callq 0x218c0
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x43ace
movq %rbx, (%r13)
movl 0x34(%rbx), %edx
movl %edx, 0x8(%r13)
movq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x87622
movl $0x60, %edi
callq 0x218c0
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
callq 0x3d514
movq %r14, %rdi
movq %r13, %rsi
callq 0x3d7b6
movq %r12, %rdi
movq %r14, %rsi
callq 0x3c9ce
movl $0x80, %edi
callq 0x218c0
movq %rax, %r12
leaq 0xb8(%rsp), %r13
movq %r13, %rdi
movq %r15, %rbx
movq %r15, %rsi
callq 0x753f8
leaq 0x118(%rsp), %r15
movq %r15, %rdi
leaq 0x80(%rsp), %rsi
callq 0x75ef0
leaq 0xe8(%rsp), %rbp
movq %rbp, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x75ef0
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x6b990
movl $0x28, %edi
callq 0x218c0
movq %rax, %r13
movq %r15, %rdi
movq %rbx, %rsi
callq 0x753f8
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rsp)
leaq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x75ef0
leaq 0xe8(%rsp), %rdi
leaq 0x100(%rsp), %rsi
movsd (%rsp), %xmm0
callq 0x767fa
leaq 0xb8(%rsp), %rdi
movq %r15, %rsi
leaq 0xe8(%rsp), %rdx
callq 0x7570f
movsd 0x20(%rsp), %xmm0
mulsd 0xac933(%rip), %xmm0    # 0xda500
movq %r13, %rdi
leaq 0xb8(%rsp), %rsi
callq 0x6a766
movq %r14, %rdi
movq %r12, %rsi
callq 0x3d7bc
movq %r14, %rdi
movq %r13, %rsi
callq 0x3d7bc
movq 0x48(%rsp), %r13
leaq 0x930(%rsp), %rbp
movl 0x10(%rsp), %r15d
movq %rbp, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r13, %rdx
callq 0x21f30
testq %rax, %rax
jne 0x2d7f0
movq %r13, %rdi
callq 0x218b0
movl $0x1, %ebx
jmp 0x2dc66
leaq 0xaca22(%rip), %rdi     # 0xda656
xorl %ebx, %ebx
movq %r14, %rsi
xorl %eax, %eax
callq 0x8a0fe
jmp 0x2dc66
movl %r15d, %esi
leaq 0xad454(%rip), %rdi     # 0xdb0a0
jmp 0x2dc58
movl %r15d, %esi
leaq 0xad4a1(%rip), %rdi     # 0xdb0f9
xorl %ebx, %ebx
movq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x8a0fe
movl %ebx, %eax
addq $0x2138, %rsp           # imm = 0x2138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x30, %esi
jmp 0x2dcc0
movq %rax, %rbx
movl $0x1b0, %esi            # imm = 0x1B0
jmp 0x2dca6
jmp 0x2dc9e
movq %rax, %rbx
movl $0x60, %esi
jmp 0x2dcb3
jmp 0x2dcb8
jmp 0x2dc9e
movq %rax, %rbx
movl $0x80, %esi
movq %r12, %rdi
jmp 0x2dcc3
movq %rax, %rbx
movl $0xb8, %esi
movq %r14, %rdi
jmp 0x2dcc3
movq %rax, %rbx
movl $0x28, %esi
movq %r13, %rdi
callq 0x218e0
movq %rbx, %rdi
callq 0x220c0