#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ ENOENT;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ stat(char const *, struct stat *);
int isfile(const char *path) {
  if (path == NULL || *path == '\0') {
    errno = ENOENT;
    return 0;
  }
  struct stat st;
  if (stat(path, &st) != 0) {
    return 0;
  }
  if (!S_ISREG(st.st_mode)) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<isfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1147 <isfile+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1165 <isfile+0x45>
mov    0x2e82(%rip),%rax
mov    (%rax),%ecx
mov    0x2e89(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11ac <isfile+0x8c>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     1188 <isfile+0x68>
movl   $0x0,-0x4(%rbp)
jmp    11ac <isfile+0x8c>
mov    -0x18(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%eax
jne    11a5 <isfile+0x85>
movl   $0x0,-0x4(%rbp)
jmp    11ac <isfile+0x8c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isfile>:
push   %rax
test   %rdi,%rdi
je     113f <isfile+0x1f>
cmpb   $0x0,(%rdi)
je     113f <isfile+0x1f>
mov    %rsp,%rsi
call   1030 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1155 <isfile+0x35>
pop    %rcx
ret
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    0x2e91(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
pop    %rcx
ret
mov    (%rsp),%edi
call   1040 <S_ISREG@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@ENOENT = global i32 0
@errno = global i32 0
define i32 @isfile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7, %1
%13 = load i32, i32* @ENOENT
store i32 %13, i32* @errno
store i32 0, i32* %2
br label %26
14: ; preds = %7
%15 = load i8*, i8** %3
%16 = call i64 @stat(i8* %15, %struct.stat* %4)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %2
br label %26
19: ; preds = %14
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @S_ISREG(i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %19
store i32 0, i32* %2
br label %26
25: ; preds = %19
store i32 1, i32* %2
br label %26
26: ; preds = %25, %24, %18, %12
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@ENOENT = global i32 0
@errno = global i32 0
define i32 @isfile(i8* %0) {
%2 = alloca %struct.stat
%3 = icmp eq i8* %0, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4, %1
%8 = load i32, i32* @ENOENT
store i32 %8, i32* @errno
br label %21
9: ; preds = %4
%10 = bitcast %struct.stat* %2 to i8*
%11 = call i64 @stat(i8* %0, %struct.stat* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @S_ISREG(i32 %15)
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %13, %9
%20 = phi i32 [ 0, %9 ], [ %18, %13 ]
br label %21
21: ; preds = %19, %7
%22 = phi i32 [ 0, %7 ], [ %20, %19 ]
ret i32 %22
}