#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 */
int /*<<< orphan*/ changedir(char *);
int /*<<< orphan*/ do_pipes(char *);
int /*<<< orphan*/ execlp(char *, char *, char *, ...);
int fork();
int /*<<< orphan*/ redir(int, char *);
char *strsep(char **, char *);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ wait(int *);
void execute(char *s) {
  if (strstr(s, "cd")) {
    changedir(s);
  } else if (strstr(s, "|")) {
    do_pipes(s);
  } else if (strstr(s, "<")) {
    redir(1, s);
  } else if (strstr(s, ">")) {
    redir(2, s);
  } else {
    int status;
    char *first = strsep(&s, " ");
    int f = fork();
    if (f == 0) {
      if (s == NULL)
        execlp(first, first, s);
      else
        execlp(first, first, s, NULL);
    } else {
      wait(&status);
    }
  }
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     11b4 <execute+0x34>
mov    -0x8(%rbp),%rdi
call   1030 <changedir@plt>
jmp    12ba <execute+0x13a>
mov    -0x8(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     11dc <execute+0x5c>
mov    -0x8(%rbp),%rdi
call   1040 <do_pipes@plt>
jmp    12b5 <execute+0x135>
mov    -0x8(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1209 <execute+0x89>
mov    -0x8(%rbp),%rsi
mov    $0x1,%edi
call   1060 <redir@plt>
jmp    12b0 <execute+0x130>
mov    -0x8(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1236 <execute+0xb6>
mov    -0x8(%rbp),%rsi
mov    $0x2,%edi
call   1060 <redir@plt>
jmp    12ab <execute+0x12b>
lea    -0x8(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    129d <execute+0x11d>
cmpq   $0x0,-0x8(%rbp)
jne    1281 <execute+0x101>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1070 <execlp@plt>
jmp    1298 <execute+0x118>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   1070 <execlp@plt>
jmp    12a6 <execute+0x126>
lea    -0xc(%rbp),%rdi
call   1080 <wait@plt>
jmp    12ab <execute+0x12b>
jmp    12b0 <execute+0x130>
jmp    12b5 <execute+0x135>
jmp    12ba <execute+0x13a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rdi,(%rsp)
lea    0xe6d(%rip),%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11aa <execute+0x2a>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <changedir@plt>
lea    0xe52(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11cb <execute+0x4b>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <do_pipes@plt>
lea    0xe33(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11e6 <execute+0x66>
mov    $0x1,%edi
jmp    11ff <execute+0x7f>
lea    0xe1a(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     120c <execute+0x8c>
mov    $0x2,%edi
mov    %rbx,%rsi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <redir@plt>
lea    0xdf6(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strsep@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1235 <execute+0xb5>
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
jmp    1258 <execute+0xd8>
mov    (%rsp),%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
test   %rdx,%rdx
je     124f <execute+0xcf>
xor    %ecx,%ecx
xor    %eax,%eax
call   1070 <execlp@plt>
jmp    1258 <execute+0xd8>
xor    %edx,%edx
xor    %eax,%eax
call   1070 <execlp@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"cd\00"
@.str.1 = [2 x i8] c"|\00"
@.str.2 = [2 x i8] c"<\00"
@.str.3 = [2 x i8] c">\00"
@.str.4 = [2 x i8] c" \00"
define void @execute(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strstr(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @changedir(i8* %10)
br label %58
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i64 @strstr(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = call i32 @do_pipes(i8* %17)
br label %57
19: ; preds = %12
%20 = load i8*, i8** %2
%21 = call i64 @strstr(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** %2
%25 = call i32 @redir(i32 1, i8* %24)
br label %56
26: ; preds = %19
%27 = load i8*, i8** %2
%28 = call i64 @strstr(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** %2
%32 = call i32 @redir(i32 2, i8* %31)
br label %55
33: ; preds = %26
%34 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %34, i8** %4
%35 = call i32 (...) @fork()
store i32 %35, i32* %5
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %52
38: ; preds = %33
%39 = load i8*, i8** %2
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %46
41: ; preds = %38
%42 = load i8*, i8** %4
%43 = load i8*, i8** %4
%44 = load i8*, i8** %2
%45 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %42, i8* %43, i8* %44)
br label %51
46: ; preds = %38
%47 = load i8*, i8** %4
%48 = load i8*, i8** %4
%49 = load i8*, i8** %2
%50 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %47, i8* %48, i8* %49, i8* null)
br label %51
51: ; preds = %46, %41
br label %54
52: ; preds = %33
%53 = call i32 @wait(i32* %3)
br label %54
54: ; preds = %52, %51
br label %55
55: ; preds = %54, %30
br label %56
56: ; preds = %55, %23
br label %57
57: ; preds = %56, %16
br label %58
58: ; preds = %57, %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"cd\00"
@.str.1 = [2 x i8] c"|\00"
@.str.2 = [2 x i8] c"<\00"
@.str.3 = [2 x i8] c">\00"
@.str.4 = [2 x i8] c" \00"
define void @execute(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @changedir(i8* %0)
br label %38
8: ; preds = %1
%9 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @do_pipes(i8* %0)
br label %38
13: ; preds = %8
%14 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 @redir(i32 1, i8* %0)
br label %38
18: ; preds = %13
%19 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call i32 @redir(i32 2, i8* %0)
br label %38
23: ; preds = %18
%24 = bitcast i32* %3 to i8*
%25 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 (...) @fork()
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = load i8*, i8** %2
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %25, i8* %25, i8* null)
br label %37
33: ; preds = %28
%34 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %25, i8* %25, i8* %29, i8* null)
br label %37
35: ; preds = %23
%36 = call i32 @wait(i32* %3)
br label %37
37: ; preds = %31, %33, %35
br label %38
38: ; preds = %11, %21, %37, %16, %6
ret void
}