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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ ftello(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
off_t filesize(const char *filename) {
  FILE *fp;
  off_t pos = 0;
  if (filename[0] == '(' && filename[1] == 'p') {
  } else {
    fp = fopen(filename, "r");
    if (fp == NULL) {
      fprintf(stderr, "Open failed on %s\n", filename);
    } else {
      fseek(fp, 0L, SEEK_END);
      pos = ftello(fp);
    }
  }
  return pos;
}


x86 assembly (clang, -O0):
<filesize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    1179 <filesize+0x39>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x70,%eax
jne    1179 <filesize+0x39>
jmp    11dd <filesize+0x9d>
mov    -0x8(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b6 <filesize+0x76>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11d8 <filesize+0x98>
mov    -0x10(%rbp),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ftello@plt>
mov    %eax,-0x14(%rbp)
jmp    11dd <filesize+0x9d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filesize>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x28,(%rdi)
jne    1152 <filesize+0x12>
cmpb   $0x70,0x1(%rbx)
je     11a3 <filesize+0x63>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     118b <filesize+0x4b>
mov    %rax,%r14
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <ftello@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Open failed on %s\0A\00"
@SEEK_END = global i32 0
define i32 @filesize(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 40
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 112
br i1 %15, label %16, label %17
16: ; preds = %10
br label %33
17: ; preds = %10, %1
%18 = load i8*, i8** %2
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %3
%20 = load i32*, i32** %3
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %2
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %32
26: ; preds = %17
%27 = load i32*, i32** %3
%28 = load i32, i32* @SEEK_END
%29 = call i32 @fseek(i32* %27, i64 0, i32 %28)
%30 = load i32*, i32** %3
%31 = call i32 @ftello(i32* %30)
store i32 %31, i32* %4
br label %32
32: ; preds = %26, %22
br label %33
33: ; preds = %32, %16
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Open failed on %s\0A\00"
@SEEK_END = global i32 0
define i32 @filesize(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 40
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 112
br i1 %7, label %18, label %8
8: ; preds = %4, %1
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %18
14: ; preds = %8
%15 = load i32, i32* @SEEK_END
%16 = tail call i32 @fseek(i32* %9, i64 0, i32 %15)
%17 = tail call i32 @ftello(i32* %9)
br label %18
18: ; preds = %11, %14, %4
%19 = phi i32 [ 0, %4 ], [ 0, %11 ], [ %17, %14 ]
ret i32 %19
}