#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 */
char *getenv(char *);
int /*<<< orphan*/ memmove(char *, char *, int);
scalar_t__ nextdir(char *, char *, int *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ wfile_fullname(char *, char *, char *);
int wfile_status(char *);
int linux_which(char *exactname, char *exename) {
  char *p;
  static char basename[512];
  static char path[4096];
  static char dir[4096];
  static char file[4096];
  int index, j;
  int used[16];
  static char *stddirs[] = {"/usr/sbin",
                            "/sbin",
                            "/bin",
                            "/usr/bin",
                            "/usr/local/bin",
                            "/usr/kerberos/sbin",
                            "/usr/kerberos/bin",
                            "/usr/X11R6/bin",
                            ".",
                            ""};
  strcpy(basename, exename);
  if (basename[0] == '\"' && basename[strlen(basename) - 1] == '\"') {
    basename[strlen(basename) - 1] = '\0';
    memmove(&basename[1], basename, strlen(basename));
  }
  p = getenv("PATH");
  if (p == NULL)
    path[0] = '\0';
  else
    strcpy(path, p);
  if (basename[0] == '/') {
    if (wfile_status(basename) == 1) {
      strcpy(exactname, basename);
      return (1);
    } else
      return (0);
  }
  index = 0;
  for (j = 0; stddirs[j][0] != '\0'; j++)
    used[j] = 0;
  while (nextdir(dir, path, &index)) {
    for (j = 0; stddirs[j][0] != '\0'; j++)
      if (!strcmp(stddirs[j], dir))
        used[j] = 1;
    wfile_fullname(file, dir, basename);
    if (wfile_status(file) == 1) {
      strcpy(exactname, file);
      return (8);
    }
  }
  for (j = 0; stddirs[j][0] != '\0'; j++) {
    if (used[j])
      continue;
    wfile_fullname(file, stddirs[j], basename);
    if (wfile_status(file) == 1) {
      strcpy(exactname, file);
      return (9);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<linux_which>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0x2f35(%rip),%rdi
call   1040 <strcpy@plt>
movsbl 0x2f29(%rip),%eax
cmp    $0x22,%eax
jne    1214 <linux_which+0x94>
lea    0x2f19(%rip),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2f07(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
jne    1214 <linux_which+0x94>
lea    0x2ef3(%rip),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2ee1(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ed6(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%edx
lea    0x2ec9(%rip),%rdi
lea    0x2ec1(%rip),%rsi
call   10a0 <memmove@plt>
lea    0xe3d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    123b <linux_which+0xbb>
movb   $0x0,0x309a(%rip)
jmp    124b <linux_which+0xcb>
mov    -0x20(%rbp),%rsi
lea    0x308a(%rip),%rdi
call   1040 <strcpy@plt>
movsbl 0x2e7e(%rip),%eax
cmp    $0x2f,%eax
jne    1298 <linux_which+0x118>
lea    0x2e6e(%rip),%rdi
call   1070 <wfile_status@plt>
cmp    $0x1,%eax
jne    128c <linux_which+0x10c>
mov    -0x10(%rbp),%rdi
lea    0x2e55(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    1459 <linux_which+0x2d9>
movl   $0x0,-0x4(%rbp)
jmp    1459 <linux_which+0x2d9>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movslq -0x28(%rbp),%rcx
lea    0x2dbf(%rip),%rax
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12db <linux_which+0x15b>
movslq -0x28(%rbp),%rax
movl   $0x0,-0x70(%rbp,%rax,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12a6 <linux_which+0x126>
jmp    12e0 <linux_which+0x160>
lea    0x3fe9(%rip),%rdi
lea    0x2fe2(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1080 <nextdir@plt>
cmp    $0x0,%rax
je     13b6 <linux_which+0x236>
movl   $0x0,-0x28(%rbp)
movslq -0x28(%rbp),%rcx
lea    0x2d5d(%rip),%rax
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1366 <linux_which+0x1e6>
movslq -0x28(%rbp),%rcx
lea    0x2d42(%rip),%rax
mov    (%rax,%rcx,8),%rdi
lea    0x3f97(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1353 <linux_which+0x1d3>
movslq -0x28(%rbp),%rax
movl   $0x1,-0x70(%rbp,%rax,4)
jmp    1358 <linux_which+0x1d8>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1308 <linux_which+0x188>
lea    0x4f63(%rip),%rdi
lea    0x3f5c(%rip),%rsi
lea    0x2d55(%rip),%rdx
call   1090 <wfile_fullname@plt>
lea    0x4f49(%rip),%rdi
call   1070 <wfile_status@plt>
cmp    $0x1,%eax
jne    13b1 <linux_which+0x231>
mov    -0x10(%rbp),%rdi
lea    0x4f30(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x8,-0x4(%rbp)
jmp    1459 <linux_which+0x2d9>
jmp    12e0 <linux_which+0x160>
movl   $0x0,-0x28(%rbp)
movslq -0x28(%rbp),%rcx
lea    0x2ca8(%rip),%rax
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1452 <linux_which+0x2d2>
movslq -0x28(%rbp),%rax
cmpl   $0x0,-0x70(%rbp,%rax,4)
je     13ec <linux_which+0x26c>
jmp    1444 <linux_which+0x2c4>
movslq -0x28(%rbp),%rcx
lea    0x2c79(%rip),%rax
mov    (%rax,%rcx,8),%rsi
lea    0x4ece(%rip),%rdi
lea    0x2cc7(%rip),%rdx
call   1090 <wfile_fullname@plt>
lea    0x4ebb(%rip),%rdi
call   1070 <wfile_status@plt>
cmp    $0x1,%eax
jne    143f <linux_which+0x2bf>
mov    -0x10(%rbp),%rdi
lea    0x4ea2(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x9,-0x4(%rbp)
jmp    1459 <linux_which+0x2d9>
jmp    1444 <linux_which+0x2c4>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    13bd <linux_which+0x23d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linux_which>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbp
lea    0x2ee8(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
cmpb   $0x22,0x2ed9(%rip)
jne    11d2 <linux_which+0x62>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x22,-0x1(%rax,%rbx,1)
jne    11d2 <linux_which+0x62>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x2ea9(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1090 <memmove@plt>
lea    0xebf(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     122b <linux_which+0xbb>
lea    0x3086(%rip),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
cmpb   $0x2f,0x2e77(%rip)
jne    123b <linux_which+0xcb>
lea    0x2e6e(%rip),%rdi
call   1060 <wfile_status@plt>
xor    %ebx,%ebx
cmp    $0x1,%eax
jne    1624 <linux_which+0x4b4>
lea    0x2e57(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    $0x1,%ebx
jmp    1624 <linux_which+0x4b4>
movb   $0x0,0x303e(%rip)
cmpb   $0x2f,0x2e37(%rip)
je     11fb <linux_which+0x8b>
mov    %rbp,0x20(%rsp)
movl   $0x0,0x1c(%rsp)
xor    %r15d,%r15d
mov    $0x1,%r12d
xor    %r14d,%r14d
xor    %ebx,%ebx
movl   $0x0,0x18(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
xor    %ebp,%ebp
lea    0x3fe9(%rip),%rdi
lea    0x2fe2(%rip),%rsi
lea    0x1c(%rsp),%rdx
call   1070 <nextdir@plt>
test   %rax,%rax
je     1442 <linux_which+0x2d2>
mov    0x3fc8(%rip),%rax
mov    %rax,%rcx
movabs $0x6962732f7273752f,%rdx
73 62 69
xor    %rdx,%rcx
movzwl 0x3fb9(%rip),%edx
xor    $0x6e,%rdx
or     %rcx,%rdx
cmove  %r12d,%ebp
mov    0x3fa0(%rip),%ecx
mov    %ecx,%edx
xor    $0x6962732f,%edx
movzwl 0x3f95(%rip),%esi
xor    $0x6e,%esi
or     %edx,%esi
cmove  %r12d,%r15d
xor    $0x6e69622f,%ecx
movzbl 0x3f7f(%rip),%edx
or     %ecx,%edx
cmove  %r12d,%r14d
mov    %rax,%rcx
movabs $0x6e69622f7273752f,%rdx
62 69 6e
xor    %rdx,%rcx
movzbl 0x3f66(%rip),%edx
or     %rcx,%rdx
cmove  %r12d,%ebx
mov    %rax,%rdx
movabs $0x636f6c2f7273752f,%rcx
6c 6f 63
xor    %rcx,%rdx
mov    0x3f47(%rip),%rcx
movabs $0x6e69622f365231,%rdi
lea    0x360f32(%rdi),%rsi
xor    %rcx,%rsi
or     %rdx,%rsi
mov    0x18(%rsp),%edx
cmove  %r12d,%edx
mov    %edx,0x18(%rsp)
movdqa 0x3f15(%rip),%xmm0
movdqu 0x3f10(%rip),%xmm1
pcmpeqb 0xc95(%rip),%xmm1
movdqa %xmm0,%xmm2
pcmpeqb 0xc99(%rip),%xmm2
pand   %xmm1,%xmm2
pmovmskb %xmm2,%edx
cmp    $0xffff,%edx
mov    0x14(%rsp),%edx
cmove  %r12d,%edx
mov    %edx,0x14(%rsp)
movzwl 0x3ee8(%rip),%edx
movd   %edx,%xmm1
pcmpeqb 0xc8c(%rip),%xmm1
pcmpeqb 0xc74(%rip),%xmm0
pand   %xmm1,%xmm0
pmovmskb %xmm0,%edx
cmp    $0xffff,%edx
mov    0x10(%rsp),%edx
cmove  %r12d,%edx
mov    %edx,0x10(%rsp)
movabs $0x3131582f7273752f,%rdx
58 31 31
xor    %rdx,%rax
xor    %rdi,%rcx
or     %rax,%rcx
mov    0xc(%rsp),%eax
cmove  %r12d,%eax
mov    %eax,0xc(%rsp)
cmpw   $0x2e,0x3e83(%rip)
2e
mov    0x8(%rsp),%eax
cmove  %r12d,%eax
mov    %eax,0x8(%rsp)
lea    0x4e70(%rip),%r13
mov    %r13,%rdi
lea    0x3e66(%rip),%rsi
lea    0x2c5f(%rip),%rdx
call   1080 <wfile_fullname@plt>
mov    %r13,%rdi
call   1060 <wfile_status@plt>
cmp    $0x1,%eax
jne    1280 <linux_which+0x110>
lea    0x4e42(%rip),%rsi
mov    0x20(%rsp),%rdi
call   1040 <strcpy@plt>
mov    $0x8,%ebx
jmp    1624 <linux_which+0x4b4>
test   %ebp,%ebp
mov    0x20(%rsp),%rbp
jne    1479 <linux_which+0x309>
lea    0x4e1e(%rip),%r12
lea    0xbe7(%rip),%rsi
lea    0x2c10(%rip),%rdx
mov    %r12,%rdi
call   1080 <wfile_fullname@plt>
mov    %r12,%rdi
call   1060 <wfile_status@plt>
cmp    $0x1,%eax
je     1610 <linux_which+0x4a0>
test   %r15d,%r15d
jne    14ac <linux_which+0x33c>
lea    0x4deb(%rip),%r15
lea    0xbb8(%rip),%rsi
lea    0x2bdd(%rip),%rdx
mov    %r15,%rdi
call   1080 <wfile_fullname@plt>
mov    %r15,%rdi
call   1060 <wfile_status@plt>
cmp    $0x1,%eax
je     1610 <linux_which+0x4a0>
test   %r14d,%r14d
jne    14df <linux_which+0x36f>
lea    0x4db8(%rip),%r14
lea    0xbd2(%rip),%rsi
lea    0x2baa(%rip),%rdx
mov    %r14,%rdi
call   1080 <wfile_fullname@plt>
mov    %r14,%rdi
call   1060 <wfile_status@plt>
cmp    $0x1,%eax
je     1610 <linux_which+0x4a0>
test   %ebx,%ebx
jne    1511 <linux_which+0x3a1>
lea    0x4d86(%rip),%rbx
lea    0xb59(%rip),%rsi
lea    0x2b78(%rip),%rdx
mov    %rbx,%rdi
call   1080 <wfile_fullname@plt>
mov    %rbx,%rdi
call   1060 <wfile_status@plt>
cmp    $0x1,%eax
je     1610 <linux_which+0x4a0>
cmpl   $0x0,0x18(%rsp)
jne    1546 <linux_which+0x3d6>
lea    0x4d51(%rip),%rbx
lea    0xb2d(%rip),%rsi
lea    0x2b43(%rip),%rdx
mov    %rbx,%rdi
call   1080 <wfile_fullname@plt>
mov    %rbx,%rdi
call   1060 <wfile_status@plt>
cmp    $0x1,%eax
je     1610 <linux_which+0x4a0>
cmpl   $0x0,0x14(%rsp)
jne    157b <linux_which+0x40b>
lea    0x4d1c(%rip),%rbx
lea    0xb07(%rip),%rsi
lea    0x2b0e(%rip),%rdx
mov    %rbx,%rdi
call   1080 <wfile_fullname@plt>
mov    %rbx,%rdi
call   1060 <wfile_status@plt>
cmp    $0x1,%eax
je     1610 <linux_which+0x4a0>
cmpl   $0x0,0x10(%rsp)
jne    15ac <linux_which+0x43c>
lea    0x4ce7(%rip),%rbx
lea    0xae5(%rip),%rsi
lea    0x2ad9(%rip),%rdx
mov    %rbx,%rdi
call   1080 <wfile_fullname@plt>
mov    %rbx,%rdi
call   1060 <wfile_status@plt>
cmp    $0x1,%eax
je     1610 <linux_which+0x4a0>
cmpl   $0x0,0xc(%rsp)
jne    15dd <linux_which+0x46d>
lea    0x4cb6(%rip),%rbx
lea    0xac6(%rip),%rsi
lea    0x2aa8(%rip),%rdx
mov    %rbx,%rdi
call   1080 <wfile_fullname@plt>
mov    %rbx,%rdi
call   1060 <wfile_status@plt>
cmp    $0x1,%eax
je     1610 <linux_which+0x4a0>
xor    %ebx,%ebx
cmpl   $0x0,0x8(%rsp)
jne    1624 <linux_which+0x4b4>
lea    0x4c83(%rip),%r14
lea    0xaa2(%rip),%rsi
lea    0x2a75(%rip),%rdx
mov    %r14,%rdi
call   1080 <wfile_fullname@plt>
mov    %r14,%rdi
call   1060 <wfile_status@plt>
cmp    $0x1,%eax
jne    1624 <linux_which+0x4b4>
lea    0x4c59(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    $0x9,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@linux_which.basename = internal global [512 x i8] zeroinitializer
@linux_which.path = internal global [4096 x i8] zeroinitializer
@linux_which.dir = internal global [4096 x i8] zeroinitializer
@linux_which.file = internal global [4096 x i8] zeroinitializer
@linux_which.stddirs = internal global [10 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i32 0, i32 0)]
@.str = [10 x i8] c"/usr/sbin\00"
@.str.1 = [6 x i8] c"/sbin\00"
@.str.2 = [5 x i8] c"/bin\00"
@.str.3 = [9 x i8] c"/usr/bin\00"
@.str.4 = [15 x i8] c"/usr/local/bin\00"
@.str.5 = [19 x i8] c"/usr/kerberos/sbin\00"
@.str.6 = [18 x i8] c"/usr/kerberos/bin\00"
@.str.7 = [15 x i8] c"/usr/X11R6/bin\00"
@.str.8 = [2 x i8] c".\00"
@.str.9 = [1 x i8] zeroinitializer
@.str.10 = [5 x i8] c"PATH\00"
define i32 @linux_which(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i32]
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @strcpy(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0), i8* %10)
%12 = load i8, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0)
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 34
br i1 %14, label %15, label %30
15: ; preds = %2
%16 = call i32 @strlen(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 34
br i1 %22, label %23, label %30
23: ; preds = %15
%24 = call i32 @strlen(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 @strlen(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%29 = call i32 @memmove(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 1), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %23, %15, %2
%31 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
store i8* %31, i8** %6
%32 = load i8*, i8** %6
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %30
store i8 0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.path, i64 0, i64 0)
br label %38
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = call i32 @strcpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.path, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %34
%39 = load i8, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0)
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 47
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = call i32 @wfile_status(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i8*, i8** %4
%47 = call i32 @strcpy(i8* %46, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
store i32 1, i32* %3
br label %136
48: ; preds = %42
store i32 0, i32* %3
br label %136
49: ; preds = %38
store i32 0, i32* %7
store i32 0, i32* %8
br label %50
50: ; preds = %63, %49
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [10 x i8*], [10 x i8*]* @linux_which.stddirs, i64 0, i64 %52
%54 = load i8*, i8** %53
%55 = getelementptr inbounds i8, i8* %54, i64 0
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %50
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [16 x i32], [16 x i32]* %9, i64 0, i64 %61
store i32 0, i32* %62
br label %63
63: ; preds = %59
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %50
66: ; preds = %50
br label %67
67: ; preds = %102, %66
%68 = call i64 @nextdir(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.path, i64 0, i64 0), i32* %7)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %103
70: ; preds = %67
store i32 0, i32* %8
br label %71
71: ; preds = %92, %70
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [10 x i8*], [10 x i8*]* @linux_which.stddirs, i64 0, i64 %73
%75 = load i8*, i8** %74
%76 = getelementptr inbounds i8, i8* %75, i64 0
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %95
80: ; preds = %71
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [10 x i8*], [10 x i8*]* @linux_which.stddirs, i64 0, i64 %82
%84 = load i8*, i8** %83
%85 = call i32 @strcmp(i8* %84, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0))
%86 = icmp ne i32 %85, 0
br i1 %86, label %91, label %87
87: ; preds = %80
%88 = load i32, i32* %8
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [16 x i32], [16 x i32]* %9, i64 0, i64 %89
store i32 1, i32* %90
br label %91
91: ; preds = %87, %80
br label %92
92: ; preds = %91
%93 = load i32, i32* %8
%94 = add nsw i32 %93, 1
store i32 %94, i32* %8
br label %71
95: ; preds = %71
%96 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%97 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%98 = icmp eq i32 %97, 1
br i1 %98, label %99, label %102
99: ; preds = %95
%100 = load i8*, i8** %4
%101 = call i32 @strcpy(i8* %100, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
store i32 8, i32* %3
br label %136
102: ; preds = %95
br label %67
103: ; preds = %67
store i32 0, i32* %8
br label %104
104: ; preds = %132, %103
%105 = load i32, i32* %8
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [10 x i8*], [10 x i8*]* @linux_which.stddirs, i64 0, i64 %106
%108 = load i8*, i8** %107
%109 = getelementptr inbounds i8, i8* %108, i64 0
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %135
113: ; preds = %104
%114 = load i32, i32* %8
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds [16 x i32], [16 x i32]* %9, i64 0, i64 %115
%117 = load i32, i32* %116
%118 = icmp ne i32 %117, 0
br i1 %118, label %119, label %120
119: ; preds = %113
br label %132
120: ; preds = %113
%121 = load i32, i32* %8
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds [10 x i8*], [10 x i8*]* @linux_which.stddirs, i64 0, i64 %122
%124 = load i8*, i8** %123
%125 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* %124, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%126 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%127 = icmp eq i32 %126, 1
br i1 %127, label %128, label %131
128: ; preds = %120
%129 = load i8*, i8** %4
%130 = call i32 @strcpy(i8* %129, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
store i32 9, i32* %3
br label %136
131: ; preds = %120
br label %132
132: ; preds = %131, %119
%133 = load i32, i32* %8
%134 = add nsw i32 %133, 1
store i32 %134, i32* %8
br label %104
135: ; preds = %104
store i32 0, i32* %3
br label %136
136: ; preds = %135, %128, %99, %48, %45
%137 = load i32, i32* %3
ret i32 %137
}

LLVM IR (-O2):
@linux_which.basename = internal global [512 x i8] zeroinitializer
@linux_which.path = internal global [4096 x i8] zeroinitializer
@linux_which.dir = internal global [4096 x i8] zeroinitializer
@linux_which.file = internal global [4096 x i8] zeroinitializer
@.str = [10 x i8] c"/usr/sbin\00"
@.str.1 = [6 x i8] c"/sbin\00"
@.str.2 = [5 x i8] c"/bin\00"
@.str.3 = [9 x i8] c"/usr/bin\00"
@.str.4 = [15 x i8] c"/usr/local/bin\00"
@.str.5 = [19 x i8] c"/usr/kerberos/sbin\00"
@.str.6 = [18 x i8] c"/usr/kerberos/bin\00"
@.str.7 = [15 x i8] c"/usr/X11R6/bin\00"
@.str.8 = [2 x i8] c".\00"
@.str.10 = [5 x i8] c"PATH\00"
define i32 @linux_which(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @strcpy(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0), i8* %1)
%6 = load i8, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0)
%7 = icmp eq i8 %6, 34
br i1 %7, label %8, label %22
8: ; preds = %2
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 34
br i1 %14, label %15, label %22
15: ; preds = %8
%16 = tail call i32 @strlen(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 %18
store i8 0, i8* %19
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%21 = tail call i32 @memmove(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 1), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %15, %8, %2
%23 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %22
store i8 0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.path, i64 0, i64 0)
br label %28
26: ; preds = %22
%27 = tail call i32 @strcpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.path, i64 0, i64 0), i8* %23)
br label %28
28: ; preds = %26, %25
%29 = load i8, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0)
%30 = icmp eq i8 %29, 47
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = tail call i32 @wfile_status(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %138
34: ; preds = %31
%35 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
br label %138
36: ; preds = %28
store i32 0, i32* %3
br label %37
37: ; preds = %36, %49
%38 = phi i32 [ 0, %36 ], [ %55, %49 ]
%39 = phi i32 [ 0, %36 ], [ %58, %49 ]
%40 = phi i32 [ 0, %36 ], [ %61, %49 ]
%41 = phi i32 [ 0, %36 ], [ %64, %49 ]
%42 = phi i32 [ 0, %36 ], [ %67, %49 ]
%43 = phi i32 [ 0, %36 ], [ %70, %49 ]
%44 = phi i32 [ 0, %36 ], [ %73, %49 ]
%45 = phi i32 [ 0, %36 ], [ %76, %49 ]
%46 = phi i32 [ 0, %36 ], [ %52, %49 ]
%47 = call i64 @nextdir(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.path, i64 0, i64 0), i32* %3)
%48 = icmp eq i64 %47, 0
br i1 %48, label %80, label %49
49: ; preds = %37
%50 = call i32 @bcmp(i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(10) getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i64 10)
%51 = icmp eq i32 %50, 0
%52 = select i1 %51, i32 1, i32 %46
%53 = call i32 @bcmp(i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(6) getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i64 6)
%54 = icmp eq i32 %53, 0
%55 = select i1 %54, i32 1, i32 %38
%56 = call i32 @bcmp(i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(5) getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i64 5)
%57 = icmp eq i32 %56, 0
%58 = select i1 %57, i32 1, i32 %39
%59 = call i32 @bcmp(i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* dereferenceable(9) getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i64 9)
%60 = icmp eq i32 %59, 0
%61 = select i1 %60, i32 1, i32 %40
%62 = call i32 @bcmp(i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* dereferenceable(15) getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i64 15)
%63 = icmp eq i32 %62, 0
%64 = select i1 %63, i32 1, i32 %41
%65 = call i32 @bcmp(i8* dereferenceable(19) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* dereferenceable(19) getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i64 19)
%66 = icmp eq i32 %65, 0
%67 = select i1 %66, i32 1, i32 %42
%68 = call i32 @bcmp(i8* dereferenceable(18) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* dereferenceable(18) getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i64 18)
%69 = icmp eq i32 %68, 0
%70 = select i1 %69, i32 1, i32 %43
%71 = call i32 @bcmp(i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* dereferenceable(15) getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i64 15)
%72 = icmp eq i32 %71, 0
%73 = select i1 %72, i32 1, i32 %44
%74 = load i16, i16* bitcast ([4096 x i8]* @linux_which.dir to i16*)
%75 = icmp eq i16 %74, 46
%76 = select i1 %75, i32 1, i32 %45
%77 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.dir, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%78 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%79 = icmp eq i32 %78, 1
br i1 %79, label %82, label %37
80: ; preds = %37
%81 = icmp eq i32 %46, 0
br i1 %81, label %84, label %90
82: ; preds = %49
%83 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
br label %138
84: ; preds = %80
%85 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%86 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%87 = icmp eq i32 %86, 1
br i1 %87, label %88, label %90
88: ; preds = %134, %128, %122, %116, %110, %104, %98, %92, %84
%89 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
br label %138
90: ; preds = %84, %80
%91 = icmp eq i32 %38, 0
br i1 %91, label %92, label %96
92: ; preds = %90
%93 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%94 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%95 = icmp eq i32 %94, 1
br i1 %95, label %88, label %96
96: ; preds = %92, %90
%97 = icmp eq i32 %39, 0
br i1 %97, label %98, label %102
98: ; preds = %96
%99 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%100 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%101 = icmp eq i32 %100, 1
br i1 %101, label %88, label %102
102: ; preds = %98, %96
%103 = icmp eq i32 %40, 0
br i1 %103, label %104, label %108
104: ; preds = %102
%105 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%106 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%107 = icmp eq i32 %106, 1
br i1 %107, label %88, label %108
108: ; preds = %104, %102
%109 = icmp eq i32 %41, 0
br i1 %109, label %110, label %114
110: ; preds = %108
%111 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%112 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%113 = icmp eq i32 %112, 1
br i1 %113, label %88, label %114
114: ; preds = %110, %108
%115 = icmp eq i32 %42, 0
br i1 %115, label %116, label %120
116: ; preds = %114
%117 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%118 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%119 = icmp eq i32 %118, 1
br i1 %119, label %88, label %120
120: ; preds = %116, %114
%121 = icmp eq i32 %43, 0
br i1 %121, label %122, label %126
122: ; preds = %120
%123 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%124 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%125 = icmp eq i32 %124, 1
br i1 %125, label %88, label %126
126: ; preds = %122, %120
%127 = icmp eq i32 %44, 0
br i1 %127, label %128, label %132
128: ; preds = %126
%129 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%130 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%131 = icmp eq i32 %130, 1
br i1 %131, label %88, label %132
132: ; preds = %128, %126
%133 = icmp eq i32 %45, 0
br i1 %133, label %134, label %138
134: ; preds = %132
%135 = call i32 @wfile_fullname(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @linux_which.basename, i64 0, i64 0))
%136 = call i32 @wfile_status(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @linux_which.file, i64 0, i64 0))
%137 = icmp eq i32 %136, 1
br i1 %137, label %88, label %138
138: ; preds = %132, %134, %31, %88, %82, %34
%139 = phi i32 [ 1, %34 ], [ 8, %82 ], [ 9, %88 ], [ 0, %31 ], [ 0, %134 ], [ 0, %132 ]
ret i32 %139
}