// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x198, %rsp            # imm = 0x198
movl %r8d, 0xc(%rsp)
movq %rcx, %rax
movl 0xc(%rsp), %ecx
movq %rax, 0x10(%rsp)
movq %rdx, %rax
movq 0x10(%rsp), %rdx
movq %rax, 0x18(%rsp)
movq %rsi, %rax
movq 0x18(%rsp), %rsi
movq %rax, 0x20(%rsp)
movq %rdi, %r8
movq 0x20(%rsp), %rdi
movb %r9b, %al
movl 0x1a8(%rsp), %r9d
movw 0x1a0(%rsp), %r9w
movq %r8, 0x188(%rsp)
movq %rdi, 0x180(%rsp)
movq %rsi, 0x178(%rsp)
movq %rdx, 0x170(%rsp)
movb %cl, 0x16f(%rsp)
movb %al, 0x16e(%rsp)
movl $0x0, 0x168(%rsp)
movzbl 0x16e(%rsp), %eax
cmpl $0x2, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x164(%rsp)
cmpq $0x34, 0x170(%rsp)
jae 0x1f15c
movl $0x0, 0x194(%rsp)
jmp 0x1f396
movq 0x178(%rsp), %rsi
movq 0x170(%rsp), %rdx
movq 0x180(%rsp), %rcx
leaq 0x28(%rsp), %rdi
callq 0x13d60
cmpl $0x0, %eax
je 0x1f1d1
movl $0x1, 0x168(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x13e00
cmpl $0x0, %eax
jne 0x1f1c1
movq 0x180(%rsp), %rsi
movl $0x26, %edi
movb $0x0, %al
callq 0x8c00
movl $0xffffffff, 0x194(%rsp) # imm = 0xFFFFFFFF
jmp 0x1f396
movq 0x150(%rsp), %rax
movq %rax, 0x178(%rsp)
movq 0x178(%rsp), %rdi
leaq 0x21160(%rip), %rsi     # 0x40340
movl $0x4, %edx
callq 0x5050
cmpl $0x0, %eax
jne 0x1f38b
movq 0x178(%rsp), %rax
movzbl 0x4(%rax), %eax
movzbl 0x16f(%rsp), %ecx
cmpl %ecx, %eax
jne 0x1f389
movq 0x178(%rsp), %rax
movzbl 0x5(%rax), %eax
movzbl 0x16e(%rsp), %ecx
cmpl %ecx, %eax
jne 0x1f389
movq 0x178(%rsp), %rax
movzbl 0x6(%rax), %eax
movl 0x1a8(%rsp), %ecx
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x1f389
movl 0x164(%rsp), %edi
movq 0x178(%rsp), %rsi
addq $0x14, %rsi
callq 0x8060
cmpl 0x1a8(%rsp), %eax
jne 0x1f389
movl 0x164(%rsp), %edi
movq 0x178(%rsp), %rsi
addq $0x12, %rsi
callq 0x8010
movzwl %ax, %eax
movzwl 0x1a0(%rsp), %ecx
cmpl %ecx, %eax
jne 0x1f389
movl 0x164(%rsp), %edi
movq 0x178(%rsp), %rsi
addq $0x10, %rsi
callq 0x8010
movzwl %ax, %ecx
movl %ecx, 0x8(%rsp)
subw $0x1, %ax
je 0x1f2d9
jmp 0x1f2c0
movl 0x8(%rsp), %eax
subl $0x2, %eax
je 0x1f2fc
jmp 0x1f2cb
movl 0x8(%rsp), %eax
subl $0x3, %eax
je 0x1f332
jmp 0x1f368
movl 0x168(%rsp), %edx
movl $0x1, %eax
movl $0x8, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, 0x194(%rsp)
jmp 0x1f396
cmpl $0x0, 0x168(%rsp)
je 0x1f325
movq 0x180(%rsp), %rsi
movq 0x188(%rsp), %rax
movq (%rax), %rdx
movl $0x28, %edi
movb $0x0, %al
callq 0x8c00
movl $0x2, 0x194(%rsp)
jmp 0x1f396
cmpl $0x0, 0x168(%rsp)
je 0x1f35b
movq 0x180(%rsp), %rsi
movq 0x188(%rsp), %rax
movq (%rax), %rdx
movl $0x27, %edi
movb $0x0, %al
callq 0x8c00
movl $0x4, 0x194(%rsp)
jmp 0x1f396
movq 0x180(%rsp), %rsi
movq 0x188(%rsp), %rax
movq (%rax), %rdx
movl $0x29, %edi
movb $0x0, %al
callq 0x8c00
jmp 0x1f389
jmp 0x1f38b
movl $0x0, 0x194(%rsp)
movl 0x194(%rsp), %eax
addq $0x198, %rsp            # imm = 0x198
retq
nopw %cs:(%rax,%rax)