#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*/ exit(int);
char *getenv(char *);
int getopt(int, char **, char *);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
size_t strlen(char *);
int main(int argc, char *argv[]) {
  struct stat sb;
  int argcount = 1;
  int cnt, o, all = 0;
  unsigned int count, counter;
  while ((o = getopt(argc, argv, "ah")) != -1)
    switch (o) {
    case 'a':
      all = 1;
      continue;
    case 'h':
      printf("Usage: which [OPTION] [FILE(S)]\n");
      printf(" -a\tPrint all matches\n");
      printf(" -h\tPrint this menu and exit\n");
      exit(0);
    case '?':
      exit(1);
    }
  for (; argcount < argc; ++argcount) {
    if (!argv[argcount])
      exit(0);
    cnt = count = counter = 0;
    size_t b = strlen(argv[argcount]);
    size_t a = strlen(getenv("PATH"));
    if (a > 10000)
      exit(1);
    char *word = malloc(a + b + 1);
    char *argg = malloc(b);
    argg = argv[argcount];
    if (!argg || !word)
      exit(1);
    for (; count <= a; ++count) {
      if (getenv("PATH")[count] != ':')
        word[cnt] = getenv("PATH")[count];
      word[++cnt] = '\0';
      if (getenv("PATH")[count] == ':' || count == a) {
        if (word[--cnt] != '/')
          word[cnt++] = '/';
        while (counter < b)
          word[cnt++] = argg[counter++];
        word[cnt] = '\0';
        if (stat(word, &sb) == 0 && sb.st_mode & S_IXUSR) {
          printf("%s\n", word);
          if (all != 1)
            break;
        }
        cnt = counter = 0;
      }
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5e(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1235 <main+0xc5>
mov    -0x24(%rbp),%eax
mov    %eax,-0x54(%rbp)
sub    $0x3f,%eax
je     1226 <main+0xb6>
jmp    11c7 <main+0x57>
mov    -0x54(%rbp),%eax
sub    $0x61,%eax
je     11e9 <main+0x79>
jmp    11d8 <main+0x68>
mov    -0x54(%rbp),%eax
sub    $0x68,%eax
je     11f5 <main+0x85>
jmp    1230 <main+0xc0>
movl   $0x1,-0x28(%rbp)
jmp    1194 <main+0x24>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1194 <main+0x24>
jmp    123a <main+0xca>
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1499 <main+0x329>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1260 <main+0xf0>
xor    %edi,%edi
call   1090 <exit@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
lea    0xdc8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x2710,-0x40(%rbp)
jbe    12ba <main+0x14a>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x40(%rbp),%rdi
add    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1302 <main+0x192>
cmpq   $0x0,-0x48(%rbp)
jne    130c <main+0x19c>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1311 <main+0x1a1>
mov    -0x2c(%rbp),%eax
cmp    -0x40(%rbp),%rax
ja     1486 <main+0x316>
lea    0xd34(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x2c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
je     1357 <main+0x1e7>
lea    0xd18(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x48(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xce7(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x2c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
je     1394 <main+0x224>
mov    -0x2c(%rbp),%eax
cmp    -0x40(%rbp),%rax
jne    1473 <main+0x303>
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     13c7 <main+0x257>
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
jmp    13cc <main+0x25c>
mov    -0x30(%rbp),%eax
cmp    -0x38(%rbp),%rax
jae    1407 <main+0x297>
mov    -0x50(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    13cc <main+0x25c>
mov    -0x48(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x48(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jne    1465 <main+0x2f5>
mov    -0x18(%rbp),%eax
mov    0x2bb4(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1465 <main+0x2f5>
mov    -0x48(%rbp),%rsi
lea    0xc14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1,-0x28(%rbp)
je     1460 <main+0x2f0>
jmp    1486 <main+0x316>
jmp    1465 <main+0x2f5>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
jmp    1478 <main+0x308>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1311 <main+0x1a1>
jmp    148b <main+0x31b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    123a <main+0xca>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
movl   $0x0,0xc(%rsp)
lea    0xe6e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1080 <getopt@plt>
cmp    $0x60,%eax
jg     11d0 <main+0x60>
cmp    $0xffffffff,%eax
je     11e7 <main+0x77>
cmp    $0x3f,%eax
jne    11a0 <main+0x30>
jmp    139d <main+0x22d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x61,%eax
je     11df <main+0x6f>
cmp    $0x68,%eax
jne    11a0 <main+0x30>
jmp    13a7 <main+0x237>
mov    $0x1,%al
mov    %eax,0xc(%rsp)
jmp    11a0 <main+0x30>
cmp    $0x2,%ebx
jl     138c <main+0x21c>
mov    %ebx,%eax
mov    %rax,0x20(%rsp)
mov    $0x1,%ebp
mov    %r15,0x28(%rsp)
jmp    1229 <main+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x30(%rsp),%rbp
add    $0x1,%rbp
cmp    0x20(%rsp),%rbp
mov    0x28(%rsp),%r15
je     138c <main+0x21c>
mov    (%r15,%rbp,8),%r13
test   %r13,%r13
je     13cb <main+0x25b>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
lea    0xdbb(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x2711,%rax
jae    139d <main+0x22d>
mov    %rbp,0x30(%rsp)
mov    %rax,0x10(%rsp)
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     139d <main+0x22d>
xor    %r15d,%r15d
xor    %r12d,%r12d
jmp    12a5 <main+0x135>
nopl   (%rax)
mov    0x10(%rsp),%rax
add    $0x1,%r15d
mov    %ebp,%r12d
cmp    %r15,%rax
jb     1210 <main+0xa0>
lea    0xd57(%rip),%rdi
call   1030 <getenv@plt>
mov    (%rax,%r15,1),%al
movslq %r12d,%r14
cmp    $0x3a,%al
je     12c4 <main+0x154>
mov    (%rsp),%rcx
mov    %al,(%rcx,%r14,1)
lea    0x1(%r14),%rbp
mov    (%rsp),%rax
movb   $0x0,0x1(%rax,%r14,1)
lea    0xd2a(%rip),%rdi
call   1030 <getenv@plt>
cmpb   $0x3a,(%rax,%r15,1)
mov    0x10(%rsp),%rax
je     12ef <main+0x17f>
cmp    %r15,%rax
jne    1295 <main+0x125>
mov    (%rsp),%rax
cmpb   $0x2f,(%rax,%r14,1)
je     1306 <main+0x196>
mov    (%rsp),%rax
movb   $0x2f,(%rax,%r14,1)
mov    %ebp,%r12d
test   %rbx,%rbx
je     133b <main+0x1cb>
movslq %r12d,%rax
add    (%rsp),%rax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x0(%r13,%rcx,1),%edx
lea    0x1(%rcx),%esi
mov    %dl,(%rax)
add    $0x1,%rax
add    $0x1,%r12d
mov    %rsi,%rcx
cmp    %rsi,%rbx
ja     1320 <main+0x1b0>
movslq %r12d,%rax
mov    (%rsp),%rdi
movb   $0x0,(%rdi,%rax,1)
lea    0x18(%rsp),%rsi
call   1060 <stat@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1290 <main+0x120>
mov    0x2c86(%rip),%rax
mov    (%rax),%eax
test   %eax,0x18(%rsp)
je     1290 <main+0x120>
mov    (%rsp),%rdi
call   1040 <puts@plt>
testb  $0x1,0xc(%rsp)
mov    0x10(%rsp),%rax
jne    1295 <main+0x125>
jmp    1210 <main+0xa0>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xc5a(%rip),%rdi
call   1040 <puts@plt>
lea    0xc6e(%rip),%rdi
call   1040 <puts@plt>
lea    0xc78(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"ah\00"
@.str.1 = [33 x i8] c"Usage: which [OPTION] [FILE(S)]\0A\00"
@.str.2 = [23 x i8] c" -a\09Print all matches\0A\00"
@.str.3 = [30 x i8] c" -h\09Print this menu and exit\0A\00"
@.str.4 = [5 x i8] c"PATH\00"
@S_IXUSR = global i32 0
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 0, i32* %10
br label %17
17: ; preds = %32, %24, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %9
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %33
22: ; preds = %17
%23 = load i32, i32* %9
switch i32 %23, label %32 [
i32 97, label %24
i32 104, label %25
i32 63, label %30
]
24: ; preds = %22
store i32 1, i32* %10
br label %17
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %22
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %22
br label %17
33: ; preds = %17
br label %34
34: ; preds = %182, %33
%35 = load i32, i32* %7
%36 = load i32, i32* %4
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %185
38: ; preds = %34
%39 = load i8**, i8*** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = icmp ne i8* %43, null
br i1 %44, label %47, label %45
45: ; preds = %38
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %38
store i32 0, i32* %12
store i32 0, i32* %11
store i32 0, i32* %8
%48 = load i8**, i8*** %5
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i64 @strlen(i8* %52)
store i64 %53, i64* %13
%54 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%55 = call i64 @strlen(i8* %54)
store i64 %55, i64* %14
%56 = load i64, i64* %14
%57 = icmp ugt i64 %56, 10000
br i1 %57, label %58, label %60
58: ; preds = %47
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %47
%61 = load i64, i64* %14
%62 = load i64, i64* %13
%63 = add i64 %61, %62
%64 = add i64 %63, 1
%65 = call i8* @malloc(i64 %64)
store i8* %65, i8** %15
%66 = load i64, i64* %13
%67 = call i8* @malloc(i64 %66)
store i8* %67, i8** %16
%68 = load i8**, i8*** %5
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
store i8* %72, i8** %16
%73 = load i8*, i8** %16
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %78
75: ; preds = %60
%76 = load i8*, i8** %15
%77 = icmp ne i8* %76, null
br i1 %77, label %80, label %78
78: ; preds = %75, %60
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %75
br label %81
81: ; preds = %178, %80
%82 = load i32, i32* %11
%83 = zext i32 %82 to i64
%84 = load i64, i64* %14
%85 = icmp ule i64 %83, %84
br i1 %85, label %86, label %181
86: ; preds = %81
%87 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%88 = load i32, i32* %11
%89 = zext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp ne i32 %92, 58
br i1 %93, label %94, label %104
94: ; preds = %86
%95 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%96 = load i32, i32* %11
%97 = zext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
%99 = load i8, i8* %98
%100 = load i8*, i8** %15
%101 = load i32, i32* %8
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %100, i64 %102
store i8 %99, i8* %103
br label %104
104: ; preds = %94, %86
%105 = load i8*, i8** %15
%106 = load i32, i32* %8
%107 = add nsw i32 %106, 1
store i32 %107, i32* %8
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %105, i64 %108
store i8 0, i8* %109
%110 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%111 = load i32, i32* %11
%112 = zext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %110, i64 %112
%114 = load i8, i8* %113
%115 = sext i8 %114 to i32
%116 = icmp eq i32 %115, 58
br i1 %116, label %122, label %117
117: ; preds = %104
%118 = load i32, i32* %11
%119 = zext i32 %118 to i64
%120 = load i64, i64* %14
%121 = icmp eq i64 %119, %120
br i1 %121, label %122, label %177
122: ; preds = %117, %104
%123 = load i8*, i8** %15
%124 = load i32, i32* %8
%125 = add nsw i32 %124, -1
store i32 %125, i32* %8
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i8, i8* %123, i64 %126
%128 = load i8, i8* %127
%129 = sext i8 %128 to i32
%130 = icmp ne i32 %129, 47
br i1 %130, label %131, label %137
131: ; preds = %122
%132 = load i8*, i8** %15
%133 = load i32, i32* %8
%134 = add nsw i32 %133, 1
store i32 %134, i32* %8
%135 = sext i32 %133 to i64
%136 = getelementptr inbounds i8, i8* %132, i64 %135
store i8 47, i8* %136
br label %137
137: ; preds = %131, %122
br label %138
138: ; preds = %143, %137
%139 = load i32, i32* %12
%140 = zext i32 %139 to i64
%141 = load i64, i64* %13
%142 = icmp ult i64 %140, %141
br i1 %142, label %143, label %155
143: ; preds = %138
%144 = load i8*, i8** %16
%145 = load i32, i32* %12
%146 = add i32 %145, 1
store i32 %146, i32* %12
%147 = zext i32 %145 to i64
%148 = getelementptr inbounds i8, i8* %144, i64 %147
%149 = load i8, i8* %148
%150 = load i8*, i8** %15
%151 = load i32, i32* %8
%152 = add nsw i32 %151, 1
store i32 %152, i32* %8
%153 = sext i32 %151 to i64
%154 = getelementptr inbounds i8, i8* %150, i64 %153
store i8 %149, i8* %154
br label %138
155: ; preds = %138
%156 = load i8*, i8** %15
%157 = load i32, i32* %8
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i8, i8* %156, i64 %158
store i8 0, i8* %159
%160 = load i8*, i8** %15
%161 = call i64 @stat(i8* %160, %struct.stat* %6)
%162 = icmp eq i64 %161, 0
br i1 %162, label %163, label %176
163: ; preds = %155
%164 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%165 = load i32, i32* %164
%166 = load i32, i32* @S_IXUSR
%167 = and i32 %165, %166
%168 = icmp ne i32 %167, 0
br i1 %168, label %169, label %176
169: ; preds = %163
%170 = load i8*, i8** %15
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %170)
%172 = load i32, i32* %10
%173 = icmp ne i32 %172, 1
br i1 %173, label %174, label %175
174: ; preds = %169
br label %181
175: ; preds = %169
br label %176
176: ; preds = %175, %163, %155
store i32 0, i32* %12
store i32 0, i32* %8
br label %177
177: ; preds = %176, %117
br label %178
178: ; preds = %177
%179 = load i32, i32* %11
%180 = add i32 %179, 1
store i32 %180, i32* %11
br label %81
181: ; preds = %174, %81
br label %182
182: ; preds = %181
%183 = load i32, i32* %7
%184 = add nsw i32 %183, 1
store i32 %184, i32* %7
br label %34
185: ; preds = %34
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"ah\00"
@.str.4 = [5 x i8] c"PATH\00"
@S_IXUSR = global i32 0
@str = [32 x i8] c"Usage: which [OPTION] [FILE(S)]\00"
@str.6 = [22 x i8] c" -a\09Print all matches\00"
@str.7 = [29 x i8] c" -h\09Print this menu and exit\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
br label %5
5: ; preds = %7, %2
%6 = phi i1 [ false, %2 ], [ true, %7 ]
br label %7
7: ; preds = %5, %7
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %7 [
i32 -1, label %9
i32 97, label %5
i32 104, label %14
i32 63, label %19
]
9: ; preds = %7
%10 = icmp sgt i32 %0, 1
br i1 %10, label %11, label %107
11: ; preds = %9
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = zext i32 %0 to i64
br label %21
14: ; preds = %7
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.7, i64 0, i64 0))
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %7
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %11, %104
%22 = phi i64 [ 1, %11 ], [ %105, %104 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %21
%29 = call i64 @strlen(i8* %24)
%30 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%31 = call i64 @strlen(i8* dereferenceable(1) %30)
%32 = icmp ugt i64 %31, 10000
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
%36 = add i64 %29, 1
%37 = add i64 %36, %31
%38 = call i8* @malloc(i64 %37)
%39 = icmp eq i8* %38, null
br i1 %39, label %42, label %40
40: ; preds = %35
%41 = icmp eq i64 %29, 0
br label %44
42: ; preds = %35
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %40, %99
%45 = phi i64 [ 0, %40 ], [ %102, %99 ]
%46 = phi i32 [ 0, %40 ], [ %100, %99 ]
%47 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%48 = getelementptr inbounds i8, i8* %47, i64 %45
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 58
br i1 %50, label %54, label %51
51: ; preds = %44
%52 = sext i32 %46 to i64
%53 = getelementptr inbounds i8, i8* %38, i64 %52
store i8 %49, i8* %53
br label %54
54: ; preds = %51, %44
%55 = add nsw i32 %46, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %38, i64 %56
store i8 0, i8* %57
%58 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%59 = getelementptr inbounds i8, i8* %58, i64 %45
%60 = load i8, i8* %59
%61 = icmp eq i8 %60, 58
%62 = icmp eq i64 %31, %45
%63 = select i1 %61, i1 true, i1 %62
br i1 %63, label %64, label %99
64: ; preds = %54
%65 = sext i32 %46 to i64
%66 = getelementptr inbounds i8, i8* %38, i64 %65
%67 = load i8, i8* %66
%68 = icmp eq i8 %67, 47
br i1 %68, label %70, label %69
69: ; preds = %64
store i8 47, i8* %66
br label %70
70: ; preds = %69, %64
%71 = phi i32 [ %55, %69 ], [ %46, %64 ]
br i1 %41, label %86, label %72
72: ; preds = %70
%73 = sext i32 %71 to i64
br label %74
74: ; preds = %72, %74
%75 = phi i64 [ %73, %72 ], [ %80, %74 ]
%76 = phi i64 [ 0, %72 ], [ %82, %74 ]
%77 = add nuw nsw i64 %76, 1
%78 = getelementptr inbounds i8, i8* %24, i64 %76
%79 = load i8, i8* %78
%80 = add i64 %75, 1
%81 = getelementptr inbounds i8, i8* %38, i64 %75
store i8 %79, i8* %81
%82 = and i64 %77, 4294967295
%83 = icmp ugt i64 %29, %82
br i1 %83, label %74, label %84
84: ; preds = %74
%85 = trunc i64 %80 to i32
br label %86
86: ; preds = %84, %70
%87 = phi i32 [ %71, %70 ], [ %85, %84 ]
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %38, i64 %88
store i8 0, i8* %89
%90 = call i64 @stat(i8* %38, %struct.stat* %3)
%91 = icmp eq i64 %90, 0
br i1 %91, label %92, label %99
92: ; preds = %86
%93 = load i32, i32* %12
%94 = load i32, i32* @S_IXUSR
%95 = and i32 %94, %93
%96 = icmp eq i32 %95, 0
br i1 %96, label %99, label %97
97: ; preds = %92
%98 = call i32 @puts(i8* %38)
br i1 %6, label %99, label %104
99: ; preds = %86, %92, %97, %54
%100 = phi i32 [ %55, %54 ], [ 0, %97 ], [ 0, %92 ], [ 0, %86 ]
%101 = add nuw nsw i64 %45, 1
%102 = and i64 %101, 4294967295
%103 = icmp ult i64 %31, %102
br i1 %103, label %104, label %44
104: ; preds = %97, %99
%105 = add nuw nsw i64 %22, 1
%106 = icmp eq i64 %105, %13
br i1 %106, label %107, label %21
107: ; preds = %104, %9
ret i32 0
}