// File: /workspace/github_c_makefile_star2_O3/mikeakohn[P]print_pe/build/../src/pdb.c
// Function: print_pdb_tpi_stream
void print_pdb_tpi_stream(
  struct pdb_dir_t *pdb_dir,
  struct pdb_header_t *pdb_header,
  FILE *in,
  int index)
{
  struct pdb_tpi_header_t tpi;

  read_data(pdb_dir, index, pdb_header->block_size, in);

  uint8_t *data = pdb_dir->heap;

  tpi.version = get_uint32(data + 0);
  tpi.header_size = get_uint32(data + 4);
  tpi.type_index_begin = get_uint32(data + 8);
  tpi.type_index_end = get_uint32(data + 12);
  tpi.type_record_bytes = get_uint32(data + 16);
  tpi.hash_stream_index = get_uint16(data + 20);
  tpi.hash_aux_stream_index = get_uint16(data + 22);
  tpi.hash_key_size = get_uint32(data + 24);
  tpi.num_hash_buckets = get_uint32(data + 28);
  tpi.hash_value_buffer_offset = get_int32(data + 32);
  tpi.hash_value_buffer_length = get_uint32(data + 36);
  tpi.index_offset_buffer_offset = get_int32(data + 40);
  tpi.index_offset_buffer_length = get_uint32(data + 44);
  tpi.hash_adj_buffer_offset = get_int32(data + 48);
  tpi.hash_adj_buffer_length = get_uint32(data + 52);

  printf(" -- %s Stream --\n", index == 2 ? "TPI" : "IPI");
  printf("                   version: %d\n", tpi.version);
  printf("               header_size: %d\n", tpi.header_size);
  printf("          type_index_begin: %d\n", tpi.type_index_begin);
  printf("            type_index_end: %d\n", tpi.type_index_end);
  printf("         type_record_bytes: %d\n", tpi.type_record_bytes);
  printf("         hash_stream_index: %d\n", tpi.hash_stream_index);
  printf("     hash_aux_stream_index: %d\n", tpi.hash_aux_stream_index);
  printf("             hash_key_size: %d\n", tpi.hash_key_size);
  printf("          num_hash_buckets: %d\n", tpi.num_hash_buckets);
  printf("  hash_value_buffer_offset: %d\n", tpi.hash_value_buffer_offset);
  printf("  hash_value_buffer_length: %d\n", tpi.hash_value_buffer_length);
  printf("index_offset_buffer_offset: %d\n", tpi.index_offset_buffer_offset);
  printf("index_offset_buffer_length: %d\n", tpi.index_offset_buffer_length);
  printf("    hash_adj_buffer_offset: %d\n", tpi.hash_adj_buffer_offset);
  printf("    hash_adj_buffer_length: %d\n", tpi.hash_adj_buffer_length);
  printf("\n");

  int offset = 0;
  int id, unknown, n;
  uint8_t *next = data + tpi.header_size;

  while (offset < tpi.type_record_bytes)
  {
    struct type_record_t *type_record = (struct type_record_t *)next;
    int total_length = type_record->length + 2;

    switch (type_record->type)
    {
      case 0x1001:
        printf(" %d 0x%04x MODIFIER\n",
          type_record->length,
          type_record->type);
        break;
      case 0x1002:
        printf(" %d 0x%04x POINTER\n",
          type_record->length,
          type_record->type);
        break;
      case 0x1008:
        printf(" %d 0x%04x PROCEDURE\n",
          type_record->length,
          type_record->type);
        break;
      case 0x1009:
        printf(" %d 0x%04x MFUNCTION\n",
          type_record->length,
          type_record->type);
        break;
      case 0x1201:
        printf(" %d 0x%04x ARGLIST\n",
          type_record->length,
          type_record->type);
        break;
      case 0x1203:
        printf(" %d 0x%04x FIELDLIST\n",
          type_record->length,
          type_record->type);
        break;
      case 0x1206:
        printf(" %d 0x%04x METHODLIST\n",
          type_record->length,
          type_record->type);
        break;
      case 0x1503:
        printf(" %d 0x%04x ARRAY\n",
          type_record->length,
          type_record->type);
        break;
      case 0x1504:
        printf(" %d 0x%04x CLASS %s\n",
          type_record->length,
          type_record->type,
          next + 22);
        break;
      case 0x1505:
        printf(" %d 0x%04x STRUCTURE %s\n",
          type_record->length,
          type_record->type,
          next + 22);
        //printf("offset=0x%04x\n", offset + 56);
        break;
      case 0x1507:
        printf(" %d 0x%04x ENUM\n",
          type_record->length,
          type_record->type);
        break;
      case 0x1601:
        id = get_uint32(next + 4);
        unknown = get_uint32(next + 8);
        printf(" %d 0x%04x FUNC_ID [%d][0x%08x]\n   %s\n",
          type_record->length,
          type_record->type,
          id,
          unknown,
          next + 12);
        break;
      case 0x1602:
        id = get_uint32(next + 4);
        unknown = get_uint32(next + 8);
        printf(" %d 0x%04x MFUNC_ID [%d][0x%08x]\n   %s\n",
          type_record->length,
          type_record->type,
          id,
          unknown,
          next + 12);
        break;
      case 0x1605:
        id = get_uint32(next + 4);
        printf(" %d 0x%04x STRING_ID [%d]\n   %s\n",
          type_record->length,
          type_record->type,
          id,
          next + 8);
        break;
      case 0x1607:
        printf(" %d 0x%04x UDT_MOD_SRC_LINE\n",
          type_record->length,
          type_record->type);
        printf("  {");
        for (n = 0; n < type_record->length - 2; n++)
        {
          printf(" %02x", next[n + 4]);
        }
        printf(" }\n");
        break;
      default:
        printf(" %d 0x%04x\n", type_record->length, type_record->type);
        // printf("offset=0x%04x\n", offset + 56);
        break;
    }

    next += total_length;
    offset += total_length;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %r13d
movq %rdx, %rcx
movq %rdi, %rbx
movl 0x58(%rsi), %edx
movl %r13d, %esi
callq 0x2aaa
movq 0x18(%rbx), %rbp
movl (%rbp), %ebx
movl 0x4(%rbp), %r12d
movl 0x8(%rbp), %r15d
movl 0xc(%rbp), %r14d
movl 0x10(%rbp), %eax
movl %eax, (%rsp)
movzwl 0x14(%rbp), %eax
movl %eax, 0x4(%rsp)
movzwl 0x16(%rbp), %eax
movl %eax, 0x8(%rsp)
movl 0x18(%rbp), %eax
movl %eax, 0xc(%rsp)
movl 0x1c(%rbp), %eax
movl %eax, 0x10(%rsp)
movl 0x20(%rbp), %eax
movl %eax, 0x14(%rsp)
movl 0x24(%rbp), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x2, %r13d
leaq 0x2a8d(%rip), %rax      # 0x59de
leaq 0x2a8a(%rip), %rsi      # 0x59e2
cmoveq %rax, %rsi
movl 0x28(%rbp), %eax
movl %eax, 0x18(%rsp)
movl 0x2c(%rbp), %eax
movl %eax, 0x20(%rsp)
movl 0x30(%rbp), %eax
movl %eax, 0x24(%rsp)
movl 0x34(%rbp), %r13d
leaq 0x2a50(%rip), %rdi      # 0x59cc
xorl %eax, %eax
callq 0x1090
leaq 0x2a5c(%rip), %rdi      # 0x59e6
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a6c(%rip), %rdi      # 0x5a06
movl %r12d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a7b(%rip), %rdi      # 0x5a26
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a8a(%rip), %rdi      # 0x5a46
movl %r14d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a99(%rip), %rdi      # 0x5a66
movl (%rsp), %ebx
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2aa6(%rip), %rdi      # 0x5a86
movl 0x4(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2ab4(%rip), %rdi      # 0x5aa6
movl 0x8(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2ac2(%rip), %rdi      # 0x5ac6
movl 0xc(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2ad0(%rip), %rdi      # 0x5ae6
movl 0x10(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2ade(%rip), %rdi      # 0x5b06
movl 0x14(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2aec(%rip), %rdi      # 0x5b26
movl 0x1c(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2afa(%rip), %rdi      # 0x5b46
movl 0x18(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2b08(%rip), %rdi      # 0x5b66
movl 0x20(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2b16(%rip), %rdi      # 0x5b86
movl 0x24(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2b24(%rip), %rdi      # 0x5ba6
movl %r13d, %esi
xorl %eax, %eax
callq 0x1090
movl $0xa, %edi
callq 0x1040
testl %ebx, %ebx
je 0x32fb
addq %r12, %rbp
leaq 0x270c(%rip), %r13      # 0x57b4
leaq 0x273d(%rip), %r15      # 0x57ec
leaq 0x28a2(%rip), %rbx      # 0x5958
xorl %r14d, %r14d
movzwl (%rbp), %r12d
movzwl 0x2(%rbp), %edx
cmpl $0x1205, %edx           # imm = 0x1205
jle 0x310c
leal -0x1503(%rdx), %eax
cmpl $0x4, %eax
jbe 0x3135
leal -0x1601(%rdx), %eax
cmpl $0x6, %eax
ja 0x31b0
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl 0x4(%rbp), %ecx
movl 0x8(%rbp), %r8d
leaq 0xc(%rbp), %r9
leaq 0x2bae(%rip), %rdi      # 0x5cad
movl %r12d, %esi
movl $0x1601, %edx           # imm = 0x1601
jmp 0x32ef
leal -0x1001(%rdx), %eax
cmpl $0x8, %eax
ja 0x3159
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
leaq 0x2a9e(%rip), %rdi      # 0x5bc6
movl %r12d, %esi
movl $0x1001, %edx           # imm = 0x1001
jmp 0x320a
leaq 0x269c(%rip), %rcx      # 0x57d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x2b10(%rip), %rdi      # 0x5c5c
movl %r12d, %esi
movl $0x1503, %edx           # imm = 0x1503
jmp 0x320a
cmpl $0x1201, %edx           # imm = 0x1201
je 0x31d5
cmpl $0x1203, %edx           # imm = 0x1203
jne 0x31c9
leaq 0x2abf(%rip), %rdi      # 0x5c2f
movl %r12d, %esi
movl $0x1203, %edx           # imm = 0x1203
jmp 0x320a
leaq 0x2a6b(%rip), %rdi      # 0x5bef
movl %r12d, %esi
movl $0x1008, %edx           # imm = 0x1008
jmp 0x320a
leaq 0x2a70(%rip), %rdi      # 0x5c05
movl %r12d, %esi
movl $0x1009, %edx           # imm = 0x1009
jmp 0x320a
leaq 0x2a35(%rip), %rdi      # 0x5bdb
movl %r12d, %esi
movl $0x1002, %edx           # imm = 0x1002
jmp 0x320a
cmpl $0x1206, %edx           # imm = 0x1206
jne 0x31c9
leaq 0x2a86(%rip), %rdi      # 0x5c45
movl %r12d, %esi
movl $0x1206, %edx           # imm = 0x1206
jmp 0x320a
leaq 0x2b6e(%rip), %rdi      # 0x5d3e
movl %r12d, %esi
jmp 0x320a
leaq 0x2a3f(%rip), %rdi      # 0x5c1b
movl %r12d, %esi
movl $0x1201, %edx           # imm = 0x1201
jmp 0x320a
leaq 0x16(%rbp), %rcx
leaq 0x2a92(%rip), %rdi      # 0x5c83
movl %r12d, %esi
movl $0x1505, %edx           # imm = 0x1505
jmp 0x323d
leaq 0x2a9a(%rip), %rdi      # 0x5c9c
movl %r12d, %esi
movl $0x1507, %edx           # imm = 0x1507
xorl %eax, %eax
callq 0x1090
addq $0x2, %r12
addq %r12, %rbp
addl %r12d, %r14d
cmpl (%rsp), %r14d
jb 0x30b9
jmp 0x32fb
leaq 0x16(%rbp), %rcx
leaq 0x2a39(%rip), %rdi      # 0x5c6e
movl %r12d, %esi
movl $0x1504, %edx           # imm = 0x1504
xorl %eax, %eax
callq 0x1090
jmp 0x3211
movl 0x4(%rbp), %ecx
leaq 0x8(%rbp), %r8
leaq 0x2aa8(%rip), %rdi      # 0x5cfc
movl %r12d, %esi
movl $0x1605, %edx           # imm = 0x1605
xorl %eax, %eax
callq 0x1090
jmp 0x3211
leaq 0x2ab1(%rip), %rdi      # 0x5d1d
movl %r12d, %esi
movl $0x1607, %edx           # imm = 0x1607
xorl %eax, %eax
callq 0x1090
leaq 0x2ab8(%rip), %rdi      # 0x5d3a
xorl %eax, %eax
callq 0x1090
cmpw $0x3, (%rbp)
jb 0x32b6
movq %rbx, %r15
xorl %r13d, %r13d
movzbl 0x4(%rbp,%r13), %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0x1090
incq %r13
movzwl (%rbp), %eax
addq $-0x2, %rax
cmpq %rax, %r13
jl 0x3296
leaq 0x36ed(%rip), %rdi      # 0x69aa
callq 0x1060
leaq 0x24eb(%rip), %r13      # 0x57b4
leaq 0x251c(%rip), %r15      # 0x57ec
jmp 0x3211
movl 0x4(%rbp), %ecx
movl 0x8(%rbp), %r8d
leaq 0xc(%rbp), %r9
leaq 0x29ed(%rip), %rdi      # 0x5cd4
movl %r12d, %esi
movl $0x1602, %edx           # imm = 0x1602
xorl %eax, %eax
callq 0x1090
jmp 0x3211
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq