// File: tomfunkhouser[P]gaps/apps/mshview/mshview.cpp
// Function: ParseArgs(int, char**)
int ParseArgs(int argc, char **argv)
{
  // Check number of arguments
  if ((argc == 2) && (*argv[1] == '-')) {
    printf("Usage: meshviewer filename [options]\n");
    exit(0);
  }

  // Parse arguments
  argc--; argv++;
  while (argc > 0) {
    if ((*argv)[0] == '-') {
      if (!strcmp(*argv, "-v")) { print_verbose = 1; }
      else if (!strcmp(*argv, "-image")) { argc--; argv++; image_name = *argv; }
      else if (!strcmp(*argv, "-vertices")) { show_vertices = TRUE; }
      else if (!strcmp(*argv, "-edges")) { show_edges = TRUE; }
      else if (!strcmp(*argv, "-back")) { show_backfacing = TRUE; }
      else if (!strcmp(*argv, "-boundaries")) { show_boundaries = TRUE; }
      else if (!strcmp(*argv, "-axes")) { show_axes = TRUE; }
      else if (!strcmp(*argv, "-materials")) { show_materials = TRUE; }
      else if (!strcmp(*argv, "-segments")) { show_segments = TRUE; }
      else if (!strcmp(*argv, "-categories")) { show_categories = TRUE; }
      else if (!strcmp(*argv, "-vertex_colors")) { show_vertex_colors = TRUE; }
      else if (!strcmp(*argv, "-window")) { 
        argv++; argc--; GLUTwindow_width = atoi(*argv); 
        argv++; argc--; GLUTwindow_height = atoi(*argv); 
      }
      else if (!strcmp(*argv, "-background")) { 
        argv++; argc--; background[0] = atof(*argv); 
        argv++; argc--; background[1] = atof(*argv); 
        argv++; argc--; background[2] = atof(*argv);
      }
      else if (!strcmp(*argv, "-camera")) { 
        RNCoord x, y, z, tx, ty, tz, ux, uy, uz;
        argv++; argc--; x = atof(*argv); 
        argv++; argc--; y = atof(*argv); 
        argv++; argc--; z = atof(*argv); 
        argv++; argc--; tx = atof(*argv); 
        argv++; argc--; ty = atof(*argv); 
        argv++; argc--; tz = atof(*argv); 
        argv++; argc--; ux = atof(*argv); 
        argv++; argc--; uy = atof(*argv); 
        argv++; argc--; uz = atof(*argv); 
        initial_camera_origin = R3Point(x, y, z);
        initial_camera_towards.Reset(tx, ty, tz);
        initial_camera_up.Reset(ux, uy, uz);
        initial_camera = TRUE;
      }
      else if (!strcmp(*argv, "-origin")) {
        RNCoord x, y, z;
        argv++; argc--; x = atof(*argv); 
        argv++; argc--; y = atof(*argv); 
        argv++; argc--; z = atof(*argv);
        initial_world_origin.Reset(x, y, z);
      }
      else { RNFail("Invalid program argument: %s", *argv); exit(1); }
      argv++; argc--;
    }
    else {
      mesh_names.Insert(*argv);
      argv++; argc--;
    }
  }

  // Check mesh filename
  if (mesh_names.IsEmpty()) {
    RNFail("You did not specify a mesh file name.\n");
    return 0;
  }

  // Return OK status 
  return 1;
}

// Assembly:
subq $0xa8, %rsp
movl %edi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
cmpl $0x2, 0xa0(%rsp)
jne 0x29be9
movq 0x98(%rsp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x29be9
leaq 0x163703(%rip), %rdi    # 0x18d2de
movb $0x0, %al
callq 0x22090
xorl %edi, %edi
callq 0x22c40
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
cmpl $0x0, 0xa0(%rsp)
jle 0x2a449
movq 0x98(%rsp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x2a408
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x1636bf(%rip), %rsi    # 0x18d304
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29c5e
movl $0x1, 0x1d173f(%rip)    # 0x1fb398
jmp 0x2a3e1
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x163697(%rip), %rsi    # 0x18d307
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29cb6
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x1d16a7(%rip)    # 0x1fb358
jmp 0x2a3df
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x163646(%rip), %rsi    # 0x18d30e
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29ce1
movl $0x1, 0x1d1650(%rip)    # 0x1fb32c
jmp 0x2a3dd
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x163625(%rip), %rsi    # 0x18d318
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29d0c
movl $0x1, 0x1d161d(%rip)    # 0x1fb324
jmp 0x2a3db
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x163601(%rip), %rsi    # 0x18d31f
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29d37
movl $0x1, 0x1d15de(%rip)    # 0x1fb310
jmp 0x2a3d9
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x1635dc(%rip), %rsi    # 0x18d325
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29d62
movl $0x1, 0x1d15cb(%rip)    # 0x1fb328
jmp 0x2a3d7
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x1635bd(%rip), %rsi    # 0x18d331
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29d8d
movl $0x1, 0x1d15cc(%rip)    # 0x1fb354
jmp 0x2a3d5
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x163598(%rip), %rsi    # 0x18d337
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29db8
movl $0x1, 0x1d1561(%rip)    # 0x1fb314
jmp 0x2a3d3
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x163578(%rip), %rsi    # 0x18d342
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29de3
movl $0x1, 0x1d153a(%rip)    # 0x1fb318
jmp 0x2a3d1
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x163557(%rip), %rsi    # 0x18d34c
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29e0e
movl $0x1, 0x1d1513(%rip)    # 0x1fb31c
jmp 0x2a3cf
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x163538(%rip), %rsi    # 0x18d358
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29e39
movl $0x1, 0x1d14ec(%rip)    # 0x1fb320
jmp 0x2a3cd
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x16351c(%rip), %rsi    # 0x18d367
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29ed0
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x23070
movl %eax, 0x1cac28(%rip)    # 0x1f4ab8
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x23070
movl %eax, 0x1cabf1(%rip)    # 0x1f4abc
jmp 0x2a3cb
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x16348d(%rip), %rsi    # 0x18d36f
callq 0x22ea0
cmpl $0x0, %eax
jne 0x29ff4
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x8(%rsp)
leaq 0x1d0c6e(%rip), %rdi    # 0x1faba0
xorl %esi, %esi
callq 0x2af00
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x10(%rsp)
leaq 0x1d0c1b(%rip), %rdi    # 0x1faba0
movl $0x1, %esi
callq 0x2af00
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x18(%rsp)
leaq 0x1d0bc5(%rip), %rdi    # 0x1faba0
movl $0x2, %esi
callq 0x2af00
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x2a3c9
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x163375(%rip), %rsi    # 0x18d37b
callq 0x22ea0
cmpl $0x0, %eax
jne 0x2a2b1
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x90(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x88(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x80(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x78(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x70(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x68(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x60(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x58(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x50(%rsp)
movsd 0x90(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movsd 0x80(%rsp), %xmm2
leaq 0x38(%rsp), %rdi
callq 0xcba90
leaq 0x1d095c(%rip), %rdi    # 0x1fabb8
leaq 0x38(%rsp), %rsi
callq 0xcc120
movsd 0x78(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
movsd 0x68(%rsp), %xmm2
leaq 0x1d0951(%rip), %rdi    # 0x1fabd0
callq 0x2af70
movsd 0x60(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
leaq 0x1d094b(%rip), %rdi    # 0x1fabe8
callq 0x2af70
movl $0x1, 0x1d10f0(%rip)    # 0x1fb39c
jmp 0x2a3c7
movq 0x98(%rsp), %rax
movq (%rax), %rdi
leaq 0x1630c0(%rip), %rsi    # 0x18d383
callq 0x22ea0
cmpl $0x0, %eax
jne 0x2a3a2
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x30(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x28(%rsp)
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
callq 0x22ce0
movsd %xmm0, 0x20(%rsp)
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
leaq 0x1d0865(%rip), %rdi    # 0x1fac00
callq 0x2afb0
jmp 0x2a3c5
movq 0x98(%rsp), %rax
movq (%rax), %rsi
leaq 0x162fd7(%rip), %rdi    # 0x18d38b
movb $0x0, %al
callq 0xf2d20
movl $0x1, %edi
callq 0x22c40
jmp 0x2a3c7
jmp 0x2a3c9
jmp 0x2a3cb
jmp 0x2a3cd
jmp 0x2a3cf
jmp 0x2a3d1
jmp 0x2a3d3
jmp 0x2a3d5
jmp 0x2a3d7
jmp 0x2a3d9
jmp 0x2a3db
jmp 0x2a3dd
jmp 0x2a3df
jmp 0x2a3e1
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
jmp 0x2a444
movq 0x98(%rsp), %rax
movq (%rax), %rsi
leaq 0x1d0776(%rip), %rdi    # 0x1fab90
callq 0x2aff0
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
jmp 0x29c0e
leaq 0x1d0740(%rip), %rdi    # 0x1fab90
callq 0x2b020
cmpl $0x0, %eax
je 0x2a475
leaq 0x162f47(%rip), %rdi    # 0x18d3a8
movb $0x0, %al
callq 0xf2d20
movl $0x0, 0xa4(%rsp)
jmp 0x2a480
movl $0x1, 0xa4(%rsp)
movl 0xa4(%rsp), %eax
addq $0xa8, %rsp
retq
nop