#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*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ X_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
scalar_t__ lstat(char const *, struct stat *);
int ok_to_execut(const char *path) {
  struct stat stbuf;
  if (access(path, X_OK) || lstat(path, &stbuf)) {
    return 0;
  }
  if (!S_ISREG(stbuf.st_mode)) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ok_to_execut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    116f <ok_to_execut+0x3f>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <lstat@plt>
cmp    $0x0,%rax
je     117b <ok_to_execut+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    119f <ok_to_execut+0x6f>
mov    -0x18(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1198 <ok_to_execut+0x68>
movl   $0x0,-0x4(%rbp)
jmp    119f <ok_to_execut+0x6f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ok_to_execut>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    116b <ok_to_execut+0x3b>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <lstat@plt>
test   %rax,%rax
jne    116b <ok_to_execut+0x3b>
mov    (%rsp),%edi
call   1040 <S_ISREG@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@X_OK = global i32 0
define i32 @ok_to_execut(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @X_OK
%7 = call i64 @access(i8* %5, i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %13, label %9
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, %1
store i32 0, 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 i32 @S_ISREG(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 %21
20: ; preds = %14
store i32 1, i32* %2
br label %21
21: ; preds = %20, %19, %13
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@X_OK = global i32 0
define i32 @ok_to_execut(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = load i32, i32* @X_OK
%5 = tail call i64 @access(i8* %0, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, 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 i32 @S_ISREG(i32 %12)
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %10, %1, %7
%17 = phi i32 [ 0, %7 ], [ 0, %1 ], [ %15, %10 ]
ret i32 %17
}