// File: tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: CreateObject(gaps::R3SurfelScene*, char const*, char const*, char const*)
static R3SurfelObject *
CreateObject(R3SurfelScene *scene, const char *object_name, 
  const char *parent_name, const char *node_name)
{
  // Get surfel tree
  R3SurfelTree *tree = scene->Tree();
  if (!tree) {
    RNFail("Scene has no tree\n");
    return NULL;
  }    

  // Find parent object
  R3SurfelObject *parent_object = scene->FindObjectByName(parent_name);
  if (!parent_object) {
    RNFail("Unable to find parent object with name %s\n", parent_name);
    return NULL;
  }

  // Find node
  R3SurfelNode *node = NULL;
  if (strcmp(node_name, "None") && strcmp(node_name, "none") && strcmp(node_name, "NONE")) {
    node = tree->FindNodeByName(node_name);
    if (!node) {
      RNFail("Unable to find parent node with name %s\n", node_name);
      return NULL;
    }
  }

  // Create object
  R3SurfelObject *object = new R3SurfelObject(object_name);
  if (!object) {
    RNFail("Unable to allocate object\n");
    return NULL;
  }
         
  // Insert node into object
  if (node) object->InsertNode(node);
  
  // Insert object into scene
  scene->InsertObject(object, parent_object);

  // Return object
  return object;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq 0x58(%rsp), %rdi
callq 0x26780
movq %rax, 0x38(%rsp)
cmpq $0x0, 0x38(%rsp)
jne 0x1e41b
leaq 0x1da2ec(%rip), %rdi    # 0x1f86f2
movb $0x0, %al
callq 0x172cb0
movq $0x0, 0x60(%rsp)
jmp 0x1e583
movq 0x58(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x70d50
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x1e458
movq 0x48(%rsp), %rsi
leaq 0x1da304(%rip), %rdi    # 0x1f8747
movb $0x0, %al
callq 0x172cb0
movq $0x0, 0x60(%rsp)
jmp 0x1e583
movq $0x0, 0x28(%rsp)
movq 0x40(%rsp), %rdi
leaq 0x1da305(%rip), %rsi    # 0x1f8772
callq 0x16a80
cmpl $0x0, %eax
je 0x1e4e2
movq 0x40(%rsp), %rdi
leaq 0x1da2f4(%rip), %rsi    # 0x1f8777
callq 0x16a80
cmpl $0x0, %eax
je 0x1e4e2
movq 0x40(%rsp), %rdi
leaq 0x1da2e3(%rip), %rsi    # 0x1f877c
callq 0x16a80
cmpl $0x0, %eax
je 0x1e4e2
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x60280
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x1e4e0
movq 0x40(%rsp), %rsi
leaq 0x1da23a(%rip), %rdi    # 0x1f8705
movb $0x0, %al
callq 0x172cb0
movq $0x0, 0x60(%rsp)
jmp 0x1e583
jmp 0x1e4e2
movl $0xf8, %edi
callq 0x16740
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
movq 0x50(%rsp), %rsi
callq 0x6ae00
jmp 0x1e503
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x1e54d
leaq 0x1da265(%rip), %rdi    # 0x1f8781
movb $0x0, %al
callq 0x172cb0
movq $0x0, 0x60(%rsp)
jmp 0x1e583
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x18(%rsp)
movl %eax, 0x14(%rsp)
movl $0xf8, %esi
callq 0x16750
jmp 0x1e58d
cmpq $0x0, 0x28(%rsp)
je 0x1e564
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x6d020
movq 0x58(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
movq 0x18(%rsp), %rdi
callq 0x16ca0
nopw (%rax,%rax)