// File: tomfunkhouser[P]gaps/apps/prp2prp/prp2prp.cpp
// Function: ApplyOperations(gaps::R3Mesh*, gaps::R3MeshPropertySet*, int, char**)
static int
ApplyOperations(R3Mesh *mesh, R3MeshPropertySet *properties, int argc, char **argv)
{
  // Check if any operations required
  if (argc == 0) return 1;

  // Start statistics
  RNTime start_time;
  start_time.Read();
  int count = 0;

  // Print message
  if (print_verbose) {
    printf("Applying operations ...\n");
    fflush(stdout);
  }

  // Apply operations
  while (argc > 0) {
    if (!strcmp(*argv, "-merge")) {
      argv++; argc--; const char *filename = *argv;
      argv++; argc--; const char *property_name = *argv;
      Merge(properties, filename, property_name);
      count++;
    }
    else if (!strcmp(*argv, "-replace")) {
      argv++; argc--; const char *property_name = *argv;
      argv++; argc--; const char *operation_name = *argv;
      Replace(properties, property_name, operation_name, argc, argv);
      count++;
    }
    else if (!strcmp(*argv, "-insert")) {
      argv++; argc--; const char *property_name = *argv;
      argv++; argc--; const char *operation_name = *argv;
      Insert(properties, property_name, operation_name, argc, argv);
      count++;
    }
    else if (!strcmp(*argv, "-multiscale")) {
      argv++; argc--; const char *property_name = *argv;
      Multiscale(properties, property_name, argc, argv);
      count++;
    }
    else if (!strcmp(*argv, "-remove")) {
      argv++; argc--; const char *property_name = *argv;
      Remove(properties, property_name);
      count++;
    }
    else if (!strcmp(*argv, "-select")) {
      argv++; argc--; const char *property_name = *argv;
      Select(properties, property_name);
      count++;
    }
    else if (!strcmp(*argv, "-rename")) {
      argv++; argc--; const char *property_name = *argv;
      argv++; argc--; const char *new_property_name = *argv;
      Rename(properties, property_name, new_property_name);
      count++;
    }
    else if (!strcmp(*argv, "-sort")) {
      properties->SortByName();
      count++;
    }
    else if (!strcmp(*argv, "-parameters_in_absolute_units")) {
      parameters_in_relative_units = 0;
    }
    else if (!strcmp(*argv, "-parameters_in_relative_units")) {
      parameters_in_relative_units = 1;
    }
    else if (!strcmp(*argv, "-debug")) {
      print_debug = 1;
    }
    else if (!strcmp(*argv, "-v")) {
      print_verbose = 1;
    }
    else {
      RNFail("Invalid program argument: %s\n", *argv);
      return 0;
    }

    // Update counters
    argv++; argc--; 
  }

  // Print statistics
  if (print_verbose) {
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Operations  %d\n", count);
    fflush(stdout);
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movq %rsi, 0x80(%rsp)
movl %edx, 0x7c(%rsp)
movq %rcx, 0x70(%rsp)
cmpl $0x0, 0x7c(%rsp)
jne 0x10877
movl $0x1, 0x94(%rsp)
jmp 0x10da9
leaq 0x60(%rsp), %rdi
callq 0xa0ab0
leaq 0x60(%rsp), %rdi
callq 0x13550
movl $0x0, 0x5c(%rsp)
cmpl $0x0, 0xbc34e(%rip)     # 0xccbe8
je 0x108b9
leaq 0x949a5(%rip), %rdi     # 0xa5248
movb $0x0, %al
callq 0xd070
movq 0xbb6ef(%rip), %rax     # 0xcbfa0
movq (%rax), %rdi
callq 0xd4e0
jmp 0x108bb
cmpl $0x0, 0x7c(%rsp)
jle 0x10d5c
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x9498c(%rip), %rsi     # 0xa5261
callq 0xd590
cmpl $0x0, %eax
jne 0x10952
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0x11010
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x10d3e
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x94907(%rip), %rsi     # 0xa5268
callq 0xd590
cmpl $0x0, %eax
jne 0x109e8
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x80(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0x7c(%rsp), %rcx
leaq 0x70(%rsp), %r8
callq 0x11160
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x10d3c
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x9487a(%rip), %rsi     # 0xa5271
callq 0xd590
cmpl $0x0, %eax
jne 0x10a7e
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x80(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x7c(%rsp), %rcx
leaq 0x70(%rsp), %r8
callq 0x11280
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x10d3a
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x947ec(%rip), %rsi     # 0xa5279
callq 0xd590
cmpl $0x0, %eax
jne 0x10ae9
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x80(%rsp), %rdi
movq 0x20(%rsp), %rsi
leaq 0x7c(%rsp), %rdx
leaq 0x70(%rsp), %rcx
callq 0x11400
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x10d38
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x9478d(%rip), %rsi     # 0xa5285
callq 0xd590
cmpl $0x0, %eax
jne 0x10b4a
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x80(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x11b20
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x10d36
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x94734(%rip), %rsi     # 0xa528d
callq 0xd590
cmpl $0x0, %eax
jne 0x10bab
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x80(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x11be0
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x10d34
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x946db(%rip), %rsi     # 0xa5295
callq 0xd590
cmpl $0x0, %eax
jne 0x10c35
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, (%rsp)
movq 0x80(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq (%rsp), %rdx
callq 0x11cb0
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x10d32
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x94659(%rip), %rsi     # 0xa529d
callq 0xd590
cmpl $0x0, %eax
jne 0x10c6b
movq 0x80(%rsp), %rdi
callq 0x13aa0
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x10d30
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x943e3(%rip), %rsi     # 0xa505d
callq 0xd590
cmpl $0x0, %eax
jne 0x10c93
movl $0x0, 0xbb772(%rip)     # 0xcc400
jmp 0x10d2e
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x943d9(%rip), %rsi     # 0xa507b
callq 0xd590
cmpl $0x0, %eax
jne 0x10cb8
movl $0x1, 0xbb74a(%rip)     # 0xcc400
jmp 0x10d2c
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x9438f(%rip), %rsi     # 0xa5056
callq 0xd590
cmpl $0x0, %eax
jne 0x10cdd
movl $0x1, 0xbbf11(%rip)     # 0xccbec
jmp 0x10d2a
movq 0x70(%rsp), %rax
movq (%rax), %rdi
leaq 0x94367(%rip), %rsi     # 0xa5053
callq 0xd590
cmpl $0x0, %eax
jne 0x10d02
movl $0x1, 0xbbee8(%rip)     # 0xccbe8
jmp 0x10d28
movq 0x70(%rsp), %rax
movq (%rax), %rsi
leaq 0x94592(%rip), %rdi     # 0xa52a3
movb $0x0, %al
callq 0xa4cd0
movl $0x0, 0x94(%rsp)
jmp 0x10da9
jmp 0x10d2a
jmp 0x10d2c
jmp 0x10d2e
jmp 0x10d30
jmp 0x10d32
jmp 0x10d34
jmp 0x10d36
jmp 0x10d38
jmp 0x10d3a
jmp 0x10d3c
jmp 0x10d3e
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x108bb
cmpl $0x0, 0xbbe85(%rip)     # 0xccbe8
je 0x10d9e
leaq 0x60(%rsp), %rdi
callq 0xa0b70
leaq 0x94392(%rip), %rdi     # 0xa5108
movb $0x1, %al
callq 0xd070
movl 0x5c(%rsp), %esi
leaq 0x94539(%rip), %rdi     # 0xa52c1
movb $0x0, %al
callq 0xd070
movq 0xbb20a(%rip), %rax     # 0xcbfa0
movq (%rax), %rdi
callq 0xd4e0
movl $0x1, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nopl (%rax,%rax)