#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 PATH_MAX;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int have_proc_fs(void) {
  struct stat buf;
  char pself[PATH_MAX + 1];
  pself[PATH_MAX] = 0;
  snprintf(pself, PATH_MAX, "%s/%s", "/proc", "self");
  return (!stat(pself, &buf) && S_ISDIR(buf.st_mode));
}


x86 assembly (clang, -O0):
<have_proc_fs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e82(%rip),%rax
movslq (%rax),%rax
movb   $0x0,(%rdi,%rax,1)
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdx
lea    0xe7a(%rip),%rcx
lea    0xe79(%rip),%r8
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    11c7 <have_proc_fs+0x97>
mov    -0x8(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<have_proc_fs>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%r14
mov    0x2eab(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
movslq (%rax),%rsi
movb   $0x0,(%rsi,%rbx,1)
lea    0xe97(%rip),%rdx
lea    0xe96(%rip),%rcx
lea    0xe95(%rip),%r8
mov    %rbx,%rdi
call   1040 <snprintf@plt>
lea    -0x18(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    11a6 <have_proc_fs+0x76>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
mov    %r14,%rsp
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [6 x i8] c"/proc\00"
@.str.2 = [5 x i8] c"self\00"
define i32 @have_proc_fs() {
%1 = alloca %struct.stat
%2 = alloca i8*
%3 = alloca i64
%4 = load i32, i32* @PATH_MAX
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %2
%8 = alloca i8, i64 %6
store i64 %6, i64* %3
%9 = load i32, i32* @PATH_MAX
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
store i8 0, i8* %11
%12 = load i32, i32* @PATH_MAX
%13 = call i32 @snprintf(i8* %8, i32 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @stat(i8* %8, %struct.stat* %1)
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %0
%17 = getelementptr inbounds %struct.stat, %struct.stat* %1, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %16, %0
%22 = phi i1 [ false, %0 ], [ %20, %16 ]
%23 = zext i1 %22 to i32
%24 = load i8*, i8** %2
ret i32 %23
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [6 x i8] c"/proc\00"
@.str.2 = [5 x i8] c"self\00"
define i32 @have_proc_fs() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = load i32, i32* @PATH_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = load i32, i32* @PATH_MAX
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
store i8 0, i8* %10
%11 = call i32 @snprintf(i8* %7, i32 %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @stat(i8* %7, %struct.stat* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %0
%15 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @S_ISDIR(i32 %16)
%18 = icmp ne i64 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %14, %0
%21 = phi i32 [ 0, %0 ], [ %19, %14 ]
ret i32 %21
}