// File: /workspace/github_c_makefile_star2_O0/sadistech[P]nesromtool2/./src/subcommands/title.c
// Function: subcommand_title_set_parse
title_opts* subcommand_title_set_parse(int argc, char **argv) {
  title_opts *opts = (title_opts*)calloc(1, sizeof(title_opts));

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

  if (strcmp(argv[0], "--help") == 0) {
    print_usage_title_set();
    exit(EXIT_SUCCESS);
  }

  strcpy(opts->romfile_path, argv[0]); // don't shift the args

  int ch;

  while ((ch = getopt_long(argc, argv, "o:h", longopts, NULL)) != -1) {
    switch (ch) {
      case 'h':
        print_usage_title_set();
        exit(EXIT_SUCCESS);
        break;

      case 'o':
        strcpy(opts->outfile_path, optarg);

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

  argc -= optind;
  argv += optind;

  // read in the title from the CLI. make sure that it doesn't go over the max length.

  char *title = argv[0];

  if (strnlen(title, NRT_TITLE_MAX_LENGTH + 1) > NRT_TITLE_MAX_LENGTH) {
    fprintf(stderr, "Title cannot be more than %d characters.\n", NRT_TITLE_MAX_LENGTH);
    free(opts);
    exit(EXIT_FAILURE);
  }

  strncpy(opts->title, title, NRT_TITLE_MAX_LENGTH);

  // if the user didn't specify an outfile, then we want the outfile to be
  // the same as the romfile.
  if (strlen(opts->outfile_path) == 0) {
    strcpy(opts->outfile_path, opts->romfile_path);
  }

  return opts;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, %edi
movl $0x8ff, %esi            # imm = 0x8FF
callq 0x21a0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x2022(%rip), %rsi      # 0x84c2
callq 0x21b0
cmpl $0x0, %eax
jne 0x64b8
movb $0x0, %al
callq 0x47b0
xorl %edi, %edi
callq 0x2310
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x2090
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x335a(%rip), %rdx      # 0x9830
leaq 0x6373(%rip), %rcx      # 0xc850
xorl %eax, %eax
movl %eax, %r8d
callq 0x2110
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
je 0x6565
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0x6539
jmp 0x64fb
movl -0x2c(%rbp), %eax
subl $0x68, %eax
je 0x650f
jmp 0x6505
movl -0x2c(%rbp), %eax
subl $0x6f, %eax
je 0x651d
jmp 0x653b
movb $0x0, %al
callq 0x47b0
xorl %edi, %edi
callq 0x2310
movq -0x18(%rbp), %rdi
addq $0x4ff, %rdi            # imm = 0x4FF
movq 0x5aa1(%rip), %rax      # 0xbfd0
movq (%rax), %rsi
callq 0x2090
jmp 0x6560
jmp 0x6560
movq 0x5ab6(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
leaq 0x30de(%rip), %rsi      # 0x962d
movb $0x0, %al
callq 0x21d0
movl $0x1, %edi
callq 0x2310
jmp 0x64c8
movq 0x5a5c(%rip), %rax      # 0xbfc8
movl (%rax), %ecx
movl -0x4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4(%rbp)
movq 0x5a4b(%rip), %rax      # 0xbfc8
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x2170
cmpq $0xff, %rax
jbe 0x65e2
movq 0x5a3f(%rip), %rax      # 0xbff8
movq (%rax), %rdi
leaq 0x3271(%rip), %rsi      # 0x9834
movl $0xff, %edx
movb $0x0, %al
callq 0x21d0
movq -0x18(%rbp), %rdi
callq 0x2040
movl $0x1, %edi
callq 0x2310
movq -0x18(%rbp), %rdi
addq $0x400, %rdi            # imm = 0x400
movq -0x28(%rbp), %rsi
movl $0xff, %edx
callq 0x2060
movq -0x18(%rbp), %rdi
addq $0x4ff, %rdi            # imm = 0x4FF
callq 0x20f0
cmpq $0x0, %rax
jne 0x6625
movq -0x18(%rbp), %rdi
addq $0x4ff, %rdi            # imm = 0x4FF
movq -0x18(%rbp), %rsi
callq 0x2090
movq -0x18(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nop