#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;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
scalar_t__ S_ISREG(int);
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
scalar_t__ stat(char const *, struct stat *);
int is_existing_regular_executable(const char *filename) {
  struct stat stat_buf = {0};
  return (stat(filename, &stat_buf) == 0) && S_ISREG(stat_buf.st_mode) &&
         ((stat_buf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0);
}


x86 assembly (clang, -O0):
<is_existing_regular_executable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
jne    11ae <is_existing_regular_executable+0x7e>
mov    -0x10(%rbp),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     11ae <is_existing_regular_executable+0x7e>
mov    -0x10(%rbp),%eax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e40(%rip),%rdx
or     (%rdx),%ecx
mov    0x2e47(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_existing_regular_executable>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1171 <is_existing_regular_executable+0x51>
mov    0x8(%rsp),%edi
call   1040 <S_ISREG@plt>
test   %rax,%rax
je     1171 <is_existing_regular_executable+0x51>
mov    0x2e8c(%rip),%rax
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e82(%rip),%rax
or     (%rax),%ecx
xor    %ebx,%ebx
test   %ecx,0x8(%rsp)
setne  %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
define i32 @is_existing_regular_executable(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
store i8* %0, i8** %2
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i8*, i8** %2
%6 = call i64 @stat(i8* %5, %struct.stat* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i64 @S_ISREG(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i32, i32* @S_IXUSR
%17 = load i32, i32* @S_IXGRP
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IXOTH
%20 = or i32 %18, %19
%21 = and i32 %15, %20
%22 = icmp ne i32 %21, 0
br label %23
23: ; preds = %13, %8, %1
%24 = phi i1 [ false, %8 ], [ false, %1 ], [ %22, %13 ]
%25 = zext i1 %24 to i32
ret i32 %25
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
define i32 @is_existing_regular_executable(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.stat*
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = call i64 @stat(i8* %0, %struct.stat* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %1
%8 = bitcast i64* %2 to i32*
%9 = load i32, i32* %8
%10 = call i64 @S_ISREG(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %7
%13 = load i32, i32* %8
%14 = load i32, i32* @S_IXUSR
%15 = load i32, i32* @S_IXGRP
%16 = or i32 %15, %14
%17 = load i32, i32* @S_IXOTH
%18 = or i32 %16, %17
%19 = and i32 %18, %13
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %12, %7, %1
%23 = phi i32 [ 0, %7 ], [ 0, %1 ], [ %21, %12 ]
ret i32 %23
}