// File: tomfunkhouser[P]gaps/apps/prp2prp/prp2prp.cpp
// Function: FindProperties(gaps::R3MeshPropertySet*, char const*)
static RNArray<R3MeshProperty *>
FindProperties(R3MeshPropertySet *properties, const char *property_name)
{
  // Make an array of matching properties
  RNArray<R3MeshProperty *> result;

  // Check if "all"
  if (!strcmp(property_name, "all")) {
    // Insert all properties
    for (int i = 0; i < properties->NProperties(); i++) {
      R3MeshProperty *property = properties->Property(i);
      result.Insert(property);
    }
  }
  else if (properties->Property(property_name)) { 
    // Insert single property
    R3MeshProperty *property = properties->Property(property_name);
    result.Insert(property);
  }
  else { 
    // Insert properties names read from a file
    char buffer[1024];
    FILE *fp = fopen(property_name, "r");
    if (!fp) { RNFail("Invalid property name: %s\n", property_name); exit(-1); }
    while (fscanf(fp, "%s", buffer) == (unsigned int) 1) {
      R3MeshProperty *property = properties->Property(buffer);
      if (!property) { RNFail("Unrecognized property %s in file %s\n", buffer, property_name); exit(-1); }
      result.Insert(property);
    }
    fclose(fp);
  }

  // Check if found any properties
  if (result.IsEmpty()) {
    RNFail("No properties found for %s\n", property_name);
    exit(-1);
  }

  // Return array of properties
  return result;
}

// Assembly:
subq $0x4a8, %rsp            # imm = 0x4A8
movq %rdi, 0x40(%rsp)
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movq %rdi, 0x4a0(%rsp)
movq %rsi, 0x498(%rsp)
movq %rdx, 0x490(%rsp)
movb $0x0, 0x48f(%rsp)
callq 0x13640
movq 0x490(%rsp), %rdi
leaq 0x9353a(%rip), %rsi     # 0xa52e2
callq 0xd590
cmpl $0x0, %eax
jne 0x11e5c
movl $0x0, 0x488(%rsp)
movl 0x488(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x498(%rsp), %rdi
callq 0x135e0
movl %eax, %ecx
movl 0x3c(%rsp), %eax
cmpl %ecx, %eax
jge 0x11e57
movq 0x498(%rsp), %rdi
movl 0x488(%rsp), %esi
callq 0x134e0
movq %rax, 0x30(%rsp)
jmp 0x11dfe
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rax
movq %rax, 0x480(%rsp)
movq 0x480(%rsp), %rsi
callq 0x13650
jmp 0x11e1f
jmp 0x11e21
movl 0x488(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x488(%rsp)
jmp 0x11dc1
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x478(%rsp)
movl %eax, 0x474(%rsp)
callq 0x13630
jmp 0x12019
jmp 0x11fb5
movq 0x498(%rsp), %rdi
movq 0x490(%rsp), %rsi
callq 0x13480
movq %rax, 0x28(%rsp)
jmp 0x11e78
movq 0x28(%rsp), %rax
cmpq $0x0, %rax
je 0x11ec5
movq 0x498(%rsp), %rdi
movq 0x490(%rsp), %rsi
callq 0x13480
movq %rax, 0x20(%rsp)
jmp 0x11e9f
movq 0x40(%rsp), %rdi
movq 0x20(%rsp), %rax
movq %rax, 0x468(%rsp)
movq 0x468(%rsp), %rsi
callq 0x13650
jmp 0x11ec0
jmp 0x11fb3
movq 0x490(%rsp), %rdi
leaq 0x93495(%rip), %rsi     # 0xa5369
callq 0xd4f0
movq %rax, 0x18(%rsp)
jmp 0x11ee0
movq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
jne 0x11f14
movq 0x490(%rsp), %rsi
leaq 0x933e5(%rip), %rdi     # 0xa52e6
xorl %eax, %eax
callq 0xa4cd0
jmp 0x11f0a
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xd510
jmp 0x11f16
movq 0x58(%rsp), %rdi
leaq 0x94134(%rip), %rsi     # 0xa6056
xorl %eax, %eax
leaq 0x60(%rsp), %rdx
callq 0xd740
movl %eax, 0x14(%rsp)
jmp 0x11f34
movl 0x14(%rsp), %eax
cmpl $0x1, %eax
jne 0x11fa5
movq 0x498(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x13480
movq %rax, 0x8(%rsp)
jmp 0x11f56
movq 0x8(%rsp), %rax
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x50(%rsp)
jne 0x11f8f
movq 0x490(%rsp), %rdx
leaq 0x9338a(%rip), %rdi     # 0xa5301
xorl %eax, %eax
leaq 0x60(%rsp), %rsi
callq 0xa4cd0
jmp 0x11f85
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xd510
movq 0x40(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x13650
jmp 0x11fa0
jmp 0x11f16
movq 0x58(%rsp), %rdi
callq 0xd3f0
jmp 0x11fb1
jmp 0x11fb3
jmp 0x11fb5
movq 0x40(%rsp), %rdi
callq 0x13680
movl %eax, 0x4(%rsp)
jmp 0x11fc5
movl 0x4(%rsp), %eax
cmpl $0x0, %eax
je 0x11ff0
movq 0x490(%rsp), %rsi
leaq 0x93349(%rip), %rdi     # 0xa5326
xorl %eax, %eax
callq 0xa4cd0
jmp 0x11fe6
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xd510
movb $0x1, 0x48f(%rsp)
testb $0x1, 0x48f(%rsp)
jne 0x1200c
movq 0x40(%rsp), %rdi
callq 0x13630
movq 0x48(%rsp), %rax
addq $0x4a8, %rsp            # imm = 0x4A8
retq
movq 0x478(%rsp), %rdi
callq 0xd6d0
nopw %cs:(%rax,%rax)