// File: /workspace/github_c_makefile_star2_O1/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 0x2ac3
movq 0x18(%rbx), %r14
movl (%r14), %ebx
movl 0x4(%r14), %r12d
movl 0x8(%r14), %ebp
movl 0xc(%r14), %r15d
movl 0x10(%r14), %eax
movl %eax, (%rsp)
movzwl 0x14(%r14), %eax
movl %eax, 0x4(%rsp)
movzwl 0x16(%r14), %eax
movl %eax, 0x8(%rsp)
movl 0x18(%r14), %eax
movl %eax, 0xc(%rsp)
movl 0x1c(%r14), %eax
movl %eax, 0x10(%rsp)
movl 0x20(%r14), %eax
movl %eax, 0x14(%rsp)
movl 0x24(%r14), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x2, %r13d
leaq 0x29db(%rip), %rax      # 0x59de
leaq 0x29d8(%rip), %rsi      # 0x59e2
cmoveq %rax, %rsi
movl 0x28(%r14), %eax
movl %eax, 0x18(%rsp)
movl 0x2c(%r14), %eax
movl %eax, 0x20(%rsp)
movl 0x30(%r14), %eax
movl %eax, 0x24(%rsp)
movl 0x34(%r14), %r13d
leaq 0x299b(%rip), %rdi      # 0x59cc
xorl %eax, %eax
callq 0x1090
leaq 0x29a7(%rip), %rdi      # 0x59e6
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x29b7(%rip), %rdi      # 0x5a06
movl %r12d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x29c6(%rip), %rdi      # 0x5a26
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x29d6(%rip), %rdi      # 0x5a46
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x29e5(%rip), %rdi      # 0x5a66
movl (%rsp), %ebx
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x29f2(%rip), %rdi      # 0x5a86
movl 0x4(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a00(%rip), %rdi      # 0x5aa6
movl 0x8(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a0e(%rip), %rdi      # 0x5ac6
movl 0xc(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a1c(%rip), %rdi      # 0x5ae6
movl 0x10(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a2a(%rip), %rdi      # 0x5b06
movl 0x14(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a38(%rip), %rdi      # 0x5b26
movl 0x1c(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a46(%rip), %rdi      # 0x5b46
movl 0x18(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a54(%rip), %rdi      # 0x5b66
movl 0x20(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a62(%rip), %rdi      # 0x5b86
movl 0x24(%rsp), %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2a70(%rip), %rdi      # 0x5ba6
movl %r13d, %esi
xorl %eax, %eax
callq 0x1090
movl $0xa, %edi
callq 0x1040
testl %ebx, %ebx
je 0x33a2
movl %r12d, %eax
addq %rax, %r14
leaq 0x2655(%rip), %rbp      # 0x57b4
leaq 0x2686(%rip), %r15      # 0x57ec
leaq 0x27eb(%rip), %rbx      # 0x5958
xorl %r13d, %r13d
movzwl (%r14), %r12d
movzwl 0x2(%r14), %edx
cmpl $0x1205, %edx           # imm = 0x1205
jle 0x31bc
leal -0x1503(%rdx), %eax
cmpl $0x4, %eax
jbe 0x31e5
leal -0x1601(%rdx), %eax
cmpl $0x6, %eax
ja 0x3260
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl 0x4(%r14), %ecx
movl 0x8(%r14), %r8d
leaq 0xc(%r14), %r9
leaq 0x2af6(%rip), %rdi      # 0x5cad
jmp 0x3393
leal -0x1001(%rdx), %eax
cmpl $0x8, %eax
ja 0x3209
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
leaq 0x29ee(%rip), %rdi      # 0x5bc6
movl %r12d, %esi
movl $0x1001, %edx           # imm = 0x1001
jmp 0x32ba
leaq 0x25ec(%rip), %rcx      # 0x57d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x2a60(%rip), %rdi      # 0x5c5c
movl %r12d, %esi
movl $0x1503, %edx           # imm = 0x1503
jmp 0x32ba
cmpl $0x1201, %edx           # imm = 0x1201
je 0x3285
cmpl $0x1203, %edx           # imm = 0x1203
jne 0x3279
leaq 0x2a0f(%rip), %rdi      # 0x5c2f
movl %r12d, %esi
movl $0x1203, %edx           # imm = 0x1203
jmp 0x32ba
leaq 0x29bb(%rip), %rdi      # 0x5bef
movl %r12d, %esi
movl $0x1008, %edx           # imm = 0x1008
jmp 0x32ba
leaq 0x29c0(%rip), %rdi      # 0x5c05
movl %r12d, %esi
movl $0x1009, %edx           # imm = 0x1009
jmp 0x32ba
leaq 0x2985(%rip), %rdi      # 0x5bdb
movl %r12d, %esi
movl $0x1002, %edx           # imm = 0x1002
jmp 0x32ba
cmpl $0x1206, %edx           # imm = 0x1206
jne 0x3279
leaq 0x29d6(%rip), %rdi      # 0x5c45
movl %r12d, %esi
movl $0x1206, %edx           # imm = 0x1206
jmp 0x32ba
leaq 0x2abe(%rip), %rdi      # 0x5d3e
movl %r12d, %esi
jmp 0x32ba
leaq 0x298f(%rip), %rdi      # 0x5c1b
movl %r12d, %esi
movl $0x1201, %edx           # imm = 0x1201
jmp 0x32ba
leaq 0x16(%r14), %rcx
leaq 0x29e2(%rip), %rdi      # 0x5c83
movl %r12d, %esi
movl $0x1505, %edx           # imm = 0x1505
jmp 0x32ed
leaq 0x29ea(%rip), %rdi      # 0x5c9c
movl %r12d, %esi
movl $0x1507, %edx           # imm = 0x1507
xorl %eax, %eax
callq 0x1090
addq $0x2, %r12
addq %r12, %r14
addl %r12d, %r13d
cmpl (%rsp), %r13d
jb 0x3170
jmp 0x33a2
leaq 0x16(%r14), %rcx
leaq 0x2989(%rip), %rdi      # 0x5c6e
movl %r12d, %esi
movl $0x1504, %edx           # imm = 0x1504
xorl %eax, %eax
callq 0x1090
jmp 0x32c1
movl 0x4(%r14), %ecx
leaq 0x8(%r14), %r8
leaq 0x29f7(%rip), %rdi      # 0x5cfc
movl %r12d, %esi
xorl %eax, %eax
callq 0x1090
jmp 0x32c1
leaq 0x2a05(%rip), %rdi      # 0x5d1d
movl %r12d, %esi
movl $0x1607, %edx           # imm = 0x1607
xorl %eax, %eax
callq 0x1090
leaq 0x2a0c(%rip), %rdi      # 0x5d3a
xorl %eax, %eax
callq 0x1090
cmpw $0x3, (%r14)
jb 0x3361
movq %rbx, %r15
xorl %ebp, %ebp
movzbl 0x4(%r14,%rbp), %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0x1090
incq %rbp
movzwl (%r14), %eax
addq $-0x2, %rax
cmpq %rax, %rbp
jl 0x3341
leaq 0x3642(%rip), %rdi      # 0x69aa
callq 0x1060
leaq 0x2440(%rip), %rbp      # 0x57b4
leaq 0x2471(%rip), %r15      # 0x57ec
jmp 0x32c1
movl 0x4(%r14), %ecx
movl 0x8(%r14), %r8d
leaq 0xc(%r14), %r9
leaq 0x2941(%rip), %rdi      # 0x5cd4
movl %r12d, %esi
xorl %eax, %eax
callq 0x1090
jmp 0x32c1
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq