#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*/ EINVAL;
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ lstat(char const *, struct stat *);
int sysfs_path_is_file(const char *path) {
  struct stat astats;
  if (!path) {
    errno = EINVAL;
    return 1;
  }
  if ((lstat(path, &astats)) != 0) {
    return 1;
  }
  if (S_ISREG(astats.st_mode))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<sysfs_path_is_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1155 <sysfs_path_is_file+0x35>
mov    0x2e9a(%rip),%rax
mov    (%rax),%ecx
mov    0x2e99(%rip),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    119d <sysfs_path_is_file+0x7d>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <lstat@plt>
cmp    $0x0,%rax
je     1178 <sysfs_path_is_file+0x58>
movl   $0x1,-0x4(%rbp)
jmp    119d <sysfs_path_is_file+0x7d>
mov    -0x18(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%rax
je     1196 <sysfs_path_is_file+0x76>
movl   $0x0,-0x4(%rbp)
jmp    119d <sysfs_path_is_file+0x7d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfs_path_is_file>:
push   %rax
test   %rdi,%rdi
je     113d <sysfs_path_is_file+0x1d>
mov    %rsp,%rsi
call   1030 <lstat@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     1156 <sysfs_path_is_file+0x36>
pop    %rcx
ret
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    0x2e93(%rip),%rcx
mov    %eax,(%rcx)
mov    $0x1,%eax
pop    %rcx
ret
mov    (%rsp),%edi
call   1040 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rcx
ret

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

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