#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, char const *);
int file_exists(const char *path_to_file) {
  FILE *fp;
  if (path_to_file != NULL) {
    if (fp = fopen(path_to_file, "r"))
      fclose(fp);
    else {
      printf("File '%s' does not exist\n", path_to_file);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1194 <file_exists+0x64>
mov    -0x10(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1173 <file_exists+0x43>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    118f <file_exists+0x5f>
mov    -0x10(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    119b <file_exists+0x6b>
jmp    1194 <file_exists+0x64>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_exists>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebp
test   %rdi,%rdi
je     116c <file_exists+0x3c>
mov    %rdi,%rbx
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     115b <file_exists+0x2b>
mov    %rax,%rdi
call   1030 <fclose@plt>
jmp    116c <file_exists+0x3c>
lea    0xea0(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"File '%s' does not exist\0A\00"
define i32 @file_exists(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32*, i32** %4
%13 = call i32 @fclose(i32* %12)
br label %17
14: ; preds = %7
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 0, i32* %2
br label %19
17: ; preds = %11
br label %18
18: ; preds = %17, %1
store i32 1, i32* %2
br label %19
19: ; preds = %18, %14
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"File '%s' does not exist\0A\00"
define i32 @file_exists(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %10, label %3
3: ; preds = %1
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @fclose(i32* %4)
br label %10
8: ; preds = %3
%9 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %1, %6, %8
%11 = phi i32 [ 0, %8 ], [ 1, %6 ], [ 1, %1 ]
ret i32 %11
}