#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  scalar_t__ *e_ident;
  scalar_t__ e_type;
  scalar_t__ e_version;
  int e_machine;
};
typedef TYPE_1__ Elf32_Ehdr;

/* Variables and functions */
size_t EI_CLASS;
scalar_t__ ELFCLASS32;
int /*<<< orphan*/ ELFMAG;
scalar_t__ ET_EXEC;
scalar_t__ EV_CURRENT;
int /*<<< orphan*/ SELFMAG;
scalar_t__ memcmp(scalar_t__ *, int /*<<< orphan*/, int /*<<< orphan*/);
bool is_epiphany_exec_elf(Elf32_Ehdr *ehdr) {
  return ehdr && memcmp(ehdr->e_ident, ELFMAG, SELFMAG) == 0 &&
         ehdr->e_ident[EI_CLASS] == ELFCLASS32 && ehdr->e_type == ET_EXEC &&
         ehdr->e_version == EV_CURRENT && ehdr->e_machine == 0x1223;
}


x86 assembly (clang, -O0):
<is_epiphany_exec_elf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x9(%rbp)
je     11d1 <is_epiphany_exec_elf+0xc1>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x9(%rbp)
jne    11d1 <is_epiphany_exec_elf+0xc1>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e66(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rcx
xor    %eax,%eax
mov    0x2e3e(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x9(%rbp)
jne    11d1 <is_epiphany_exec_elf+0xc1>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
xor    %eax,%eax
mov    0x2e31(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x9(%rbp)
jne    11d1 <is_epiphany_exec_elf+0xc1>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rcx
xor    %eax,%eax
mov    0x2e2c(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x9(%rbp)
jne    11d1 <is_epiphany_exec_elf+0xc1>
mov    -0x8(%rbp),%rax
cmpl   $0x1223,0x18(%rax)
sete   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_epiphany_exec_elf>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     1186 <is_epiphany_exec_elf+0x76>
mov    %rdi,%rbx
mov    (%rdi),%rdi
mov    0x2ec1(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    1186 <is_epiphany_exec_elf+0x76>
mov    (%rbx),%rax
mov    0x2e8a(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
jne    1186 <is_epiphany_exec_elf+0x76>
mov    0x8(%rbx),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
jne    1186 <is_epiphany_exec_elf+0x76>
mov    0x10(%rbx),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
jne    1186 <is_epiphany_exec_elf+0x76>
xor    %ebp,%ebp
cmpl   $0x1223,0x18(%rbx)
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64*, i64, i64, i32 }
@ELFMAG = global i32 0
@SELFMAG = global i32 0
@EI_CLASS = global i64 0
@ELFCLASS32 = global i64 0
@ET_EXEC = global i64 0
@EV_CURRENT = global i64 0
define i32 @is_epiphany_exec_elf(%struct.TYPE_3__* %0) {
%2 = alloca %struct.TYPE_3__*
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %2
%3 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%4 = icmp ne %struct.TYPE_3__* %3, null
br i1 %4, label %5, label %39
5: ; preds = %1
%6 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%8 = load i64*, i64** %7
%9 = load i32, i32* @ELFMAG
%10 = load i32, i32* @SELFMAG
%11 = call i64 @memcmp(i64* %8, i32 %9, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %39
13: ; preds = %5
%14 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 0
%16 = load i64*, i64** %15
%17 = load i64, i64* @EI_CLASS
%18 = getelementptr inbounds i64, i64* %16, i64 %17
%19 = load i64, i64* %18
%20 = load i64, i64* @ELFCLASS32
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %39
22: ; preds = %13
%23 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 1
%25 = load i64, i64* %24
%26 = load i64, i64* @ET_EXEC
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %39
28: ; preds = %22
%29 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %29, i32 0, i32 2
%31 = load i64, i64* %30
%32 = load i64, i64* @EV_CURRENT
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 3
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, 4643
br label %39
39: ; preds = %34, %28, %22, %13, %5, %1
%40 = phi i1 [ false, %28 ], [ false, %22 ], [ false, %13 ], [ false, %5 ], [ false, %1 ], [ %38, %34 ]
%41 = zext i1 %40 to i32
ret i32 %41
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64*, i64, i64, i32 }
@ELFMAG = global i32 0
@SELFMAG = global i32 0
@EI_CLASS = global i64 0
@ELFCLASS32 = global i64 0
@ET_EXEC = global i64 0
@EV_CURRENT = global i64 0
define i32 @is_epiphany_exec_elf(%struct.TYPE_3__* %0) {
%2 = icmp eq %struct.TYPE_3__* %0, null
br i1 %2, label %32, label %3
3: ; preds = %1
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%5 = load i64*, i64** %4
%6 = load i32, i32* @ELFMAG
%7 = load i32, i32* @SELFMAG
%8 = tail call i64 @memcmp(i64* %5, i32 %6, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %32
10: ; preds = %3
%11 = load i64*, i64** %4
%12 = load i64, i64* @EI_CLASS
%13 = getelementptr inbounds i64, i64* %11, i64 %12
%14 = load i64, i64* %13
%15 = load i64, i64* @ELFCLASS32
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %32
17: ; preds = %10
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%19 = load i64, i64* %18
%20 = load i64, i64* @ET_EXEC
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %17
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 2
%24 = load i64, i64* %23
%25 = load i64, i64* @EV_CURRENT
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 3
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 4643
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %27, %22, %17, %10, %3, %1
%33 = phi i32 [ 0, %22 ], [ 0, %17 ], [ 0, %10 ], [ 0, %3 ], [ 0, %1 ], [ %31, %27 ]
ret i32 %33
}