// File: /workspace/github_c_makefile_star2_O1/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_symbols
void elf32_symbols(struct GlobalVars *gv,struct Elf32_Ehdr *ehdr,
                   struct ObjectUnit *ou,struct Elf32_Shdr *shdr)
/* convert ELF symbol definitions into internal format */
{
  bool be = (ehdr->e_ident[EI_DATA] == ELFDATA2MSB);
  uint8_t flags = (read32(be,shdr->sh_type)==SHT_DYNSYM) ? SYMF_SHLIB : 0;
  struct LinkFile *lf = ou->lnkfile;
  uint8_t *data = (uint8_t *)ehdr + read32(be,shdr->sh_offset);
  unsigned long entsize = read32(be,shdr->sh_entsize);
  int nsyms = (int)(read32(be,shdr->sh_size) / (uint32_t)entsize);
  char *strtab = elf32_strtab(lf,ehdr,read32(be,shdr->sh_link));
  struct Section *sec;
  struct Elf32_Sym *elfsym;

  if ((data < lf->data) || 
      (data + read32(be,shdr->sh_size) > lf->data + lf->length))
    error(51,lf->pathname,"symbol",lf->objname);  /* illegal offset */

  /* read ELF xdef symbols and convert to internal format */
  while (--nsyms > 0) {
    int shndx;
    char *symname;
    uint8_t type=0;
    uint8_t objinfo,objbind;

    elfsym = (struct Elf32_Sym *)(data += entsize);
    symname = strtab + read32(be,elfsym->st_name);
    if (symname<(char *)lf->data || symname>(char *)lf->data+lf->length)
      error(127,lf->pathname,read32(be,elfsym->st_name),lf->objname);

    if (flags & SYMF_SHLIB) {
      /* don't import linker symbols from shared objects - we make our own */
      int i;

      for (i=0; i<(sizeof(elf32_symnames)/sizeof(elf32_symnames[0])); i++) {
        if (!strcmp(elf32_symnames[i],symname)) {
          symname = NULL;
          break;
        }
      }
      if (!symname)
        continue;
    }

    switch (shndx = (int)read16(be,elfsym->st_shndx)) {
      case SHN_UNDEF:
        sec = NULL;  /* ignore xrefs for now */
        break;
      /* assign a section for ABS and COMMON symbols */
      case SHN_ABS:
        sec = abs_section(ou);
        type = SYM_ABS;
        break;
      case SHN_COMMON:
        sec = common_section(gv,ou);
        type = SYM_COMMON;
        break;
      /* reloc symbols have a definite section to which they belong */
      default:
        if (read32(be,shdr->sh_type) == SHT_DYNSYM) {
          /* just put dynamic symbols into the first section -
             the section index might be wrong in .dynsym */
          sec = abs_section(ou);
        }
        else if (!(sec = find_sect_id(ou,shndx))) {
          /* a section with this index doesn't exist! */
          if (ELF32_ST_TYPE(*elfsym->st_info) != STT_SECTION)
            error(53,lf->pathname,symname,lf->objname,shndx);
        }
        type = SYM_RELOC;
        break;
    }

    if ((objinfo = ELF32_ST_TYPE(*elfsym->st_info)) == STT_SECTION)
      sec = NULL;  /* ignore section defines - will be reproduced */

    if (sec) {
      if (objinfo > STT_FILE) {
        /* illegal symbol type */
        error(54,lf->pathname,(int)objinfo,symname,lf->objname);
        objinfo = STT_NOTYPE;
      }
      switch (ELF32_ST_BIND(*elfsym->st_info)) {
        case STB_LOCAL:
          objbind = SYMB_LOCAL;
          break;
        case STB_GLOBAL:
          objbind = SYMB_GLOBAL;
          break;
        case STB_WEAK:
          objbind = SYMB_WEAK;
          break;
        default:  /* illegal binding type */
          error(55,lf->pathname,symname,ELF32_ST_BIND(*elfsym->st_info),
                lf->objname);
          objbind = SYMB_LOCAL;
          break;
      }

      /* add a new symbol definition */
      if (objbind == SYMB_LOCAL) {
        addlocsymbol(gv,sec,symname,NULL,(int32_t)read32(be,elfsym->st_value),
                     type,flags,objinfo,read32(be,elfsym->st_size));
      }
      else {
        addsymbol(gv,sec,symname,NULL,(int32_t)read32(be,elfsym->st_value),
                  type,flags,objinfo,objbind,read32(be,elfsym->st_size),TRUE);
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r13
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, 0x20(%rsp)
xorl %r14d, %r14d
cmpb $0x2, 0x5(%rsi)
sete %r14b
leaq 0x4(%rcx), %rsi
movl %r14d, %edi
movq %rsi, 0x40(%rsp)
callq 0x69b3
movl %eax, 0x4(%rsp)
cmpl $0xb, %eax
sete 0x3(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x10(%rbx), %rbx
leaq 0x10(%r13), %rsi
movl %r14d, %edi
callq 0x69b3
movl %eax, %r15d
addq %r12, %r15
leaq 0x24(%r13), %rsi
movl %r14d, %edi
callq 0x69b3
movl %eax, %ebp
leaq 0x14(%r13), %rsi
movl %r14d, %edi
movq %rsi, 0x8(%rsp)
callq 0x69b3
xorl %edx, %edx
movl %ebp, 0x28(%rsp)
divl %ebp
movq %rax, 0x30(%rsp)
addq $0x18, %r13
movl %r14d, %edi
movq %r13, %rsi
callq 0x69b3
movq %rbx, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x14362
movq %rax, 0x50(%rsp)
cmpq 0x28(%rbx), %r15
jb 0x1478f
movl %r14d, %edi
movq 0x8(%rsp), %rsi
callq 0x69b3
movl %eax, %eax
addq %r15, %rax
movq 0x28(%rbx), %rcx
addq 0x30(%rbx), %rcx
cmpq %rcx, %rax
jbe 0x147aa
movq 0x10(%rbx), %rsi
movq 0x20(%rbx), %rcx
leaq 0xcf71(%rip), %rdx      # 0x2170f
movl $0x33, %edi
xorl %eax, %eax
callq 0x6f84
movq %rbx, 0x8(%rsp)
cmpl $0x2, 0x30(%rsp)
movl 0x4(%rsp), %r13d
jl 0x14a2f
movl 0x28(%rsp), %eax
movq %rax, 0x28(%rsp)
shlb $0x4, 0x3(%rsp)
movl %r14d, 0x14(%rsp)
addq 0x28(%rsp), %r15
movl %r14d, %edi
movq %r15, %rsi
callq 0x69b3
movl %eax, %r12d
addq 0x50(%rsp), %r12
movq 0x8(%rsp), %rbp
movq 0x28(%rbp), %rax
cmpq %rax, %r12
jb 0x14801
addq 0x30(%rbp), %rax
cmpq %rax, %r12
jbe 0x14825
movq 0x10(%rbp), %rbx
movl %r14d, %edi
movq %r15, %rsi
callq 0x69b3
movq 0x20(%rbp), %rcx
movl $0x7f, %edi
movq %rbx, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x6f84
cmpl $0xb, %r13d
jne 0x1485c
xorl %ebx, %ebx
leaq 0x1afec(%rip), %rbp     # 0x2f820
movq (%rbx,%rbp), %rdi
movq %r12, %rsi
callq 0x5160
testl %eax, %eax
je 0x14850
addq $0x8, %rbx
cmpq $0x38, %rbx
jne 0x14834
jmp 0x14853
xorl %r12d, %r12d
testq %r12, %r12
je 0x14a19
leaq 0xe(%r15), %rsi
movl %r14d, %edi
callq 0x6993
testw %ax, %ax
je 0x148a1
movzwl %ax, %ebp
cmpl $0xfff2, %ebp           # imm = 0xFFF2
je 0x1488e
cmpl $0xfff1, %ebp           # imm = 0xFFF1
jne 0x148a7
movq 0x18(%rsp), %rdi
callq 0xc30c
movb $0x1, %bl
jmp 0x14905
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xc242
movb $0x3, %bl
jmp 0x14905
xorl %eax, %eax
xorl %ebx, %ebx
jmp 0x14905
movl %r14d, %edi
movq 0x40(%rsp), %rsi
callq 0x69b3
cmpl $0xb, %eax
jne 0x148c7
movq 0x18(%rsp), %rdi
callq 0xc30c
movb $0x2, %bl
jmp 0x14905
movq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0xbe4a
movb $0x2, %bl
testq %rax, %rax
jne 0x14905
movb 0xc(%r15), %al
andb $0xf, %al
cmpb $0x3, %al
je 0x14903
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rax), %rcx
movl $0x35, %edi
movq %r12, %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x6f84
xorl %eax, %eax
movzbl 0xc(%r15), %ebp
andl $0xf, %ebp
cmpl $0x3, %ebp
je 0x14a19
testq %rax, %rax
je 0x14a19
movq %rax, 0x38(%rsp)
cmpb $0x5, %bpl
jb 0x1494a
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rax), %r8
movl $0x36, %edi
movl %ebp, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0x6f84
xorl %ebp, %ebp
movq %rbx, 0x48(%rsp)
movzbl 0xc(%r15), %eax
movl %eax, %r13d
shrl $0x4, %r13d
cmpl $0x30, %eax
jae 0x1496f
movl %r13d, %ecx
andb $0x7, %cl
movb $0x1, %bl
shrb %cl, %bl
incb %r13b
jmp 0x14993
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rax), %r8
movl $0x37, %edi
movq %r12, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x6f84
movb $0x1, %bl
movb $0x1, %r13b
leaq 0x4(%r15), %rsi
movl %r14d, %edi
callq 0x69b3
movl %r14d, %edi
movslq %eax, %r14
leaq 0x8(%r15), %rsi
callq 0x69b3
movzbl %bpl, %r11d
movzbl 0x3(%rsp), %r10d
movzbl 0x48(%rsp), %r9d
subq $0x8, %rsp
testb %bl, %bl
je 0x149e8
movq 0x28(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq %r14, %r8
pushq %rax
pushq %r11
pushq %r10
callq 0xadae
addq $0x20, %rsp
jmp 0x14a0f
movzbl %r13b, %ebx
movq 0x28(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq %r14, %r8
pushq $0x1
pushq %rax
pushq %rbx
pushq %r11
pushq %r10
callq 0xaba4
addq $0x30, %rsp
movl 0x14(%rsp), %r14d
movl 0x4(%rsp), %r13d
movq 0x30(%rsp), %rcx
leal -0x1(%rcx), %eax
cmpl $0x2, %ecx
movq %rax, 0x30(%rsp)
jg 0x147d2
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq