#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *);
int file_exists(const char *filename) {
  FILE *file = fopen(filename, "r");
  if (file) {
    fseek(file, 0, SEEK_END);
    long len = ftell(file);
    fclose(file);
    if (len > 0) {
      printf("Skipped: '%s', file exists.\n", filename);
      return len;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d1 <file_exists+0x81>
mov    -0x18(%rbp),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
jle    11cc <file_exists+0x7c>
mov    -0x10(%rbp),%rsi
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11d8 <file_exists+0x88>
jmp    11d1 <file_exists+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_exists>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe9f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11af <file_exists+0x5f>
mov    %rax,%rbx
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %r15,%r15
jle    11b1 <file_exists+0x61>
lea    0xe60(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r15d,%ebp
jmp    11b1 <file_exists+0x61>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.1 = [29 x i8] c"Skipped: '%s', file exists.\0A\00"
define i32 @file_exists(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @fseek(i32* %2, i32 0, i32 %5)
%7 = tail call i64 @ftell(i32* %2)
%8 = tail call i32 @fclose(i32* %2)
%9 = icmp sgt i64 %7, 0
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = trunc i64 %7 to i32
br label %13
13: ; preds = %1, %4, %10
%14 = phi i32 [ %12, %10 ], [ 0, %4 ], [ 0, %1 ]
ret i32 %14
}