#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*/ uint8_t;
typedef scalar_t__ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
scalar_t__ get_be32(int /*<<< orphan*/ *);
int /*<<< orphan*/ memcmp(int /*<<< orphan*/ *, char *, int);
bool nrg_check_footer(FILE *f, uint32_t *offp) {
  uint8_t buf[12];
  uint32_t off_hi;
  uint32_t off_lo;
  if (fseek(f, -12, SEEK_END) < 0 || fread(buf, 1, 12, f) != 12)
    return false;
  if (!memcmp(buf, "NER5", 4)) {
    off_hi = get_be32(buf + 4);
    off_lo = get_be32(buf + 8);
  } else if (!memcmp(buf + 4, "NERO", 4)) {
    off_hi = 0;
    off_lo = get_be32(buf + 8);
  } else
    return false;
  if (off_hi || !off_lo)
    return false;
  if (offp)
    *offp = off_lo;
  return true;
}


x86 assembly (clang, -O0):
<nrg_check_footer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff4,%esi
call   1060 <fseek@plt>
cmp    $0x0,%rax
jl     1191 <nrg_check_footer+0x51>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc,%edx
call   1040 <fread@plt>
cmp    $0xc,%eax
je     119d <nrg_check_footer+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    1272 <nrg_check_footer+0x132>
lea    -0x50(%rbp),%rdi
lea    0xe58(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%eax
jne    11e2 <nrg_check_footer+0xa2>
lea    -0x50(%rbp),%rdi
add    $0x10,%rdi
call   1030 <get_be32@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
add    $0x20,%rdi
call   1030 <get_be32@plt>
mov    %rax,-0x60(%rbp)
jmp    1233 <nrg_check_footer+0xf3>
lea    -0x50(%rbp),%rdi
add    $0x10,%rdi
lea    0xe14(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%eax
jne    1222 <nrg_check_footer+0xe2>
movq   $0x0,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
add    $0x20,%rdi
call   1030 <get_be32@plt>
mov    %rax,-0x60(%rbp)
jmp    122e <nrg_check_footer+0xee>
movl   $0x0,-0x4(%rbp)
jmp    1272 <nrg_check_footer+0x132>
jmp    1233 <nrg_check_footer+0xf3>
cmpq   $0x0,-0x58(%rbp)
jne    1249 <nrg_check_footer+0x109>
cmpq   $0x0,-0x60(%rbp)
jne    1255 <nrg_check_footer+0x115>
movl   $0x0,-0x4(%rbp)
jmp    1272 <nrg_check_footer+0x132>
cmpq   $0x0,-0x18(%rbp)
je     126b <nrg_check_footer+0x12b>
mov    -0x60(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nrg_check_footer>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff4,%esi
call   1060 <fseek@plt>
xor    %ebp,%ebp
test   %rax,%rax
js     11f4 <nrg_check_footer+0xb4>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0xc,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0xc,%eax
jne    11f4 <nrg_check_footer+0xb4>
lea    0xe73(%rip),%rsi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
lea    0x10(%rsp),%rdi
test   %eax,%eax
je     11c6 <nrg_check_footer+0x86>
lea    0xe5b(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcmp@plt>
test   %eax,%eax
jne    11f4 <nrg_check_footer+0xb4>
lea    0x20(%rsp),%rdi
call   1030 <get_be32@plt>
mov    $0x1,%cl
jmp    11de <nrg_check_footer+0x9e>
call   1030 <get_be32@plt>
mov    %rax,%rbx
lea    0x20(%rsp),%rdi
call   1030 <get_be32@plt>
test   %rbx,%rbx
sete   %cl
test   %cl,%cl
je     11f4 <nrg_check_footer+0xb4>
test   %rax,%rax
je     11f4 <nrg_check_footer+0xb4>
mov    $0x1,%ebp
test   %r14,%r14
je     11f4 <nrg_check_footer+0xb4>
mov    %rax,(%r14)
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [5 x i8] c"NER5\00"
@.str.1 = [5 x i8] c"NERO\00"
define i32 @nrg_check_footer(i32* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64*
%6 = alloca [12 x i32]
%7 = alloca i64
%8 = alloca i64
store i32* %0, i32** %4
store i64* %1, i64** %5
%9 = load i32*, i32** %4
%10 = load i32, i32* @SEEK_END
%11 = call i64 @fseek(i32* %9, i32 -12, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = getelementptr inbounds [12 x i32], [12 x i32]* %6, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i32 @fread(i32* %14, i32 1, i32 12, i32* %15)
%17 = icmp ne i32 %16, 12
br i1 %17, label %18, label %19
18: ; preds = %13, %2
store i32 0, i32* %3
br label %55
19: ; preds = %13
%20 = getelementptr inbounds [12 x i32], [12 x i32]* %6, i64 0, i64 0
%21 = call i32 @memcmp(i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%22 = icmp ne i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %19
%24 = getelementptr inbounds [12 x i32], [12 x i32]* %6, i64 0, i64 0
%25 = getelementptr inbounds i32, i32* %24, i64 4
%26 = call i64 @get_be32(i32* %25)
store i64 %26, i64* %7
%27 = getelementptr inbounds [12 x i32], [12 x i32]* %6, i64 0, i64 0
%28 = getelementptr inbounds i32, i32* %27, i64 8
%29 = call i64 @get_be32(i32* %28)
store i64 %29, i64* %8
br label %41
30: ; preds = %19
%31 = getelementptr inbounds [12 x i32], [12 x i32]* %6, i64 0, i64 0
%32 = getelementptr inbounds i32, i32* %31, i64 4
%33 = call i32 @memcmp(i32* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%34 = icmp ne i32 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %30
store i64 0, i64* %7
%36 = getelementptr inbounds [12 x i32], [12 x i32]* %6, i64 0, i64 0
%37 = getelementptr inbounds i32, i32* %36, i64 8
%38 = call i64 @get_be32(i32* %37)
store i64 %38, i64* %8
br label %40
39: ; preds = %30
store i32 0, i32* %3
br label %55
40: ; preds = %35
br label %41
41: ; preds = %40, %23
%42 = load i64, i64* %7
%43 = icmp ne i64 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = load i64, i64* %8
%46 = icmp ne i64 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %44, %41
store i32 0, i32* %3
br label %55
48: ; preds = %44
%49 = load i64*, i64** %5
%50 = icmp ne i64* %49, null
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i64, i64* %8
%53 = load i64*, i64** %5
store i64 %52, i64* %53
br label %54
54: ; preds = %51, %48
store i32 1, i32* %3
br label %55
55: ; preds = %54, %47, %39, %18
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [5 x i8] c"NER5\00"
@.str.1 = [5 x i8] c"NERO\00"
define i32 @nrg_check_footer(i32* nocapture %0, i64* writeonly %1) {
%3 = alloca [12 x i32]
%4 = bitcast [12 x i32]* %3 to i8*
%5 = load i32, i32* @SEEK_END
%6 = tail call i64 @fseek(i32* %0, i32 -12, i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %35, label %8
8: ; preds = %2
%9 = getelementptr inbounds [12 x i32], [12 x i32]* %3, i64 0, i64 0
%10 = call i32 @fread(i32* %9, i32 1, i32 12, i32* %0)
%11 = icmp eq i32 %10, 12
br i1 %11, label %12, label %35
12: ; preds = %8
%13 = call i32 @memcmp(i32* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = icmp eq i32 %13, 0
%15 = getelementptr inbounds [12 x i32], [12 x i32]* %3, i64 0, i64 4
br i1 %14, label %16, label %21
16: ; preds = %12
%17 = call i64 @get_be32(i32* %15)
%18 = getelementptr inbounds [12 x i32], [12 x i32]* %3, i64 0, i64 8
%19 = call i64 @get_be32(i32* %18)
%20 = icmp eq i64 %17, 0
br label %27
21: ; preds = %12
%22 = call i32 @memcmp(i32* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = getelementptr inbounds [12 x i32], [12 x i32]* %3, i64 0, i64 8
%26 = call i64 @get_be32(i32* %25)
br label %27
27: ; preds = %24, %16
%28 = phi i1 [ true, %24 ], [ %20, %16 ]
%29 = phi i64 [ %26, %24 ], [ %19, %16 ]
%30 = icmp ne i64 %29, 0
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = icmp eq i64* %1, null
br i1 %33, label %35, label %34
34: ; preds = %32
store i64 %29, i64* %1
br label %35
35: ; preds = %32, %34, %27, %21, %2, %8
%36 = phi i32 [ 0, %8 ], [ 0, %2 ], [ 0, %21 ], [ 0, %27 ], [ 1, %34 ], [ 1, %32 ]
ret i32 %36
}