// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movq %rdx, %rcx
movq %rdi, %rbx
movl 0x58(%rsi), %edx
movl %ebp, %esi
callq 0x298d
movq 0x18(%rbx), %r15
movl (%r15), %r13d
movl 0x4(%r15), %r14d
movl 0x8(%r15), %r12d
movl 0xc(%r15), %eax
movl %eax, (%rsp)
movl 0x10(%r15), %ebx
movzwl 0x14(%r15), %eax
movl %eax, 0x4(%rsp)
movzwl 0x16(%r15), %eax
movl %eax, 0x8(%rsp)
movl 0x18(%r15), %eax
movl %eax, 0xc(%rsp)
movl 0x1c(%r15), %eax
movl %eax, 0x10(%rsp)
movl 0x20(%r15), %eax
movl %eax, 0x14(%rsp)
movl 0x24(%r15), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x2, %ebp
leaq 0x1bd2(%rip), %rax      # 0x49de
leaq 0x1bcf(%rip), %rsi      # 0x49e2
cmoveq %rax, %rsi
movl 0x28(%r15), %eax
movl %eax, 0x18(%rsp)
movl 0x2c(%r15), %eax
movl %eax, 0x20(%rsp)
movl 0x30(%r15), %eax
movl %eax, 0x24(%rsp)
movl 0x34(%r15), %ebp
leaq 0x1b92(%rip), %rdi      # 0x49cc
xorl %eax, %eax
callq 0x1090
leaq 0x1b9e(%rip), %rdi      # 0x49e6
movl %r13d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1bad(%rip), %rdi      # 0x4a06
movl %r14d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1bbc(%rip), %rdi      # 0x4a26
movl %r12d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1bcb(%rip), %rdi      # 0x4a46
movl (%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1bda(%rip), %rdi      # 0x4a66
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1bea(%rip), %rdi      # 0x4a86
movl 0x4(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1bf8(%rip), %rdi      # 0x4aa6
movl 0x8(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1c06(%rip), %rdi      # 0x4ac6
movl 0xc(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1c14(%rip), %rdi      # 0x4ae6
movl 0x10(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1c22(%rip), %rdi      # 0x4b06
movl 0x14(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1c30(%rip), %rdi      # 0x4b26
movl 0x1c(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1c3e(%rip), %rdi      # 0x4b46
movl 0x18(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1c4c(%rip), %rdi      # 0x4b66
movl 0x20(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1c5a(%rip), %rdi      # 0x4b86
movl 0x24(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1c68(%rip), %rdi      # 0x4ba6
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
pushq $0xa
popq %rdi
callq 0x1040
addq %r14, %r15
leaq 0x1893(%rip), %rbp      # 0x47ec
leaq 0x19f8(%rip), %r13      # 0x4958
xorl %r14d, %r14d
cmpl %ebx, %r14d
jae 0x31a9
movzwl (%r15), %r12d
movzwl 0x2(%r15), %edx
leal -0x1001(%rdx), %eax
cmpl $0x8, %eax
jbe 0x2fc0
leal -0x1503(%rdx), %eax
cmpl $0x4, %eax
jbe 0x2fe4
leal -0x1601(%rdx), %eax
cmpl $0x6, %eax
ja 0x3008
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
movl 0x4(%r15), %ecx
movl 0x8(%r15), %r8d
leaq 0xc(%r15), %r9
leaq 0x1cfa(%rip), %rdi      # 0x4cad
movl %r12d, %esi
movl $0x1601, %edx           # imm = 0x1601
jmp 0x316a
leaq 0x17ed(%rip), %rcx      # 0x47b4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1bef(%rip), %rdi      # 0x4bc6
movl %r12d, %esi
movl $0x1001, %edx           # imm = 0x1001
jmp 0x3193
leaq 0x17ed(%rip), %rcx      # 0x47d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1c61(%rip), %rdi      # 0x4c5c
movl %r12d, %esi
movl $0x1503, %edx           # imm = 0x1503
jmp 0x3193
cmpl $0x1201, %edx           # imm = 0x1201
je 0x3184
cmpl $0x1203, %edx           # imm = 0x1203
je 0x3173
cmpl $0x1206, %edx           # imm = 0x1206
jne 0x303c
leaq 0x1c16(%rip), %rdi      # 0x4c45
movl %r12d, %esi
movl $0x1206, %edx           # imm = 0x1206
jmp 0x3193
leaq 0x1cfb(%rip), %rdi      # 0x4d3e
movl %r12d, %esi
jmp 0x3193
leaq 0x1b9d(%rip), %rdi      # 0x4bef
movl %r12d, %esi
movl $0x1008, %edx           # imm = 0x1008
jmp 0x3193
leaq 0x1b9f(%rip), %rdi      # 0x4c05
movl %r12d, %esi
movl $0x1009, %edx           # imm = 0x1009
jmp 0x3193
leaq 0x1b61(%rip), %rdi      # 0x4bdb
movl %r12d, %esi
movl $0x1002, %edx           # imm = 0x1002
jmp 0x3193
leaq 0x16(%r15), %rcx
leaq 0x1bf1(%rip), %rdi      # 0x4c83
movl %r12d, %esi
movl $0x1505, %edx           # imm = 0x1505
jmp 0x30c3
leaq 0x1bf9(%rip), %rdi      # 0x4c9c
movl %r12d, %esi
movl $0x1507, %edx           # imm = 0x1507
jmp 0x3193
leaq 0x16(%r15), %rcx
leaq 0x1bb3(%rip), %rdi      # 0x4c6e
movl %r12d, %esi
movl $0x1504, %edx           # imm = 0x1504
xorl %eax, %eax
callq 0x1090
jmp 0x319a
movl 0x4(%r15), %ecx
leaq 0x8(%r15), %r8
leaq 0x1c1e(%rip), %rdi      # 0x4cfc
movl %r12d, %esi
movl $0x1605, %edx           # imm = 0x1605
xorl %eax, %eax
callq 0x1090
jmp 0x319a
leaq 0x1c24(%rip), %rdi      # 0x4d1d
movl %r12d, %esi
movl $0x1607, %edx           # imm = 0x1607
xorl %eax, %eax
callq 0x1090
leaq 0x1c2b(%rip), %rdi      # 0x4d3a
xorl %eax, %eax
callq 0x1090
xorl %ebp, %ebp
movzwl (%r15), %eax
addq $-0x2, %rax
cmpq %rax, %rbp
jge 0x313a
movzbl 0x4(%r15,%rbp), %esi
movq %r13, %rdi
xorl %eax, %eax
callq 0x1090
incq %rbp
jmp 0x3118
leaq 0x2869(%rip), %rdi      # 0x59aa
callq 0x1060
leaq 0x169f(%rip), %rbp      # 0x47ec
jmp 0x319a
movl 0x4(%r15), %ecx
movl 0x8(%r15), %r8d
leaq 0xc(%r15), %r9
leaq 0x1b72(%rip), %rdi      # 0x4cd4
movl %r12d, %esi
movl $0x1602, %edx           # imm = 0x1602
xorl %eax, %eax
callq 0x1090
jmp 0x319a
leaq 0x1ab5(%rip), %rdi      # 0x4c2f
movl %r12d, %esi
movl $0x1203, %edx           # imm = 0x1203
jmp 0x3193
leaq 0x1a90(%rip), %rdi      # 0x4c1b
movl %r12d, %esi
movl $0x1201, %edx           # imm = 0x1201
xorl %eax, %eax
callq 0x1090
addq $0x2, %r12
addq %r12, %r15
addl %r12d, %r14d
jmp 0x2f63
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq