// File: /workspace/github_c_makefile_star2_O0/sadistech[P]nesromtool2/./src/tilec_main.c
// Function: parse_opts
tilec_opts* parse_opts(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage: %s <outfile> <infile> [ <infile> ... ]\n", argv[0]);
    exit(EXIT_FAILURE);
  }

  tilec_opts *opts = (tilec_opts*)calloc(1, sizeof(tilec_opts));

  static struct option longopts[] = {
    { "help", no_argument, NULL, 'h' },
    { "outfile", required_argument, NULL, 'o' },
    { "varfile", required_argument, NULL, 'V' },
    { NULL, 0, NULL, 0 }
  };

  int ch;

  while ((ch = getopt_long(argc, argv, "ho:V:", longopts, NULL)) != -1) {
    switch (ch) {
      case 'h':
        printf("USAGE\n");
        exit(EXIT_SUCCESS);
        break;

      case 'o':
        strncpy(opts->outfile, optarg, PATH_MAX);
        break;

      case 'V':
        strncpy(opts->varfile, optarg, PATH_MAX);
        break;

      case 0:
        break;
      default:
        fprintf(stderr, "Invalid argument: -%c\n", ch);
        exit(EXIT_FAILURE);
    }
  }

  // set up default values if they aren't already in there.
  if (opts->outfile[0] == 0) {
    strncpy(opts->outfile, DEFAULT_OUTFILE, PATH_MAX);
  }

  if (opts->varfile[0] == 0) {
    strncpy(opts->varfile, DEFAULT_VARFILE, PATH_MAX);
  }

  argc -= optind;
  argv += optind;

  opts->argc = argc;
  opts->argv = argv;

  return opts;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x4(%rbp)
jge 0x6bce
movq 0x544c(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2cad(%rip), %rsi      # 0x986a
movb $0x0, %al
callq 0x21c0
movl $0x1, %edi
callq 0x22f0
movl $0x1, %edi
movl $0x2010, %esi           # imm = 0x2010
callq 0x2190
movq %rax, -0x18(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x2cb2(%rip), %rdx      # 0x98a1
leaq 0x5d6a(%rip), %rcx      # 0xc960
xorl %eax, %eax
movl %eax, %r8d
callq 0x2110
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
je 0x6cb2
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
testl %eax, %eax
je 0x6c86
jmp 0x6c18
movl -0x20(%rbp), %eax
subl $0x56, %eax
je 0x6c6c
jmp 0x6c22
movl -0x20(%rbp), %eax
subl $0x68, %eax
je 0x6c36
jmp 0x6c2c
movl -0x20(%rbp), %eax
subl $0x6f, %eax
je 0x6c4b
jmp 0x6c88
leaq 0x2c6a(%rip), %rdi      # 0x98a7
movb $0x0, %al
callq 0x2120
xorl %edi, %edi
callq 0x22f0
movq -0x18(%rbp), %rdi
addq $0x1000, %rdi           # imm = 0x1000
movq 0x5373(%rip), %rax      # 0xbfd0
movq (%rax), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x2060
jmp 0x6cad
movq -0x18(%rbp), %rdi
movq 0x5359(%rip), %rax      # 0xbfd0
movq (%rax), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x2060
jmp 0x6cad
jmp 0x6cad
movq 0x5369(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
leaq 0x2991(%rip), %rsi      # 0x962d
movb $0x0, %al
callq 0x21c0
movl $0x1, %edi
callq 0x22f0
jmp 0x6be1
movq -0x18(%rbp), %rax
movsbl 0x1000(%rax), %eax
cmpl $0x0, %eax
jne 0x6cde
movq -0x18(%rbp), %rdi
addq $0x1000, %rdi           # imm = 0x1000
leaq 0x2bda(%rip), %rsi      # 0x98ae
movl $0x1000, %edx           # imm = 0x1000
callq 0x2060
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x6cff
movq -0x18(%rbp), %rdi
leaq 0x2bc2(%rip), %rsi      # 0x98b7
movl $0x1000, %edx           # imm = 0x1000
callq 0x2060
movq 0x52c2(%rip), %rax      # 0xbfc8
movl (%rax), %ecx
movl -0x4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4(%rbp)
movq 0x52b1(%rip), %rax      # 0xbfc8
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movl -0x4(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x2000(%rax)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x2008(%rax)
movq -0x18(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)