// File: /workspace/github_c_makefile_star2_O2/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 0x3e10
movq %rax, %rbx
leaq 0x28ca(%rip), %rsi      # 0x6744
movq %rax, %rdi
callq 0x22c0
testq %rax, %rax
jne 0x3ea0
leaq 0x3606(%rip), %rdi      # 0x7494
callq 0x22d0
movq %rbx, %rdi
callq 0x2040
jmp 0x3fd2
movq %rax, %r15
movq %rax, %rdi
callq 0x305d
movq %rax, %r14
movq %r15, %rdi
callq 0x2100
movq (%r14), %rdi
callq 0x2632
testb %al, %al
je 0x3fc1
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 0x3544(%rip), %rdi      # 0x74c5
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 0x34e7(%rip), %rdi      # 0x74af
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2140
pushq $0x1
popq %rdi
callq 0x2330
nop