// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_parse
void elf32_parse(struct GlobalVars *gv,struct LinkFile *lf,
                 struct Elf32_Ehdr *ehdr,
                 uint8_t (*reloc_elf2vlink)(uint8_t,struct RelocInsert *))
/* parses a complete ELF file and converts into vlink-internal format */
{
  static const char *fn = "elf32_parse(): ";
  bool be = (ehdr->e_ident[EI_DATA] == ELFDATA2MSB);
  struct ObjectUnit *u;
  struct Elf32_Shdr *shdr;
  uint16_t i,num_shdr,dynstr_idx,dynsym_idx;
  char *shstrtab,*dynstrtab;
  struct Elf32_Dyn *dyn;

  shstrtab = elf32_shstrtab(lf,ehdr);
  u = create_objunit(gv,lf,lf->objname);

  switch (read16(be,ehdr->e_type)) {

    case ET_REL:  /* relocatable object file */
      if (read16(be,ehdr->e_phnum) > 0)
        error(47,lf->pathname,lf->objname);  /* ignoring program hdr. tab */
      num_shdr = read16(be,ehdr->e_shnum);

      /* create vlink sections */
      for (i=1; i<num_shdr; i++) {
        shdr = elf32_shdr(lf,ehdr,i);

        switch (read32(be,shdr->sh_type)) {
          case SHT_PROGBITS:
          case SHT_NOBITS:
          case SHT_NOTE:
            /* create a new section */
            elf32_section(gv,ehdr,u,shdr,i,shstrtab);
          default:
            break;
        }
      }

      /* parse the other section headers */
      for (i=1; i<num_shdr; i++) {
        shdr = elf32_shdr(lf,ehdr,i);

        switch (read32(be,shdr->sh_type)) {
          case SHT_NULL:
          case SHT_STRTAB:
          case SHT_NOTE:
          case SHT_PROGBITS:
          case SHT_NOBITS:
            break;
          case SHT_SYMTAB:
            elf32_symbols(gv,ehdr,u,shdr);  /* symbol definitions */
            break;
          case SHT_REL:
          case SHT_RELA:
            elf32_reloc(gv,ehdr,u,shdr,shstrtab,be,reloc_elf2vlink);
            break;
          default:
            /* section header type not needed in relocatable objects */
            error(48,lf->pathname,read32(be,shdr->sh_type),lf->objname);
            break;
        }
      }

      elf32_stabs(gv,lf,ehdr,u);  /* convert .stab into internal format */
      break;


    case ET_DYN:  /* shared object file */
      dynstrtab = NULL;
      dyn = NULL;
      dynstr_idx = dynsym_idx = 0;
      num_shdr = read16(be,ehdr->e_shnum);

      /* create vlink sections */
      for (i=1; i<num_shdr; i++) {
        shdr = elf32_shdr(lf,ehdr,i);

        switch (read32(be,shdr->sh_type)) {
          case SHT_DYNAMIC:
            /* remember pointer to .dynamic section contents */
            dyn = (struct Elf32_Dyn *)((uint8_t *)ehdr
                                       + read32(be,shdr->sh_offset));
            break;
          case SHT_DYNSYM:
            dynsym_idx = i;
            break;
          case SHT_PROGBITS:
          case SHT_NOBITS:
            /* create a new section */
            elf32_section(gv,ehdr,u,shdr,i,shstrtab);
          default:
            break;
        }
      }

      /* parse the other section headers */
      for (i=1; i<num_shdr; i++) {
        shdr = elf32_shdr(lf,ehdr,i);

        switch (read32(be,shdr->sh_type)) {
          case SHT_NULL:
          case SHT_STRTAB:
          case SHT_NOTE:
          case SHT_PROGBITS:
          case SHT_NOBITS:
          case SHT_HASH:
          case SHT_DYNAMIC:
          case SHT_SYMTAB:
            break;
          case SHT_DYNSYM:
            dynstr_idx = read32(be,shdr->sh_link);
            elf32_symbols(gv,ehdr,u,shdr);  /* symbol definitions */
            break;
          case SHT_REL:
          case SHT_RELA:
            if (fff[gv->dest_format]->flags & FFF_DYN_RESOLVE_ALL) {
              /* The dynamic link editor is limited, so we even have to
                 resolve references from the shared object at link time.
                 But only those which are linked to .dynsym. */
              if (read32(be,shdr->sh_link) == dynsym_idx)
                elf32_dynrefs(gv,ehdr,u,shdr,be,reloc_elf2vlink);
            }
            break;
          default:
            /* section header type not needed in shared objects */
            error(60,lf->pathname,read32(be,shdr->sh_type),lf->objname);
            break;
        }
      }

      if (dynstr_idx!=0 && dyn!=NULL) {
        /* set ObjectUnit's objname to the SONAME of the shared object */
        uint32_t tag;

        shdr = elf32_shdr(lf,ehdr,dynstr_idx);  /* .dynstr */
        while (tag = read32(be,dyn->d_tag)) {
          if (tag == DT_SONAME) {
            u->objname = (char *)ehdr + read32(be,shdr->sh_offset)
                         + read32(be,dyn->d_val);
            break;
          }
          dyn++;
        }
      }
      break;


    case ET_EXEC: /* executable file */
      /* @@@ */
      ierror("%s%s: Executables are currently not supported",fn,lf->pathname);
      break;


    default:
      error(41,lf->pathname,lf->objname);  /* illegal fmt./file corrupted */
      break;
  }

  /* add new object unit to the appropriate list */
  add_objunit(gv,u,FALSE);
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movq 0x90(%rsp), %rax
movb 0x5(%rax), %al
subb $0x2, %al
sete %al
movzbl %al, %eax
movl %eax, 0x84(%rsp)
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x1f690
movq %rax, 0x60(%rsp)
movq 0xa0(%rsp), %rdi
movq 0x98(%rsp), %rsi
movq 0x20(%rsi), %rdx
callq 0x12270
movq %rax, 0x78(%rsp)
movl 0x84(%rsp), %edi
movq 0x90(%rsp), %rsi
addq $0x10, %rsi
callq 0x8010
movzwl %ax, %ecx
movl %ecx, 0x48(%rsp)
subw $0x1, %ax
je 0x207c1
jmp 0x207a0
movl 0x48(%rsp), %eax
subl $0x2, %eax
je 0x20de2
jmp 0x207af
movl 0x48(%rsp), %eax
subl $0x3, %eax
je 0x20a40
jmp 0x20e05
movl 0x84(%rsp), %edi
movq 0x90(%rsp), %rsi
addq $0x2c, %rsi
callq 0x8010
movzwl %ax, %eax
cmpl $0x0, %eax
jle 0x20805
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x98(%rsp), %rax
movq 0x20(%rax), %rdx
movl $0x2f, %edi
movb $0x0, %al
callq 0x8c00
movl 0x84(%rsp), %edi
movq 0x90(%rsp), %rsi
addq $0x30, %rsi
callq 0x8010
movw %ax, 0x6c(%rsp)
movw $0x1, 0x6e(%rsp)
movzwl 0x6e(%rsp), %eax
movzwl 0x6c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x208cb
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movzwl 0x6e(%rsp), %edx
callq 0x1f7f0
movq %rax, 0x70(%rsp)
movl 0x84(%rsp), %edi
movq 0x70(%rsp), %rsi
addq $0x4, %rsi
callq 0x8060
movl %eax, %ecx
movl %ecx, 0x44(%rsp)
subl $0x1, %eax
je 0x2088a
jmp 0x2087c
movl 0x44(%rsp), %eax
addl $-0x7, %eax
subl $0x1, %eax
ja 0x208b4
jmp 0x2088a
movq 0xa0(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rcx
movzwl 0x6e(%rsp), %r8d
movq 0x60(%rsp), %r9
callq 0x1fbd0
jmp 0x208b6
jmp 0x208b8
movw 0x6e(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x6e(%rsp)
jmp 0x20829
movw $0x1, 0x6e(%rsp)
movzwl 0x6e(%rsp), %eax
movzwl 0x6c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x20a19
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movzwl 0x6e(%rsp), %edx
callq 0x1f7f0
movq %rax, 0x70(%rsp)
movl 0x84(%rsp), %edi
movq 0x70(%rsp), %rsi
addq $0x4, %rsi
callq 0x8060
movl %eax, %ecx
movl %ecx, 0x40(%rsp)
subl $0x2, %eax
jb 0x2095f
jmp 0x20925
movl 0x40(%rsp), %eax
subl $0x2, %eax
je 0x20964
jmp 0x20930
movl 0x40(%rsp), %eax
subl $0x3, %eax
je 0x2095f
jmp 0x2093b
movl 0x40(%rsp), %eax
subl $0x4, %eax
je 0x20985
jmp 0x20946
movl 0x40(%rsp), %eax
addl $-0x7, %eax
subl $0x2, %eax
jb 0x2095f
jmp 0x20954
movl 0x40(%rsp), %eax
subl $0x9, %eax
je 0x20985
jmp 0x209bf
jmp 0x20a04
movq 0xa0(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rcx
callq 0x1ff40
jmp 0x20a04
movq 0xa0(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rcx
movq 0x60(%rsp), %r8
movl 0x84(%rsp), %r9d
movq 0x88(%rsp), %rax
movq %rax, (%rsp)
callq 0x20e50
jmp 0x20a04
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x38(%rsp)
movl 0x84(%rsp), %edi
movq 0x70(%rsp), %rsi
addq $0x4, %rsi
callq 0x8060
movq 0x38(%rsp), %rsi
movl %eax, %edx
movq 0x98(%rsp), %rax
movq 0x20(%rax), %rcx
movl $0x30, %edi
movb $0x0, %al
callq 0x8c00
jmp 0x20a06
movw 0x6e(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x6e(%rsp)
jmp 0x208d2
movq 0xa0(%rsp), %rdi
movq 0x98(%rsp), %rsi
movq 0x90(%rsp), %rdx
movq 0x78(%rsp), %rcx
callq 0x216f0
jmp 0x20e29
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movw $0x0, 0x68(%rsp)
movw $0x0, 0x6a(%rsp)
movl 0x84(%rsp), %edi
movq 0x90(%rsp), %rsi
addq $0x30, %rsi
callq 0x8010
movw %ax, 0x6c(%rsp)
movw $0x1, 0x6e(%rsp)
movzwl 0x6e(%rsp), %eax
movzwl 0x6c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x20b73
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movzwl 0x6e(%rsp), %edx
callq 0x1f7f0
movq %rax, 0x70(%rsp)
movl 0x84(%rsp), %edi
movq 0x70(%rsp), %rsi
addq $0x4, %rsi
callq 0x8060
decl %eax
movl %eax, %ecx
movq %rcx, 0x30(%rsp)
subl $0xa, %eax
ja 0x20b5c
movq 0x30(%rsp), %rax
leaq 0x156a8(%rip), %rcx     # 0x36190
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x90(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0x84(%rsp), %edi
movq 0x70(%rsp), %rsi
addq $0x10, %rsi
callq 0x8060
movl %eax, %ecx
movq 0x28(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x20b5e
movw 0x6e(%rsp), %ax
movw %ax, 0x68(%rsp)
jmp 0x20b5e
movq 0xa0(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rcx
movzwl 0x6e(%rsp), %r8d
movq 0x60(%rsp), %r9
callq 0x1fbd0
jmp 0x20b5e
jmp 0x20b60
movw 0x6e(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x6e(%rsp)
jmp 0x20a84
movw $0x1, 0x6e(%rsp)
movzwl 0x6e(%rsp), %eax
movzwl 0x6c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x20d14
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movzwl 0x6e(%rsp), %edx
callq 0x1f7f0
movq %rax, 0x70(%rsp)
movl 0x84(%rsp), %edi
movq 0x70(%rsp), %rsi
addq $0x4, %rsi
callq 0x8060
movl %eax, %ecx
movl %ecx, 0x24(%rsp)
subl $0x4, %eax
jb 0x20bff
jmp 0x20bcd
movl 0x24(%rsp), %eax
subl $0x4, %eax
je 0x20c42
jmp 0x20bd8
movl 0x24(%rsp), %eax
addl $-0x5, %eax
subl $0x4, %eax
jb 0x20bff
jmp 0x20be6
movl 0x24(%rsp), %eax
subl $0x9, %eax
je 0x20c42
jmp 0x20bf1
movl 0x24(%rsp), %eax
subl $0xb, %eax
je 0x20c04
jmp 0x20cba
jmp 0x20cff
movl 0x84(%rsp), %edi
movq 0x70(%rsp), %rsi
addq $0x18, %rsi
callq 0x8060
movw %ax, 0x6a(%rsp)
movq 0xa0(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rcx
callq 0x1ff40
jmp 0x20cff
movq 0xa0(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x1edd9(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movl 0xac(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x20cb8
movl 0x84(%rsp), %edi
movq 0x70(%rsp), %rsi
addq $0x18, %rsi
callq 0x8060
movzwl 0x68(%rsp), %ecx
cmpl %ecx, %eax
jne 0x20cb6
movq 0xa0(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rcx
movl 0x84(%rsp), %r8d
movq 0x88(%rsp), %r9
callq 0x21b20
jmp 0x20cb8
jmp 0x20cff
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x18(%rsp)
movl 0x84(%rsp), %edi
movq 0x70(%rsp), %rsi
addq $0x4, %rsi
callq 0x8060
movq 0x18(%rsp), %rsi
movl %eax, %edx
movq 0x98(%rsp), %rax
movq 0x20(%rax), %rcx
movl $0x3c, %edi
movb $0x0, %al
callq 0x8c00
jmp 0x20d01
movw 0x6e(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x6e(%rsp)
jmp 0x20b7a
movzwl 0x6a(%rsp), %eax
cmpl $0x0, %eax
je 0x20de0
cmpq $0x0, 0x50(%rsp)
je 0x20de0
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movzwl 0x6a(%rsp), %edx
callq 0x1f7f0
movq %rax, 0x70(%rsp)
movl 0x84(%rsp), %edi
movq 0x50(%rsp), %rsi
callq 0x8060
movl %eax, 0x4c(%rsp)
cmpl $0x0, %eax
je 0x20dde
cmpl $0xe, 0x4c(%rsp)
jne 0x20dcb
movq 0x90(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x84(%rsp), %edi
movq 0x70(%rsp), %rsi
addq $0x10, %rsi
callq 0x8060
movl %eax, %ecx
movq 0x8(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movl 0x84(%rsp), %edi
movq 0x50(%rsp), %rsi
addq $0x4, %rsi
callq 0x8060
movq 0x10(%rsp), %rcx
movl %eax, %eax
addq %rax, %rcx
movq 0x78(%rsp), %rax
movq %rcx, 0x18(%rax)
jmp 0x20dde
movq 0x50(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x50(%rsp)
jmp 0x20d4d
jmp 0x20de0
jmp 0x20e29
movq 0x1f56f(%rip), %rsi     # 0x40358
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rdx
leaq 0x1556d(%rip), %rdi     # 0x36369
movb $0x0, %al
callq 0x8ae0
jmp 0x20e29
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x98(%rsp), %rax
movq 0x20(%rax), %rdx
movl $0x29, %edi
movb $0x0, %al
callq 0x8c00
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %rsi
xorl %edx, %edx
callq 0x123e0
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)