// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_identify
int elf32_identify(struct FFFuncs *ff,char *name,struct Elf32_Ehdr *p,
                   unsigned long plen,unsigned char class,
                   unsigned char endian,uint16_t machine,uint32_t ver)
/* check a possible ELF file against the requirements, then */
/* return its type (object, library, shared object) */
{
  bool arflag = FALSE;
  bool be = (endian == ELFDATA2MSB);
  struct ar_info ai;

  if (plen < sizeof(struct Elf32_Ehdr))
    return ID_UNKNOWN;

  if (ar_init(&ai,(char *)p,plen,name)) {
    /* library archive detected, extract 1st archive member */
    arflag = TRUE;
    if (!(ar_extract(&ai))) {
      error(38,name);  /* Empty archive ignored */
      return ID_IGNORE;
    }
    p = (struct Elf32_Ehdr *)ai.data;
  }

  if (!strncmp(p->e_ident,ELFid,4)) {
    /* ELF identification found */
    if (p->e_ident[EI_CLASS]==class && p->e_ident[EI_DATA]==endian &&
        p->e_ident[EI_VERSION]==(unsigned char)ver &&
        read32(be,p->e_version)==ver && read16(be,p->e_machine)==machine) {
      switch (read16(be,p->e_type)) {
        case ET_REL:
          return arflag ? ID_LIBARCH : ID_OBJECT;
        case ET_EXEC:
          if (arflag) /* no executables in library archives */
            error(40,name,ff->tname);
          return ID_EXECUTABLE;
        case ET_DYN:
          if (arflag) /* no shared objects in library archives */
            error(39,name,ff->tname);
          return ID_SHAREDOBJ;
        default:
          error(41,name,ff->tname);  /* illegal fmt. / file corrupted */
          break;
      }
    }
  }

  return ID_UNKNOWN;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
cmpl $0x2, %r9d
sete %r12b
xorl %ebx, %ebx
cmpq $0x34, %rcx
jb 0x12d93
movl %r9d, %r15d
movl %r8d, %ebp
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r14, %rcx
callq 0xc6e0
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0x12ceb
leaq 0x10(%rsp), %rdi
callq 0xc745
testl %eax, %eax
je 0x12d83
movq 0x138(%rsp), %r13
leaq 0x1cb9e(%rip), %rsi     # 0x2f890
pushq $0x4
popq %rdx
movq %r13, %rdi
callq 0x5070
testl %eax, %eax
jne 0x12d93
cmpb %bpl, 0x4(%r13)
jne 0x12d93
cmpb %r15b, 0x5(%r13)
jne 0x12d93
movl 0x188(%rsp), %ebp
cmpb %bpl, 0x6(%r13)
jne 0x12d93
xorl %r15d, %r15d
movb %r12b, %r15b
leaq 0x14(%r13), %rsi
movl %r15d, %edi
callq 0x664d
cmpl %ebp, %eax
jne 0x12d93
movzwl 0x180(%rsp), %ebp
leaq 0x12(%r13), %rsi
movl %r15d, %edi
callq 0x663d
cmpw %bp, %ax
jne 0x12d93
addq $0x10, %r13
movl %r15d, %edi
movq %r13, %rsi
callq 0x663d
cmpw $0x3, %ax
je 0x12dbd
movzwl %ax, %eax
cmpl $0x2, %eax
je 0x12da7
cmpl $0x1, %eax
jne 0x12dd3
cmpl $0x0, 0x4(%rsp)
pushq $0x1
popq %rax
pushq $0x8
popq %rbx
cmovel %eax, %ebx
jmp 0x12d93
pushq $0x26
popq %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x6c19
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x2
popq %rbx
cmpl $0x0, 0x4(%rsp)
je 0x12d93
movq 0x8(%rsp), %rax
movq (%rax), %rdx
pushq $0x28
jmp 0x12ddf
pushq $0x4
popq %rbx
cmpl $0x0, 0x4(%rsp)
je 0x12d93
movq 0x8(%rsp), %rax
movq (%rax), %rdx
pushq $0x27
jmp 0x12ddf
movq 0x8(%rsp), %rax
movq (%rax), %rdx
xorl %ebx, %ebx
pushq $0x29
popq %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x6c19
jmp 0x12d93