// File: tomfunkhouser[P]gaps/apps/msh2df/msh2df.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")) print_debug = 1; 
      else if (!strcmp(*argv, "-estimate_sign")) estimate_sign = 1; 
      else if (!strcmp(*argv, "-estimate_sign_using_normals")) { estimate_sign = 1; sign_estimation_method = 0; }
      else if (!strcmp(*argv, "-estimate_sign_using_flood_fill")) { estimate_sign = 1; sign_estimation_method = 1; }
      else if (!strcmp(*argv, "-sign_estimation_method")) { argc--; argv++; sign_estimation_method = atoi(*argv); }
      else if (!strcmp(*argv, "-truncation_distance")) { argc--; argv++; truncation_distance = atof(*argv); }
      else if (!strcmp(*argv, "-spacing")) { argc--; argv++; target_grid_spacing = atof(*argv); }
      else if (!strcmp(*argv, "-border")) { argc--; argv++; grid_border = atof(*argv); }
      else if (!strcmp(*argv, "-max_resolution")) { argc--; argv++; grid_max_resolution = atoi(*argv); }
      else if (!strcmp(*argv, "-refinement_radius")) { argc--; argv++; refinement_radius = atoi(*argv); }
      else if (!strcmp(*argv, "-output_mesh")) { argc--; argv++; output_mesh_filename = *argv; }
      else if (!strcmp(*argv, "-output_points")) { argc--; argv++; output_points_filename = *argv; }
      else if (!strcmp(*argv, "-input_is_manifold")) { input_is_manifold = 1; }
      else if (!strcmp(*argv, "-input_is_range_scan")) { input_is_range_scan = 1; }
      else if (!strcmp(*argv, "-scan_viewpoint")) {
        argc--; argv++; scan_viewpoint[0] = atof(*argv);
        argc--; argv++; scan_viewpoint[1] = atof(*argv);
        argc--; argv++; scan_viewpoint[2] = atof(*argv);
      }
      else if (!strcmp(*argv, "-bbox")) {
        argc--; argv++; grid_bbox[0][0] = atof(*argv);
        argc--; argv++; grid_bbox[0][1] = atof(*argv);
        argc--; argv++; grid_bbox[0][2] = atof(*argv);
        argc--; argv++; grid_bbox[1][0] = atof(*argv);
        argc--; argv++; grid_bbox[1][1] = atof(*argv);
        argc--; argv++; grid_bbox[1][2] = atof(*argv);
      }
      else {
        RNFail("Invalid program argument: %s", *argv);
        exit(1);
      }
    }
    else {
      if (!input_mesh_filename) input_mesh_filename = *argv;
      else if (!output_grid_filename) output_grid_filename = *argv;
      else { RNFail("Invalid program argument: %s", *argv); exit(1); }
    }
    argv++; argc--;
  }

  // Check filenames
  if (!input_mesh_filename || !output_grid_filename) {
    RNFail("Usage: msh2df inputmeshfile outputgridfile [options]\n");
    return 0;
  }

  // Flood fill sign estimation does not work with grid distances near boundary
  if (estimate_sign && (sign_estimation_method == 1) && (refinement_radius < 3)) {
    refinement_radius = 3;
  }

  // Return OK status 
  return 1;
}

// Assembly:
subq $0x58, %rsp
movl %edi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
cmpl $0x0, 0x50(%rsp)
jle 0x13253
movq 0x48(%rsp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x131db
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d55c(%rip), %rsi    # 0x140090
callq 0xf700
cmpl $0x0, %eax
jne 0x12b4d
movl $0x1, 0x173ab0(%rip)    # 0x1865f8
jmp 0x131d9
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d537(%rip), %rsi    # 0x140093
callq 0xf700
cmpl $0x0, %eax
jne 0x12b75
movl $0x1, 0x173a8c(%rip)    # 0x1865fc
jmp 0x131d7
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d516(%rip), %rsi    # 0x14009a
callq 0xf700
cmpl $0x0, %eax
jne 0x12b9d
movl $0x1, 0x173a3c(%rip)    # 0x1865d4
jmp 0x131d5
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d4fd(%rip), %rsi    # 0x1400a9
callq 0xf700
cmpl $0x0, %eax
jne 0x12bcf
movl $0x1, 0x173a14(%rip)    # 0x1865d4
movl $0x0, 0x16a936(%rip)    # 0x17d500
jmp 0x131d3
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d4e8(%rip), %rsi    # 0x1400c6
callq 0xf700
cmpl $0x0, %eax
jne 0x12c01
movl $0x1, 0x1739e2(%rip)    # 0x1865d4
movl $0x1, 0x16a904(%rip)    # 0x17d500
jmp 0x131d1
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d4d6(%rip), %rsi    # 0x1400e6
callq 0xf700
cmpl $0x0, %eax
jne 0x12c4b
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf7b0
movl %eax, 0x16a8ba(%rip)    # 0x17d500
jmp 0x131cf
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d4a4(%rip), %rsi    # 0x1400fe
callq 0xf700
cmpl $0x0, %eax
jne 0x12c97
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x17394e(%rip)   # 0x1865e0
jmp 0x131cd
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d46d(%rip), %rsi    # 0x140113
callq 0xf700
cmpl $0x0, %eax
jne 0x12ce3
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x16a82a(%rip)   # 0x17d508
jmp 0x131cb
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d42a(%rip), %rsi    # 0x14011c
callq 0xf700
cmpl $0x0, %eax
jne 0x12d2f
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x16a7ee(%rip)   # 0x17d518
jmp 0x131c9
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d3e6(%rip), %rsi    # 0x140124
callq 0xf700
cmpl $0x0, %eax
jne 0x12d79
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf7b0
movl %eax, 0x16a79c(%rip)    # 0x17d510
jmp 0x131c7
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d3ac(%rip), %rsi    # 0x140134
callq 0xf700
cmpl $0x0, %eax
jne 0x12dc3
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf7b0
movl %eax, 0x16a762(%rip)    # 0x17d520
jmp 0x131c5
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d375(%rip), %rsi    # 0x140147
callq 0xf700
cmpl $0x0, %eax
jne 0x12e09
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x1737ec(%rip)    # 0x1865f0
jmp 0x131c3
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d33c(%rip), %rsi    # 0x140154
callq 0xf700
cmpl $0x0, %eax
jne 0x12e4f
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x17378e(%rip)    # 0x1865d8
jmp 0x131c1
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d305(%rip), %rsi    # 0x140163
callq 0xf700
cmpl $0x0, %eax
jne 0x12e77
movl $0x1, 0x17375e(%rip)    # 0x1865d0
jmp 0x131bf
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d2f0(%rip), %rsi    # 0x140176
callq 0xf700
cmpl $0x0, %eax
jne 0x12e9f
movl $0x1, 0x173766(%rip)    # 0x186600
jmp 0x131bd
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d2dd(%rip), %rsi    # 0x14018b
callq 0xf700
cmpl $0x0, %eax
jne 0x12f93
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x30(%rsp)
leaq 0x1736c1(%rip), %rdi    # 0x1865b0
xorl %esi, %esi
callq 0x17800
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x38(%rsp)
leaq 0x17367d(%rip), %rdi    # 0x1865b0
movl $0x1, %esi
callq 0x17800
movsd 0x38(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x40(%rsp)
leaq 0x173636(%rip), %rdi    # 0x1865b0
movl $0x2, %esi
callq 0x17800
movsd 0x40(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x131bb
movq 0x48(%rsp), %rax
movq (%rax), %rdi
leaq 0x12d1f9(%rip), %rsi    # 0x14019b
callq 0xf700
cmpl $0x0, %eax
jne 0x13199
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, (%rsp)
leaq 0x173596(%rip), %rdi    # 0x186578
xorl %esi, %esi
callq 0x17820
movq %rax, %rdi
xorl %esi, %esi
callq 0x17800
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x8(%rsp)
leaq 0x173549(%rip), %rdi    # 0x186578
xorl %esi, %esi
callq 0x17820
movq %rax, %rdi
movl $0x1, %esi
callq 0x17800
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x10(%rsp)
leaq 0x1734f8(%rip), %rdi    # 0x186578
xorl %esi, %esi
callq 0x17820
movq %rax, %rdi
movl $0x2, %esi
callq 0x17800
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x18(%rsp)
leaq 0x1734a7(%rip), %rdi    # 0x186578
movl $0x1, %esi
callq 0x17820
movq %rax, %rdi
xorl %esi, %esi
callq 0x17800
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x20(%rsp)
leaq 0x173456(%rip), %rdi    # 0x186578
movl $0x1, %esi
callq 0x17820
movq %rax, %rdi
movl $0x1, %esi
callq 0x17800
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0xf640
movsd %xmm0, 0x28(%rsp)
leaq 0x173402(%rip), %rdi    # 0x186578
movl $0x1, %esi
callq 0x17820
movq %rax, %rdi
movl $0x2, %esi
callq 0x17800
movsd 0x28(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x131b9
movq 0x48(%rsp), %rax
movq (%rax), %rsi
leaq 0x12cff9(%rip), %rdi    # 0x1401a1
movb $0x0, %al
callq 0xe2150
movl $0x1, %edi
callq 0xf600
jmp 0x131bb
jmp 0x131bd
jmp 0x131bf
jmp 0x131c1
jmp 0x131c3
jmp 0x131c5
jmp 0x131c7
jmp 0x131c9
jmp 0x131cb
jmp 0x131cd
jmp 0x131cf
jmp 0x131d1
jmp 0x131d3
jmp 0x131d5
jmp 0x131d7
jmp 0x131d9
jmp 0x13235
cmpq $0x0, 0x1733e5(%rip)    # 0x1865c8
jne 0x131f6
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x1733d4(%rip)    # 0x1865c8
jmp 0x13233
cmpq $0x0, 0x1733ea(%rip)    # 0x1865e8
jne 0x13211
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x1733d9(%rip)    # 0x1865e8
jmp 0x13231
movq 0x48(%rsp), %rax
movq (%rax), %rsi
leaq 0x12cf81(%rip), %rdi    # 0x1401a1
movb $0x0, %al
callq 0xe2150
movl $0x1, %edi
callq 0xf600
jmp 0x13233
jmp 0x13235
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x12b06
cmpq $0x0, 0x17336d(%rip)    # 0x1865c8
je 0x13267
cmpq $0x0, 0x173383(%rip)    # 0x1865e8
jne 0x1327f
leaq 0x12cf50(%rip), %rdi    # 0x1401be
movb $0x0, %al
callq 0xe2150
movl $0x0, 0x54(%rsp)
jmp 0x132ac
cmpl $0x0, 0x17334e(%rip)    # 0x1865d4
je 0x132a4
cmpl $0x1, 0x16a271(%rip)    # 0x17d500
jne 0x132a4
cmpl $0x3, 0x16a288(%rip)    # 0x17d520
jge 0x132a4
movl $0x3, 0x16a27c(%rip)    # 0x17d520
movl $0x1, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)