// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: Mask(gaps::R3SurfelScene*, char const*, gaps::R3SurfelConstraint*)
static int
Mask(R3SurfelScene *scene, const char *node_name, R3SurfelConstraint *constraint)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Get useful variables
  R3SurfelTree *tree = scene->Tree();
  if (!tree) {
    RNFail("Scene has no surfel tree\n");
    return 0;
  }    

  // Get surfel database
  R3SurfelDatabase *database = tree->Database();
  if (!database) {
    RNFail("Tree has no surfel database\n");
    return 0;
  }    

  // Find node
  R3SurfelNode *node = tree->RootNode();
  if (strcmp(node_name, "All") && strcmp(node_name, "Root")) {
    node = tree->FindNodeByName(node_name);
    if (!node) {
      RNFail("Unable to find node with name %s\n", node_name);
      return 0;
    }
  }

  // Remove surfels not satistfying constraint
  RNArray<R3SurfelNode *> remove_nodes;
  tree->SplitLeafNodes(node, *constraint, NULL, &remove_nodes);
  for (int i = 0; i < remove_nodes.NEntries(); i++) {
    R3SurfelNode *node = remove_nodes.Kth(i);

    // Make array of blocks
    RNArray<R3SurfelBlock *> blocks;
    while (node->NBlocks() > 0) {
      R3SurfelBlock *block = node->Block(0);
      node->RemoveBlock(block);
      blocks.Insert(block);
    }

    // Remove/delete node
    tree->RemoveNode(node);
    delete node;

    // Remove/delete blocks
    for (int j = 0; j < blocks.NEntries(); j++) {
      R3SurfelBlock *block = blocks.Kth(j);
      database->RemoveBlock(block);
      delete block;
    }
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0xc2368
xorl %r14d, %r14d
movq %r13, %rdi
xorl %esi, %esi
callq 0x15a20
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
je 0x1c9ca
movq 0x10(%rbx), %r14
testq %r14, %r14
je 0x1c9d3
movq 0x18(%rbx), %rax
movq (%rax), %r13
leaq 0xed25f(%rip), %rsi     # 0x109afb
movq %r12, %rdi
callq 0x158c0
testl %eax, %eax
je 0x1c8d2
leaq 0xf838f(%rip), %rsi     # 0x114c3e
movq %r12, %rdi
callq 0x158c0
testl %eax, %eax
je 0x1c8d2
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3aaf0
movq %rax, %r13
testq %rax, %rax
je 0x1c9f6
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0xc2904
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
movq %r12, %r8
callq *0x30(%rax)
cmpl $0x0, 0x24(%rsp)
jle 0x1c9b8
xorl %ebp, %ebp
leaq 0x8(%rsp), %r15
movq 0x18(%rsp), %rax
movq (%rax,%rbp,8), %r12
movq %r15, %rdi
callq 0xc2904
cmpl $0x0, 0x4c(%r12)
jle 0x1c944
movq (%r12), %rax
movq 0x40(%r12), %rcx
movq (%rcx), %r13
movq %r12, %rdi
movq %r13, %rsi
callq *0x30(%rax)
movl 0x14(%rsp), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0xc299a
jmp 0x1c916
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3ab54
movq (%r12), %rax
movq %r12, %rdi
callq *0x8(%rax)
cmpl $0x0, 0x14(%rsp)
jle 0x1c99f
xorl %r13d, %r13d
movq 0x8(%rsp), %rax
movq (%rax,%r13,8), %r12
movq (%r14), %rax
movq %r14, %rdi
movq %r12, %rsi
callq *0x18(%rax)
testq %r12, %r12
je 0x1c992
movq %r12, %rdi
callq 0x2f42a
movl $0xc8, %esi
movq %r12, %rdi
callq 0x15620
incq %r13
movslq 0x14(%rsp), %rax
cmpq %rax, %r13
jl 0x1c963
movq %r15, %rdi
callq 0xc296e
incq %rbp
movslq 0x24(%rsp), %rax
cmpq %rax, %rbp
jl 0x1c905
leaq 0x18(%rsp), %rdi
callq 0xc296e
movl $0x1, %r14d
jmp 0x1c9e4
leaq 0xed0f3(%rip), %rdi     # 0x109ac4
jmp 0x1c9dd
leaq 0xed104(%rip), %rdi     # 0x109ade
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xc5782
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xed102(%rip), %rdi     # 0x109aff
xorl %r14d, %r14d
movq %r12, %rsi
xorl %eax, %eax
callq 0xc5782
jmp 0x1c9e4
jmp 0x1ca10
jmp 0x1ca17
movq %rax, %rbx
jmp 0x1ca24
jmp 0x1ca17
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xc296e
leaq 0x18(%rsp), %rdi
callq 0xc296e
movq %rbx, %rdi
callq 0x15ae0