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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char const *);
void file_open(FILE **f, int *size, const char *filename) {
  *f = fopen(filename, "r");
  if (!*f) {
    perror(filename);
    exit(1);
  }
  fseek(*f, 0, SEEK_END);
  *size = ftell(*f);
  fseek(*f, 0, SEEK_SET);
}


x86 assembly (clang, -O0):
<file_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    119f <file_open+0x4f>
mov    -0x18(%rbp),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <ftell@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_open>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe9b(%rip),%rsi
mov    %rdx,%rdi
call   1050 <fopen@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11ab <file_open+0x5b>
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
mov    (%rbx),%rdi
call   1030 <ftell@plt>
mov    %eax,(%r14)
mov    (%rbx),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fseek@plt>
mov    %r15,%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define void @file_open(i32** %0, i32* %1, i8* %2) {
%4 = alloca i32**
%5 = alloca i32*
%6 = alloca i8*
store i32** %0, i32*** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%7 = load i8*, i8** %6
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = load i32**, i32*** %4
store i32* %8, i32** %9
%10 = load i32**, i32*** %4
%11 = load i32*, i32** %10
%12 = icmp ne i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = call i32 @perror(i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
%18 = load i32**, i32*** %4
%19 = load i32*, i32** %18
%20 = load i32, i32* @SEEK_END
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32**, i32*** %4
%23 = load i32*, i32** %22
%24 = call i32 @ftell(i32* %23)
%25 = load i32*, i32** %5
store i32 %24, i32* %25
%26 = load i32**, i32*** %4
%27 = load i32*, i32** %26
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %27, i32 0, i32 %28)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define void @file_open(i32** nocapture %0, i32* nocapture writeonly %1, i8* nocapture %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %0
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @perror(i8* %2)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %3
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %4, i32 0, i32 %10)
%12 = load i32*, i32** %0
%13 = tail call i32 @ftell(i32* %12)
store i32 %13, i32* %1
%14 = load i32*, i32** %0
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %14, i32 0, i32 %15)
ret void
}