#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 */
scalar_t__ S_ISREG(int);
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int /*<<< orphan*/ X_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
int _pu_path_is_exe(const char *pathname) {
  struct stat statbuf;
  if (stat(pathname, &statbuf) < 0)
    return 0;
  return S_ISREG(statbuf.st_mode) != 0 &&
         (statbuf.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR)) &&
         access(pathname, X_OK) == 0;
}


x86 assembly (clang, -O0):
<_pu_path_is_exe>:
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    115f <_pu_path_is_exe+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    11ce <_pu_path_is_exe+0x9e>
mov    -0x18(%rbp),%edi
call   1040 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     11c3 <_pu_path_is_exe+0x93>
mov    -0x18(%rbp),%ecx
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    0x2e4c(%rip),%rdx
or     (%rdx),%eax
mov    0x2e4b(%rip),%rdx
or     (%rdx),%eax
and    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     11c3 <_pu_path_is_exe+0x93>
mov    -0x10(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
sete   %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):
<_pu_path_is_exe>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rsi
call   1030 <stat@plt>
xor    %ebx,%ebx
test   %rax,%rax
js     118c <_pu_path_is_exe+0x5c>
mov    (%rsp),%edi
call   1040 <S_ISREG@plt>
test   %rax,%rax
je     118c <_pu_path_is_exe+0x5c>
mov    0x2e8e(%rip),%rax
mov    0x2e77(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e74(%rip),%rax
or     (%rax),%ecx
test   %ecx,(%rsp)
je     118c <_pu_path_is_exe+0x5c>
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <access@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IXOTH = global i32 0
@S_IXGRP = global i32 0
@S_IXUSR = global i32 0
@X_OK = global i32 0
define i32 @_pu_path_is_exe(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 %9
8: ; preds = %1
store i32 0, i32* %2
br label %32
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i64 @S_ISREG(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %9
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = load i32, i32* @S_IXOTH
%18 = load i32, i32* @S_IXGRP
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IXUSR
%21 = or i32 %19, %20
%22 = and i32 %16, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %14
%25 = load i8*, i8** %3
%26 = load i32, i32* @X_OK
%27 = call i64 @access(i8* %25, i32 %26)
%28 = icmp eq i64 %27, 0
br label %29
29: ; preds = %24, %14, %9
%30 = phi i1 [ false, %14 ], [ false, %9 ], [ %28, %24 ]
%31 = zext i1 %30 to i32
store i32 %31, i32* %2
br label %32
32: ; preds = %29, %8
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IXOTH = global i32 0
@S_IXGRP = global i32 0
@S_IXUSR = global i32 0
@X_OK = global i32 0
define i32 @_pu_path_is_exe(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 %25, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = call i64 @S_ISREG(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %6
%12 = load i32, i32* %7
%13 = load i32, i32* @S_IXOTH
%14 = load i32, i32* @S_IXGRP
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IXUSR
%17 = or i32 %15, %16
%18 = and i32 %17, %12
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %11
%21 = load i32, i32* @X_OK
%22 = call i64 @access(i8* %0, i32 %21)
%23 = icmp eq i64 %22, 0
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %6, %11, %20, %1
%26 = phi i32 [ 0, %1 ], [ 0, %11 ], [ 0, %6 ], [ %24, %20 ]
ret i32 %26
}