#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*/ Error_write(int, char *, int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strlen(char *);
int FileUtil_exists(char *fName) {
  FILE *fp;
  if (fName == NULL) {
    Error_write(11, "FileUtil_exists", 2, "fName is NULL");
    return 0;
  }
  if (strlen(fName) == 0) {
    Error_write(20, "FileUtil_exists", 2, "fName");
    return 0;
  }
  if ((fp = fopen(fName, "r")) == NULL) {
    return 0;
  }
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<FileUtil_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1180 <FileUtil_exists+0x40>
mov    $0xb,%edi
lea    0xe9d(%rip),%rsi
mov    $0x2,%edx
lea    0xea1(%rip),%rcx
call   1050 <Error_write@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <FileUtil_exists+0xb6>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11bc <FileUtil_exists+0x7c>
mov    $0x14,%edi
lea    0xe61(%rip),%rsi
mov    $0x2,%edx
lea    0xe73(%rip),%rcx
call   1050 <Error_write@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <FileUtil_exists+0xb6>
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e6 <FileUtil_exists+0xa6>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <FileUtil_exists+0xb6>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileUtil_exists>:
push   %rax
test   %rdi,%rdi
je     115b <FileUtil_exists+0x2b>
cmpb   $0x0,(%rdi)
je     1170 <FileUtil_exists+0x40>
lea    0xee2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118d <FileUtil_exists+0x5d>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xe9e(%rip),%rsi
lea    0xea7(%rip),%rcx
mov    $0xb,%edi
jmp    1183 <FileUtil_exists+0x53>
lea    0xe89(%rip),%rsi
lea    0xea0(%rip),%rcx
mov    $0x14,%edi
mov    $0x2,%edx
call   1040 <Error_write@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"FileUtil_exists\00"
@.str.1 = [14 x i8] c"fName is NULL\00"
@.str.2 = [6 x i8] c"fName\00"
@.str.3 = [2 x i8] c"r\00"
define i32 @FileUtil_exists(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @Error_write(i32 11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %23
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @Error_write(i32 20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %23
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %17, i32** %4
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 0, i32* %2
br label %23
20: ; preds = %15
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
store i32 1, i32* %2
br label %23
23: ; preds = %20, %19, %13, %7
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [16 x i8] c"FileUtil_exists\00"
@.str.1 = [14 x i8] c"fName is NULL\00"
@.str.2 = [6 x i8] c"fName\00"
@.str.3 = [2 x i8] c"r\00"
define i32 @FileUtil_exists(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @Error_write(i32 11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %15
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @Error_write(i32 20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %15
10: ; preds = %5
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @fclose(i32* %11)
br label %15
15: ; preds = %10, %13, %8, %3
%16 = phi i32 [ 0, %3 ], [ 0, %8 ], [ 1, %13 ], [ 0, %10 ]
ret i32 %16
}