#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 char uint8_t;
typedef size_t uint32_t;
typedef int int32_t;

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int WTERMSIG(int);
int /*<<< orphan*/ ece391_strcpy(char *, char const *);
int ece391_strlen(char const *);
int /*<<< orphan*/ execv(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int);
int /*<<< orphan*/ wait(int *);
int32_t ece391_execute(const uint8_t *command) {
  int status;
  uint8_t buf[1026];
  char *args[1024];
  uint8_t *scan;
  uint32_t n_arg;
  if (1023 < ece391_strlen(command))
    return -1;
  buf[0] = '.';
  buf[1] = '/';
  ece391_strcpy(buf + 2, command);
  for (scan = buf + 2; '\0' != *scan && ' ' != *scan && '\n' != *scan; scan++)
    ;
  args[0] = (char *)buf;
  n_arg = 1;
  if ('\0' != *scan) {
    *scan++ = '\0';
    while (1) {
      while (' ' == *scan)
        scan++;
      if ('\0' == *scan || '\n' == *scan) {
        *scan = '\0';
        break;
      }
      args[n_arg++] = (char *)scan;
      while ('\0' != *scan && ' ' != *scan && '\n' != *scan)
        scan++;
      if ('\0' != *scan)
        *scan++ = '\0';
    }
  }
  args[n_arg] = NULL;
  if (0 == fork()) {
    execv((char *)buf, args);
    kill(getpid(), 9);
  }
  (void)wait(&status);
  if (WIFEXITED(status))
    return WEXITSTATUS(status);
  if (9 == WTERMSIG(status))
    return -1;
  return 256;
}


x86 assembly (clang, -O0):
<ece391_execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2440,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ece391_strlen@plt>
mov    %eax,%ecx
mov    $0x3ff,%eax
cmp    %ecx,%eax
jge    11d3 <ece391_execute+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b9 <ece391_execute+0x319>
movb   $0x2e,-0x420(%rbp)
movb   $0x2f,-0x41f(%rbp)
lea    -0x420(%rbp),%rdi
add    $0x2,%rdi
mov    -0x10(%rbp),%rsi
call   1050 <ece391_strcpy@plt>
lea    -0x420(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x2428(%rbp)
mov    -0x2428(%rbp),%rax
movsbl (%rax),%edx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %edx,%ecx
mov    %al,-0x2431(%rbp)
je     125c <ece391_execute+0xbc>
mov    -0x2428(%rbp),%rax
movsbl (%rax),%edx
xor    %eax,%eax
mov    $0x20,%ecx
cmp    %edx,%ecx
mov    %al,-0x2431(%rbp)
je     125c <ece391_execute+0xbc>
mov    -0x2428(%rbp),%rax
movsbl (%rax),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
setne  %al
mov    %al,-0x2431(%rbp)
mov    -0x2431(%rbp),%al
test   $0x1,%al
jne    126f <ece391_execute+0xcf>
jmp    128b <ece391_execute+0xeb>
jmp    1274 <ece391_execute+0xd4>
mov    -0x2428(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2428(%rbp)
jmp    1207 <ece391_execute+0x67>
lea    -0x420(%rbp),%rax
mov    %rax,-0x2420(%rbp)
movq   $0x1,-0x2430(%rbp)
mov    -0x2428(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1416 <ece391_execute+0x276>
mov    -0x2428(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x2428(%rbp)
movb   $0x0,(%rax)
jmp    12d5 <ece391_execute+0x135>
mov    -0x2428(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x20,%eax
cmp    %ecx,%eax
jne    1303 <ece391_execute+0x163>
mov    -0x2428(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2428(%rbp)
jmp    12d5 <ece391_execute+0x135>
mov    -0x2428(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     132e <ece391_execute+0x18e>
mov    -0x2428(%rbp),%rax
movsbl (%rax),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
jne    133d <ece391_execute+0x19d>
mov    -0x2428(%rbp),%rax
movb   $0x0,(%rax)
jmp    1411 <ece391_execute+0x271>
mov    -0x2428(%rbp),%rcx
mov    -0x2430(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x2430(%rbp)
mov    %rcx,-0x2420(%rbp,%rax,8)
ff
mov    -0x2428(%rbp),%rax
movsbl (%rax),%edx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %edx,%ecx
mov    %al,-0x2432(%rbp)
je     13b6 <ece391_execute+0x216>
mov    -0x2428(%rbp),%rax
movsbl (%rax),%edx
xor    %eax,%eax
mov    $0x20,%ecx
cmp    %edx,%ecx
mov    %al,-0x2432(%rbp)
je     13b6 <ece391_execute+0x216>
mov    -0x2428(%rbp),%rax
movsbl (%rax),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
setne  %al
mov    %al,-0x2432(%rbp)
mov    -0x2432(%rbp),%al
test   $0x1,%al
jne    13c9 <ece391_execute+0x229>
jmp    13e0 <ece391_execute+0x240>
mov    -0x2428(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2428(%rbp)
jmp    1361 <ece391_execute+0x1c1>
mov    -0x2428(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     140c <ece391_execute+0x26c>
mov    -0x2428(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x2428(%rbp)
movb   $0x0,(%rax)
jmp    12d0 <ece391_execute+0x130>
jmp    1416 <ece391_execute+0x276>
mov    -0x2430(%rbp),%rax
movq   $0x0,-0x2420(%rbp,%rax,8)
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1464 <ece391_execute+0x2c4>
lea    -0x420(%rbp),%rdi
lea    -0x2420(%rbp),%rsi
call   10b0 <execv@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    $0x9,%esi
call   1060 <kill@plt>
lea    -0x14(%rbp),%rdi
call   10a0 <wait@plt>
mov    -0x14(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%rax
je     148f <ece391_execute+0x2ef>
mov    -0x14(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    14b9 <ece391_execute+0x319>
mov    -0x14(%rbp),%edi
call   1070 <WTERMSIG@plt>
mov    %eax,%ecx
mov    $0x9,%eax
cmp    %ecx,%eax
jne    14b2 <ece391_execute+0x312>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b9 <ece391_execute+0x319>
movl   $0x100,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ece391_execute>:
push   %r14
push   %rbx
sub    $0x2428,%rsp
mov    %rdi,%r14
call   1030 <ece391_strlen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x3ff,%ecx
jg     12cf <ece391_execute+0x12f>
movw   $0x2f2e,0x10(%rsp)
lea    0x12(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <ece391_strcpy@plt>
movabs $0x100000401,%rax
jmp    11f4 <ece391_execute+0x54>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
movzbl (%rbx),%ecx
cmp    $0x20,%rcx
ja     11f0 <ece391_execute+0x50>
bt     %rcx,%rax
jae    11f0 <ece391_execute+0x50>
lea    0x10(%rsp),%rax
mov    %rax,0x420(%rsp)
mov    $0x1,%eax
test   %cl,%cl
je     125a <ece391_execute+0xba>
movb   $0x0,(%rbx)
nopl   0x0(%rax)
add    $0x1,%rbx
mov    (%rbx),%cl
cmp    $0x20,%cl
je     1220 <ece391_execute+0x80>
test   %cl,%cl
je     1257 <ece391_execute+0xb7>
cmp    $0xa,%cl
je     1257 <ece391_execute+0xb7>
mov    %rbx,0x420(%rsp,%rax,8)
add    $0x1,%rax
movzbl (%rbx),%ecx
test   %cl,%cl
je     1224 <ece391_execute+0x84>
cmp    $0xa,%cl
je     1219 <ece391_execute+0x79>
cmp    $0x20,%cl
je     1219 <ece391_execute+0x79>
add    $0x1,%rbx
jmp    1240 <ece391_execute+0xa0>
movb   $0x0,(%rbx)
movq   $0x0,0x420(%rsp,%rax,8)
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jne    1297 <ece391_execute+0xf7>
lea    0x10(%rsp),%rdi
lea    0x420(%rsp),%rsi
call   10b0 <execv@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%edi
mov    $0x9,%esi
call   1060 <kill@plt>
lea    0xc(%rsp),%rdi
call   10a0 <wait@plt>
mov    0xc(%rsp),%edi
call   1090 <WIFEXITED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
je     12ba <ece391_execute+0x11a>
call   1080 <WEXITSTATUS@plt>
jmp    12cf <ece391_execute+0x12f>
call   1070 <WTERMSIG@plt>
cmp    $0x9,%eax
mov    $0xffffffff,%ecx
mov    $0x100,%eax
cmove  %ecx,%eax
add    $0x2428,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @ece391_execute(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1026 x i8]
%6 = alloca [1024 x i8*]
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @ece391_strlen(i8* %9)
%11 = icmp slt i32 1023, %10
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %134
13: ; preds = %1
%14 = getelementptr inbounds [1026 x i8], [1026 x i8]* %5, i64 0, i64 0
store i8 46, i8* %14
%15 = getelementptr inbounds [1026 x i8], [1026 x i8]* %5, i64 0, i64 1
store i8 47, i8* %15
%16 = getelementptr inbounds [1026 x i8], [1026 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds i8, i8* %16, i64 2
%18 = load i8*, i8** %3
%19 = call i32 @ece391_strcpy(i8* %17, i8* %18)
%20 = getelementptr inbounds [1026 x i8], [1026 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds i8, i8* %20, i64 2
store i8* %21, i8** %7
br label %22
22: ; preds = %40, %13
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 0, %25
br i1 %26, label %27, label %37
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 32, %30
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 10, %35
br label %37
37: ; preds = %32, %27, %22
%38 = phi i1 [ false, %27 ], [ false, %22 ], [ %36, %32 ]
br i1 %38, label %39, label %43
39: ; preds = %37
br label %40
40: ; preds = %39
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %7
br label %22
43: ; preds = %37
%44 = getelementptr inbounds [1026 x i8], [1026 x i8]* %5, i64 0, i64 0
%45 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 0
store i8* %44, i8** %45
store i64 1, i64* %8
%46 = load i8*, i8** %7
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 0, %48
br i1 %49, label %50, label %109
50: ; preds = %43
%51 = load i8*, i8** %7
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %7
store i8 0, i8* %51
br label %53
53: ; preds = %50, %107
br label %54
54: ; preds = %59, %53
%55 = load i8*, i8** %7
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 32, %57
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i8*, i8** %7
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %7
br label %54
62: ; preds = %54
%63 = load i8*, i8** %7
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 0, %65
br i1 %66, label %72, label %67
67: ; preds = %62
%68 = load i8*, i8** %7
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 10, %70
br i1 %71, label %72, label %74
72: ; preds = %67, %62
%73 = load i8*, i8** %7
store i8 0, i8* %73
br label %108
74: ; preds = %67
%75 = load i8*, i8** %7
%76 = load i64, i64* %8
%77 = add i64 %76, 1
store i64 %77, i64* %8
%78 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 %76
store i8* %75, i8** %78
br label %79
79: ; preds = %96, %74
%80 = load i8*, i8** %7
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp ne i32 0, %82
br i1 %83, label %84, label %94
84: ; preds = %79
%85 = load i8*, i8** %7
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = icmp ne i32 32, %87
br i1 %88, label %89, label %94
89: ; preds = %84
%90 = load i8*, i8** %7
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp ne i32 10, %92
br label %94
94: ; preds = %89, %84, %79
%95 = phi i1 [ false, %84 ], [ false, %79 ], [ %93, %89 ]
br i1 %95, label %96, label %99
96: ; preds = %94
%97 = load i8*, i8** %7
%98 = getelementptr inbounds i8, i8* %97, i32 1
store i8* %98, i8** %7
br label %79
99: ; preds = %94
%100 = load i8*, i8** %7
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = icmp ne i32 0, %102
br i1 %103, label %104, label %107
104: ; preds = %99
%105 = load i8*, i8** %7
%106 = getelementptr inbounds i8, i8* %105, i32 1
store i8* %106, i8** %7
store i8 0, i8* %105
br label %107
107: ; preds = %104, %99
br label %53
108: ; preds = %72
br label %109
109: ; preds = %108, %43
%110 = load i64, i64* %8
%111 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 %110
store i8* null, i8** %111
%112 = call i64 (...) @fork()
%113 = icmp eq i64 0, %112
br i1 %113, label %114, label %120
114: ; preds = %109
%115 = getelementptr inbounds [1026 x i8], [1026 x i8]* %5, i64 0, i64 0
%116 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 0
%117 = call i32 @execv(i8* %115, i8** %116)
%118 = call i32 (...) @getpid()
%119 = call i32 @kill(i32 %118, i32 9)
br label %120
120: ; preds = %114, %109
%121 = call i32 @wait(i32* %4)
%122 = load i32, i32* %4
%123 = call i64 @WIFEXITED(i32 %122)
%124 = icmp ne i64 %123, 0
br i1 %124, label %125, label %128
125: ; preds = %120
%126 = load i32, i32* %4
%127 = call i32 @WEXITSTATUS(i32 %126)
store i32 %127, i32* %2
br label %134
128: ; preds = %120
%129 = load i32, i32* %4
%130 = call i32 @WTERMSIG(i32 %129)
%131 = icmp eq i32 9, %130
br i1 %131, label %132, label %133
132: ; preds = %128
store i32 -1, i32* %2
br label %134
133: ; preds = %128
store i32 256, i32* %2
br label %134
134: ; preds = %133, %132, %125, %12
%135 = load i32, i32* %2
ret i32 %135
}

LLVM IR (-O2):
define i32 @ece391_execute(i8* %0) {
%2 = alloca i32
%3 = alloca [1026 x i8]
%4 = alloca [1024 x i8*]
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [1026 x i8], [1026 x i8]* %3, i64 0, i64 0
%7 = bitcast [1024 x i8*]* %4 to i8*
%8 = tail call i32 @ece391_strlen(i8* %0)
%9 = icmp sgt i32 %8, 1023
br i1 %9, label %65, label %10
10: ; preds = %1
store i8 46, i8* %6
%11 = getelementptr inbounds [1026 x i8], [1026 x i8]* %3, i64 0, i64 1
store i8 47, i8* %11
%12 = getelementptr inbounds [1026 x i8], [1026 x i8]* %3, i64 0, i64 2
%13 = call i32 @ece391_strcpy(i8* %12, i8* %0)
br label %14
14: ; preds = %17, %10
%15 = phi i8* [ %12, %10 ], [ %18, %17 ]
%16 = load i8, i8* %15
switch i8 %16, label %17 [
i8 0, label %19
i8 32, label %19
i8 10, label %19
]
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %15, i64 1
br label %14
19: ; preds = %14, %14, %14
%20 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %4, i64 0, i64 0
store i8* %6, i8** %20
%21 = icmp eq i8 %16, 0
br i1 %21, label %44, label %23
22: ; preds = %39, %39
br label %23
23: ; preds = %19, %22
%24 = phi i8* [ %40, %22 ], [ %15, %19 ]
%25 = phi i64 [ %37, %22 ], [ 1, %19 ]
%26 = getelementptr inbounds i8, i8* %24, i64 1
store i8 0, i8* %24
br label %27
27: ; preds = %39, %23
%28 = phi i8* [ %26, %23 ], [ %40, %39 ]
%29 = phi i64 [ %25, %23 ], [ %37, %39 ]
br label %30
30: ; preds = %33, %27
%31 = phi i8* [ %28, %27 ], [ %34, %33 ]
%32 = load i8, i8* %31
switch i8 %32, label %36 [
i8 32, label %33
i8 0, label %35
i8 10, label %35
]
33: ; preds = %30
%34 = getelementptr inbounds i8, i8* %31, i64 1
br label %30
35: ; preds = %30, %30
store i8 0, i8* %31
br label %44
36: ; preds = %30
%37 = add i64 %29, 1
%38 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %4, i64 0, i64 %29
store i8* %31, i8** %38
br label %39
39: ; preds = %42, %36
%40 = phi i8* [ %31, %36 ], [ %43, %42 ]
%41 = load i8, i8* %40
switch i8 %41, label %42 [
i8 0, label %27
i8 10, label %22
i8 32, label %22
]
42: ; preds = %39
%43 = getelementptr inbounds i8, i8* %40, i64 1
br label %39
44: ; preds = %35, %19
%45 = phi i64 [ %29, %35 ], [ 1, %19 ]
%46 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %4, i64 0, i64 %45
store i8* null, i8** %46
%47 = call i64 (...) @fork()
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = call i32 @execv(i8* %6, i8** %20)
%51 = call i32 (...) @getpid()
%52 = call i32 @kill(i32 %51, i32 9)
br label %53
53: ; preds = %49, %44
%54 = call i32 @wait(i32* %2)
%55 = load i32, i32* %2
%56 = call i64 @WIFEXITED(i32 %55)
%57 = icmp eq i64 %56, 0
%58 = load i32, i32* %2
br i1 %57, label %61, label %59
59: ; preds = %53
%60 = call i32 @WEXITSTATUS(i32 %58)
br label %65
61: ; preds = %53
%62 = call i32 @WTERMSIG(i32 %58)
%63 = icmp eq i32 %62, 9
%64 = select i1 %63, i32 -1, i32 256
br label %65
65: ; preds = %61, %1, %59
%66 = phi i32 [ %60, %59 ], [ -1, %1 ], [ %64, %61 ]
ret i32 %66
}