// File: /workspace/github_c_makefile_star2_O0/mikeakohn[P]print_pe/build/../src/imports.c
// Function: imports_print
int imports_print(
  FILE *in,
  int address,
  int size,
  int address_size,
  struct section_header_t *section_header)
{
  struct import_dir_t import_dir;
  char name[1024];
  long marker;
  int total_size;
  uint32_t virtual_address, raw_ptr;
  int func_addr;
  int t,ptr;

  virtual_address = section_header->VirtualAddress;
  raw_ptr = section_header->PointerToRawData;

  address = (address - virtual_address) + raw_ptr;

  marker = ftell(in);
  fseek(in, address, SEEK_SET);

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

  total_size = 0;

  while (total_size < size)
  {
    import_dir_read(&import_dir, in);

    if (import_dir.FunctionNameList == 0) { break; }

    printf("  FunctionNameList: 0x%04x\n", import_dir.FunctionNameList);
    printf("     TimeDateStamp: %s", ctime((time_t *)&import_dir.TimeDateStamp));
    printf("      ForwardChain: %d\n", import_dir.ForwardChain);
    get_string(in, name, import_dir.ModuleName);
    printf("        ModuleName: ");
    print_string(in, (import_dir.ModuleName - virtual_address) + raw_ptr);
    printf("\n");
    printf("FunctionAddresList: 0x%04x\n", import_dir.FunctionAddressList);
    printf("\n");

    printf("     Function Name                   Address\n");

    t = 0;

    while (1)
    {
      func_addr = get_ptr(in, (import_dir.FunctionAddressList - virtual_address) + raw_ptr + t);

      if (func_addr == 0) { break; }

      ptr = get_ptr(in, (import_dir.FunctionNameList - virtual_address) + raw_ptr + t);
      get_string(in, name, (ptr - virtual_address) + raw_ptr + 2);
      printf("     %-30s  0x%08x\n", name, func_addr);

      t = t + address_size;
    }

    printf("\n");
    total_size = total_size + sizeof(import_dir);
  }

  fseek(in, marker, SEEK_SET);

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x460, %rsp            # imm = 0x460
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x450(%rbp)
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x454(%rbp)
movl -0xc(%rbp), %eax
subl -0x450(%rbp), %eax
addl -0x454(%rbp), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rdi
callq 0x30e0
movq %rax, -0x448(%rbp)
movq -0x8(%rbp), %rdi
movslq -0xc(%rbp), %rsi
xorl %edx, %edx
callq 0x3100
leaq 0x52a7(%rip), %rdi      # 0xb6e5
movb $0x0, %al
callq 0x3080
movl $0x0, -0x44c(%rbp)
movl -0x44c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x65ff
movq -0x8(%rbp), %rsi
leaq -0x34(%rbp), %rdi
callq 0x6620
cmpl $0x0, -0x34(%rbp)
jne 0x6476
jmp 0x65ff
movl -0x34(%rbp), %esi
leaq 0x527f(%rip), %rdi      # 0xb6ff
movb $0x0, %al
callq 0x3080
leaq -0x34(%rbp), %rdi
addq $0x4, %rdi
callq 0x3070
movq %rax, %rsi
leaq 0x48ba(%rip), %rdi      # 0xad58
movb $0x0, %al
callq 0x3080
movl -0x2c(%rbp), %esi
leaq 0x526c(%rip), %rdi      # 0xb71b
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rdi
leaq -0x440(%rbp), %rsi
movl -0x28(%rbp), %edx
callq 0x62a0
leaq 0x5263(%rip), %rdi      # 0xb733
movb $0x0, %al
callq 0x3080
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %esi
subl -0x450(%rbp), %esi
addl -0x454(%rbp), %esi
callq 0x6230
leaq 0x3c36(%rip), %rdi      # 0xa12c
movb $0x0, %al
callq 0x3080
movl -0x24(%rbp), %esi
leaq 0x5241(%rip), %rdi      # 0xb748
movb $0x0, %al
callq 0x3080
leaq 0x3c17(%rip), %rdi      # 0xa12c
movb $0x0, %al
callq 0x3080
leaq 0x5241(%rip), %rdi      # 0xb764
movb $0x0, %al
callq 0x3080
movl $0x0, -0x45c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
subl -0x450(%rbp), %esi
addl -0x454(%rbp), %esi
addl -0x45c(%rbp), %esi
callq 0x6330
movl %eax, -0x458(%rbp)
cmpl $0x0, -0x458(%rbp)
jne 0x6563
jmp 0x65db
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
subl -0x450(%rbp), %esi
addl -0x454(%rbp), %esi
addl -0x45c(%rbp), %esi
callq 0x6330
movl %eax, -0x460(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x440(%rbp), %rsi
movl -0x460(%rbp), %edx
subl -0x450(%rbp), %edx
addl -0x454(%rbp), %edx
addl $0x2, %edx
callq 0x62a0
leaq -0x440(%rbp), %rsi
movl -0x458(%rbp), %edx
leaq 0x51d2(%rip), %rdi      # 0xb792
movb $0x0, %al
callq 0x3080
movl -0x45c(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x45c(%rbp)
jmp 0x6534
leaq 0x3b4a(%rip), %rdi      # 0xa12c
movb $0x0, %al
callq 0x3080
movslq -0x44c(%rbp), %rax
addq $0x14, %rax
movl %eax, -0x44c(%rbp)
jmp 0x644f
movq -0x8(%rbp), %rdi
movq -0x448(%rbp), %rsi
xorl %edx, %edx
callq 0x3100
xorl %eax, %eax
addq $0x460, %rsp            # imm = 0x460
popq %rbp
retq
nopl (%rax)