#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
off_t file_size(char *fn) {
  struct stat sb;
  off_t size;
  if (stat(fn, &sb) == -1) {
    fprintf(stderr, "Cannot stat '%s': %s\n", fn, strerror(errno));
    exit(1);
  }
  size = sb.st_size;
  return size;
}


x86 assembly (clang, -O0):
<file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    11a4 <file_size+0x64>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe6b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_size>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
je     115d <file_size+0x1d>
mov    (%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e7c(%rip),%rax
mov    (%rax),%ebp
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe85(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"Cannot stat '%s': %s\0A\00"
@errno = global i32 0
define i32 @file_size(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @stat(i8* %5, %struct.stat* %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%17 = load i32, i32* %16
store i32 %17, i32* %4
%18 = load i32, i32* %4
ret i32 %18
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"Cannot stat '%s': %s\0A\00"
@errno = global i32 0
define i32 @file_size(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%14 = load i32, i32* %13
ret i32 %14
}