// File: /workspace/github_c_makefile_star2_O0/mikeakohn[P]print_pe/build/../src/optional_header.c
// Function: optional_header_print
int optional_header_print(struct optional_header_t *optional_header)
{
  int t;

  printf("---------------------------------------------\n");
  printf("Image Optional Header\n");
  printf("---------------------------------------------\n");

  const char *magic;

  switch (optional_header->Magic)
  {
    case 0x10b: magic = "PE32 32 Bit Exe"; break;
    case 0x20b: magic = "PE32+ 64 Bit Exe"; break;
    case 0x107: magic = "ROM"; break;
    default: magic = "Unknown"; break;
  }

  printf("             Magic: 0x%04x (%s)\n", optional_header->Magic, magic);

  printf("MajorLinkerVersion: %d\n", optional_header->MajorLinkerVersion);
  printf("MinorLinkerVersion: %d\n", optional_header->MinorLinkerVersion);
  printf("        SizeOfCode: %d\n", optional_header->SizeOfCode);
  printf("SizeOfInitilzdData: %d\n", optional_header->SizeOfInitializedData);
  printf("SizeOfUnintlzdData: %d\n", optional_header->SizeOfUninitializedData);
  printf("  AddrOfEntryPoint: %d\n", optional_header->AddressOfEntryPoint);
  printf("        BaseOfCode: %d\n", optional_header->BaseOfCode);
  printf("        BaseOfData: %d\n", optional_header->BaseOfData);
  printf("         ImageBase: 0x%" PRIx64 "\n", optional_header->ImageBase);
  printf("  SectionAlignment: %d\n", optional_header->SectionAlignment);
  printf("     FileAlignment: %d\n", optional_header->FileAlignment);
  printf("    MajorOSVersion: %d\n", optional_header->MajorOperatingSystemVersion);
  printf("    MinorOSVersion: %d\n", optional_header->MinorOperatingSystemVersion);
  printf(" MajorImageVersion: %d\n", optional_header->MajorImageVersion);
  printf(" MinorImageVersion: %d\n", optional_header->MinorImageVersion);
  printf(" MajorSubsystemVer: %d\n", optional_header->MajorSubsystemVersion);
  printf(" MinorSubsystemVer: %d\n", optional_header->MinorSubsystemVersion);
  printf("         Reserved1: %d\n", optional_header->Reserved1);
  printf("       SizeOfImage: %d\n", optional_header->SizeOfImage);
  printf("     SizeOfHeaders: %d\n", optional_header->SizeOfHeaders);
  printf("          CheckSum: %d\n", optional_header->CheckSum);

  const char *subsystem;

  switch (optional_header->Subsystem)
  {
    case 1: subsystem = "Native"; break;
    case 2: subsystem = "GUI"; break;
    case 3: subsystem = "Console"; break;
    case 5: subsystem = "OS2 GUI"; break;
    case 7: subsystem = "Posix Console"; break;
    case 9: subsystem = "Windows CE GUI"; break;
    case 10: subsystem = "EFI App"; break;
    case 11: subsystem = "EFI Boot Service Driver"; break;
    case 12: subsystem = "EFI Runtime Driver"; break;
    case 13: subsystem = "EFI ROM"; break;
    case 14: subsystem = "Xbox"; break;
    case 15: subsystem = "Windows Boot Application"; break;
    default: subsystem = "Unknown"; break;
  }

  printf("         Subsystem: %d (%s)\n", optional_header->Subsystem, subsystem);
  printf("DllCharacteristics: 0x%04x", optional_header->DllCharacteristics);

  if ((optional_header->DllCharacteristics & 1) != 0)
  {
    printf(" (Reserved_1)");
  }

  if ((optional_header->DllCharacteristics & 2) != 0)
  {
    printf(" (Reserved_2)");
  }

  if ((optional_header->DllCharacteristics & 4) != 0)
  {
    printf(" (Reserved_4)");
  }

  if ((optional_header->DllCharacteristics & 8) != 0)
  {
    printf(" (Reserved_8)");
  }

  if ((optional_header->DllCharacteristics & 0x40) != 0)
  {
    printf(" (Dyanamic Base)");
  }

  if ((optional_header->DllCharacteristics & 0x80) != 0)
  {
    printf(" (Force Integrity)");
  }

  if ((optional_header->DllCharacteristics & 0x100) != 0)
  {
    printf(" (NX Compatiblity)");
  }

  if ((optional_header->DllCharacteristics & 0x200) != 0)
  {
    printf(" (No Isolation)");
  }

  if ((optional_header->DllCharacteristics & 0x400) != 0)
  {
    printf(" (No Structure Exception Handling)");
  }

  if ((optional_header->DllCharacteristics & 0x800) != 0)
  {
    printf(" (No Bind)");
  }

  if ((optional_header->DllCharacteristics & 0x2000) != 0)
  {
    printf(" (WDM Driver)");
  }

  if ((optional_header->DllCharacteristics & 0x8000) != 0)
  {
    printf(" (Terminal Server Aware)");
  }

  printf("\n");

  printf("SizeOfStackReserve: %" PRId64 "\n", optional_header->SizeOfStackReserve);
  printf(" SizeOfStackCommit: %" PRId64 "\n", optional_header->SizeOfStackCommit);
  printf(" SizeOfHeapReserve: %" PRId64 "\n", optional_header->SizeOfHeapReserve);
  printf("  SizeOfHeapCommit: %" PRId64 "\n", optional_header->SizeOfHeapCommit);
  printf("       LoaderFlags: %d\n", optional_header->LoaderFlags);
  printf("  NumOfRvaAndSizes: %d\n", optional_header->NumberOfRvaAndSizes);
  printf("\n");

  if (optional_header->DataDirectoryCount != 0)
  {
    printf("   Directory Description             VirtualAddr  Size\n");

    for (t = 0; t < optional_header->DataDirectoryCount; t++)
    {
      const char *desc;

      if (t < sizeof(dir_entries) / sizeof(char *))
      {
        desc = dir_entries[t];
      }
        else
      {
        desc = "";
      }

      printf("%2d %-33s 0x%08x   0x%08x (%d)\n", t, desc,
        optional_header->directory_entry[t].virtual_address,
        optional_header->directory_entry[t].size,
        optional_header->directory_entry[t].size);
    }

    if (t != 0) { printf("\n"); }
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x360f(%rip), %rdi      # 0xa1f2
movq %rdi, -0x38(%rbp)
xorl %eax, %eax
movb %al, -0x2d(%rbp)
callq 0x3080
movb -0x2d(%rbp), %al
leaq 0x4cb9(%rip), %rdi      # 0xb8b4
callq 0x3080
movq -0x38(%rbp), %rdi
movb -0x2d(%rbp), %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl (%rax), %eax
movl %eax, -0x2c(%rbp)
subl $0x107, %eax            # imm = 0x107
je 0x6c51
jmp 0x6c1f
movl -0x2c(%rbp), %eax
subl $0x10b, %eax            # imm = 0x10B
je 0x6c37
jmp 0x6c2b
movl -0x2c(%rbp), %eax
subl $0x20b, %eax            # imm = 0x20B
je 0x6c44
jmp 0x6c5e
leaq 0x4c8d(%rip), %rax      # 0xb8cb
movq %rax, -0x18(%rbp)
jmp 0x6c69
leaq 0x4c90(%rip), %rax      # 0xb8db
movq %rax, -0x18(%rbp)
jmp 0x6c69
leaq 0x4f13(%rip), %rax      # 0xbb6b
movq %rax, -0x18(%rbp)
jmp 0x6c69
leaq 0x4059(%rip), %rax      # 0xacbe
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movzwl (%rax), %esi
movq -0x18(%rbp), %rdx
leaq 0x4c71(%rip), %rdi      # 0xb8ec
xorl %eax, %eax
movb %al, -0x41(%rbp)
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movzbl 0x2(%rcx), %esi
leaq 0x4c76(%rip), %rdi      # 0xb90d
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movzbl 0x3(%rcx), %esi
leaq 0x4c77(%rip), %rdi      # 0xb925
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x4(%rcx), %esi
leaq 0x4c79(%rip), %rdi      # 0xb93d
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %esi
leaq 0x4c7b(%rip), %rdi      # 0xb955
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0xc(%rcx), %esi
leaq 0x4c7d(%rip), %rdi      # 0xb96d
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %esi
leaq 0x4c7f(%rip), %rdi      # 0xb985
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %esi
leaq 0x4c81(%rip), %rdi      # 0xb99d
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %esi
leaq 0x4c83(%rip), %rdi      # 0xb9b5
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rsi
leaq 0x4c84(%rip), %rdi      # 0xb9cd
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x28(%rcx), %esi
leaq 0x4c89(%rip), %rdi      # 0xb9e8
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x2c(%rcx), %esi
leaq 0x4c8b(%rip), %rdi      # 0xba00
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movzwl 0x30(%rcx), %esi
leaq 0x4c8c(%rip), %rdi      # 0xba18
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movzwl 0x32(%rcx), %esi
leaq 0x4c8d(%rip), %rdi      # 0xba30
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movzwl 0x34(%rcx), %esi
leaq 0x4c8e(%rip), %rdi      # 0xba48
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movzwl 0x36(%rcx), %esi
leaq 0x4c8f(%rip), %rdi      # 0xba60
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movzwl 0x38(%rcx), %esi
leaq 0x4c90(%rip), %rdi      # 0xba78
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movzwl 0x3a(%rcx), %esi
leaq 0x4c91(%rip), %rdi      # 0xba90
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x3c(%rcx), %esi
leaq 0x4c93(%rip), %rdi      # 0xbaa8
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x40(%rcx), %esi
leaq 0x4c95(%rip), %rdi      # 0xbac0
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x44(%rcx), %esi
leaq 0x4c97(%rip), %rdi      # 0xbad8
callq 0x3080
movb -0x41(%rbp), %al
movq -0x8(%rbp), %rcx
movl 0x48(%rcx), %esi
leaq 0x4c99(%rip), %rdi      # 0xbaf0
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4c(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0xe, %eax
ja 0x6f2e
movq -0x40(%rbp), %rax
leaq 0x4928(%rip), %rcx      # 0xb7a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x4c78(%rip), %rax      # 0xbb08
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c73(%rip), %rax      # 0xbb13
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c6d(%rip), %rax      # 0xbb1d
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c4f(%rip), %rax      # 0xbb0f
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c4a(%rip), %rax      # 0xbb17
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c4b(%rip), %rax      # 0xbb25
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c4d(%rip), %rax      # 0xbb34
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c48(%rip), %rax      # 0xbb3c
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c53(%rip), %rax      # 0xbb54
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c59(%rip), %rax      # 0xbb67
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c54(%rip), %rax      # 0xbb6f
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x4c4c(%rip), %rax      # 0xbb74
movq %rax, -0x20(%rbp)
jmp 0x6f39
leaq 0x3d89(%rip), %rax      # 0xacbe
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x4c(%rax), %esi
movq -0x20(%rbp), %rdx
leaq 0x4c41(%rip), %rdi      # 0xbb8d
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %esi
leaq 0x4c48(%rip), %rdi      # 0xbbaa
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6f87
leaq 0x4c45(%rip), %rdi      # 0xbbc5
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x6fa5
leaq 0x4c35(%rip), %rdi      # 0xbbd3
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x6fc3
leaq 0x4c25(%rip), %rdi      # 0xbbe1
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x6fe1
leaq 0x4c15(%rip), %rdi      # 0xbbef
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x6fff
leaq 0x4c05(%rip), %rdi      # 0xbbfd
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x701f
leaq 0x4bf6(%rip), %rdi      # 0xbc0e
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x703f
leaq 0x4be9(%rip), %rdi      # 0xbc21
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x705f
leaq 0x4bdc(%rip), %rdi      # 0xbc34
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x707f
leaq 0x4bcc(%rip), %rdi      # 0xbc44
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x709f
leaq 0x4bcf(%rip), %rdi      # 0xbc67
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x70bf
leaq 0x4bba(%rip), %rdi      # 0xbc72
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movzwl 0x4e(%rax), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x70df
leaq 0x4ba8(%rip), %rdi      # 0xbc80
movb $0x0, %al
callq 0x3080
leaq 0x3046(%rip), %rdi      # 0xa12c
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rsi
leaq 0x4b9d(%rip), %rdi      # 0xbc99
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rsi
leaq 0x4ba0(%rip), %rdi      # 0xbcb2
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rsi
leaq 0x4ba3(%rip), %rdi      # 0xbccb
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rsi
leaq 0x4ba6(%rip), %rdi      # 0xbce4
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movl 0x70(%rax), %esi
leaq 0x4baa(%rip), %rdi      # 0xbcfd
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
movl 0x74(%rax), %esi
leaq 0x4bad(%rip), %rdi      # 0xbd15
movb $0x0, %al
callq 0x3080
leaq 0x2fb6(%rip), %rdi      # 0xa12c
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rax
cmpl $0x0, 0x78(%rax)
je 0x723b
leaq 0x4b9b(%rip), %rdi      # 0xbd2d
movb $0x0, %al
callq 0x3080
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x78(%rcx), %eax
jge 0x7225
movslq -0xc(%rbp), %rax
cmpq $0xf, %rax
jae 0x71cb
movslq -0xc(%rbp), %rcx
leaq 0x7eff(%rip), %rax      # 0xf0c0
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
jmp 0x71d6
leaq 0x2f5b(%rip), %rax      # 0xa12d
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %esi
movq -0x28(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl 0x7c(%rax,%rcx,8), %ecx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rdi
movl 0x80(%rax,%rdi,8), %r8d
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rdi
movl 0x80(%rax,%rdi,8), %r9d
leaq 0x4b55(%rip), %rdi      # 0xbd65
movb $0x0, %al
callq 0x3080
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x71a0
cmpl $0x0, -0xc(%rbp)
je 0x7239
leaq 0x2efa(%rip), %rdi      # 0xa12c
movb $0x0, %al
callq 0x3080
jmp 0x723b
xorl %eax, %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)