// File: tomfunkhouser[P]gaps/apps/mshsegment/mshsegment.cpp
// Function: ParseArgs(int, char**)
static int 
ParseArgs(int argc, char **argv)
{
  // Parse arguments
  argc--; argv++;
  while (argc > 0) {
    if ((*argv)[0] == '-') {
      if (!strcmp(*argv, "-v")) print_verbose = 1;
      else if (!strcmp(*argv, "-debug")) options.print_progress = 1;
      else if (!strcmp(*argv, "-dont_refine_boundaries")) refine_mesh_boundaries = 0;
      else if (!strcmp(*argv, "-refine_boundaries")) refine_mesh_boundaries = 1;
      else if (!strcmp(*argv, "-set_face_materials")) set_face_materials = 1;
      else if (!strcmp(*argv, "-initialize_with_region_growing")) {
        options.initialize_hierarchically = 0;
      }
      else if (!strcmp(*argv, "-allow_outlier_points")) {
        options.allow_outlier_points = 1;
      }
      else if (!strcmp(*argv, "-min_segments")) {
        argc--; argv++; options.min_clusters = atoi(*argv);
      }
      else if (!strcmp(*argv, "-max_segments")) {
        argc--; argv++; options.max_clusters = atoi(*argv);
      }
      else if (!strcmp(*argv, "-min_pair_affinity")) {
        argc--; argv++; options.min_pair_affinity = atof(*argv);
      }
      else if (!strcmp(*argv, "-max_refinement_iterations")) {
        argc--; argv++; options.max_refinement_iterations = atoi(*argv);
      }
      else if (!strcmp(*argv, "-max_reassignment_iterations")) {
        argc--; argv++; options.max_reassignment_iterations = atoi(*argv);
      }
      else if (!strcmp(*argv, "-max_distance")) {
        argc--; argv++; RNScalar max_distance = atof(*argv);
        options.max_cluster_primitive_distance = max_distance;
        options.max_pair_primitive_distance = max_distance;
      }
      else if (!strcmp(*argv, "-max_angle")) {
        argc--; argv++; RNScalar max_angle = atof(*argv);
        options.max_cluster_normal_angle = max_angle;
        options.max_pair_normal_angle = max_angle;
      }
      else if (!strcmp(*argv, "-max_color_difference")) {
        argc--; argv++; RNScalar max_color_difference = atof(*argv);
        options.max_cluster_color_difference = max_color_difference;
        options.max_pair_color_difference = max_color_difference;
      }
      else if (!strcmp(*argv, "-max_neighbor_normal_angle")) {
        argc--; argv++; max_neighbor_normal_angle = atof(*argv);
      }
      else if (!strcmp(*argv, "-max_neighbor_color_difference")) {
        argc--; argv++; max_neighbor_color_difference = atof(*argv);
      }
      else if (!strcmp(*argv, "-min_faces_per_segment")) {
        argc--; argv++; options.min_cluster_points = atoi(*argv);
      }
      else if (!strcmp(*argv, "-min_area_per_segment")) {
        argc--; argv++; options.min_cluster_area = atof(*argv);
      }
      else if (!strcmp(*argv, "-output_json")) {
        argc--; argv++; output_json_name = *argv;
      }
      else if (!strcmp(*argv, "-output_ascii")) {
        argc--; argv++; output_ascii_name = *argv;
      }
      else {
        RNFail("Invalid program argument: %s", *argv);
        exit(1);
      }
      argv++; argc--;
    }
    else {
      if (!input_mesh_name) input_mesh_name = *argv;
      else if (!output_mesh_name) output_mesh_name = *argv;
      else { RNFail("Invalid program argument: %s", *argv); exit(1); }
      argv++; argc--;
    }
  }

  // Check filenames
  if (!input_mesh_name || !output_mesh_name) {
    RNFail("Usage: mshseg inputmesh outputmesh\n");
    return 0;
  }

  // Return OK status 
  return 1;
}

// Assembly:
subq $0x28, %rsp
movl %edi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x20(%rsp)
jle 0x107fd
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x10787
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ae6c(%rip), %rsi     # 0xab030
callq 0xd560
cmpl $0x0, %eax
jne 0x101dd
movl $0x1, 0xc1af0(%rip)     # 0xd1cc8
jmp 0x1076c
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ae47(%rip), %rsi     # 0xab033
callq 0xd560
cmpl $0x0, %eax
jne 0x10205
movl $0x1, 0xc1aa4(%rip)     # 0xd1ca4
jmp 0x1076a
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ae26(%rip), %rsi     # 0xab03a
callq 0xd560
cmpl $0x0, %eax
jne 0x1022d
movl $0x0, 0xc11b8(%rip)     # 0xd13e0
jmp 0x10768
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ae16(%rip), %rsi     # 0xab052
callq 0xd560
cmpl $0x0, %eax
jne 0x10255
movl $0x1, 0xc1190(%rip)     # 0xd13e0
jmp 0x10766
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ae01(%rip), %rsi     # 0xab065
callq 0xd560
cmpl $0x0, %eax
jne 0x1027d
movl $0x1, 0xc1a54(%rip)     # 0xd1ccc
jmp 0x10764
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9aded(%rip), %rsi     # 0xab079
callq 0xd560
cmpl $0x0, %eax
jne 0x102a5
movl $0x0, 0xc19f8(%rip)     # 0xd1c98
jmp 0x10762
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ade5(%rip), %rsi     # 0xab099
callq 0xd560
cmpl $0x0, %eax
jne 0x102cd
movl $0x1, 0xc19d4(%rip)     # 0xd1c9c
jmp 0x10760
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9add3(%rip), %rsi     # 0xab0af
callq 0xd560
cmpl $0x0, %eax
jne 0x10317
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd5e0
movl %eax, 0xc18e6(%rip)     # 0xd1bf8
jmp 0x1075e
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ad97(%rip), %rsi     # 0xab0bd
callq 0xd560
cmpl $0x0, %eax
jne 0x10361
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd5e0
movl %eax, 0xc18a0(%rip)     # 0xd1bfc
jmp 0x1075c
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ad5b(%rip), %rsi     # 0xab0cb
callq 0xd560
cmpl $0x0, %eax
jne 0x103ad
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd500
movsd %xmm0, 0xc18d0(%rip)    # 0xd1c78
jmp 0x1075a
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ad22(%rip), %rsi     # 0xab0de
callq 0xd560
cmpl $0x0, %eax
jne 0x103f7
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd5e0
movl %eax, 0xc188e(%rip)     # 0xd1c80
jmp 0x10758
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9acf3(%rip), %rsi     # 0xab0f9
callq 0xd560
cmpl $0x0, %eax
jne 0x10441
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd5e0
movl %eax, 0xc1848(%rip)     # 0xd1c84
jmp 0x10756
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9acc6(%rip), %rsi     # 0xab116
callq 0xd560
cmpl $0x0, %eax
jne 0x104a7
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd500
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0xc178c(%rip)    # 0xd1c20
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0xc17ae(%rip)    # 0xd1c50
jmp 0x10754
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ac6e(%rip), %rsi     # 0xab124
callq 0xd560
cmpl $0x0, %eax
jne 0x1050d
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd500
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0xc172e(%rip)    # 0xd1c28
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0xc1750(%rip)    # 0xd1c58
jmp 0x10752
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ac13(%rip), %rsi     # 0xab12f
callq 0xd560
cmpl $0x0, %eax
jne 0x10570
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd500
movsd %xmm0, (%rsp)
movsd (%rsp), %xmm0
movsd %xmm0, 0xc16d2(%rip)    # 0xd1c30
movsd (%rsp), %xmm0
movsd %xmm0, 0xc16f5(%rip)    # 0xd1c60
jmp 0x10750
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9abc6(%rip), %rsi     # 0xab145
callq 0xd560
cmpl $0x0, %eax
jne 0x105bc
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd500
movsd %xmm0, 0xc1719(%rip)    # 0xd1cd0
jmp 0x1074e
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ab95(%rip), %rsi     # 0xab160
callq 0xd560
cmpl $0x0, %eax
jne 0x10608
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd500
movsd %xmm0, 0xc16d5(%rip)    # 0xd1cd8
jmp 0x1074c
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ab68(%rip), %rsi     # 0xab17f
callq 0xd560
cmpl $0x0, %eax
jne 0x10652
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd5e0
movl %eax, 0xc15b3(%rip)     # 0xd1c00
jmp 0x1074a
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9ab35(%rip), %rsi     # 0xab196
callq 0xd560
cmpl $0x0, %eax
jne 0x1069e
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0xd500
movsd %xmm0, 0xc156f(%rip)    # 0xd1c08
jmp 0x10748
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9aaff(%rip), %rsi     # 0xab1ac
callq 0xd560
cmpl $0x0, %eax
jne 0x106e1
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xc15d9(%rip)     # 0xd1cb8
jmp 0x10746
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x9aac9(%rip), %rsi     # 0xab1b9
callq 0xd560
cmpl $0x0, %eax
jne 0x10724
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xc159e(%rip)     # 0xd1cc0
jmp 0x10744
movq 0x18(%rsp), %rax
movq (%rax), %rsi
leaq 0x9aa94(%rip), %rdi     # 0xab1c7
movb $0x0, %al
callq 0xa9e70
movl $0x1, %edi
callq 0xd4e0
jmp 0x10746
jmp 0x10748
jmp 0x1074a
jmp 0x1074c
jmp 0x1074e
jmp 0x10750
jmp 0x10752
jmp 0x10754
jmp 0x10756
jmp 0x10758
jmp 0x1075a
jmp 0x1075c
jmp 0x1075e
jmp 0x10760
jmp 0x10762
jmp 0x10764
jmp 0x10766
jmp 0x10768
jmp 0x1076a
jmp 0x1076c
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x107f8
cmpq $0x0, 0xc1519(%rip)     # 0xd1ca8
jne 0x107a2
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xc1508(%rip)     # 0xd1ca8
jmp 0x107df
cmpq $0x0, 0xc1506(%rip)     # 0xd1cb0
jne 0x107bd
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xc14f5(%rip)     # 0xd1cb0
jmp 0x107dd
movq 0x18(%rsp), %rax
movq (%rax), %rsi
leaq 0x9a9fb(%rip), %rdi     # 0xab1c7
movb $0x0, %al
callq 0xa9e70
movl $0x1, %edi
callq 0xd4e0
jmp 0x107df
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x10196
cmpq $0x0, 0xc14a3(%rip)     # 0xd1ca8
je 0x10811
cmpq $0x0, 0xc14a1(%rip)     # 0xd1cb0
jne 0x10829
leaq 0x9a9cc(%rip), %rdi     # 0xab1e4
movb $0x0, %al
callq 0xa9e70
movl $0x0, 0x24(%rsp)
jmp 0x10831
movl $0x1, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopw (%rax,%rax)