#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();
scalar_t__ stat(char *, struct stat *);
int is_there(char *candidate) {
  struct stat fin;
  if (access(candidate, X_OK) == 0 && stat(candidate, &fin) == 0 &&
      S_ISREG(fin.st_mode) &&
      (getuid() != 0 || (fin.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0))
    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    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    11d7 <is_there+0x97>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jne    11d7 <is_there+0x97>
mov    -0x18(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     11d7 <is_there+0x97>
mov    $0x0,%al
call   1030 <getuid@plt>
cmp    $0x0,%rax
jne    11cb <is_there+0x8b>
mov    -0x18(%rbp),%eax
mov    0x2e34(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e23(%rip),%rdx
or     (%rdx),%ecx
mov    0x2e2a(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11d7 <is_there+0x97>
movl   $0x1,-0x4(%rbp)
jmp    11de <is_there+0x9e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_there>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
jne    116d <is_there+0x2d>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %rax,%rax
je     1175 <is_there+0x35>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%edi
call   1050 <S_ISREG@plt>
test   %rax,%rax
je     116d <is_there+0x2d>
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    116f <is_there+0x2f>
mov    0x2e42(%rip),%rcx
mov    0x2e33(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e38(%rip),%rcx
or     (%rcx),%edx
test   %edx,0x8(%rsp)
jne    116f <is_there+0x2f>
jmp    116d <is_there+0x2d>

LLVM IR (-O0):
%struct.stat = type { i32 }
@X_OK = global i32 0
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
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 %32
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 %32
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 %32
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_IXGRP
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IXOTH
%28 = or i32 %26, %27
%29 = and i32 %23, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %21, %18
store i32 1, i32* %2
br label %33
32: ; preds = %21, %13, %9, %1
store i32 0, i32* %2
br label %33
33: ; preds = %32, %31
%34 = load i32, i32* %2
ret i32 %34
}

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