#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 ENOENT;
scalar_t__ S_ISBLK(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int errno;
scalar_t__ stat(char const *, struct stat *);
int path_is_reg_or_block_device(const char *filename) {
  struct stat st_buf;
  if (stat(filename, &st_buf) < 0) {
    if (errno == ENOENT)
      return 0;
    else
      return -errno;
  }
  return (S_ISBLK(st_buf.st_mode) || S_ISREG(st_buf.st_mode));
}


x86 assembly (clang, -O0):
<path_is_reg_or_block_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jge    118a <path_is_reg_or_block_device+0x5a>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%eax
jne    1177 <path_is_reg_or_block_device+0x47>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <path_is_reg_or_block_device+0x91>
xor    %eax,%eax
mov    0x2e60(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11c1 <path_is_reg_or_block_device+0x91>
mov    -0x18(%rbp),%edi
call   1050 <S_ISBLK@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
jne    11b6 <path_is_reg_or_block_device+0x86>
mov    -0x18(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_is_reg_or_block_device>:
push   %rax
mov    %rsp,%rsi
call   1030 <stat@plt>
test   %rax,%rax
js     1155 <path_is_reg_or_block_device+0x25>
mov    (%rsp),%edi
call   1050 <S_ISBLK@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     1172 <path_is_reg_or_block_device+0x42>
pop    %rcx
ret
mov    0x2e84(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6b(%rip),%rdx
mov    %ecx,%esi
neg    %esi
xor    %eax,%eax
cmp    (%rdx),%ecx
cmovne %esi,%eax
pop    %rcx
ret
mov    (%rsp),%edi
call   1040 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
pop    %rcx
ret

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

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