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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
size_t _rvm_get_file_size(int fd) {
  struct stat stat_struct;
  if (fstat(fd, &stat_struct) == 0) {
  } else {
    fprintf(stderr, "Could not stat: %s\n", strerror(errno));
    exit(1);
  }
  return stat_struct.st_size;
}


x86 assembly (clang, -O0):
<_rvm_get_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <fstat@plt>
cmp    $0x0,%rax
jne    1166 <_rvm_get_file_size+0x26>
jmp    119c <_rvm_get_file_size+0x5c>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe73(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_rvm_get_file_size>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
call   1060 <fstat@plt>
test   %rax,%rax
jne    115f <_rvm_get_file_size+0x1f>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e7a(%rip),%rax
mov    (%rax),%ebx
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe83(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

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

LLVM IR (-O2):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [20 x i8] c"Could not stat: %s\0A\00"
@errno = global i32 0
define i64 @_rvm_get_file_size(i32 %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @fstat(i32 %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
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 ([20 x i8], [20 x i8]* @.str, i64 0, i64 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 i64, i64* %13
ret i64 %14
}