#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 */

/* Variables and functions */
scalar_t__ check_executable(char *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ *getcwd(char *, int);
char *getenv(char *);
int /*<<< orphan*/ lt_fatal(char *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
scalar_t__ xmalloc(int);
char *xstrdup(char const *);
char *find_executable(const char *wrapper) {
  int has_slash = 0;
  const char *p;
  const char *p_next;
  char tmp[1024 + 1];
  int tmp_len;
  char *concat_name;

  ;
  if ((wrapper == NULL) || (*wrapper == '\0'))
    return NULL;
  if (((wrapper[0]) == '/')) {
    concat_name = xstrdup(wrapper);
    if (check_executable(concat_name))
      return concat_name;
    do {
      if (concat_name) {
        free((void *)concat_name);
        concat_name = 0;
      }
    } while (0);
  }
  for (p = wrapper; *p; p++)
    if (*p == '/') {
      has_slash = 1;
      break;
    }
  if (!has_slash) {
    const char *path = getenv("PATH");
    if (path != NULL) {
      for (p = path; *p; p = p_next) {
        const char *q;
        size_t p_len;
        for (q = p; *q; q++)
          if (((*q) == ':'))
            break;
        p_len = q - p;
        p_next = (*q == '\0' ? q : q + 1);
        if (p_len == 0) {
          if (getcwd(tmp, 1024) == NULL)
            lt_fatal("getcwd failed");
          tmp_len = strlen(tmp);
          concat_name = ((char *)xmalloc((tmp_len + 1 + strlen(wrapper) + 1) *
                                         sizeof(char)));
          memcpy(concat_name, tmp, tmp_len);
          concat_name[tmp_len] = '/';
          strcpy(concat_name + tmp_len + 1, wrapper);
        } else {
          concat_name = ((char *)xmalloc((p_len + 1 + strlen(wrapper) + 1) *
                                         sizeof(char)));
          memcpy(concat_name, p, p_len);
          concat_name[p_len] = '/';
          strcpy(concat_name + p_len + 1, wrapper);
        }
        if (check_executable(concat_name))
          return concat_name;
        do {
          if (concat_name) {
            free((void *)concat_name);
            concat_name = 0;
          }
        } while (0);
      }
    }
  }
  if (getcwd(tmp, 1024) == NULL)
    lt_fatal("getcwd failed");
  tmp_len = strlen(tmp);
  concat_name =
      ((char *)xmalloc((tmp_len + 1 + strlen(wrapper) + 1) * sizeof(char)));
  memcpy(concat_name, tmp, tmp_len);
  concat_name[tmp_len] = '/';
  strcpy(concat_name + tmp_len + 1, wrapper);
  if (check_executable(concat_name))
    return concat_name;
  do {
    if (concat_name) {
      free((void *)concat_name);
      concat_name = 0;
    }
  } while (0);
  return NULL;
}


x86 assembly (clang, -O0):
<find_executable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d1 <find_executable+0x31>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11de <find_executable+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    1666 <find_executable+0x4c6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1258 <find_executable+0xb8>
mov    -0x10(%rbp),%rdi
call   10a0 <xstrdup@plt>
mov    %rax,-0x440(%rbp)
mov    -0x440(%rbp),%rdi
call   10c0 <check_executable@plt>
cmp    $0x0,%rax
je     1224 <find_executable+0x84>
mov    -0x440(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1666 <find_executable+0x4c6>
jmp    1229 <find_executable+0x89>
cmpq   $0x0,-0x440(%rbp)
je     124e <find_executable+0xae>
mov    -0x440(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x440(%rbp)
jmp    1253 <find_executable+0xb3>
jmp    1258 <find_executable+0xb8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     129f <find_executable+0xff>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1289 <find_executable+0xe9>
movl   $0x1,-0x14(%rbp)
jmp    129f <find_executable+0xff>
jmp    128e <find_executable+0xee>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1260 <find_executable+0xc0>
cmpl   $0x0,-0x14(%rbp)
jne    154e <find_executable+0x3ae>
lea    0xd50(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
je     1549 <find_executable+0x3a9>
mov    -0x448(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1544 <find_executable+0x3a4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x450(%rbp)
mov    -0x450(%rbp),%rax
cmpb   $0x0,(%rax)
je     1331 <find_executable+0x191>
mov    -0x450(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1315 <find_executable+0x175>
jmp    1331 <find_executable+0x191>
jmp    131a <find_executable+0x17a>
mov    -0x450(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x450(%rbp)
jmp    12ed <find_executable+0x14d>
mov    -0x450(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x458(%rbp)
mov    -0x450(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    136c <find_executable+0x1cc>
mov    -0x450(%rbp),%rax
mov    %rax,-0x460(%rbp)
jmp    137e <find_executable+0x1de>
mov    -0x450(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x460(%rbp)
mov    -0x460(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x458(%rbp)
jne    1457 <find_executable+0x2b7>
lea    -0x430(%rbp),%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
cmp    $0x0,%rax
jne    13be <find_executable+0x21e>
lea    0xc4c(%rip),%rdi
call   1050 <lt_fatal@plt>
lea    -0x430(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x434(%rbp)
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x464(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x464(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <xmalloc@plt>
mov    %rax,-0x440(%rbp)
mov    -0x440(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x434(%rbp),%edx
call   10b0 <memcpy@plt>
mov    -0x440(%rbp),%rax
movslq -0x434(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x440(%rbp),%rdi
movslq -0x434(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcpy@plt>
jmp    14dd <find_executable+0x33d>
mov    -0x458(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x470(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x470(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <xmalloc@plt>
mov    %rax,-0x440(%rbp)
mov    -0x440(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x458(%rbp),%rax
mov    %eax,%edx
call   10b0 <memcpy@plt>
mov    -0x440(%rbp),%rax
mov    -0x458(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x440(%rbp),%rdi
add    -0x458(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcpy@plt>
mov    -0x440(%rbp),%rdi
call   10c0 <check_executable@plt>
cmp    $0x0,%rax
je     1503 <find_executable+0x363>
mov    -0x440(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1666 <find_executable+0x4c6>
jmp    1508 <find_executable+0x368>
cmpq   $0x0,-0x440(%rbp)
je     152d <find_executable+0x38d>
mov    -0x440(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x440(%rbp)
jmp    1532 <find_executable+0x392>
jmp    1537 <find_executable+0x397>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    12d5 <find_executable+0x135>
jmp    1549 <find_executable+0x3a9>
jmp    154e <find_executable+0x3ae>
lea    -0x430(%rbp),%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
cmp    $0x0,%rax
jne    1575 <find_executable+0x3d5>
lea    0xa95(%rip),%rdi
call   1050 <lt_fatal@plt>
lea    -0x430(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x434(%rbp)
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x474(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x474(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <xmalloc@plt>
mov    %rax,-0x440(%rbp)
mov    -0x440(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x434(%rbp),%edx
call   10b0 <memcpy@plt>
mov    -0x440(%rbp),%rax
movslq -0x434(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x440(%rbp),%rdi
movslq -0x434(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcpy@plt>
mov    -0x440(%rbp),%rdi
call   10c0 <check_executable@plt>
cmp    $0x0,%rax
je     162f <find_executable+0x48f>
mov    -0x440(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1666 <find_executable+0x4c6>
jmp    1634 <find_executable+0x494>
cmpq   $0x0,-0x440(%rbp)
je     1659 <find_executable+0x4b9>
mov    -0x440(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x440(%rbp)
jmp    165e <find_executable+0x4be>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_executable>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
test   %rdi,%rdi
je     13c0 <find_executable+0x220>
mov    %rdi,%rbp
mov    (%rdi),%al
test   %al,%al
je     13c0 <find_executable+0x220>
cmp    $0x2f,%al
jne    11f4 <find_executable+0x54>
mov    %rbp,%rdi
call   10a0 <xstrdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10c0 <check_executable@plt>
test   %rax,%rax
jne    13c2 <find_executable+0x222>
test   %rbx,%rbx
je     11f4 <find_executable+0x54>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %rbp,%rax
nopw   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
test   %cl,%cl
je     1216 <find_executable+0x76>
cmp    $0x2f,%cl
je     133e <find_executable+0x19e>
add    $0x1,%rax
jmp    1200 <find_executable+0x60>
lea    0xde3(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     133e <find_executable+0x19e>
mov    %rax,%r15
mov    (%rax),%al
test   %al,%al
je     133e <find_executable+0x19e>
mov    %r15,%r13
nopl   0x0(%rax,%rax,1)
xor    %r14d,%r14d
test   %al,%al
je     1265 <find_executable+0xc5>
nopw   0x0(%rax,%rax,1)
cmp    $0x3a,%al
je     1265 <find_executable+0xc5>
movzbl 0x1(%r13),%eax
add    $0x1,%r13
add    $0xffffffffffffffff,%r14
test   %al,%al
jne    1250 <find_executable+0xb0>
cmp    $0x1,%al
sbb    $0xffffffffffffffff,%r13
test   %r14,%r14
je     12b0 <find_executable+0x110>
mov    %rbp,%r12
mov    %rbp,%rdi
call   1070 <strlen@plt>
sub    %r14d,%eax
mov    %r14d,%ebp
neg    %ebp
lea    0x2(%rax),%edi
call   1090 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   10b0 <memcpy@plt>
mov    %rbx,%rdi
sub    %r14,%rdi
mov    %r12,%rbp
jmp    1307 <find_executable+0x167>
cs nopw 0x0(%rax,%rax,1)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
test   %rax,%rax
jne    12d1 <find_executable+0x131>
lea    0xd39(%rip),%rdi
call   1050 <lt_fatal@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1070 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x2,%edi
call   1090 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   10b0 <memcpy@plt>
movslq %r15d,%rdi
add    %rbx,%rdi
movb   $0x2f,(%rdi)
add    $0x1,%rdi
mov    %rbp,%rsi
call   1060 <strcpy@plt>
mov    %rbx,%rdi
call   10c0 <check_executable@plt>
test   %rax,%rax
jne    13c2 <find_executable+0x222>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    0x0(%r13),%al
mov    %r13,%r15
test   %al,%al
jne    1240 <find_executable+0xa0>
mov    %rsp,%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
test   %rax,%rax
jne    135c <find_executable+0x1bc>
lea    0xcae(%rip),%rdi
call   1050 <lt_fatal@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1070 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x2,%edi
call   1090 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   10b0 <memcpy@plt>
movslq %r15d,%rax
movb   $0x2f,(%rbx,%rax,1)
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
mov    %rbp,%rsi
call   1060 <strcpy@plt>
mov    %rbx,%rdi
call   10c0 <check_executable@plt>
test   %rax,%rax
jne    13c2 <find_executable+0x222>
test   %rbx,%rbx
je     13c0 <find_executable+0x220>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [14 x i8] c"getcwd failed\00"
define i8* @find_executable(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1025 x i8]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
store i8* %0, i8** %3
store i32 0, i32* %4
%13 = load i8*, i8** %3
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15, %1
store i8* null, i8** %2
br label %237
21: ; preds = %15
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 47
br i1 %26, label %27, label %44
27: ; preds = %21
%28 = load i8*, i8** %3
%29 = call i8* @xstrdup(i8* %28)
store i8* %29, i8** %9
%30 = load i8*, i8** %9
%31 = call i64 @check_executable(i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = load i8*, i8** %9
store i8* %34, i8** %2
br label %237
35: ; preds = %27
br label %36
36: ; preds = %35
%37 = load i8*, i8** %9
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i8*, i8** %9
%41 = call i32 @free(i8* %40)
store i8* null, i8** %9
br label %42
42: ; preds = %39, %36
br label %43
43: ; preds = %42
br label %44
44: ; preds = %43, %21
%45 = load i8*, i8** %3
store i8* %45, i8** %5
br label %46
46: ; preds = %57, %44
%47 = load i8*, i8** %5
%48 = load i8, i8* %47
%49 = icmp ne i8 %48, 0
br i1 %49, label %50, label %60
50: ; preds = %46
%51 = load i8*, i8** %5
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 47
br i1 %54, label %55, label %56
55: ; preds = %50
store i32 1, i32* %4
br label %60
56: ; preds = %50
br label %57
57: ; preds = %56
%58 = load i8*, i8** %5
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %5
br label %46
60: ; preds = %55, %46
%61 = load i32, i32* %4
%62 = icmp ne i32 %61, 0
br i1 %62, label %188, label %63
63: ; preds = %60
%64 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %64, i8** %10
%65 = load i8*, i8** %10
%66 = icmp ne i8* %65, null
br i1 %66, label %67, label %187
67: ; preds = %63
%68 = load i8*, i8** %10
store i8* %68, i8** %5
br label %69
69: ; preds = %184, %67
%70 = load i8*, i8** %5
%71 = load i8, i8* %70
%72 = icmp ne i8 %71, 0
br i1 %72, label %73, label %186
73: ; preds = %69
%74 = load i8*, i8** %5
store i8* %74, i8** %11
br label %75
75: ; preds = %86, %73
%76 = load i8*, i8** %11
%77 = load i8, i8* %76
%78 = icmp ne i8 %77, 0
br i1 %78, label %79, label %89
79: ; preds = %75
%80 = load i8*, i8** %11
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %82, 58
br i1 %83, label %84, label %85
84: ; preds = %79
br label %89
85: ; preds = %79
br label %86
86: ; preds = %85
%87 = load i8*, i8** %11
%88 = getelementptr inbounds i8, i8* %87, i32 1
store i8* %88, i8** %11
br label %75
89: ; preds = %84, %75
%90 = load i8*, i8** %11
%91 = load i8*, i8** %5
%92 = ptrtoint i8* %90 to i64
%93 = ptrtoint i8* %91 to i64
%94 = sub i64 %92, %93
store i64 %94, i64* %12
%95 = load i8*, i8** %11
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = icmp eq i32 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %89
%100 = load i8*, i8** %11
br label %104
101: ; preds = %89
%102 = load i8*, i8** %11
%103 = getelementptr inbounds i8, i8* %102, i64 1
br label %104
104: ; preds = %101, %99
%105 = phi i8* [ %100, %99 ], [ %103, %101 ]
store i8* %105, i8** %6
%106 = load i64, i64* %12
%107 = icmp eq i64 %106, 0
br i1 %107, label %108, label %143
108: ; preds = %104
%109 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%110 = call i32* @getcwd(i8* %109, i32 1024)
%111 = icmp eq i32* %110, null
br i1 %111, label %112, label %114
112: ; preds = %108
%113 = call i32 @lt_fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %114
114: ; preds = %112, %108
%115 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%116 = call i32 @strlen(i8* %115)
store i32 %116, i32* %8
%117 = load i32, i32* %8
%118 = add nsw i32 %117, 1
%119 = load i8*, i8** %3
%120 = call i32 @strlen(i8* %119)
%121 = add nsw i32 %118, %120
%122 = add nsw i32 %121, 1
%123 = sext i32 %122 to i64
%124 = mul i64 %123, 1
%125 = trunc i64 %124 to i32
%126 = call i64 @xmalloc(i32 %125)
%127 = inttoptr i64 %126 to i8*
store i8* %127, i8** %9
%128 = load i8*, i8** %9
%129 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%130 = load i32, i32* %8
%131 = call i32 @memcpy(i8* %128, i8* %129, i32 %130)
%132 = load i8*, i8** %9
%133 = load i32, i32* %8
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i8, i8* %132, i64 %134
store i8 47, i8* %135
%136 = load i8*, i8** %9
%137 = load i32, i32* %8
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i8, i8* %136, i64 %138
%140 = getelementptr inbounds i8, i8* %139, i64 1
%141 = load i8*, i8** %3
%142 = call i32 @strcpy(i8* %140, i8* %141)
br label %169
143: ; preds = %104
%144 = load i64, i64* %12
%145 = add i64 %144, 1
%146 = load i8*, i8** %3
%147 = call i32 @strlen(i8* %146)
%148 = sext i32 %147 to i64
%149 = add i64 %145, %148
%150 = add i64 %149, 1
%151 = mul i64 %150, 1
%152 = trunc i64 %151 to i32
%153 = call i64 @xmalloc(i32 %152)
%154 = inttoptr i64 %153 to i8*
store i8* %154, i8** %9
%155 = load i8*, i8** %9
%156 = load i8*, i8** %5
%157 = load i64, i64* %12
%158 = trunc i64 %157 to i32
%159 = call i32 @memcpy(i8* %155, i8* %156, i32 %158)
%160 = load i8*, i8** %9
%161 = load i64, i64* %12
%162 = getelementptr inbounds i8, i8* %160, i64 %161
store i8 47, i8* %162
%163 = load i8*, i8** %9
%164 = load i64, i64* %12
%165 = getelementptr inbounds i8, i8* %163, i64 %164
%166 = getelementptr inbounds i8, i8* %165, i64 1
%167 = load i8*, i8** %3
%168 = call i32 @strcpy(i8* %166, i8* %167)
br label %169
169: ; preds = %143, %114
%170 = load i8*, i8** %9
%171 = call i64 @check_executable(i8* %170)
%172 = icmp ne i64 %171, 0
br i1 %172, label %173, label %175
173: ; preds = %169
%174 = load i8*, i8** %9
store i8* %174, i8** %2
br label %237
175: ; preds = %169
br label %176
176: ; preds = %175
%177 = load i8*, i8** %9
%178 = icmp ne i8* %177, null
br i1 %178, label %179, label %182
179: ; preds = %176
%180 = load i8*, i8** %9
%181 = call i32 @free(i8* %180)
store i8* null, i8** %9
br label %182
182: ; preds = %179, %176
br label %183
183: ; preds = %182
br label %184
184: ; preds = %183
%185 = load i8*, i8** %6
store i8* %185, i8** %5
br label %69
186: ; preds = %69
br label %187
187: ; preds = %186, %63
br label %188
188: ; preds = %187, %60
%189 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%190 = call i32* @getcwd(i8* %189, i32 1024)
%191 = icmp eq i32* %190, null
br i1 %191, label %192, label %194
192: ; preds = %188
%193 = call i32 @lt_fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %194
194: ; preds = %192, %188
%195 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%196 = call i32 @strlen(i8* %195)
store i32 %196, i32* %8
%197 = load i32, i32* %8
%198 = add nsw i32 %197, 1
%199 = load i8*, i8** %3
%200 = call i32 @strlen(i8* %199)
%201 = add nsw i32 %198, %200
%202 = add nsw i32 %201, 1
%203 = sext i32 %202 to i64
%204 = mul i64 %203, 1
%205 = trunc i64 %204 to i32
%206 = call i64 @xmalloc(i32 %205)
%207 = inttoptr i64 %206 to i8*
store i8* %207, i8** %9
%208 = load i8*, i8** %9
%209 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%210 = load i32, i32* %8
%211 = call i32 @memcpy(i8* %208, i8* %209, i32 %210)
%212 = load i8*, i8** %9
%213 = load i32, i32* %8
%214 = sext i32 %213 to i64
%215 = getelementptr inbounds i8, i8* %212, i64 %214
store i8 47, i8* %215
%216 = load i8*, i8** %9
%217 = load i32, i32* %8
%218 = sext i32 %217 to i64
%219 = getelementptr inbounds i8, i8* %216, i64 %218
%220 = getelementptr inbounds i8, i8* %219, i64 1
%221 = load i8*, i8** %3
%222 = call i32 @strcpy(i8* %220, i8* %221)
%223 = load i8*, i8** %9
%224 = call i64 @check_executable(i8* %223)
%225 = icmp ne i64 %224, 0
br i1 %225, label %226, label %228
226: ; preds = %194
%227 = load i8*, i8** %9
store i8* %227, i8** %2
br label %237
228: ; preds = %194
br label %229
229: ; preds = %228
%230 = load i8*, i8** %9
%231 = icmp ne i8* %230, null
br i1 %231, label %232, label %235
232: ; preds = %229
%233 = load i8*, i8** %9
%234 = call i32 @free(i8* %233)
store i8* null, i8** %9
br label %235
235: ; preds = %232, %229
br label %236
236: ; preds = %235
store i8* null, i8** %2
br label %237
237: ; preds = %236, %226, %173, %33, %20
%238 = load i8*, i8** %2
ret i8* %238
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [14 x i8] c"getcwd failed\00"
define i8* @find_executable(i8* %0) {
%2 = alloca [1025 x i8]
%3 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %102, label %5
5: ; preds = %1
%6 = load i8, i8* %0
switch i8 %6, label %15 [
i8 0, label %102
i8 47, label %7
]
7: ; preds = %5
%8 = tail call i8* @xstrdup(i8* %0)
%9 = tail call i64 @check_executable(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %102
11: ; preds = %7
%12 = icmp eq i8* %8, null
br i1 %12, label %15, label %13
13: ; preds = %11
%14 = tail call i32 @free(i8* %8)
br label %15
15: ; preds = %5, %11, %13
br label %16
16: ; preds = %15, %19
%17 = phi i8* [ %20, %19 ], [ %0, %15 ]
%18 = load i8, i8* %17
switch i8 %18, label %19 [
i8 0, label %21
i8 47, label %79
]
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %17, i64 1
br label %16
21: ; preds = %16
%22 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %79, label %24
24: ; preds = %21
%25 = load i8, i8* %22
%26 = icmp eq i8 %25, 0
br i1 %26, label %79, label %27
27: ; preds = %24, %75
%28 = phi i8 [ %77, %75 ], [ %25, %24 ]
%29 = phi i8* [ %42, %75 ], [ %22, %24 ]
br label %30
30: ; preds = %27, %33
%31 = phi i8 [ %35, %33 ], [ %28, %27 ]
%32 = phi i8* [ %34, %33 ], [ %29, %27 ]
switch i8 %31, label %33 [
i8 0, label %36
i8 58, label %36
]
33: ; preds = %30
%34 = getelementptr inbounds i8, i8* %32, i64 1
%35 = load i8, i8* %34
br label %30
36: ; preds = %30, %30
%37 = ptrtoint i8* %32 to i64
%38 = ptrtoint i8* %29 to i64
%39 = sub i64 %37, %38
%40 = icmp ne i8 %31, 0
%41 = zext i1 %40 to i64
%42 = getelementptr i8, i8* %32, i64 %41
%43 = icmp eq i64 %39, 0
br i1 %43, label %44, label %59
44: ; preds = %36
%45 = call i32* @getcwd(i8* %3, i32 1024)
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @lt_fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %44
%50 = call i32 @strlen(i8* %3)
%51 = call i32 @strlen(i8* %0)
%52 = add i32 %50, 2
%53 = add i32 %52, %51
%54 = call i64 @xmalloc(i32 %53)
%55 = inttoptr i64 %54 to i8*
%56 = call i32 @memcpy(i8* %55, i8* %3, i32 %50)
%57 = sext i32 %50 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
br label %68
59: ; preds = %36
%60 = call i32 @strlen(i8* %0)
%61 = trunc i64 %39 to i32
%62 = add i32 %61, 2
%63 = add i32 %62, %60
%64 = call i64 @xmalloc(i32 %63)
%65 = inttoptr i64 %64 to i8*
%66 = call i32 @memcpy(i8* %65, i8* %29, i32 %61)
%67 = getelementptr inbounds i8, i8* %65, i64 %39
br label %68
68: ; preds = %59, %49
%69 = phi i8* [ %67, %59 ], [ %58, %49 ]
%70 = phi i8* [ %65, %59 ], [ %55, %49 ]
store i8 47, i8* %69
%71 = getelementptr inbounds i8, i8* %69, i64 1
%72 = call i32 @strcpy(i8* %71, i8* %0)
%73 = call i64 @check_executable(i8* %70)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %102
75: ; preds = %68
%76 = call i32 @free(i8* %70)
%77 = load i8, i8* %42
%78 = icmp eq i8 %77, 0
br i1 %78, label %79, label %27
79: ; preds = %16, %75, %24, %21
%80 = call i32* @getcwd(i8* %3, i32 1024)
%81 = icmp eq i32* %80, null
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = call i32 @lt_fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %84
84: ; preds = %82, %79
%85 = call i32 @strlen(i8* %3)
%86 = call i32 @strlen(i8* %0)
%87 = add i32 %85, 2
%88 = add i32 %87, %86
%89 = call i64 @xmalloc(i32 %88)
%90 = inttoptr i64 %89 to i8*
%91 = call i32 @memcpy(i8* %90, i8* %3, i32 %85)
%92 = sext i32 %85 to i64
%93 = getelementptr inbounds i8, i8* %90, i64 %92
store i8 47, i8* %93
%94 = getelementptr inbounds i8, i8* %93, i64 1
%95 = call i32 @strcpy(i8* %94, i8* %0)
%96 = call i64 @check_executable(i8* %90)
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %102
98: ; preds = %84
%99 = icmp eq i64 %89, 0
br i1 %99, label %102, label %100
100: ; preds = %98
%101 = call i32 @free(i8* %90)
br label %102
102: ; preds = %68, %98, %100, %84, %7, %5, %1
%103 = phi i8* [ null, %5 ], [ null, %1 ], [ %8, %7 ], [ %90, %84 ], [ null, %100 ], [ null, %98 ], [ %70, %68 ]
ret i8* %103
}