#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 */
int S_IXUSR;
int /*<<< orphan*/ dirAndFil(char *, char **, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
scalar_t__ getcwd(char *, int);
char *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int stat(char *, struct stat *);
scalar_t__ strchr(char *, char);
char *strdup(char const *);
int strlen(char *);
char *whereAmI(const char *argvz, char **dir, char **fil) {
  char *workd, *path, *retname;
  char *pathelem[1024];
  int i, j, osl;
  struct stat sbuf;
  char *argvzd = strdup(argvz);
  if (!argvzd) {
    perror("strdup");
    exit(1);
  }
  if (argvzd[0] == '/') {
    dirAndFil(argvzd, dir, fil);
    return argvzd;
  }
  if (strchr(argvzd, '/')) {
    workd = (char *)malloc(1024 * sizeof(char));
    if (!workd) {
      perror("malloc");
      exit(1);
    }
    if (getcwd(workd, 1024)) {
      retname =
          (char *)malloc((strlen(workd) + strlen(argvzd) + 2) * sizeof(char));
      if (!retname) {
        perror("malloc");
        exit(1);
      }
      sprintf(retname, "%s/%s", workd, argvzd);
      free(workd);
      dirAndFil(retname, dir, fil);
      free(argvzd);
      return retname;
    }
  }
  path = getenv("PATH");
  if (path == NULL) {
    return NULL;
  }
  path = strdup(path);
  memset(pathelem, 0, 1024 * sizeof(char *));
  pathelem[0] = path;
  i = 1;
  osl = strlen(path);
  for (j = 0; j < osl; j++) {
    for (; path[j] != '\0' && path[j] != ':'; j++)
      ;
    if (path[j] == ':') {
      path[j] = '\0';
      j++;
      pathelem[i++] = path + j;
    }
  }
  for (i = 0; pathelem[i]; i++) {
    retname = (char *)malloc((strlen(pathelem[i]) + strlen(argvzd) + 2) *
                             sizeof(char));
    if (!retname) {
      perror("malloc");
      exit(1);
    }
    sprintf(retname, "%s/%s", pathelem[i], argvzd);
    if (stat(retname, &sbuf) == -1) {
      free(retname);
      continue;
    }
    if (sbuf.st_mode & S_IXUSR) {
      dirAndFil(retname, dir, fil);
      free(argvzd);
      return retname;
    }
    free(retname);
  }
  dir = NULL;
  fil = NULL;
  free(argvzd);
  return NULL;
}


x86 assembly (clang, -O0):
<whereAmI>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2070,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x2058(%rbp)
cmpq   $0x0,-0x2058(%rbp)
jne    121b <whereAmI+0x4b>
lea    0xdf4(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x2058(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1252 <whereAmI+0x82>
mov    -0x2058(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dirAndFil@plt>
mov    -0x2058(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1622 <whereAmI+0x452>
mov    -0x2058(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
je     1361 <whereAmI+0x191>
mov    $0x400,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    129c <whereAmI+0xcc>
lea    0xd7a(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    $0x400,%esi
call   1090 <getcwd@plt>
cmp    $0x0,%rax
je     135c <whereAmI+0x18c>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x205c(%rbp)
mov    -0x2058(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x205c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    130e <whereAmI+0x13e>
lea    0xd08(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x2058(%rbp),%rcx
lea    0xcea(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <free@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dirAndFil@plt>
mov    -0x2058(%rbp),%rdi
call   1050 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1622 <whereAmI+0x452>
jmp    1361 <whereAmI+0x191>
lea    0xcac(%rip),%rdi
call   1040 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1389 <whereAmI+0x1b9>
movq   $0x0,-0x8(%rbp)
jmp    1622 <whereAmI+0x452>
mov    -0x30(%rbp),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x30(%rbp)
lea    -0x2040(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1080 <memset@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x2040(%rbp)
movl   $0x1,-0x2044(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x204c(%rbp)
movl   $0x0,-0x2048(%rbp)
mov    -0x2048(%rbp),%eax
cmp    -0x204c(%rbp),%eax
jge    14cd <whereAmI+0x2fd>
jmp    13ee <whereAmI+0x21e>
mov    -0x30(%rbp),%rax
movslq -0x2048(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x205d(%rbp)
je     1429 <whereAmI+0x259>
mov    -0x30(%rbp),%rax
movslq -0x2048(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x205d(%rbp)
mov    -0x205d(%rbp),%al
test   $0x1,%al
jne    143c <whereAmI+0x26c>
jmp    1455 <whereAmI+0x285>
jmp    1441 <whereAmI+0x271>
mov    -0x2048(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2048(%rbp)
jmp    13ee <whereAmI+0x21e>
mov    -0x30(%rbp),%rax
movslq -0x2048(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    14b4 <whereAmI+0x2e4>
mov    -0x30(%rbp),%rax
movslq -0x2048(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2048(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2048(%rbp)
mov    -0x30(%rbp),%rcx
movslq -0x2048(%rbp),%rax
add    %rax,%rcx
mov    -0x2044(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x2044(%rbp)
cltq
mov    %rcx,-0x2040(%rbp,%rax,8)
ff
jmp    14b9 <whereAmI+0x2e9>
mov    -0x2048(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2048(%rbp)
jmp    13d7 <whereAmI+0x207>
movl   $0x0,-0x2044(%rbp)
movslq -0x2044(%rbp),%rax
cmpq   $0x0,-0x2040(%rbp,%rax,8)
je     15fe <whereAmI+0x42e>
movslq -0x2044(%rbp),%rax
mov    -0x2040(%rbp,%rax,8),%rdi
ff
call   1060 <strlen@plt>
mov    %eax,-0x2064(%rbp)
mov    -0x2058(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x2064(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1552 <whereAmI+0x382>
lea    0xac4(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x38(%rbp),%rdi
movslq -0x2044(%rbp),%rax
mov    -0x2040(%rbp,%rax,8),%rdx
ff
mov    -0x2058(%rbp),%rcx
lea    0xa9b(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x2050(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0xffffffff,%eax
jne    159f <whereAmI+0x3cf>
mov    -0x38(%rbp),%rdi
call   1050 <free@plt>
jmp    15ea <whereAmI+0x41a>
mov    -0x2050(%rbp),%eax
mov    0x2a3c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     15e1 <whereAmI+0x411>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dirAndFil@plt>
mov    -0x2058(%rbp),%rdi
call   1050 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1622 <whereAmI+0x452>
mov    -0x38(%rbp),%rdi
call   1050 <free@plt>
mov    -0x2044(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2044(%rbp)
jmp    14d7 <whereAmI+0x307>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x2058(%rbp),%rdi
call   1050 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<whereAmI>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2028,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
call   10f0 <strdup@plt>
test   %rax,%rax
je     142c <whereAmI+0x25c>
mov    %rax,%r12
cmpb   $0x2f,(%rax)
jne    1210 <whereAmI+0x40>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <dirAndFil@plt>
jmp    140e <whereAmI+0x23e>
mov    %r12,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     12b2 <whereAmI+0xe2>
mov    $0x400,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     1423 <whereAmI+0x253>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x400,%esi
call   1090 <getcwd@plt>
test   %rax,%rax
je     12b2 <whereAmI+0xe2>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x2,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     1423 <whereAmI+0x253>
mov    %rax,%rbp
lea    0xd90(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r12,%rcx
call   10d0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <free@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <dirAndFil@plt>
mov    %r12,%rdi
call   1050 <free@plt>
mov    %rbp,%r12
jmp    140e <whereAmI+0x23e>
lea    0xd5b(%rip),%rdi
call   1040 <getenv@plt>
test   %rax,%rax
je     140b <whereAmI+0x23b>
mov    %r14,0x18(%rsp)
mov    %rax,%rdi
call   10f0 <strdup@plt>
mov    %rax,%r14
lea    0x20(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x2000,%edx
call   1080 <memset@plt>
mov    %r14,0x20(%rsp)
mov    %r14,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    1355 <whereAmI+0x185>
mov    $0x1,%ecx
jmp    132e <whereAmI+0x15e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%rdx)
add    $0x1,%ebp
movslq %ebp,%rdx
add    %r14,%rdx
movslq %ecx,%rsi
add    $0x1,%ecx
mov    %rdx,0x20(%rsp,%rsi,8)
add    $0x1,%ebp
cmp    %eax,%ebp
jge    1355 <whereAmI+0x185>
movslq %ebp,%rdx
add    %r14,%rdx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rdx),%ebx
test   %bl,%bl
je     1327 <whereAmI+0x157>
cmp    $0x3a,%bl
je     1310 <whereAmI+0x140>
add    $0x1,%ebp
add    $0x1,%rdx
jmp    1340 <whereAmI+0x170>
mov    %r15,0x10(%rsp)
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
je     1403 <whereAmI+0x233>
lea    0x28(%rsp),%r14
lea    0xc9a(%rip),%r13
lea    0x8(%rsp),%rbx
mov    0x2c68(%rip),%r15
jmp    13a4 <whereAmI+0x1d4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1050 <free@plt>
mov    (%r14),%rdi
add    $0x8,%r14
test   %rdi,%rdi
je     1403 <whereAmI+0x233>
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x2,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     1423 <whereAmI+0x253>
mov    %rax,%rbp
mov    -0x8(%r14),%rdx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rcx
call   10d0 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <stat@plt>
cmp    $0xffffffff,%eax
je     1390 <whereAmI+0x1c0>
mov    (%r15),%eax
test   %eax,0x8(%rsp)
je     1390 <whereAmI+0x1c0>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
jmp    129d <whereAmI+0xcd>
mov    %r12,%rdi
call   1050 <free@plt>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x2028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbdd(%rip),%rdi
jmp    1433 <whereAmI+0x263>
lea    0xbcd(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c"strdup\00"
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [5 x i8] c"PATH\00"
@S_IXUSR = global i32 0
define i8* @whereAmI(i8* nocapture %0, i8** %1, i8** %2) {
%4 = alloca [1024 x i8*]
%5 = alloca %struct.stat
%6 = bitcast [1024 x i8*]* %4 to i8*
%7 = bitcast %struct.stat* %5 to i8*
%8 = tail call i8* @strdup(i8* %0)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %3
%14 = load i8, i8* %8
%15 = icmp eq i8 %14, 47
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @dirAndFil(i8* %8, i8** %1, i8** %2)
br label %123
18: ; preds = %13
%19 = tail call i64 @strchr(i8* %8, i8 signext 47)
%20 = icmp eq i64 %19, 0
br i1 %20, label %47, label %21
21: ; preds = %18
%22 = tail call i64 @malloc(i32 1024)
%23 = inttoptr i64 %22 to i8*
%24 = icmp eq i64 %22, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = tail call i64 @getcwd(i8* %23, i32 1024)
%30 = icmp eq i64 %29, 0
br i1 %30, label %47, label %31
31: ; preds = %28
%32 = tail call i32 @strlen(i8* %23)
%33 = tail call i32 @strlen(i8* %8)
%34 = add i32 %32, 2
%35 = add i32 %34, %33
%36 = tail call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
%38 = icmp eq i64 %36, 0
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %31
%43 = tail call i32 @sprintf(i8* %37, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %8)
%44 = tail call i32 @free(i8* %23)
%45 = tail call i32 @dirAndFil(i8* %37, i8** %1, i8** %2)
%46 = tail call i32 @free(i8* %8)
br label %123
47: ; preds = %28, %18
%48 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%49 = icmp eq i8* %48, null
br i1 %49, label %123, label %50
50: ; preds = %47
%51 = tail call i8* @strdup(i8* %48)
%52 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %4, i64 0, i64 0
%53 = call i32 @memset(i8** %52, i32 0, i32 8192)
store i8* %51, i8** %52
%54 = call i32 @strlen(i8* %51)
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %50, %82
%57 = phi i32 [ %85, %82 ], [ 0, %50 ]
%58 = phi i32 [ %83, %82 ], [ 1, %50 ]
%59 = sext i32 %57 to i64
br label %65
60: ; preds = %82, %50
%61 = load i8*, i8** %52
%62 = icmp eq i8* %61, null
br i1 %62, label %121, label %63
63: ; preds = %60
%64 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
br label %87
65: ; preds = %56, %69
%66 = phi i64 [ %59, %56 ], [ %70, %69 ]
%67 = getelementptr inbounds i8, i8* %51, i64 %66
%68 = load i8, i8* %67
switch i8 %68, label %69 [
i8 58, label %71
i8 0, label %80
]
69: ; preds = %65
%70 = add i64 %66, 1
br label %65
71: ; preds = %65
%72 = getelementptr inbounds i8, i8* %51, i64 %66
%73 = trunc i64 %66 to i32
store i8 0, i8* %72
%74 = add nsw i32 %73, 1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %51, i64 %75
%77 = add nsw i32 %58, 1
%78 = sext i32 %58 to i64
%79 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %4, i64 0, i64 %78
store i8* %76, i8** %79
br label %82
80: ; preds = %65
%81 = trunc i64 %66 to i32
br label %82
82: ; preds = %80, %71
%83 = phi i32 [ %77, %71 ], [ %58, %80 ]
%84 = phi i32 [ %74, %71 ], [ %81, %80 ]
%85 = add nsw i32 %84, 1
%86 = icmp slt i32 %85, %54
br i1 %86, label %56, label %60
87: ; preds = %63, %115
%88 = phi i64 [ 0, %63 ], [ %117, %115 ]
%89 = phi i8* [ %61, %63 ], [ %119, %115 ]
%90 = phi i8** [ %52, %63 ], [ %118, %115 ]
%91 = call i32 @strlen(i8* %89)
%92 = call i32 @strlen(i8* %8)
%93 = add i32 %91, 2
%94 = add i32 %93, %92
%95 = call i64 @malloc(i32 %94)
%96 = inttoptr i64 %95 to i8*
%97 = icmp eq i64 %95, 0
br i1 %97, label %98, label %101
98: ; preds = %87
%99 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %87
%102 = load i8*, i8** %90
%103 = call i32 @sprintf(i8* %96, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %102, i8* %8)
%104 = call i32 @stat(i8* %96, %struct.stat* %5)
%105 = icmp eq i32 %104, -1
br i1 %105, label %115, label %106
106: ; preds = %101
%107 = load i32, i32* %64
%108 = load i32, i32* @S_IXUSR
%109 = and i32 %108, %107
%110 = icmp eq i32 %109, 0
br i1 %110, label %115, label %111
111: ; preds = %106
%112 = inttoptr i64 %95 to i8*
%113 = call i32 @dirAndFil(i8* %112, i8** %1, i8** %2)
%114 = call i32 @free(i8* %8)
br label %123
115: ; preds = %106, %101
%116 = call i32 @free(i8* %96)
%117 = add nuw i64 %88, 1
%118 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %4, i64 0, i64 %117
%119 = load i8*, i8** %118
%120 = icmp eq i8* %119, null
br i1 %120, label %121, label %87
121: ; preds = %115, %60
%122 = call i32 @free(i8* %8)
br label %123
123: ; preds = %47, %121, %111, %42, %16
%124 = phi i8* [ %8, %16 ], [ %37, %42 ], [ %112, %111 ], [ null, %121 ], [ null, %47 ]
ret i8* %124
}