#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__ EOF;
int /*<<< orphan*/ Exit(char *);
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int FileSize(char *filename) {
  FILE *fp;
  int fs;
  if ((fp = fopen(filename, "rb")) == NULL)
    Exit("File open error\n");
  fseek(fp, 0, SEEK_END);
  fs = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  if (fclose(fp) == EOF)
    Exit("File close error\n");
  return (fs);
}


x86 assembly (clang, -O0):
<FileSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1186 <FileSize+0x36>
lea    0xe82(%rip),%rdi
call   1050 <Exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e16(%rip),%rcx
cmp    (%rcx),%rax
jne    11df <FileSize+0x8f>
lea    0xe3a(%rip),%rdi
call   1050 <Exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileSize>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1173 <FileSize+0x23>
lea    0xe95(%rip),%rdi
call   1050 <Exit@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1040 <ftell@plt>
mov    %eax,%ebp
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%rax
jne    11c3 <FileSize+0x73>
lea    0xe56(%rip),%rdi
call   1050 <Exit@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [17 x i8] c"File open error\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i64 0
@.str.2 = [18 x i8] c"File close error\0A\00"
define i32 @FileSize(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @Exit(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %2, i32 0, i32 %7)
%9 = tail call i32 @ftell(i32* %2)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %2, i32 0, i32 %10)
%12 = tail call i64 @fclose(i32* %2)
%13 = load i64, i64* @EOF
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = tail call i32 @Exit(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %6
ret i32 %9
}