#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 *, int /*<<< orphan*/);
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ stat(char *, struct stat *);
int is_there(char *candidate) {
  struct stat stbuf;
  if (access(candidate, X_OK) == 0 && stat(candidate, &stbuf) == 0 &&
      S_ISREG(stbuf.st_mode) &&
      (getuid() != 0 || (stbuf.st_mode & (S_IXUSR | S_IXOTH | S_IXGRP)) != 0)) {
    printf("%s\n", candidate);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_there>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    11f7 <is_there+0xa7>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    11f7 <is_there+0xa7>
mov    -0x18(%rbp),%edi
call   1060 <S_ISREG@plt>
cmp    $0x0,%rax
je     11f7 <is_there+0xa7>
mov    $0x0,%al
call   1030 <getuid@plt>
cmp    $0x0,%rax
jne    11db <is_there+0x8b>
mov    -0x18(%rbp),%eax
mov    0x2e24(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e23(%rip),%rdx
or     (%rdx),%ecx
mov    0x2e0a(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11f7 <is_there+0xa7>
mov    -0x10(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fe <is_there+0xae>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_there>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    11ca <is_there+0x7a>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
test   %rax,%rax
jne    11ca <is_there+0x7a>
mov    (%rsp),%edi
call   1060 <S_ISREG@plt>
test   %rax,%rax
je     11ca <is_there+0x7a>
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getuid@plt>
test   %rax,%rax
jne    11b6 <is_there+0x66>
mov    0x2e43(%rip),%rax
mov    0x2e44(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e29(%rip),%rax
or     (%rax),%ecx
test   %ecx,(%rsp)
je     11ca <is_there+0x7a>
lea    0xe43(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@X_OK = global i32 0
@S_IXUSR = global i32 0
@S_IXOTH = global i32 0
@S_IXGRP = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @is_there(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 eq i64 %5, 0
br i1 %6, label %7, label %29
7: ; preds = %1
%8 = call i64 @stat(i8* %0, %struct.stat* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %29
10: ; preds = %7
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @S_ISREG(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %29, label %15
15: ; preds = %10
%16 = call i64 (...) @getuid()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i32, i32* %11
%20 = load i32, i32* @S_IXUSR
%21 = load i32, i32* @S_IXOTH
%22 = or i32 %21, %20
%23 = load i32, i32* @S_IXGRP
%24 = or i32 %22, %23
%25 = and i32 %24, %19
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %18, %15
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %29
29: ; preds = %1, %7, %10, %18, %27
%30 = phi i32 [ 1, %27 ], [ 0, %18 ], [ 0, %10 ], [ 0, %7 ], [ 0, %1 ]
ret i32 %30
}