#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 */
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(unsigned char **, int, int, int /*<<< orphan*/ *);
int memcmp(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int is_auxv_64_file(FILE *f, bool *result) {
  unsigned char v[5];
  size_t r = fread(&v, 1, sizeof v, f);
  if (r != sizeof v) {
    if (ferror(f))
      perror(0);
    return -1;
  }
  static const unsigned char elf64_magic[] = {0x7f, 0x45, 0x4c, 0x46, 0x02};
  int x = memcmp(v, elf64_magic, sizeof v);
  *result = !x;
  return 0;
}


x86 assembly (clang, -O0):
<is_auxv_64_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x1d(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x5,%edx
call   1040 <fread@plt>
cltq
mov    %rax,-0x28(%rbp)
cmpq   $0x5,-0x28(%rbp)
je     119e <is_auxv_64_file+0x5e>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1192 <is_auxv_64_file+0x52>
xor    %edi,%edi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <is_auxv_64_file+0x91>
lea    -0x1d(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x5,%edx
call   1050 <memcmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_auxv_64_file>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x3(%rsp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x5,%eax
jne    118a <is_auxv_64_file+0x4a>
lea    0xe93(%rip),%rsi
lea    0x3(%rsp),%rdi
mov    $0x5,%edx
call   1050 <memcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,(%r14)
xor    %ebx,%ebx
jmp    11a3 <is_auxv_64_file+0x63>
mov    %rbx,%rdi
call   1030 <ferror@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11a3 <is_auxv_64_file+0x63>
xor    %edi,%edi
call   1060 <perror@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@is_auxv_64_file.elf64_magic = internal constant [5 x i8] c"\7FELF\02"
define i32 @is_auxv_64_file(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [5 x i8]
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = bitcast [5 x i8]* %6 to i8**
%10 = load i32*, i32** %4
%11 = call i32 @fread(i8** %9, i32 1, i32 5, i32* %10)
%12 = sext i32 %11 to i64
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = icmp ne i64 %13, 5
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = call i64 @ferror(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i32 0)
br label %21
21: ; preds = %19, %15
store i32 -1, i32* %3
br label %30
22: ; preds = %2
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%24 = call i32 @memcmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @is_auxv_64_file.elf64_magic, i64 0, i64 0), i32 5)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
%28 = zext i1 %27 to i32
%29 = load i32*, i32** %5
store i32 %28, i32* %29
store i32 0, i32* %3
br label %30
30: ; preds = %22, %21
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@is_auxv_64_file.elf64_magic = internal constant [5 x i8] c"\7FELF\02"
define i32 @is_auxv_64_file(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%5 = bitcast [5 x i8]* %3 to i8**
%6 = call i32 @fread(i8** %5, i32 1, i32 5, i32* %0)
%7 = icmp eq i32 %6, 5
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i64 @ferror(i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = tail call i32 @perror(i32 0)
br label %17
13: ; preds = %2
%14 = call i32 @memcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @is_auxv_64_file.elf64_magic, i64 0, i64 0), i32 5)
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
store i32 %16, i32* %1
br label %17
17: ; preds = %8, %11, %13
%18 = phi i32 [ 0, %13 ], [ -1, %11 ], [ -1, %8 ]
ret i32 %18
}