#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 {
  long long st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
FILE *open_file(char *filename, long long *filesize) {
  struct stat filestats;
  stat(filename, &filestats);
  *filesize = filestats.st_size;
  static FILE *stream;
  stream = fopen(filename, "rb");
  if (!stream)
    fprintf(stderr, "ERROR: Video File not found!\n");
  return stream;
}


x86 assembly (clang, -O0):
<open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,0x2ed1(%rip)
cmpq   $0x0,0x2ec9(%rip)
jne    1192 <open_file+0x62>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2ea7(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1040 <stat@plt>
mov    (%rsp),%rax
mov    %rax,(%r14)
lea    0xeb0(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,0x2ee1(%rip)
test   %rax,%rax
jne    1180 <open_file+0x50>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2ec0(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@open_file.stream = internal global i32* null
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"ERROR: Video File not found!\0A\00"
define i32* @open_file(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca %struct.stat
store i8* %0, i8** %3
store i64* %1, i64** %4
%6 = load i8*, i8** %3
%7 = call i32 @stat(i8* %6, %struct.stat* %5)
%8 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load i64*, i64** %4
store i64 %9, i64* %10
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** @open_file.stream
%13 = load i32*, i32** @open_file.stream
%14 = icmp ne i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %15, %2
%19 = load i32*, i32** @open_file.stream
ret i32* %19
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@open_file.stream = internal unnamed_addr global i32* null
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"ERROR: Video File not found!\0A\00"
define i32* @open_file(i8* nocapture %0, i64* nocapture writeonly %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @stat(i8* %0, %struct.stat* %3)
%6 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%7 = load i64, i64* %6
store i64 %7, i64* %1
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** @open_file.stream
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32*, i32** @open_file.stream
br label %14
14: ; preds = %10, %2
%15 = phi i32* [ %13, %10 ], [ %8, %2 ]
ret i32* %15
}