#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int F_OK;
int R_OK;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int W_OK;
int X_OK;
int access(char *, int);
char *ems1Gthreadbuf();
char *getenv(char const *);
int /*<<< orphan*/ starFree(char *);
scalar_t__ starMalloc(int);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int strspn(char const *, char *);
char *strtok(char *, char *);
int ems1Starf(const char *envar, const char *relpath, const char *acmode,
              char **filename, int *pathlen) {
  char *dir;
  char *pathname;
  char *s;
  char *strtok_context = NULL;
  char *tmppath;
  int accno;
  int notfound;
  struct stat statb;
  pathname = ems1Gthreadbuf();
  notfound = 1;
  switch (acmode[0]) {
  case 'x':
    accno = X_OK;
    break;
  case 'w':
    accno = W_OK;
    break;
  case 'r':
    accno = R_OK;
    break;
  case 'X':
    accno = X_OK;
    break;
  case 'W':
    accno = W_OK;
    break;
  case 'R':
    accno = R_OK;
    break;
  default:
    accno = F_OK;
  }
  if ((s = getenv(envar)) != NULL) {
    if (strspn(s, " ") == strlen(s)) {
      tmppath = (char *)starMalloc(3);
      if (tmppath)
        strcpy(tmppath, " :");
    } else {
      tmppath = (char *)starMalloc(strlen(s) + 1);
      if (tmppath)
        strcpy(tmppath, s);
    }
  } else {
    tmppath = (char *)starMalloc(3);
    if (tmppath)
      strcpy(tmppath, " :");
  }
  if (!tmppath) {
    *pathlen = 0;
    return 0;
  }
  for (s = tmppath; ((dir = strtok(s, ":")) != NULL) && notfound; s = NULL) {
    (void)strcpy(pathname, dir);
    if (strspn(pathname, " ") != strlen(pathname)) {
      if (strspn(relpath, " ") != strlen(relpath)) {
        (void)strcat(pathname, "/");
        (void)strcat(pathname, relpath);
      }
    } else {
      if (strspn(relpath, " ") != strlen(relpath)) {
        (void)strcpy(pathname, relpath);
      } else {
        *pathname = '\0';
      }
    }
    if (!*pathname) {
      continue;
    } else {
      notfound = access(pathname, accno);
      if (!notfound) {
        if (!stat(pathname, &statb)) {
          if (S_ISDIR(statb.st_mode)) {
            notfound = 1;
          }
        }
      }
    }
  }
  if (tmppath)
    starFree(tmppath);
  if (!notfound) {
    *pathlen = strlen(pathname) - 1;
  } else {
    *pathlen = 0;
  }
  *filename = pathname;
  return !notfound;
}


x86 assembly (clang, -O0):
<ems1Starf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movq   $0x0,-0x50(%rbp)
xor    %eax,%eax
call   10e0 <ems1Gthreadbuf@plt>
mov    %rax,-0x40(%rbp)
movl   $0x1,-0x60(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffae,%eax
mov    %eax,%ecx
mov    %rcx,-0x70(%rbp)
sub    $0x26,%eax
ja     128c <ems1Starf+0xcc>
mov    -0x70(%rbp),%rax
lea    0xde3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    1298 <ems1Starf+0xd8>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    1298 <ems1Starf+0xd8>
mov    0x2d81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    1298 <ems1Starf+0xd8>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    1298 <ems1Starf+0xd8>
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    1298 <ems1Starf+0xd8>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    1298 <ems1Starf+0xd8>
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     133f <ems1Starf+0x17f>
mov    -0x48(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1080 <strspn@plt>
mov    %eax,-0x74(%rbp)
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
cmp    %ecx,%eax
jne    1306 <ems1Starf+0x146>
mov    $0x3,%edi
call   10a0 <starMalloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1301 <ems1Starf+0x141>
mov    -0x58(%rbp),%rdi
lea    0xda2(%rip),%rsi
call   1040 <strcpy@plt>
jmp    133a <ems1Starf+0x17a>
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   10a0 <starMalloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1335 <ems1Starf+0x175>
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    133a <ems1Starf+0x17a>
jmp    136d <ems1Starf+0x1ad>
mov    $0x3,%edi
call   10a0 <starMalloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1368 <ems1Starf+0x1a8>
mov    -0x58(%rbp),%rdi
lea    0xd3b(%rip),%rsi
call   1040 <strcpy@plt>
jmp    136d <ems1Starf+0x1ad>
cmpq   $0x0,-0x58(%rbp)
jne    138e <ems1Starf+0x1ce>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    157c <ems1Starf+0x3bc>
mov    -0x58(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xcfe(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,%rcx
mov    %rcx,-0x38(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x75(%rbp)
je     13c6 <ems1Starf+0x206>
cmpl   $0x0,-0x60(%rbp)
setne  %al
mov    %al,-0x75(%rbp)
mov    -0x75(%rbp),%al
test   $0x1,%al
jne    13d6 <ems1Starf+0x216>
jmp    151f <ems1Starf+0x35f>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
lea    0xcae(%rip),%rsi
call   1080 <strspn@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
cmp    %ecx,%eax
je     1457 <ems1Starf+0x297>
mov    -0x18(%rbp),%rdi
lea    0xc85(%rip),%rsi
call   1080 <strspn@plt>
mov    %eax,-0x80(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x80(%rbp),%eax
cmp    %ecx,%eax
je     1452 <ems1Starf+0x292>
mov    -0x40(%rbp),%rdi
lea    0xc61(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10d0 <strcat@plt>
jmp    14a4 <ems1Starf+0x2e4>
mov    -0x18(%rbp),%rdi
lea    0xc3a(%rip),%rsi
call   1080 <strspn@plt>
mov    %eax,-0x84(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
cmp    %ecx,%eax
je     1498 <ems1Starf+0x2d8>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    149f <ems1Starf+0x2df>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
jmp    14a4 <ems1Starf+0x2e4>
mov    -0x40(%rbp),%rax
cmpb   $0x0,(%rax)
jne    14b6 <ems1Starf+0x2f6>
jmp    1512 <ems1Starf+0x352>
mov    -0x40(%rbp),%rdi
mov    -0x5c(%rbp),%esi
call   10b0 <access@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
jne    1508 <ems1Starf+0x348>
mov    -0x40(%rbp),%rdi
lea    -0x68(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%eax
jne    1503 <ems1Starf+0x343>
mov    -0x68(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     14fe <ems1Starf+0x33e>
movl   $0x1,-0x60(%rbp)
jmp    1503 <ems1Starf+0x343>
jmp    1508 <ems1Starf+0x348>
jmp    150d <ems1Starf+0x34d>
jmp    1512 <ems1Starf+0x352>
movq   $0x0,-0x48(%rbp)
jmp    1396 <ems1Starf+0x1d6>
cmpq   $0x0,-0x58(%rbp)
je     1533 <ems1Starf+0x373>
mov    -0x58(%rbp),%rdi
call   1070 <starFree@plt>
cmpl   $0x0,-0x60(%rbp)
jne    1556 <ems1Starf+0x396>
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
sub    $0x1,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
jmp    1560 <ems1Starf+0x3a0>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x0,-0x60(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ems1Starf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r15
mov    %rcx,%r13
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r14
xor    %eax,%eax
call   10e0 <ems1Gthreadbuf@plt>
mov    %rax,%rbx
movsbl 0x0(%rbp),%ecx
add    $0xffffffae,%ecx
cmp    $0x26,%ecx
ja     121c <ems1Starf+0x5c>
mov    0x2de6(%rip),%rax
lea    0xdff(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    0x2dbf(%rip),%rax
jmp    1223 <ems1Starf+0x63>
mov    0x2dce(%rip),%rax
jmp    1223 <ems1Starf+0x63>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1258 <ems1Starf+0x98>
mov    %rax,%rbp
lea    0xe5c(%rip),%rsi
mov    %rax,%rdi
call   1080 <strspn@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmp    %eax,%r14d
jne    127f <ems1Starf+0xbf>
mov    $0x3,%edi
call   10a0 <starMalloc@plt>
test   %rax,%rax
je     1410 <ems1Starf+0x250>
lea    0xe2c(%rip),%rsi
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <strcpy@plt>
jmp    12a9 <ems1Starf+0xe9>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   10a0 <starMalloc@plt>
test   %rax,%rax
je     1410 <ems1Starf+0x250>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rbp
lea    0xdef(%rip),%rsi
mov    %rbp,%rdi
call   10c0 <strtok@plt>
test   %rax,%rax
je     141b <ems1Starf+0x25b>
mov    %rbp,0x10(%rsp)
mov    %r13,0x18(%rsp)
mov    %r15,0x20(%rsp)
mov    $0x1,%r13d
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
lea    0xda7(%rip),%rbp
mov    %rbp,%rsi
call   1080 <strspn@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %r12,%rdi
mov    %rbp,%rsi
call   1080 <strspn@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
cmp    %r14d,%r15d
jne    1340 <ems1Starf+0x180>
cmp    %eax,%ebp
jne    1370 <ems1Starf+0x1b0>
movb   $0x0,(%rbx)
jmp    13c0 <ems1Starf+0x200>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    %eax,%ebp
je     135e <ems1Starf+0x19e>
mov    %rbx,%rdi
lea    0xd53(%rip),%rsi
call   10d0 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10d0 <strcat@plt>
cmpb   $0x0,(%rbx)
jne    1380 <ems1Starf+0x1c0>
jmp    13c0 <ems1Starf+0x200>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
cmpb   $0x0,(%rbx)
je     13c0 <ems1Starf+0x200>
mov    %rbx,%rdi
mov    0xc(%rsp),%esi
call   10b0 <access@plt>
mov    %eax,%r13d
test   %eax,%eax
jne    13c0 <ems1Starf+0x200>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   1090 <stat@plt>
xor    %r13d,%r13d
test   %eax,%eax
jne    13c0 <ems1Starf+0x200>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
xor    %r13d,%r13d
test   %rax,%rax
setne  %r13b
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
lea    0xcd6(%rip),%rsi
call   10c0 <strtok@plt>
test   %rax,%rax
je     13dc <ems1Starf+0x21c>
test   %r13d,%r13d
jne    12e0 <ems1Starf+0x120>
mov    0x10(%rsp),%rdi
call   1070 <starFree@plt>
xor    %eax,%eax
mov    $0x0,%ecx
test   %r13d,%r13d
mov    0x20(%rsp),%r15
mov    0x18(%rsp),%r13
jne    1427 <ems1Starf+0x267>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    $0x1,%eax
jmp    1427 <ems1Starf+0x267>
movl   $0x0,(%r15)
xor    %eax,%eax
jmp    142e <ems1Starf+0x26e>
mov    %rbp,%rdi
call   1070 <starFree@plt>
xor    %eax,%eax
xor    %ecx,%ecx
mov    %ecx,(%r15)
mov    %rbx,0x0(%r13)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@X_OK = global i32 0
@W_OK = global i32 0
@R_OK = global i32 0
@F_OK = global i32 0
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c" :\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [2 x i8] c"/\00"
define i32 @ems1Starf(i8* nocapture %0, i8* %1, i8* nocapture %2, i8** nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = alloca %struct.stat
%7 = bitcast %struct.stat* %6 to i8*
%8 = tail call i8* (...) @ems1Gthreadbuf()
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
switch i32 %10, label %15 [
i32 120, label %16
i32 119, label %11
i32 114, label %12
i32 88, label %16
i32 87, label %13
i32 82, label %14
]
11: ; preds = %5
br label %16
12: ; preds = %5
br label %16
13: ; preds = %5
br label %16
14: ; preds = %5
br label %16
15: ; preds = %5
br label %16
16: ; preds = %5, %5, %15, %14, %13, %12, %11
%17 = phi i32* [ @F_OK, %15 ], [ @R_OK, %14 ], [ @W_OK, %13 ], [ @R_OK, %12 ], [ @W_OK, %11 ], [ @X_OK, %5 ], [ @X_OK, %5 ]
%18 = load i32, i32* %17
%19 = tail call i8* @getenv(i8* %0)
%20 = icmp eq i8* %19, null
br i1 %20, label %39, label %21
21: ; preds = %16
%22 = tail call i32 @strspn(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @strlen(i8* %19)
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = tail call i64 @starMalloc(i32 3)
%27 = inttoptr i64 %26 to i8*
%28 = icmp eq i64 %26, 0
br i1 %28, label %53, label %29
29: ; preds = %25
%30 = tail call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %45
31: ; preds = %21
%32 = tail call i32 @strlen(i8* %19)
%33 = add nsw i32 %32, 1
%34 = tail call i64 @starMalloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
%36 = icmp eq i64 %34, 0
br i1 %36, label %53, label %37
37: ; preds = %31
%38 = tail call i32 @strcpy(i8* %35, i8* %19)
br label %45
39: ; preds = %16
%40 = tail call i64 @starMalloc(i32 3)
%41 = inttoptr i64 %40 to i8*
%42 = icmp eq i64 %40, 0
br i1 %42, label %53, label %43
43: ; preds = %39
%44 = tail call i32 @strcpy(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %43, %29, %37
%46 = phi i8* [ %27, %29 ], [ %35, %37 ], [ %41, %43 ]
%47 = tail call i8* @strtok(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = tail call i32 @starFree(i8* %46)
br label %97
51: ; preds = %45
%52 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
br label %54
53: ; preds = %39, %31, %25
store i32 0, i32* %4
br label %100
54: ; preds = %51, %86
%55 = phi i8* [ %47, %51 ], [ %88, %86 ]
%56 = phi i32 [ 1, %51 ], [ %87, %86 ]
%57 = tail call i32 @strcpy(i8* %8, i8* %55)
%58 = tail call i32 @strspn(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%59 = tail call i32 @strlen(i8* %8)
%60 = icmp eq i32 %58, %59
%61 = tail call i32 @strspn(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%62 = tail call i32 @strlen(i8* %1)
%63 = icmp eq i32 %61, %62
br i1 %60, label %68, label %64
64: ; preds = %54
br i1 %63, label %72, label %65
65: ; preds = %64
%66 = tail call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%67 = tail call i32 @strcat(i8* %8, i8* %1)
br label %72
68: ; preds = %54
br i1 %63, label %71, label %69
69: ; preds = %68
%70 = tail call i32 @strcpy(i8* %8, i8* %1)
br label %72
71: ; preds = %68
store i8 0, i8* %8
br label %86
72: ; preds = %69, %64, %65
%73 = load i8, i8* %8
%74 = icmp eq i8 %73, 0
br i1 %74, label %86, label %75
75: ; preds = %72
%76 = tail call i32 @access(i8* %8, i32 %18)
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %86
78: ; preds = %75
%79 = call i32 @stat(i8* %8, %struct.stat* %6)
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %86
81: ; preds = %78
%82 = load i32, i32* %52
%83 = tail call i64 @S_ISDIR(i32 %82)
%84 = icmp ne i64 %83, 0
%85 = zext i1 %84 to i32
br label %86
86: ; preds = %71, %81, %78, %75, %72
%87 = phi i32 [ %76, %75 ], [ 0, %78 ], [ %56, %72 ], [ %85, %81 ], [ %56, %71 ]
%88 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%89 = icmp ne i8* %88, null
%90 = icmp ne i32 %87, 0
%91 = select i1 %89, i1 %90, i1 false
br i1 %91, label %54, label %92
92: ; preds = %86
%93 = tail call i32 @starFree(i8* %46)
br i1 %90, label %97, label %94
94: ; preds = %92
%95 = tail call i32 @strlen(i8* %8)
%96 = add nsw i32 %95, -1
br label %97
97: ; preds = %49, %92, %94
%98 = phi i32 [ 1, %94 ], [ 0, %92 ], [ 0, %49 ]
%99 = phi i32 [ %96, %94 ], [ 0, %92 ], [ 0, %49 ]
store i32 %99, i32* %4
store i8* %8, i8** %3
br label %100
100: ; preds = %97, %53
%101 = phi i32 [ %98, %97 ], [ 0, %53 ]
ret i32 %101
}