#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 S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ X_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
bool is_exe(const char *path) {
  struct stat s;
  if (access(path, X_OK) < 0)
    return false;
  if (stat(path, &s) < 0)
    return false;
  return S_ISREG(s.st_mode);
}


x86 assembly (clang, -O0):
<is_exe>:
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
jge    1164 <is_exe+0x34>
movl   $0x0,-0x4(%rbp)
jmp    1192 <is_exe+0x62>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jge    1187 <is_exe+0x57>
movl   $0x0,-0x4(%rbp)
jmp    1192 <is_exe+0x62>
mov    -0x18(%rbp),%edi
call   1040 <S_ISREG@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_exe>:
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
js     1165 <is_exe+0x35>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <stat@plt>
test   %rax,%rax
js     1165 <is_exe+0x35>
mov    (%rsp),%edi
call   1040 <S_ISREG@plt>
mov    %eax,%ebp
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 @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 = load i32, i32* @X_OK
%7 = call i64 @access(i8* %5, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %19
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @stat(i8* %11, %struct.stat* %4)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 0, i32* %2
br label %19
15: ; preds = %10
%16 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @S_ISREG(i32 %17)
store i32 %18, i32* %2
br label %19
19: ; preds = %15, %14, %9
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@X_OK = global i32 0
define i32 @is_exe(i8* %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 slt i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = call i64 @stat(i8* %0, %struct.stat* %2)
%9 = icmp slt i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @S_ISREG(i32 %12)
br label %14
14: ; preds = %7, %1, %10
%15 = phi i32 [ %13, %10 ], [ 0, %1 ], [ 0, %7 ]
ret i32 %15
}