#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 st_size;
};

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(char *, char const *, char *);
int stat(char const *, struct stat *);
char *strerror(int /*<<< orphan*/);
int file_size(const char *filename) {
  int ret;
  struct stat stat_buf;
  ret = stat(filename, &stat_buf);
  if (ret == -1) {
    error("Failed to get stat on %s file, %s.", filename, strerror(errno));
    return -1;
  }
  return stat_buf.st_size;
}


x86 assembly (clang, -O0):
<file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118b <file_size+0x5b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe86(%rip),%rdi
call   1040 <error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <file_size+0x61>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_size>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
je     114d <file_size+0x1d>
mov    0x8(%rsp),%eax
jmp    1172 <file_size+0x42>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9e(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <error@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [35 x i8] c"Failed to get stat on %s file, %s.\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 %10
6: ; preds = %1
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @error(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %8)
br label %13
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
br label %13
13: ; preds = %10, %6
%14 = phi i32 [ -1, %6 ], [ %12, %10 ]
ret i32 %14
}