#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 */
scalar_t__ ENOENT;
int FILENAME_MAX;
scalar_t__ errno;
int execve(char const *, char *const *, char *const *);
char *getenv(char *);
int /*<<< orphan*/ strcat(char *, char const *);
char *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int execvep(const char *path, char *__const argv[], char *__const envp[]) {
  if (!strchr(path, '/')) {
    char *p = getenv("PATH");
    if (!p)
      p = "/bin:/usr/bin";
    for (; p && *p;) {
      char partial[FILENAME_MAX];
      char *p2;
      p2 = strchr(p, ':');
      if (p2) {
        size_t len = p2 - p;
        strncpy(partial, p, len);
        partial[len] = 0;
      } else {
        strcpy(partial, p);
      }
      if (strlen(partial))
        strcat(partial, "/");
      strcat(partial, path);
      execve(partial, argv, envp);
      if (errno != ENOENT)
        return -1;
      if (p2) {
        p = p2 + 1;
      } else {
        p = 0;
      }
    }
    return -1;
  } else
    return execve(path, argv, envp);
}


x86 assembly (clang, -O0):
<execvep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
jne    1344 <execvep+0x1d4>
lea    0xe5d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c2 <execvep+0x52>
lea    0xe47(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11c7 <execvep+0x57>
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x4d(%rbp)
je     11e7 <execvep+0x77>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    11f7 <execvep+0x87>
jmp    1338 <execvep+0x1c8>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1271 <execvep+0x101>
mov    -0x58(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x58(%rbp),%rax
mov    -0x48(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    127e <execvep+0x10e>
mov    -0x58(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x58(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
je     12a1 <execvep+0x131>
mov    -0x58(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x58(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <execve@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%rax
mov    0x2cf8(%rip),%rcx
cmp    (%rcx),%rax
je     12ec <execvep+0x17c>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1317 <execvep+0x1a7>
cmpq   $0x0,-0x40(%rbp)
je     1308 <execvep+0x198>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1310 <execvep+0x1a0>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4c(%rbp),%eax
test   %eax,%eax
je     1333 <execvep+0x1c3>
jmp    132e <execvep+0x1be>
jmp    1358 <execvep+0x1e8>
jmp    11c7 <execvep+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    1358 <execvep+0x1e8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <execve@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execvep>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11a5 <execvep+0x45>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <execve@plt>
mov    %rbx,-0x30(%rbp)
lea    0xe50(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe46(%rip),%rbx
cmovne %rax,%rbx
mov    %r13,-0x38(%rbp)
jmp    1212 <execvep+0xb2>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1070 <execve@plt>
lea    0x1(%r15),%rbx
test   %r15,%r15
mov    0x2de1(%rip),%rax
mov    (%rax),%rax
cmove  %r15,%rbx
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%rax
mov    -0x40(%rbp),%rsp
jne    12ae <execvep+0x14e>
test   %rbx,%rbx
je     12ae <execvep+0x14e>
cmpb   $0x0,(%rbx)
je     12ae <execvep+0x14e>
mov    %rsp,-0x40(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
je     1280 <execvep+0x120>
mov    %r14,%r13
mov    %r15,%r14
sub    %rbx,%r14
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <strncpy@plt>
movb   $0x0,(%r12,%r14,1)
mov    %r13,%r14
mov    -0x38(%rbp),%r13
jmp    128b <execvep+0x12b>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    -0x30(%rbp),%rbx
cmpb   $0x0,(%r12)
je     11d0 <execvep+0x70>
mov    %r12,%rdi
lea    0xd6f(%rip),%rsi
call   1080 <strcat@plt>
jmp    11d0 <execvep+0x70>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [14 x i8] c"/bin:/usr/bin\00"
@FILENAME_MAX = global i32 0
@.str.2 = [2 x i8] c"/\00"
@errno = global i64 0
@ENOENT = global i64 0
define i32 @execvep(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%14 = load i8*, i8** %5
%15 = call i8* @strchr(i8* %14, i8 signext 47)
%16 = icmp ne i8* %15, null
br i1 %16, label %84, label %17
17: ; preds = %3
%18 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %17
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %22
22: ; preds = %21, %17
br label %23
23: ; preds = %82, %22
%24 = load i8*, i8** %8
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i8*, i8** %8
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br label %31
31: ; preds = %26, %23
%32 = phi i1 [ false, %23 ], [ %30, %26 ]
br i1 %32, label %33, label %83
33: ; preds = %31
%34 = load i32, i32* @FILENAME_MAX
%35 = zext i32 %34 to i64
%36 = call i8* @llvm.stacksave()
store i8* %36, i8** %9
%37 = alloca i8, i64 %35
store i64 %35, i64* %10
%38 = load i8*, i8** %8
%39 = call i8* @strchr(i8* %38, i8 signext 58)
store i8* %39, i8** %11
%40 = load i8*, i8** %11
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %53
42: ; preds = %33
%43 = load i8*, i8** %11
%44 = load i8*, i8** %8
%45 = ptrtoint i8* %43 to i64
%46 = ptrtoint i8* %44 to i64
%47 = sub i64 %45, %46
store i64 %47, i64* %12
%48 = load i8*, i8** %8
%49 = load i64, i64* %12
%50 = call i32 @strncpy(i8* %37, i8* %48, i64 %49)
%51 = load i64, i64* %12
%52 = getelementptr inbounds i8, i8* %37, i64 %51
store i8 0, i8* %52
br label %56
53: ; preds = %33
%54 = load i8*, i8** %8
%55 = call i32 @strcpy(i8* %37, i8* %54)
br label %56
56: ; preds = %53, %42
%57 = call i64 @strlen(i8* %37)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @strcat(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %61
61: ; preds = %59, %56
%62 = load i8*, i8** %5
%63 = call i32 @strcat(i8* %37, i8* %62)
%64 = load i8**, i8*** %6
%65 = load i8**, i8*** %7
%66 = call i32 @execve(i8* %37, i8** %64, i8** %65)
%67 = load i64, i64* @errno
%68 = load i64, i64* @ENOENT
%69 = icmp ne i64 %67, %68
br i1 %69, label %70, label %71
70: ; preds = %61
store i32 -1, i32* %4
store i32 1, i32* %13
br label %79
71: ; preds = %61
%72 = load i8*, i8** %11
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = load i8*, i8** %11
%76 = getelementptr inbounds i8, i8* %75, i64 1
store i8* %76, i8** %8
br label %78
77: ; preds = %71
store i8* null, i8** %8
br label %78
78: ; preds = %77, %74
store i32 0, i32* %13
br label %79
79: ; preds = %78, %70
%80 = load i8*, i8** %9
%81 = load i32, i32* %13
switch i32 %81, label %91 [
i32 0, label %82
i32 1, label %89
]
82: ; preds = %79
br label %23
83: ; preds = %31
store i32 -1, i32* %4
br label %89
84: ; preds = %3
%85 = load i8*, i8** %5
%86 = load i8**, i8*** %6
%87 = load i8**, i8*** %7
%88 = call i32 @execve(i8* %85, i8** %86, i8** %87)
store i32 %88, i32* %4
br label %89
89: ; preds = %84, %83, %79
%90 = load i32, i32* %4
ret i32 %90
91: ; preds = %79
unreachable
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [14 x i8] c"/bin:/usr/bin\00"
@FILENAME_MAX = global i32 0
@.str.2 = [2 x i8] c"/\00"
@errno = global i64 0
@ENOENT = global i64 0
define i32 @execvep(i8* %0, i8** %1, i8** %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %44
6: ; preds = %3
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
%9 = select i1 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %7
br label %10
10: ; preds = %6, %36
%11 = phi i8* [ %43, %36 ], [ %9, %6 ]
%12 = icmp eq i8* %11, null
br i1 %12, label %46, label %13
13: ; preds = %10
%14 = load i8, i8* %11
%15 = icmp eq i8 %14, 0
br i1 %15, label %46, label %16
16: ; preds = %13
%17 = load i32, i32* @FILENAME_MAX
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
%20 = alloca i8, i64 %18
%21 = call i8* @strchr(i8* %11, i8 signext 58)
%22 = icmp eq i8* %21, null
br i1 %22, label %29, label %23
23: ; preds = %16
%24 = ptrtoint i8* %21 to i64
%25 = ptrtoint i8* %11 to i64
%26 = sub i64 %24, %25
%27 = call i32 @strncpy(i8* %20, i8* %11, i64 %26)
%28 = getelementptr inbounds i8, i8* %20, i64 %26
store i8 0, i8* %28
br label %31
29: ; preds = %16
%30 = call i32 @strcpy(i8* %20, i8* %11)
br label %31
31: ; preds = %29, %23
%32 = load i8, i8* %20
%33 = icmp eq i8 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = call i32 @strcat(i8* %20, i8* %0)
%38 = call i32 @execve(i8* %20, i8** %1, i8** %2)
%39 = load i64, i64* @errno
%40 = load i64, i64* @ENOENT
%41 = icmp eq i64 %39, %40
%42 = getelementptr inbounds i8, i8* %21, i64 1
%43 = select i1 %22, i8* null, i8* %42
br i1 %41, label %10, label %46
44: ; preds = %3
%45 = tail call i32 @execve(i8* %0, i8** %1, i8** %2)
br label %46
46: ; preds = %36, %10, %13, %44
%47 = phi i32 [ %45, %44 ], [ -1, %13 ], [ -1, %10 ], [ -1, %36 ]
ret i32 %47
}