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

/* Variables and functions */
int /*<<< orphan*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ asprintf(char **, char *, char *, char *, ...);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *lookupPath(char **argv, char **dir) {
  char *result;
  char pName[96];
  if (*argv[0] == '/') {
    return argv[0];
  } else if (*argv[0] == '.') {
    if (*++argv[0] == '.') {
      if (getcwd(pName, sizeof(pName)) == 0)
        perror("getcwd(): error\n");
      else {
        *--argv[0];
        asprintf(&result, "%s%s%s", pName, "/", argv[0]);
      }
      return result;
    }
    *--argv[0];
    if (*++argv[0] == '/') {
      if (getcwd(pName, sizeof(pName)) == 0)
        perror("getcwd(): error\n");
      else {
        asprintf(&result, "%s%s", pName, argv[0]);
      }
      return result;
    }
  }
  int i;
  for (i = 0; i < 64; i++) {
    if (dir[i] != 0) {
      asprintf(&result, "%s%s%s", dir[i], "/", argv[0]);
      if (access(result, X_OK) == 0) {
        return result;
      }
    } else
      continue;
  }
  fprintf(stderr, "%s: command not found\n", argv[0]);
  return 0;
}


x86 assembly (clang, -O0):
<lookupPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1186 <lookupPath+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1374 <lookupPath+0x224>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    12a3 <lookupPath+0x153>
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    121f <lookupPath+0xcf>
lea    -0x80(%rbp),%rdi
mov    $0x60,%esi
call   1030 <getcwd@plt>
cmp    $0x0,%rax
jne    11e0 <lookupPath+0x90>
lea    0xe2a(%rip),%rdi
call   1070 <perror@plt>
jmp    1212 <lookupPath+0xc2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
lea    -0x80(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%r8
lea    -0x20(%rbp),%rdi
lea    0xe0d(%rip),%rsi
lea    0xe0d(%rip),%rcx
mov    $0x0,%al
call   1050 <asprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1374 <lookupPath+0x224>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    129e <lookupPath+0x14e>
lea    -0x80(%rbp),%rdi
mov    $0x60,%esi
call   1030 <getcwd@plt>
cmp    $0x0,%rax
jne    1274 <lookupPath+0x124>
lea    0xd96(%rip),%rdi
call   1070 <perror@plt>
jmp    1291 <lookupPath+0x141>
lea    -0x80(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    -0x20(%rbp),%rdi
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   1050 <asprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1374 <lookupPath+0x224>
jmp    12a3 <lookupPath+0x153>
jmp    12a8 <lookupPath+0x158>
movl   $0x0,-0x84(%rbp)
cmpl   $0x40,-0x84(%rbp)
jge    1350 <lookupPath+0x200>
mov    -0x18(%rbp),%rax
movslq -0x84(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1332 <lookupPath+0x1e2>
mov    -0x18(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%r8
lea    -0x20(%rbp),%rdi
lea    0xd1b(%rip),%rsi
lea    0xd1b(%rip),%rcx
mov    $0x0,%al
call   1050 <asprintf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2cd9(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    132d <lookupPath+0x1dd>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1374 <lookupPath+0x224>
jmp    1337 <lookupPath+0x1e7>
jmp    133c <lookupPath+0x1ec>
jmp    133c <lookupPath+0x1ec>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    12b2 <lookupPath+0x162>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xcb3(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookupPath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    (%rdi),%rax
mov    (%rax),%cl
cmp    $0x2f,%cl
je     128d <lookupPath+0x13d>
mov    %rsi,%rbx
mov    %rdi,%r14
cmp    $0x2e,%cl
jne    1212 <lookupPath+0xc2>
lea    0x1(%rax),%rcx
mov    %rcx,(%r14)
cmpb   $0x2e,0x1(%rax)
jne    11d3 <lookupPath+0x83>
lea    0x10(%rsp),%rdi
mov    $0x60,%esi
call   1030 <getcwd@plt>
test   %rax,%rax
je     129c <lookupPath+0x14c>
mov    (%r14),%r8
add    $0xffffffffffffffff,%r8
mov    %r8,(%r14)
lea    0xe60(%rip),%rsi
lea    0xe60(%rip),%rcx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <asprintf@plt>
mov    0x8(%rsp),%rax
jmp    128d <lookupPath+0x13d>
cmpb   $0x2f,(%rcx)
jne    1212 <lookupPath+0xc2>
lea    0x10(%rsp),%rdi
mov    $0x60,%esi
call   1030 <getcwd@plt>
test   %rax,%rax
je     129c <lookupPath+0x14c>
mov    (%r14),%rcx
lea    0xe19(%rip),%rsi
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <asprintf@plt>
mov    0x8(%rsp),%rax
jmp    128d <lookupPath+0x13d>
lea    0xdff(%rip),%r12
lea    0x8(%rsp),%r13
mov    0x2dc3(%rip),%rbp
xor    %r15d,%r15d
jmp    123a <lookupPath+0xea>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    $0x40,%r15
je     1273 <lookupPath+0x123>
mov    (%rbx,%r15,8),%rdx
test   %rdx,%rdx
je     1230 <lookupPath+0xe0>
mov    (%r14),%r8
mov    %r13,%rdi
lea    0xdc1(%rip),%rsi
mov    %r12,%rcx
xor    %eax,%eax
call   1050 <asprintf@plt>
mov    0x8(%rsp),%rdi
mov    0x0(%rbp),%esi
call   1060 <access@plt>
test   %rax,%rax
jne    1230 <lookupPath+0xe0>
mov    0x8(%rsp),%rax
jmp    128d <lookupPath+0x13d>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd94(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5d(%rip),%rdi
call   1070 <perror@plt>
jmp    128d <lookupPath+0x13d>

LLVM IR (-O0):
@.str = [17 x i8] c"getcwd(): error\0A\00"
@.str.1 = [7 x i8] c"%s%s%s\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [5 x i8] c"%s%s\00"
@X_OK = global i32 0
@stderr = global i32 0
@.str.4 = [23 x i8] c"%s: command not found\0A\00"
define i8* @lookupPath(i8** %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [96 x i8]
%8 = alloca i32
store i8** %0, i8*** %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 47
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
store i8* %18, i8** %3
br label %121
19: ; preds = %2
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 46
br i1 %25, label %26, label %81
26: ; preds = %19
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %28
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 46
br i1 %33, label %34, label %53
34: ; preds = %26
%35 = getelementptr inbounds [96 x i8], [96 x i8]* %7, i64 0, i64 0
%36 = call i64 @getcwd(i8* %35, i32 96)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %51
40: ; preds = %34
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = getelementptr inbounds i8, i8* %43, i32 -1
store i8* %44, i8** %42
%45 = load i8, i8* %44
%46 = getelementptr inbounds [96 x i8], [96 x i8]* %7, i64 0, i64 0
%47 = load i8**, i8*** %4
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 (i8**, i8*, i8*, i8*, ...) @asprintf(i8** %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %40, %38
%52 = load i8*, i8** %6
store i8* %52, i8** %3
br label %121
53: ; preds = %26
%54 = load i8**, i8*** %4
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = getelementptr inbounds i8, i8* %56, i32 -1
store i8* %57, i8** %55
%58 = load i8, i8* %57
%59 = load i8**, i8*** %4
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %60
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 47
br i1 %65, label %66, label %80
66: ; preds = %53
%67 = getelementptr inbounds [96 x i8], [96 x i8]* %7, i64 0, i64 0
%68 = call i64 @getcwd(i8* %67, i32 96)
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %78
72: ; preds = %66
%73 = getelementptr inbounds [96 x i8], [96 x i8]* %7, i64 0, i64 0
%74 = load i8**, i8*** %4
%75 = getelementptr inbounds i8*, i8** %74, i64 0
%76 = load i8*, i8** %75
%77 = call i32 (i8**, i8*, i8*, i8*, ...) @asprintf(i8** %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %73, i8* %76)
br label %78
78: ; preds = %72, %70
%79 = load i8*, i8** %6
store i8* %79, i8** %3
br label %121
80: ; preds = %53
br label %81
81: ; preds = %80, %19
br label %82
82: ; preds = %81
store i32 0, i32* %8
br label %83
83: ; preds = %112, %82
%84 = load i32, i32* %8
%85 = icmp slt i32 %84, 64
br i1 %85, label %86, label %115
86: ; preds = %83
%87 = load i8**, i8*** %5
%88 = load i32, i32* %8
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8*, i8** %87, i64 %89
%91 = load i8*, i8** %90
%92 = icmp ne i8* %91, null
br i1 %92, label %93, label %110
93: ; preds = %86
%94 = load i8**, i8*** %5
%95 = load i32, i32* %8
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8*, i8** %94, i64 %96
%98 = load i8*, i8** %97
%99 = load i8**, i8*** %4
%100 = getelementptr inbounds i8*, i8** %99, i64 0
%101 = load i8*, i8** %100
%102 = call i32 (i8**, i8*, i8*, i8*, ...) @asprintf(i8** %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %98, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %101)
%103 = load i8*, i8** %6
%104 = load i32, i32* @X_OK
%105 = call i64 @access(i8* %103, i32 %104)
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %109
107: ; preds = %93
%108 = load i8*, i8** %6
store i8* %108, i8** %3
br label %121
109: ; preds = %93
br label %111
110: ; preds = %86
br label %112
111: ; preds = %109
br label %112
112: ; preds = %111, %110
%113 = load i32, i32* %8
%114 = add nsw i32 %113, 1
store i32 %114, i32* %8
br label %83
115: ; preds = %83
%116 = load i32, i32* @stderr
%117 = load i8**, i8*** %4
%118 = getelementptr inbounds i8*, i8** %117, i64 0
%119 = load i8*, i8** %118
%120 = call i32 @fprintf(i32 %116, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %119)
store i8* null, i8** %3
br label %121
121: ; preds = %115, %107, %78, %51, %15
%122 = load i8*, i8** %3
ret i8* %122
}

LLVM IR (-O2):
@.str = [17 x i8] c"getcwd(): error\0A\00"
@.str.1 = [7 x i8] c"%s%s%s\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [5 x i8] c"%s%s\00"
@X_OK = global i32 0
@stderr = global i32 0
@.str.4 = [23 x i8] c"%s: command not found\0A\00"
define i8* @lookupPath(i8** nocapture %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca [96 x i8]
%5 = bitcast i8** %3 to i8*
%6 = getelementptr inbounds [96 x i8], [96 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %0
%8 = load i8, i8* %7
switch i8 %8, label %26 [
i8 47, label %57
i8 46, label %9
]
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %7, i64 1
store i8* %10, i8** %0
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 46
br i1 %12, label %13, label %23
13: ; preds = %9
%14 = call i64 @getcwd(i8* %6, i32 96)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %57
18: ; preds = %13
%19 = load i8*, i8** %0
%20 = getelementptr inbounds i8, i8* %19, i64 -1
store i8* %20, i8** %0
%21 = call i32 (i8**, i8*, i8*, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %3
br label %57
23: ; preds = %9
%24 = load i8, i8* %10
%25 = icmp eq i8 %24, 47
br i1 %25, label %27, label %26
26: ; preds = %2, %23
br label %36
27: ; preds = %23
%28 = call i64 @getcwd(i8* %6, i32 96)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %57
32: ; preds = %27
%33 = load i8*, i8** %0
%34 = call i32 (i8**, i8*, i8*, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* %33)
%35 = load i8*, i8** %3
br label %57
36: ; preds = %26, %50
%37 = phi i64 [ %51, %50 ], [ 0, %26 ]
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
%39 = load i8*, i8** %38
%40 = icmp eq i8* %39, null
br i1 %40, label %50, label %41
41: ; preds = %36
%42 = load i8*, i8** %0
%43 = call i32 (i8**, i8*, i8*, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %3
%45 = load i32, i32* @X_OK
%46 = call i64 @access(i8* %44, i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %41
%49 = load i8*, i8** %3
br label %57
50: ; preds = %41, %36
%51 = add nuw nsw i64 %37, 1
%52 = icmp eq i64 %51, 64
br i1 %52, label %53, label %36
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %0
%56 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %30, %32, %16, %18, %48, %53, %2
%58 = phi i8* [ %7, %2 ], [ %49, %48 ], [ null, %53 ], [ %22, %18 ], [ undef, %16 ], [ %35, %32 ], [ undef, %30 ]
ret i8* %58
}