#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 st_mode;
};

/* Variables and functions */
int S_IRUSR;
int /*<<< orphan*/ S_ISLNK(int);
int /*<<< orphan*/ S_ISREG(int);
int stat(char const *, struct stat *);
int blossom_path_readable(const char *path) {
  struct stat statbuf;
  if (stat(path, &statbuf) == -1)
    return 0;
  if (!S_ISREG(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode))
    return 0;
  if (!(statbuf.st_mode & S_IRUSR))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<blossom_path_readable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    115e <blossom_path_readable+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <blossom_path_readable+0x84>
mov    -0x18(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%eax
jne    118c <blossom_path_readable+0x5c>
mov    -0x18(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%eax
jne    118c <blossom_path_readable+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <blossom_path_readable+0x84>
mov    -0x18(%rbp),%eax
mov    0x2e4a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11ad <blossom_path_readable+0x7d>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <blossom_path_readable+0x84>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blossom_path_readable>:
push   %rbp
push   %rbx
push   %rax
mov    %rsp,%rsi
call   1040 <stat@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
je     1169 <blossom_path_readable+0x39>
mov    (%rsp),%ebp
mov    %ebp,%edi
call   1050 <S_ISREG@plt>
test   %eax,%eax
jne    115b <blossom_path_readable+0x2b>
mov    %ebp,%edi
call   1030 <S_ISLNK@plt>
test   %eax,%eax
je     1169 <blossom_path_readable+0x39>
mov    0x2e7e(%rip),%rax
xor    %ebx,%ebx
test   %ebp,(%rax)
setne  %bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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