#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 */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fread(unsigned int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ElfCheck(FILE *fp) {
  unsigned int magic = 0;
  if (!fp)
    return 0;
  fseek(fp, 0, SEEK_SET);
  fread(&magic, 4, 1, fp);
  if (magic == 0x464c457f)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<ElfCheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114a <ElfCheck+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    1195 <ElfCheck+0x75>
mov    -0x10(%rbp),%rdi
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmpl   $0x464c457f,-0x14(%rbp)
jne    118e <ElfCheck+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    1195 <ElfCheck+0x75>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ElfCheck>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
test   %rdi,%rdi
je     116b <ElfCheck+0x4b>
mov    %rdi,%rbx
mov    0x2ea4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %eax,%eax
cmpl   $0x464c457f,0xc(%rsp)
46
sete   %al
jmp    116d <ElfCheck+0x4d>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @ElfCheck(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %4
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 0, i32* %2
br label %18
8: ; preds = %1
%9 = load i32*, i32** %3
%10 = load i32, i32* @SEEK_SET
%11 = call i32 @fseek(i32* %9, i32 0, i32 %10)
%12 = load i32*, i32** %3
%13 = call i32 @fread(i32* %4, i32 4, i32 1, i32* %12)
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1179403647
br i1 %15, label %16, label %17
16: ; preds = %8
store i32 1, i32* %2
br label %18
17: ; preds = %8
store i32 0, i32* %2
br label %18
18: ; preds = %17, %16, %7
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @ElfCheck(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = icmp eq i32* %0, null
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @fseek(i32* %0, i32 0, i32 %6)
%8 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %0)
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 1179403647
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %5, %1
%13 = phi i32 [ 0, %1 ], [ %11, %5 ]
ret i32 %13
}