// File: /workspace/github_c_makefile_star2_O3/sadistech[P]nesromtool2/./src/subcommands/info.c
// Function: subcommand_info
void subcommand_info(int argc, char **argv) {
  info_opts *opts = subcommand_info_parse(argc, argv);

  FILE *romfile = fopen(opts->romfile_path, "r");

  if (!romfile) {
    perror("Failed to read in rom file");
    free(opts);
    exit(EXIT_FAILURE);
  }

  nrt_rom *rom = nrt_read_rom_from_file(romfile);
  fclose(romfile);

  if (!nrt_validate_header(rom->header)) {
    printf(
      "Path: %s\n"
      "Valid: FAIL\n",
      opts->romfile_path
    );
    exit(EXIT_FAILURE);
  }

  printf(
    "Path: %s\n"
    "Valid: OK\n"
    "PRG Banks: %d\n"
    "CHR Banks: %d\n"
    "\n"
    "Mapper lower nybble: %d\n"
    "Ignore mirroring control: %d\n"
    "Trainer present: %d\n"
    "Persistent memory: %d\n"
    "Mirror mode: %d\n"
    "\n"
    "Mapper upper nybble: %d\n"
    "Flag format: %d\n"
    "Playchoice: %d\n"
    "VS Unisystem: %d\n"
    "\n"
    "PRG RAM Size: %d\n"
    "\n"
    "TV System: %d\n"
    "\n"
    "Bus conflicts: %d\n"
    "PRG RAM absent: %d\n"
    "TV System (2): %d\n"
    "\n"
    "Title: %s\n",
    opts->romfile_path,
    rom->prgs->count,
    rom->chrs->count,

    rom->header->mapper_nybble_lower,
    rom->header->ignore_mirroring_control,
    rom->header->trainer_present,
    rom->header->persistent_memory,
    rom->header->mirror_mode,

    rom->header->mapper_nybble_upper,
    rom->header->flag_format,
    rom->header->playchoice,
    rom->header->vs_unisystem,

    rom->header->prg_ram_size,

    rom->header->tv_system,

    rom->header->bus_conflicts,
    rom->header->prg_ram_absent,
    rom->header->tv_system_2,

    rom->title
  );

  exit(EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
callq 0x4a08
movq %rax, %rbx
leaq 0x2cd0(%rip), %rsi      # 0x7744
movq %rax, %rdi
callq 0x22c0
testq %rax, %rax
jne 0x4a9a
leaq 0x3a0c(%rip), %rdi      # 0x8494
callq 0x22d0
movq %rbx, %rdi
callq 0x2040
jmp 0x4bcc
movq %rax, %r15
movq %rax, %rdi
callq 0x38d1
movq %rax, %r14
movq %r15, %rdi
callq 0x2100
movq (%r14), %rdi
callq 0x2d78
testb %al, %al
je 0x4bbb
movq (%r14), %rax
movq 0x8(%r14), %rcx
movl (%rcx), %edx
movq 0x10(%r14), %rcx
movl (%rcx), %ecx
movzwl 0x6(%rax), %r15d
movl %r15d, %r8d
andl $0xf, %r8d
movl %r15d, %r9d
shrl $0x4, %r9d
andl $0x1, %r9d
movl %r15d, %esi
shrl $0x5, %esi
andl $0x1, %esi
movq %rsi, 0x30(%rsp)
movl %r15d, %esi
shrl $0x6, %esi
andl $0x1, %esi
movq %rsi, 0x28(%rsp)
movl %r15d, %esi
shrl $0x7, %esi
andl $0x1, %esi
movq %rsi, 0x20(%rsp)
movl %r15d, %esi
shrl $0x8, %esi
andl $0xf, %esi
movq %rsi, 0x18(%rsp)
movl %r15d, %esi
shrl $0xc, %esi
andl $0x3, %esi
movq %rsi, 0x10(%rsp)
movl %r15d, %r10d
shrl $0xe, %r10d
andl $0x1, %r10d
shrl $0xf, %r15d
movzbl 0x8(%rax), %esi
movq %rsi, 0x8(%rsp)
movzwl 0x9(%rax), %r12d
movl %r12d, %r11d
shrl $0x7, %r11d
andl $0x1, %r11d
movl %r12d, %r13d
shrl $0xa, %r13d
andl $0x1, %r13d
movl %r12d, %ebp
shrl $0xb, %ebp
andl $0x1, %ebp
shrl $0xe, %r12d
addq $0x18, %r14
subq $0x8, %rsp
leaq 0x394a(%rip), %rdi      # 0x84c5
movq %rbx, %rsi
xorl %eax, %eax
pushq %r14
pushq %r12
pushq %rbp
pushq %r13
pushq %r11
pushq 0x38(%rsp)
pushq %r15
pushq %r10
pushq 0x58(%rsp)
pushq 0x68(%rsp)
pushq 0x78(%rsp)
pushq 0x88(%rsp)
pushq 0x98(%rsp)
callq 0x2140
addq $0x70, %rsp
xorl %edi, %edi
callq 0x2330
leaq 0x38ed(%rip), %rdi      # 0x84af
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2140
movl $0x1, %edi
callq 0x2330
nop