#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 */
typedef int /*<<< orphan*/ lBuff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ strcat(char *, char const *const);
int /*<<< orphan*/ strchr(char *, char);
int detectPresence(char const *const aExecutable) {
  char lBuff[1024];
  char lTestedString[1024] = "which ";
  FILE *lIn;
  strcat(lTestedString, aExecutable);
  lIn = popen(lTestedString, "r");
  if ((fgets(lBuff, sizeof(lBuff), lIn) != NULL) && (!strchr(lBuff, ':'))) {
    pclose(lIn);
    return 1;
  } else {
    pclose(lIn);
    return 0;
  }
}


x86 assembly (clang, -O0):
<detectPresence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movb   $0x77,-0x810(%rbp)
movb   $0x68,-0x80f(%rbp)
movb   $0x69,-0x80e(%rbp)
movb   $0x63,-0x80d(%rbp)
movb   $0x68,-0x80c(%rbp)
movb   $0x20,-0x80b(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x810(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x818(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x818(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     122a <detectPresence+0xca>
lea    -0x410(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
cmp    $0x0,%eax
jne    122a <detectPresence+0xca>
mov    -0x818(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    123d <detectPresence+0xdd>
mov    -0x818(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detectPresence>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%rbx
mov    %rsp,%rbp
xor    %r14d,%r14d
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x63696877,(%rsp)
movw   $0x2068,0x4(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
lea    0xe5d(%rip),%rsi
mov    %rbp,%rdi
call   1070 <popen@plt>
mov    %rax,%rbx
lea    0x400(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e4 <detectPresence+0x84>
lea    0x400(%rsp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %eax,%eax
jne    11e4 <detectPresence+0x84>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %r14d,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @detectPresence(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
%7 = bitcast [1024 x i8]* %5 to i8*
%8 = bitcast i8* %7 to [1024 x i8]*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i32 0, i32 0
store i8 119, i8* %9
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i32 0, i32 1
store i8 104, i8* %10
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i32 0, i32 2
store i8 105, i8* %11
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i32 0, i32 3
store i8 99, i8* %12
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i32 0, i32 4
store i8 104, i8* %13
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i32 0, i32 5
store i8 32, i8* %14
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = load i8*, i8** %3
%17 = call i32 @strcat(i8* %15, i8* %16)
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = call i32* @popen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%21 = load i32*, i32** %6
%22 = call i32* @fgets(i8* %20, i32 1024, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %31
24: ; preds = %1
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%26 = call i32 @strchr(i8* %25, i8 signext 58)
%27 = icmp ne i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = load i32*, i32** %6
%30 = call i32 @pclose(i32* %29)
store i32 1, i32* %2
br label %34
31: ; preds = %24, %1
%32 = load i32*, i32** %6
%33 = call i32 @pclose(i32* %32)
store i32 0, i32* %2
br label %34
34: ; preds = %31, %28
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @detectPresence(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
store i8 119, i8* %5
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
store i8 104, i8* %6
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 2
store i8 105, i8* %7
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 3
store i8 99, i8* %8
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 4
store i8 104, i8* %9
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 5
store i8 32, i8* %10
%11 = call i32 @strcat(i8* %5, i8* %0)
%12 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = call i32* @fgets(i8* %4, i32 1024, i32* %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %1
%16 = call i32 @strchr(i8* %4, i8 signext 58)
%17 = icmp eq i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %15, %1
br label %19
19: ; preds = %15, %18
%20 = phi i32 [ 0, %18 ], [ 1, %15 ]
%21 = call i32 @pclose(i32* %12)
ret i32 %20
}