#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_IXUSR;
scalar_t__ stat(char const *, struct stat *);
int check_executable(const char *path) {
  struct stat st;

  ;
  if ((!path) || (!*path))
    return 0;
  if ((stat(path, &st) >= 0) && (st.st_mode & (S_IXUSR | 0 | 0)))
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<check_executable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1134 <check_executable+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1140 <check_executable+0x30>
movl   $0x0,-0x4(%rbp)
jmp    1187 <check_executable+0x77>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jl     1180 <check_executable+0x70>
mov    -0x18(%rbp),%eax
mov    0x2e87(%rip),%rcx
mov    (%rcx),%ecx
or     $0x0,%ecx
or     $0x0,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1180 <check_executable+0x70>
movl   $0x1,-0x4(%rbp)
jmp    1187 <check_executable+0x77>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_executable>:
push   %rax
xor    %eax,%eax
test   %rdi,%rdi
je     113d <check_executable+0x2d>
cmpb   $0x0,(%rdi)
je     113d <check_executable+0x2d>
mov    %rsp,%rsi
call   1030 <stat@plt>
test   %rax,%rax
js     113f <check_executable+0x2f>
mov    0x2eb7(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%eax
test   %ecx,(%rsp)
je     113f <check_executable+0x2f>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

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

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