#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 *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ pfan_isdir(char *);
int /*<<< orphan*/ stderr;
int pfan_readaccess_file(char *path) {
  FILE *file = fopen(path, "r");
  if (!file) {
    fprintf(stderr, "Can not open to '%s'.\n", path);
    return 0;
  }
  fclose(file);
  if (pfan_isdir(path)) {
    fprintf(stderr, "%s: is not a file.\n", path);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<pfan_readaccess_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <pfan_readaccess_file+0x50>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <pfan_readaccess_file+0x98>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1050 <pfan_isdir@plt>
cmp    $0x0,%rax
je     11d1 <pfan_readaccess_file+0x91>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe59(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <pfan_readaccess_file+0x98>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pfan_readaccess_file>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1173 <pfan_readaccess_file+0x33>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1050 <pfan_isdir@plt>
test   %rax,%rax
je     118f <pfan_readaccess_file+0x4f>
lea    0xea8(%rip),%rsi
jmp    117a <pfan_readaccess_file+0x3a>
lea    0xe88(%rip),%rsi
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Can not open to '%s'.\0A\00"
@.str.2 = [20 x i8] c"%s: is not a file.\0A\00"
define i32 @pfan_readaccess_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %3
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %11)
store i32 0, i32* %2
br label %24
13: ; preds = %1
%14 = load i32*, i32** %4
%15 = call i32 @fclose(i32* %14)
%16 = load i8*, i8** %3
%17 = call i64 @pfan_isdir(i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %3
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %21)
store i32 0, i32* %2
br label %24
23: ; preds = %13
store i32 1, i32* %2
br label %24
24: ; preds = %23, %19, %9
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Can not open to '%s'.\0A\00"
@.str.2 = [20 x i8] c"%s: is not a file.\0A\00"
define i32 @pfan_readaccess_file(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 %8, label %4
4: ; preds = %1
%5 = tail call i32 @fclose(i32* %2)
%6 = tail call i64 @pfan_isdir(i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %4, %1
%9 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %1 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), %4 ]
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* %9, i8* %0)
br label %12
12: ; preds = %8, %4
%13 = phi i32 [ 1, %4 ], [ 0, %8 ]
ret i32 %13
}