#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_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int getOldFileLength() {
  FILE *f = fopen("HallOfShame.dat", "rb");
  if (f == NULL || ferror(f)) {
    if (f)
      fclose(f);
    return -1;
  }
  fseek(f, 0, SEEK_END);
  int len = ftell(f);
  fclose(f);
  return len;
}


x86 assembly (clang, -O0):
<getOldFileLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118d <getOldFileLength+0x3d>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ad <getOldFileLength+0x5d>
cmpq   $0x0,-0x10(%rbp)
je     11a1 <getOldFileLength+0x51>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <getOldFileLength+0x8c>
mov    -0x10(%rbp),%rdi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getOldFileLength>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a7 <getOldFileLength+0x57>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <ferror@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    119d <getOldFileLength+0x4d>
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11ac <getOldFileLength+0x5c>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"HallOfShame.dat\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @getOldFileLength() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = call i64 @ferror(i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %7, %0
%12 = load i32*, i32** %2
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
br label %17
17: ; preds = %14, %11
store i32 -1, i32* %1
br label %27
18: ; preds = %7
%19 = load i32*, i32** %2
%20 = load i32, i32* @SEEK_END
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32*, i32** %2
%23 = call i32 @ftell(i32* %22)
store i32 %23, i32* %3
%24 = load i32*, i32** %2
%25 = call i32 @fclose(i32* %24)
%26 = load i32, i32* %3
store i32 %26, i32* %1
br label %27
27: ; preds = %18, %17
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [16 x i8] c"HallOfShame.dat\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @getOldFileLength() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = tail call i64 @ferror(i32* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %1, i32 0, i32 %7)
%9 = tail call i32 @ftell(i32* %1)
br label %10
10: ; preds = %3, %6
%11 = phi i32 [ %9, %6 ], [ -1, %3 ]
%12 = tail call i32 @fclose(i32* %1)
br label %13
13: ; preds = %10, %0
%14 = phi i32 [ -1, %0 ], [ %11, %10 ]
ret i32 %14
}