// File: /workspace/github_c_makefile_star2_O0/mikeakohn[P]print_pe/build/../src/pdb.c
// Function: print_pdb_symbols
void print_pdb_symbols(
  struct pdb_dir_t *pdb_dir,
  struct pdb_header_t *pdb_header,
  struct pdb_dbi_t *pdb_dbi,
  FILE *in,
  uint8_t demangle_symbols)
{
  if (pdb_dbi->version_signature == 0)
  {
    read_pdb_dbi_stream(pdb_dir, pdb_header, pdb_dbi, in);
  }

  uint8_t *data = pdb_dir->heap;
  uint32_t virtual_address = 0;

  // Need to find .text section to find the offset to the code.
  if (pdb_dbi->optional_debug_header_size != 0)
  {
    uint8_t *debug_section = data + 64 +
      pdb_dbi->mod_info_size +
      pdb_dbi->section_contribution_size +
      pdb_dbi->section_map_size +
      pdb_dbi->source_info_size +
      pdb_dbi->type_server_size +
      pdb_dbi->ec_substream_size;

    int index = get_int16(debug_section + 10);
    int length = pdb_dir->stream_sizes[index];
    int n = 0;
    uint8_t *next = pdb_dir->heap;
    read_data(pdb_dir, index, pdb_header->block_size, in);

    printf("  -- sections --\n");

    while (n < length)
    {
      const char *name = (char *)next;
      printf("                      name: %-8s\n", name);
      printf("              virtual_size: 0x%08x\n", get_uint32(next + 8));
      printf("           virtual_address: 0x%08x\n", get_uint32(next + 12));
      printf("          size_of_raw_data: 0x%04x\n", get_uint32(next + 16));
      printf("       pointer_to_raw_data: 0x%04x\n", get_uint32(next + 20));
      printf("    pointer_to_relocations: 0x%04x\n", get_uint32(next + 24));
      printf("   pointer_to_line_numbers: 0x%04x\n", get_uint32(next + 28));
      printf("          relocation_count: %d\n", get_uint16(next + 32));
      printf("         line_number_count: %d\n", get_uint16(next + 34));
      printf("           characteristics: 0x%08x\n", get_uint32(next + 36));
      printf("\n");

      if (strncmp(name, ".text", 8) == 0)
      {
        virtual_address = get_uint32(next + 12);
      }

      n += 40;
      next += 40;
    }
  }

  read_data(pdb_dir, pdb_dbi->symbol_record_stream, pdb_header->block_size, in);

  struct symbol_record_t symbol_record;
  int length = pdb_dir->stream_sizes[pdb_dbi->symbol_record_stream];
  uint8_t *next = data;
  int n = 0;

  printf("  -- Symbols --\n");

  while (n < length)
  {
    int offset = 14;

    symbol_record.length = get_uint16(next + 0);
    symbol_record.type = get_uint16(next + 2);

    printf("       length: %d\n", symbol_record.length);

    switch (symbol_record.type)
    {
      case 0x110e:
        printf("  symbol_type: 0x%04x (PUB32)\n", symbol_record.type);
        printf("      section: %d\n", get_int32(next+ 4));
        if (virtual_address != 0)
        {
          printf("       offset: 0x%04x (address=0x%04x)\n",
            get_uint32(next + 8),
            get_uint32(next + 8) + virtual_address);
        }
          else
        {
          printf("       offset: 0x%04x\n", get_uint32(next + 8));
        }
        printf("        index: %d\n", get_uint16(next + 12));
        break;
      case 0x1125:
        printf("  symbol_type: 0x%04x (PROCREF)\n", symbol_record.type);
        printf("      section: %d\n", get_int32(next+ 4));
        printf("       offset: 0x%04x\n", get_uint32(next + 8));
        printf("        index: %d\n", get_uint16(next + 12));
        break;
      case 0x1107:
        printf("  symbol_type: 0x%04x (CONSTANT)\n", symbol_record.type);
        printf("       offset: 0x%04x\n", get_uint32(next + 4));
        printf("        index: %d\n", get_uint16(next + 8));
        offset = 10;
        break;
      case 0x1108:
        printf("  symbol_type: 0x%04x (UDT)\n", symbol_record.type);
        printf("       offset: 0x%04x\n", get_uint32(next + 4));
        offset = 8;
        break;
      case 0x110c:
        printf("  symbol_type: 0x%04x (LDATA32)\n", symbol_record.type);
        printf("      section: %d\n", get_int32(next+ 4));
        printf("       offset: 0x%04x\n", get_uint32(next + 8));
        printf("        index: %d\n", get_uint16(next + 12));
        break;
      case 0x110d:
        printf("  symbol_type: 0x%04x (GDATA32)\n", symbol_record.type);
        printf("      section: %d\n", get_int32(next+ 4));
        printf("       offset: 0x%04x\n", get_uint32(next + 8));
        printf("        index: %d\n", get_uint16(next + 12));
        break;
      case 0x1127:
        printf("  symbol_type: 0x%04x (LPROCREF)\n", symbol_record.type);
        printf("      section: %d\n", get_int32(next+ 4));
        printf("       offset: 0x%04x\n", get_uint32(next + 8));
        printf("        index: %d\n", get_uint16(next + 12));
        break;
      default:
        printf("  symbol_type: 0x%04x (UNKNOWN)\n", symbol_record.type);
        printf("      section: %d\n", get_int32(next+ 4));
        printf("       offset: 0x%04x\n", get_uint32(next + 8));
        printf("        index: %d\n", get_uint16(next + 12));
        break;
    }

    printf("%s\n", next + offset);

    if (demangle_symbols == 1)
    {
      char demangled[1024];

      int r = demangle(
        (const char *)next + offset,
        demangled,
        sizeof(demangled));

      if (r > 0) { printf("%s\n", demangled); }
    }

    printf(" --------\n");

    int align = (symbol_record.length + 3) & ~3;

    next += align;
    n += align;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movb %al, -0x21(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x535f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x43e0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x55aa
movq -0x30(%rbp), %rax
addq $0x40, %rax
movq -0x18(%rbp), %rcx
movslq 0x18(%rcx), %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movslq 0x20(%rcx), %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movslq 0x24(%rcx), %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movslq 0x28(%rcx), %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movslq 0x34(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
addq $0xa, %rdi
callq 0x45f0
cwtl
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x10(%rbp), %rax
movl 0x58(%rax), %edx
movq -0x20(%rbp), %rcx
callq 0x36b0
leaq 0x23aa(%rip), %rdi      # 0x77cc
movb $0x0, %al
callq 0x1070
movl -0x4c(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x55a8
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rsi
leaq 0x2396(%rip), %rdi      # 0x77de
movb $0x0, %al
callq 0x1070
movq -0x58(%rbp), %rdi
addq $0x8, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x239b(%rip), %rdi      # 0x7800
movb $0x0, %al
callq 0x1070
movq -0x58(%rbp), %rdi
addq $0xc, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x23a2(%rip), %rdi      # 0x7824
movb $0x0, %al
callq 0x1070
movq -0x58(%rbp), %rdi
addq $0x10, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x23a9(%rip), %rdi      # 0x7848
movb $0x0, %al
callq 0x1070
movq -0x58(%rbp), %rdi
addq $0x14, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x23b0(%rip), %rdi      # 0x786c
movb $0x0, %al
callq 0x1070
movq -0x58(%rbp), %rdi
addq $0x18, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x23b7(%rip), %rdi      # 0x7890
movb $0x0, %al
callq 0x1070
movq -0x58(%rbp), %rdi
addq $0x1c, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x23be(%rip), %rdi      # 0x78b4
movb $0x0, %al
callq 0x1070
movq -0x58(%rbp), %rdi
addq $0x20, %rdi
callq 0x4370
movzwl %ax, %esi
leaq 0x23c4(%rip), %rdi      # 0x78d8
movb $0x0, %al
callq 0x1070
movq -0x58(%rbp), %rdi
addq $0x22, %rdi
callq 0x4370
movzwl %ax, %esi
leaq 0xe71(%rip), %rdi       # 0x63a3
movb $0x0, %al
callq 0x1070
movq -0x58(%rbp), %rdi
addq $0x24, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x23a9(%rip), %rdi      # 0x78f8
movb $0x0, %al
callq 0x1070
leaq 0x107e(%rip), %rdi      # 0x65db
movb $0x0, %al
callq 0x1070
movq -0x60(%rbp), %rdi
leaq 0x23ad(%rip), %rsi      # 0x791c
movl $0x8, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x558e
movq -0x58(%rbp), %rdi
addq $0xc, %rdi
callq 0x3c40
movl %eax, -0x34(%rbp)
movl -0x4c(%rbp), %eax
addl $0x28, %eax
movl %eax, -0x4c(%rbp)
movq -0x58(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x58(%rbp)
jmp 0x5429
jmp 0x55aa
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzwl 0x14(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x58(%rax), %edx
movq -0x20(%rbp), %rcx
callq 0x36b0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movzwl 0x14(%rcx), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x74(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
leaq 0x232d(%rip), %rdi      # 0x7922
movb $0x0, %al
callq 0x1070
movl -0x84(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x5a97
movl $0xe, -0x88(%rbp)
movq -0x80(%rbp), %rdi
callq 0x4370
movw %ax, -0x70(%rbp)
movq -0x80(%rbp), %rdi
addq $0x2, %rdi
callq 0x4370
movw %ax, -0x6e(%rbp)
movzwl -0x70(%rbp), %esi
leaq 0x22f5(%rip), %rdi      # 0x7933
xorl %eax, %eax
callq 0x1070
movzwl -0x6e(%rbp), %eax
addl $0xffffeef9, %eax       # imm = 0xFFFFEEF9
movl %eax, %ecx
movq %rcx, -0x4a0(%rbp)
subl $0x20, %eax
ja 0x597a
movq -0x4a0(%rbp), %rax
leaq 0x11de(%rip), %rcx      # 0x684c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzwl -0x6e(%rbp), %esi
leaq 0x22c4(%rip), %rdi      # 0x7946
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x4, %rdi
callq 0x43a0
movl %eax, %esi
leaq 0x1b65(%rip), %rdi      # 0x7204
movb $0x0, %al
callq 0x1070
cmpl $0x0, -0x34(%rbp)
je 0x56e7
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x3c40
movl %eax, -0x4a4(%rbp)
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x3c40
movl -0x4a4(%rbp), %esi
movl %eax, %edx
addl -0x34(%rbp), %edx
leaq 0x2287(%rip), %rdi      # 0x7965
movb $0x0, %al
callq 0x1070
jmp 0x5704
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x2290(%rip), %rdi      # 0x798d
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0xc, %rdi
callq 0x4370
movzwl %ax, %esi
leaq 0x2289(%rip), %rdi      # 0x79a4
movb $0x0, %al
callq 0x1070
jmp 0x59e4
movzwl -0x6e(%rbp), %esi
leaq 0x2285(%rip), %rdi      # 0x79b7
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x4, %rdi
callq 0x43a0
movl %eax, %esi
leaq 0x1ab5(%rip), %rdi      # 0x7204
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x2221(%rip), %rdi      # 0x798d
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0xc, %rdi
callq 0x4370
movzwl %ax, %esi
leaq 0x221a(%rip), %rdi      # 0x79a4
movb $0x0, %al
callq 0x1070
jmp 0x59e4
movzwl -0x6e(%rbp), %esi
leaq 0x2237(%rip), %rdi      # 0x79d8
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x4, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x21cf(%rip), %rdi      # 0x798d
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x4370
movzwl %ax, %esi
leaq 0x21c8(%rip), %rdi      # 0x79a4
movb $0x0, %al
callq 0x1070
movl $0xa, -0x88(%rbp)
jmp 0x59e4
movzwl -0x6e(%rbp), %esi
leaq 0x21fd(%rip), %rdi      # 0x79fa
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x4, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x2173(%rip), %rdi      # 0x798d
movb $0x0, %al
callq 0x1070
movl $0x8, -0x88(%rbp)
jmp 0x59e4
movzwl -0x6e(%rbp), %esi
leaq 0x21dc(%rip), %rdi      # 0x7a17
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x4, %rdi
callq 0x43a0
movl %eax, %esi
leaq 0x19ac(%rip), %rdi      # 0x7204
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x2118(%rip), %rdi      # 0x798d
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0xc, %rdi
callq 0x4370
movzwl %ax, %esi
leaq 0x2111(%rip), %rdi      # 0x79a4
movb $0x0, %al
callq 0x1070
jmp 0x59e4
movzwl -0x6e(%rbp), %esi
leaq 0x218e(%rip), %rdi      # 0x7a38
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x4, %rdi
callq 0x43a0
movl %eax, %esi
leaq 0x193d(%rip), %rdi      # 0x7204
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x20a9(%rip), %rdi      # 0x798d
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0xc, %rdi
callq 0x4370
movzwl %ax, %esi
leaq 0x20a2(%rip), %rdi      # 0x79a4
movb $0x0, %al
callq 0x1070
jmp 0x59e4
movzwl -0x6e(%rbp), %esi
leaq 0x2140(%rip), %rdi      # 0x7a59
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x4, %rdi
callq 0x43a0
movl %eax, %esi
leaq 0x18ce(%rip), %rdi      # 0x7204
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x203a(%rip), %rdi      # 0x798d
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0xc, %rdi
callq 0x4370
movzwl %ax, %esi
leaq 0x2033(%rip), %rdi      # 0x79a4
movb $0x0, %al
callq 0x1070
jmp 0x59e4
movzwl -0x6e(%rbp), %esi
leaq 0x20f6(%rip), %rdi      # 0x7a7b
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x4, %rdi
callq 0x43a0
movl %eax, %esi
leaq 0x1862(%rip), %rdi      # 0x7204
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x3c40
movl %eax, %esi
leaq 0x1fce(%rip), %rdi      # 0x798d
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rdi
addq $0xc, %rdi
callq 0x4370
movzwl %ax, %esi
leaq 0x1fc7(%rip), %rdi      # 0x79a4
movb $0x0, %al
callq 0x1070
movq -0x80(%rbp), %rsi
movslq -0x88(%rbp), %rax
addq %rax, %rsi
leaq 0x1504(%rip), %rdi      # 0x6efd
movb $0x0, %al
callq 0x1070
movzbl -0x21(%rbp), %eax
cmpl $0x1, %eax
jne 0x5a4e
movq -0x80(%rbp), %rdi
movslq -0x88(%rbp), %rax
addq %rax, %rdi
leaq -0x490(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x2470
movl %eax, -0x494(%rbp)
cmpl $0x0, -0x494(%rbp)
jle 0x5a4c
leaq -0x490(%rbp), %rsi
leaq 0x14b8(%rip), %rdi      # 0x6efd
movb $0x0, %al
callq 0x1070
jmp 0x5a4e
leaq 0x2047(%rip), %rdi      # 0x7a9c
movb $0x0, %al
callq 0x1070
movzwl -0x70(%rbp), %eax
addl $0x3, %eax
andl $-0x4, %eax
movl %eax, -0x498(%rbp)
movl -0x498(%rbp), %ecx
movq -0x80(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl -0x498(%rbp), %eax
addl -0x84(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0x55fc
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq