#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*/ assert(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(struct stat *);
struct stat *malloc(int);
int /*<<< orphan*/ perror(char *);
int stat(char *, struct stat *);
off_t get_filesize(char *file) {
  int status;
  off_t size;
  struct stat *sb = malloc(sizeof(struct stat));
  assert(NULL != sb);
  status = stat(file, sb);
  if (0 != status) {
    perror(file);
    exit(-1);
  }
  size = sb->st_size;
  free(sb);
  return size;
}


x86 assembly (clang, -O0):
<get_filesize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
je     11bb <get_filesize+0x5b>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filesize>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <stat@plt>
test   %eax,%eax
jne    11a2 <get_filesize+0x42>
mov    (%rbx),%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @get_filesize(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat*
store i8* %0, i8** %2
%6 = call %struct.stat* @malloc(i32 4)
store %struct.stat* %6, %struct.stat** %5
%7 = load %struct.stat*, %struct.stat** %5
%8 = icmp ne %struct.stat* null, %7
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %2
%12 = load %struct.stat*, %struct.stat** %5
%13 = call i32 @stat(i8* %11, %struct.stat* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp ne i32 0, %14
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i8*, i8** %2
%18 = call i32 @perror(i8* %17)
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %1
%21 = load %struct.stat*, %struct.stat** %5
%22 = getelementptr inbounds %struct.stat, %struct.stat* %21, i32 0, i32 0
%23 = load i32, i32* %22
store i32 %23, i32* %4
%24 = load %struct.stat*, %struct.stat** %5
%25 = call i32 @free(%struct.stat* %24)
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @get_filesize(i8* nocapture %0) {
%2 = tail call %struct.stat* @malloc(i32 4)
%3 = icmp ne %struct.stat* %2, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @stat(i8* %0, %struct.stat* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = tail call i32 @perror(i8* %0)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 @free(%struct.stat* %2)
ret i32 %13
}