// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/t_amigahunk.c
// Function: identify
static int identify(char *name,uint8_t *p,unsigned long plen,bool lib)
/* Identify AmigaDOS or extended hunk format */
{
  uint32_t w = read32be(p);
  struct HunkInfo hi;
  int type;

  if (w == HUNK_HEADER) {
    error(12,name);  /* file is already an executable */
    return (ID_EXECUTABLE);  /* EHF-executables don't exist! */
  }
  else if (w!=HUNK_UNIT && w!=HUNK_LIB)
    return (ID_UNKNOWN);

  /* @@@ EHF will never be in HUNK_LIB format, because HUNK_PPC_CODE */
  /* (0x4e9) conflicts with HUNK_CODE|(MEMB_CHIP<<14) = 0x7e9. @@@   */
  if (w == HUNK_LIB)
    return (ID_LIBARCH);  /* SAS/C-style library */

  if (!lib) {
    /* Check, by comparing the suffix with ".LIB", if the units */
    /* of this object file have to be handled as part of an object */
    /* or library archive.  Yes, this is the only way... */
    int l;

    type = ID_OBJECT;
    if ((l = strlen(name)-4) > 0) {
      if (name[l]=='.' &&
          toupper((unsigned char)name[l+1])=='L' &&
          toupper((unsigned char)name[l+2])=='I' &&
          toupper((unsigned char)name[l+3])=='B')
        type = ID_LIBARCH;
    }
  }
  else
    type = ID_LIBARCH;  /* given with -l, will be regarded as a library */

  /* Now check if any unit contains EHF hunks */
  init_hunkinfo(&hi,name,p,plen);
  while (w = skiphunk(&hi)) {
    if (w == HUNK_PPC_CODE)
      return (-type);  /* it's an EHF object/library, containing PPC code */
  }
  return (type);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %ebx
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r15
movq %rsi, %rdi
callq 0x6607
cmpl $0x3e7, %eax            # imm = 0x3E7
je 0x116e4
cmpl $0x3fa, %eax            # imm = 0x3FA
je 0x116d0
xorl %ebx, %ebx
cmpl $0x3f3, %eax            # imm = 0x3F3
jne 0x116d3
pushq $0xc
popq %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x6c19
pushq $0x2
jmp 0x116d2
pushq $0x8
popq %rbx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ebx, %ebx
je 0x11910
pushq $0x8
popq %rbx
leaq 0x10(%rsp), %r14
movq %r12, (%r14)
movq %r12, 0x8(%r14)
movq %r13, 0x10(%r14)
movq %r15, 0x18(%r14)
movq %r12, %rdi
callq 0x6607
xorl %ecx, %ecx
cmpl $0x3f3, %eax            # imm = 0x3F3
sete %cl
movl %ecx, 0x20(%r14)
pushq $0xd
popq %rbp
leaq 0xf88d(%rip), %r15      # 0x20fb0
pushq $0x2
popq %r13
movq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x6607
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
leal -0x3e7(%rax), %ecx
cmpl $0x17, %ecx
ja 0x11780
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
addq $0x4, %r12
movq %r12, %rdi
callq 0x6607
leal 0x2(%rax), %esi
movq %r14, %rdi
callq 0x11989
movq %r14, %rdi
callq 0x11a45
testl %eax, %eax
je 0x116d3
cmpl $0x4e9, %eax            # imm = 0x4E9
jne 0x11727
jmp 0x11909
cmpl $0x4ec, %eax            # imm = 0x4EC
je 0x11849
cmpl $0x4e9, %eax            # imm = 0x4E9
je 0x1174d
movq 0x28(%rsp), %rsi
movl %ebp, %edi
xorl %eax, %eax
callq 0x6c19
jmp 0x11764
movq %r14, %rdi
callq 0x119b7
movq %r14, %rdi
callq 0x119b7
testl %eax, %eax
je 0x11764
movl %eax, %r12d
movl %eax, %esi
andl $0xffffff, %esi         # imm = 0xFFFFFF
testl %eax, %eax
js 0x117c9
incl %esi
jmp 0x11807
movq %r14, %rdi
callq 0x11989
movl %r12d, %eax
shrl $0x18, %eax
cmpl $0x82, %eax
je 0x117f5
cmpl $0x89, %eax
je 0x117f5
addl $0x30000000, %r12d      # imm = 0x30000000
cmpl $0x2ffffff, %r12d       # imm = 0x2FFFFFF
ja 0x117fd
movq %r14, %rdi
callq 0x119b7
movq %r14, %rdi
callq 0x119b7
movl %eax, %esi
movq %r14, %rdi
callq 0x11989
jmp 0x117aa
movq %r14, %rdi
callq 0x119b7
jmp 0x11764
cmpl $0x0, 0x30(%rsp)
je 0x11849
movq %r14, %rdi
callq 0x119b7
movq %r14, %rdi
callq 0x119e0
testw %ax, %ax
je 0x1186f
movzwl %ax, %esi
incl %esi
movq %r14, %rdi
callq 0x11a09
jmp 0x1182d
movq %r14, %rdi
callq 0x119b7
movq %r14, %rdi
callq 0x119b7
testl %eax, %eax
je 0x11764
incl %eax
movq %r14, %rdi
movl %eax, %esi
callq 0x11989
jmp 0x11851
movq %r14, %rdi
callq 0x11a36
jmp 0x11764
addq $0x4, %r12
movq %r12, %rdi
callq 0x6607
leal 0x3(%rax), %esi
jmp 0x1175c
movq %r14, %rdi
movl %r13d, %esi
jmp 0x1175f
movq %r14, %rdi
callq 0x119b7
movq %r14, %rdi
callq 0x119b7
leal 0x2(%rax), %esi
movq %r14, %rdi
callq 0x11989
movq %r14, %rdi
callq 0x119b7
movl %ebx, 0xc(%rsp)
movl %ebp, %ebx
movl %r13d, %ebp
movl %eax, %r13d
movq %r14, %rdi
callq 0x119b7
movl %eax, %r12d
notl %r12d
addl %r13d, %r12d
movl %ebp, %r13d
movl %ebx, %ebp
movl 0xc(%rsp), %ebx
testl %r12d, %r12d
je 0x11764
movq %r14, %rdi
callq 0x119b7
cmpl $0xc0000000, %eax       # imm = 0xC0000000
jb 0x11904
movq %r14, %rdi
callq 0x119b7
incl %r12d
jmp 0x118e4
negl %ebx
jmp 0x116d3
movq %r15, %rdi
callq 0x50e0
movq %rax, %r14
addl $-0x4, %eax
pushq $0x1
popq %rbx
testl %eax, %eax
jle 0x116ef
movl %eax, %eax
cmpb $0x2e, (%r15,%rax)
jne 0x116ef
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
callq 0x5030
movq (%rax), %rax
leal (%r14,%rbp), %ecx
movzbl (%r15,%rcx), %ecx
cmpl $0x4c, (%rax,%rcx,4)
jne 0x116ef
leal (%r14,%rbp), %ecx
incl %ecx
movzbl (%r15,%rcx), %ecx
cmpl $0x49, (%rax,%rcx,4)
jne 0x116ef
leal (%r14,%rbp), %ecx
addl $0x2, %ecx
movzbl (%r15,%rcx), %ecx
cmpl $0x42, (%rax,%rcx,4)
pushq $0x8
popq %rax
pushq $0x1
popq %rbx
cmovel %eax, %ebx
jmp 0x116ef