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

/* Variables and functions */
scalar_t__ ENAMETOOLONG;
scalar_t__ ENOENT;
scalar_t__ errno;
int execve(char *, char **, char **);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int execute(char **cmd) {
  static char *nullenv[] = {NULL};
  char command[128];
  char *path[] = {"/sbin", "/bin", "/usr/sbin", "/usr/bin"};
  int i;
  if (cmd[0][0] == '/') {
    return execve(cmd[0], cmd, nullenv);
  }
  for (i = 0; i < 4; i++) {
    if (strlen(path[i]) + 1 + strlen(cmd[0]) + 1 > sizeof(command)) {
      errno = ENAMETOOLONG;
      return -1;
    }
    strcpy(command, path[i]);
    strcat(command, "/");
    strcat(command, cmd[0]);
    execve(command, cmd, nullenv);
    if (errno != ENOENT)
      break;
  }
  return -1;
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2c8a(%rip),%rax
mov    %rax,-0xb0(%rbp)
mov    0x2c84(%rip),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2c7e(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    0x2c78(%rip),%rax
mov    %rax,-0x98(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11b9 <execute+0x79>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
lea    0x2e9c(%rip),%rdx
call   1050 <execve@plt>
mov    %eax,-0x4(%rbp)
jmp    12cb <execute+0x18b>
movl   $0x0,-0xb4(%rbp)
cmpl   $0x4,-0xb4(%rbp)
jge    12c4 <execute+0x184>
movslq -0xb4(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rdi
ff
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xb8(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
cmp    $0x80,%rax
jbe    1234 <execute+0xf4>
mov    0x2db5(%rip),%rax
mov    (%rax),%rcx
mov    0x2db3(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12cb <execute+0x18b>
lea    -0x90(%rbp),%rdi
movslq -0xb4(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rsi
ff
call   1030 <strcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1060 <strcat@plt>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0x2dc1(%rip),%rdx
call   1050 <execve@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%rax
mov    0x2d23(%rip),%rcx
cmp    (%rcx),%rax
je     12ab <execute+0x16b>
jmp    12c4 <execute+0x184>
jmp    12b0 <execute+0x170>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    11c3 <execute+0x83>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%r14
mov    (%rdi),%rdi
cmpb   $0x2f,(%rdi)
jne    1176 <execute+0x36>
lea    0x2ee8(%rip),%rdx
mov    %r14,%rsi
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <execve@plt>
lea    0xe87(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    (%r14),%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0xffffff81,%eax
cmp    $0xffffff7f,%eax
jb     12f1 <execute+0x1b1>
lea    0xe61(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    (%r14),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
lea    0x2e79(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <execve@plt>
mov    0x2dff(%rip),%r15
mov    (%r15),%rax
mov    0x2ddd(%rip),%r12
cmp    (%r12),%rax
jne    1305 <execute+0x1c5>
lea    0xe12(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    (%r14),%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0xffffff81,%eax
cmp    $0xffffff7f,%eax
jb     12f1 <execute+0x1b1>
lea    0xdec(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xddf(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    (%r14),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
lea    0x2dfa(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <execve@plt>
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1305 <execute+0x1c5>
lea    0xd93(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    (%r14),%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0xffffff81,%eax
cmp    $0xffffff7f,%eax
jb     12f1 <execute+0x1b1>
lea    0xd71(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xd72(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    (%r14),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
lea    0x2d8d(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <execve@plt>
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1305 <execute+0x1c5>
lea    0xd34(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    (%r14),%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0xffffff81,%eax
cmp    $0xffffff7f,%eax
jae    1319 <execute+0x1d9>
mov    0x2ce0(%rip),%rax
mov    (%rax),%rax
mov    0x2cde(%rip),%rcx
mov    %rax,(%rcx)
mov    $0xffffffff,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xcea(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xce1(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    (%r14),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
lea    0x2cfc(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <execve@plt>
jmp    1305 <execute+0x1c5>

LLVM IR (-O0):
@execute.nullenv = internal global [1 x i8*] zeroinitializer
@.str = [6 x i8] c"/sbin\00"
@.str.1 = [5 x i8] c"/bin\00"
@.str.2 = [10 x i8] c"/usr/sbin\00"
@.str.3 = [9 x i8] c"/usr/bin\00"
@__const.execute.path = [4 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0)]
@ENAMETOOLONG = global i64 0
@errno = global i64 0
@.str.4 = [2 x i8] c"/\00"
@ENOENT = global i64 0
define i32 @execute(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca [128 x i8]
%5 = alloca [4 x i8*]
%6 = alloca i32
store i8** %0, i8*** %3
%7 = bitcast [4 x i8*]* %5 to i8*
%8 = load i8**, i8*** %3
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 47
br i1 %14, label %15, label %21
15: ; preds = %1
%16 = load i8**, i8*** %3
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = load i8**, i8*** %3
%20 = call i32 @execve(i8* %18, i8** %19, i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @execute.nullenv, i64 0, i64 0))
store i32 %20, i32* %2
br label %68
21: ; preds = %1
store i32 0, i32* %6
br label %22
22: ; preds = %64, %21
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 4
br i1 %24, label %25, label %67
25: ; preds = %22
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %30, 1
%32 = load i8**, i8*** %3
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 %31, %35
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = icmp ugt i64 %38, 128
br i1 %39, label %40, label %42
40: ; preds = %25
%41 = load i64, i64* @ENAMETOOLONG
store i64 %41, i64* @errno
store i32 -1, i32* %2
br label %68
42: ; preds = %25
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 @strcpy(i8* %43, i8* %47)
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%50 = call i32 @strcat(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%52 = load i8**, i8*** %3
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i32 @strcat(i8* %51, i8* %54)
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%57 = load i8**, i8*** %3
%58 = call i32 @execve(i8* %56, i8** %57, i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @execute.nullenv, i64 0, i64 0))
%59 = load i64, i64* @errno
%60 = load i64, i64* @ENOENT
%61 = icmp ne i64 %59, %60
br i1 %61, label %62, label %63
62: ; preds = %42
br label %67
63: ; preds = %42
br label %64
64: ; preds = %63
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %22
67: ; preds = %62, %22
store i32 -1, i32* %2
br label %68
68: ; preds = %67, %40, %15
%69 = load i32, i32* %2
ret i32 %69
}

LLVM IR (-O2):
@execute.nullenv = internal global [1 x i8*] zeroinitializer
@.str = [6 x i8] c"/sbin\00"
@.str.1 = [5 x i8] c"/bin\00"
@.str.2 = [10 x i8] c"/usr/sbin\00"
@.str.3 = [9 x i8] c"/usr/bin\00"
@ENAMETOOLONG = global i64 0
@errno = global i64 0
@.str.4 = [2 x i8] c"/\00"
@ENOENT = global i64 0
define i32 @execute(i8** %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = load i8*, i8** %0
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 47
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %0
%10 = call i32 @strlen(i8* %9)
%11 = add i32 %8, -127
%12 = add i32 %11, %10
%13 = icmp ult i32 %12, -129
br i1 %13, label %61, label %63
14: ; preds = %1
%15 = tail call i32 @execve(i8* %4, i8** %0, i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @execute.nullenv, i64 0, i64 0))
br label %72
16: ; preds = %63
%17 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8*, i8** %0
%19 = call i32 @strlen(i8* %18)
%20 = add i32 %17, -127
%21 = add i32 %20, %19
%22 = icmp ult i32 %21, -129
br i1 %22, label %61, label %23
23: ; preds = %16
%24 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = load i8*, i8** %0
%27 = call i32 @strcat(i8* %3, i8* %26)
%28 = call i32 @execve(i8* %3, i8** %0, i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @execute.nullenv, i64 0, i64 0))
%29 = load i64, i64* @errno
%30 = load i64, i64* @ENOENT
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %72
32: ; preds = %23
%33 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%34 = load i8*, i8** %0
%35 = call i32 @strlen(i8* %34)
%36 = add i32 %33, -127
%37 = add i32 %36, %35
%38 = icmp ult i32 %37, -129
br i1 %38, label %61, label %39
39: ; preds = %32
%40 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%42 = load i8*, i8** %0
%43 = call i32 @strcat(i8* %3, i8* %42)
%44 = call i32 @execve(i8* %3, i8** %0, i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @execute.nullenv, i64 0, i64 0))
%45 = load i64, i64* @errno
%46 = load i64, i64* @ENOENT
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %72
48: ; preds = %39
%49 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%50 = load i8*, i8** %0
%51 = call i32 @strlen(i8* %50)
%52 = add i32 %49, -127
%53 = add i32 %52, %51
%54 = icmp ult i32 %53, -129
br i1 %54, label %61, label %55
55: ; preds = %48
%56 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%58 = load i8*, i8** %0
%59 = call i32 @strcat(i8* %3, i8* %58)
%60 = call i32 @execve(i8* %3, i8** %0, i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @execute.nullenv, i64 0, i64 0))
br label %72
61: ; preds = %48, %32, %16, %7
%62 = load i64, i64* @ENAMETOOLONG
store i64 %62, i64* @errno
br label %72
63: ; preds = %7
%64 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%65 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%66 = load i8*, i8** %0
%67 = call i32 @strcat(i8* %3, i8* %66)
%68 = call i32 @execve(i8* %3, i8** %0, i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @execute.nullenv, i64 0, i64 0))
%69 = load i64, i64* @errno
%70 = load i64, i64* @ENOENT
%71 = icmp eq i64 %69, %70
br i1 %71, label %16, label %72
72: ; preds = %55, %63, %23, %39, %61, %14
%73 = phi i32 [ %15, %14 ], [ -1, %61 ], [ -1, %55 ], [ -1, %39 ], [ -1, %23 ], [ -1, %63 ]
ret i32 %73
}