#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int STDIN_FILENO;
int STDOUT_FILENO;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ execute_command(char **, int, int, int, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
scalar_t__ strlen(char *);
char *strtok(char *, char *);
void parse_command(char *command_str) {
  assert(strlen(command_str) > 0);
  char *c_argv[32];
  char *token = strtok(command_str, " \t");
  int run_command = 0;
  int no_more_commands = 0;
  int c_argc = 0;
  int fg = 1;
  int out_fd = STDOUT_FILENO;
  int in_fd = STDIN_FILENO;
  int next_in_fd = -1;
  for (;;) {
    if (next_in_fd != -1) {
      in_fd = next_in_fd;
      next_in_fd = -1;
    }
    if (token == NULL) {
      no_more_commands = 1;
      run_command = 1;
    } else if (strcmp(token, "&") == 0) {
      fg = 0;
      run_command = 1;
    } else if (strcmp(token, ";") == 0) {
      run_command = 1;
    } else if ((strcmp(token, "|") == 0) && (out_fd == STDOUT_FILENO)) {
      int pipe_fds[2];
      if (pipe(pipe_fds) == -1) {
        perror("pipe");
        break;
      }
      out_fd = pipe_fds[1];
      next_in_fd = pipe_fds[0];
      run_command = 1;
    } else if ((strcmp(token, ">") == 0) && (out_fd == STDOUT_FILENO)) {
      char *out_name = strtok(NULL, " \t");
      if (out_name == NULL) {
        fputs("Error: missing output redirection location\n", stderr);
        break;
      }
      out_fd = open(out_name, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
      if (out_fd == -1) {
        perror("open");
        break;
      }
    } else if ((strcmp(token, "<") == 0) && (in_fd == STDIN_FILENO)) {
      char *in_name = strtok(NULL, " \t");
      if (in_name == NULL) {
        fputs("Error: missing input redirection location\n", stderr);
        break;
      }
      in_fd = open(in_name, O_RDONLY);
      if (in_fd == -1) {
        perror("open");
        break;
      }
    } else {
      c_argv[c_argc++] = strdup(token);
    }
    if (run_command && c_argc) {
      c_argv[c_argc] = NULL;
      c_argc--;
      execute_command(c_argv, c_argc, fg, in_fd, out_fd);
      int i;
      for (i = 0; i <= c_argc; i++)
        free(c_argv[i]);
      c_argc = 0;
      run_command = 0;
      fg = 1;
      if (out_fd != STDOUT_FILENO) {
        close(out_fd);
        out_fd = STDOUT_FILENO;
      }
      if (in_fd != STDIN_FILENO) {
        close(in_fd);
        in_fd = STDIN_FILENO;
      }
    }
    if (no_more_commands) {
      return;
    }
    token = strtok(NULL, " \t");
  }
}


x86 assembly (clang, -O0):
<parse_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x118(%rbp)
movl   $0x0,-0x11c(%rbp)
movl   $0x0,-0x120(%rbp)
movl   $0x0,-0x124(%rbp)
movl   $0x1,-0x128(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x130(%rbp)
movl   $0xffffffff,-0x134(%rbp)
ff ff ff
cmpl   $0xffffffff,-0x134(%rbp)
je     1273 <parse_command+0xb3>
mov    -0x134(%rbp),%eax
mov    %eax,-0x130(%rbp)
movl   $0xffffffff,-0x134(%rbp)
ff ff ff
cmpq   $0x0,-0x118(%rbp)
jne    129a <parse_command+0xda>
movl   $0x1,-0x120(%rbp)
movl   $0x1,-0x11c(%rbp)
jmp    153b <parse_command+0x37b>
mov    -0x118(%rbp),%rdi
lea    0xd5b(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12d0 <parse_command+0x110>
movl   $0x0,-0x128(%rbp)
movl   $0x1,-0x11c(%rbp)
jmp    1536 <parse_command+0x376>
mov    -0x118(%rbp),%rdi
lea    0xd27(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12fc <parse_command+0x13c>
movl   $0x1,-0x11c(%rbp)
jmp    1531 <parse_command+0x371>
mov    -0x118(%rbp),%rdi
lea    0xcfd(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    137b <parse_command+0x1bb>
mov    -0x12c(%rbp),%eax
mov    0x2cc2(%rip),%rcx
cmp    (%rcx),%eax
jne    137b <parse_command+0x1bb>
lea    -0x13c(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1354 <parse_command+0x194>
lea    0xcbf(%rip),%rdi
call   10b0 <perror@plt>
jmp    168f <parse_command+0x4cf>
mov    -0x138(%rbp),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x13c(%rbp),%eax
mov    %eax,-0x134(%rbp)
movl   $0x1,-0x11c(%rbp)
jmp    152c <parse_command+0x36c>
mov    -0x118(%rbp),%rdi
lea    0xc85(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1447 <parse_command+0x287>
mov    -0x12c(%rbp),%eax
mov    0x2c43(%rip),%rcx
cmp    (%rcx),%eax
jne    1447 <parse_command+0x287>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc48(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jne    13ec <parse_command+0x22c>
mov    0x2be7(%rip),%rax
mov    (%rax),%esi
lea    0xc2e(%rip),%rdi
call   1050 <fputs@plt>
jmp    168f <parse_command+0x4cf>
mov    -0x148(%rbp),%rdi
mov    0x2bfe(%rip),%rax
mov    (%rax),%esi
mov    0x2b9d(%rip),%rax
or     (%rax),%esi
mov    0x2bac(%rip),%rax
mov    (%rax),%edx
mov    0x2bbb(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0xffffffff,-0x12c(%rbp)
jne    1442 <parse_command+0x282>
lea    0xc04(%rip),%rdi
call   10b0 <perror@plt>
jmp    168f <parse_command+0x4cf>
jmp    1527 <parse_command+0x367>
mov    -0x118(%rbp),%rdi
lea    0xbec(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    14f8 <parse_command+0x338>
mov    -0x130(%rbp),%eax
mov    0x2b3f(%rip),%rcx
cmp    (%rcx),%eax
jne    14f8 <parse_command+0x338>
xor    %eax,%eax
mov    %eax,%edi
lea    0xb7c(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x150(%rbp)
cmpq   $0x0,-0x150(%rbp)
jne    14b8 <parse_command+0x2f8>
mov    0x2b1b(%rip),%rax
mov    (%rax),%esi
lea    0xb95(%rip),%rdi
call   1050 <fputs@plt>
jmp    168f <parse_command+0x4cf>
mov    -0x150(%rbp),%rdi
mov    0x2b12(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x130(%rbp)
cmpl   $0xffffffff,-0x130(%rbp)
jne    14f3 <parse_command+0x333>
lea    0xb53(%rip),%rdi
call   10b0 <perror@plt>
jmp    168f <parse_command+0x4cf>
jmp    1522 <parse_command+0x362>
mov    -0x118(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,%rcx
mov    -0x124(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x124(%rbp)
cltq
mov    %rcx,-0x110(%rbp,%rax,8)
ff
jmp    1527 <parse_command+0x367>
jmp    152c <parse_command+0x36c>
jmp    1531 <parse_command+0x371>
jmp    1536 <parse_command+0x376>
jmp    153b <parse_command+0x37b>
cmpl   $0x0,-0x11c(%rbp)
je     1661 <parse_command+0x4a1>
cmpl   $0x0,-0x124(%rbp)
je     1661 <parse_command+0x4a1>
movslq -0x124(%rbp),%rax
movq   $0x0,-0x110(%rbp,%rax,8)
mov    -0x124(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x124(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x124(%rbp),%esi
mov    -0x128(%rbp),%edx
mov    -0x130(%rbp),%ecx
mov    -0x12c(%rbp),%r8d
call   10d0 <execute_command@plt>
movl   $0x0,-0x154(%rbp)
mov    -0x154(%rbp),%eax
cmp    -0x124(%rbp),%eax
jg     15e0 <parse_command+0x420>
movslq -0x154(%rbp),%rax
mov    -0x110(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x154(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x154(%rbp)
jmp    15a6 <parse_command+0x3e6>
movl   $0x0,-0x124(%rbp)
movl   $0x0,-0x11c(%rbp)
movl   $0x1,-0x128(%rbp)
mov    -0x12c(%rbp),%eax
mov    0x29dd(%rip),%rcx
cmp    (%rcx),%eax
je     162d <parse_command+0x46d>
mov    -0x12c(%rbp),%edi
call   1060 <close@plt>
mov    0x29c3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x130(%rbp),%eax
mov    0x2976(%rip),%rcx
cmp    (%rcx),%eax
je     165c <parse_command+0x49c>
mov    -0x130(%rbp),%edi
call   1060 <close@plt>
mov    0x295c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x130(%rbp)
jmp    1661 <parse_command+0x4a1>
cmpl   $0x0,-0x120(%rbp)
je     1673 <parse_command+0x4b3>
jmp    168f <parse_command+0x4cf>
xor    %eax,%eax
mov    %eax,%edi
lea    0x982(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x118(%rbp)
jmp    1250 <parse_command+0x90>
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_command>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rdi,%rbp
call   1040 <strlen@plt>
xor    %edi,%edi
test   %rax,%rax
setg   %dil
call   1090 <assert@plt>
lea    0xe12(%rip),%rsi
mov    %rbp,%rdi
mov    %rsi,%rbx
call   10c0 <strtok@plt>
mov    %rax,%r14
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2da0(%rip),%rax
mov    (%rax),%r12d
mov    $0xffffffff,%r13d
movl   $0x1,0xc(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
cmp    $0xffffffff,%r13d
cmovne %r13d,%r12d
xor    %r15d,%r15d
test   %r14,%r14
je     12c8 <parse_command+0x108>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
lea    0xdb1(%rip),%rsi
call   1080 <strcmp@plt>
mov    $0x1,%r15b
test   %rax,%rax
je     12c0 <parse_command+0x100>
mov    %r14,%rdi
lea    0xd9c(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12d5 <parse_command+0x115>
mov    %r14,%rdi
lea    0xd8a(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12f3 <parse_command+0x133>
mov    0x2d5a(%rip),%rax
mov    0x4(%rsp),%ecx
cmp    (%rax),%ecx
jne    12f3 <parse_command+0x133>
lea    0x18(%rsp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
je     14fc <parse_command+0x33c>
mov    0x18(%rsp),%r13d
mov    0x1c(%rsp),%eax
mov    %eax,0x4(%rsp)
jmp    12db <parse_command+0x11b>
nopl   0x0(%rax,%rax,1)
movl   $0x0,0xc(%rsp)
mov    $0xffffffff,%r13d
mov    $0x1,%eax
jmp    12e3 <parse_command+0x123>
mov    $0xffffffff,%r13d
mov    $0x1,%eax
mov    $0x1,%r15b
mov    %rbx,%r14
test   %eax,%eax
jne    13d8 <parse_command+0x218>
jmp    1475 <parse_command+0x2b5>
mov    %r14,%rdi
lea    0xd11(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1366 <parse_command+0x1a6>
mov    0x2cda(%rip),%rax
mov    0x4(%rsp),%ecx
cmp    (%rax),%ecx
jne    1366 <parse_command+0x1a6>
xor    %edi,%edi
mov    %rbx,%r14
mov    %rbx,%rsi
call   10c0 <strtok@plt>
test   %rax,%rax
je     14ce <parse_command+0x30e>
mov    0x2c6d(%rip),%rcx
mov    (%rcx),%esi
mov    0x2cbc(%rip),%rcx
or     (%rcx),%esi
mov    0x2c8b(%rip),%rcx
mov    (%rcx),%edx
mov    0x2c6a(%rip),%rcx
or     (%rcx),%edx
mov    %rax,%rdi
xor    %eax,%eax
call   10a0 <open@plt>
mov    $0xffffffff,%r13d
mov    %eax,0x4(%rsp)
jmp    13c0 <parse_command+0x200>
mov    %r14,%rdi
lea    0xcd1(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1497 <parse_command+0x2d7>
mov    0x2c2b(%rip),%rax
cmp    (%rax),%r12d
jne    1497 <parse_command+0x2d7>
xor    %edi,%edi
mov    %rbx,%r14
mov    %rbx,%rsi
call   10c0 <strtok@plt>
test   %rax,%rax
je     14e5 <parse_command+0x325>
mov    0x2c2d(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
xor    %eax,%eax
call   10a0 <open@plt>
mov    %eax,%r12d
mov    $0xffffffff,%r13d
cmp    $0xffffffff,%eax
mov    $0x1,%r15b
mov    0x8(%rsp),%eax
je     1505 <parse_command+0x345>
test   %eax,%eax
je     1475 <parse_command+0x2b5>
mov    0x10(%rsp),%rbx
test   %ebx,%ebx
je     1475 <parse_command+0x2b5>
movslq %ebx,%rax
movq   $0x0,0x20(%rsp,%rax,8)
lea    -0x1(%rbx),%esi
lea    0x20(%rsp),%rdi
mov    0xc(%rsp),%edx
mov    %r12d,%ecx
mov    0x4(%rsp),%r8d
call   10d0 <execute_command@plt>
test   %ebx,%ebx
jle    1433 <parse_command+0x273>
mov    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x20(%rsp,%rbp,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1420 <parse_command+0x260>
mov    0x2bae(%rip),%rbx
mov    0x4(%rsp),%edi
cmp    (%rbx),%edi
je     144d <parse_command+0x28d>
call   1060 <close@plt>
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
mov    0x2b5c(%rip),%rbx
movl   $0x1,0xc(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
cmp    (%rbx),%r12d
je     1473 <parse_command+0x2b3>
mov    %r12d,%edi
call   1060 <close@plt>
mov    (%rbx),%r12d
xor    %eax,%eax
test   %r15b,%r15b
je     1511 <parse_command+0x351>
xor    %edi,%edi
mov    %r14,%rbx
mov    %r14,%rsi
mov    %eax,%ebp
call   10c0 <strtok@plt>
mov    %rax,%r14
mov    %ebp,%eax
jmp    1230 <parse_command+0x70>
mov    %r14,%rdi
call   10e0 <strdup@plt>
mov    0x10(%rsp),%rdx
movslq %edx,%rcx
add    $0x1,%edx
mov    %rdx,0x10(%rsp)
mov    %rax,0x20(%rsp,%rcx,8)
mov    $0xffffffff,%r13d
mov    $0x1,%r15b
mov    %rbx,%r14
mov    0x8(%rsp),%eax
test   %eax,%eax
jne    13d8 <parse_command+0x218>
jmp    1475 <parse_command+0x2b5>
mov    0x2aeb(%rip),%rax
mov    (%rax),%esi
lea    0xb32(%rip),%rdi
call   1050 <fputs@plt>
jmp    1511 <parse_command+0x351>
mov    0x2ad4(%rip),%rax
mov    (%rax),%esi
lea    0xb4e(%rip),%rdi
call   1050 <fputs@plt>
jmp    1511 <parse_command+0x351>
lea    0xb06(%rip),%rdi
jmp    150c <parse_command+0x34c>
lea    0xb30(%rip),%rdi
call   10b0 <perror@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" \09\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@.str.1 = [2 x i8] c"&\00"
@.str.2 = [2 x i8] c";\00"
@.str.3 = [2 x i8] c"|\00"
@.str.4 = [5 x i8] c"pipe\00"
@.str.5 = [2 x i8] c">\00"
@.str.6 = [44 x i8] c"Error: missing output redirection location\0A\00"
@stderr = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.7 = [5 x i8] c"open\00"
@.str.8 = [2 x i8] c"<\00"
@.str.9 = [43 x i8] c"Error: missing input redirection location\0A\00"
@O_RDONLY = global i32 0
define void @parse_command(i8* %0) {
%2 = alloca i8*
%3 = alloca [32 x i8*]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [2 x i32]
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
store i8* %0, i8** %2
%16 = load i8*, i8** %2
%17 = call i64 @strlen(i8* %16)
%18 = icmp sgt i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %2
%22 = call i8* @strtok(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %8
%23 = load i32, i32* @STDOUT_FILENO
store i32 %23, i32* %9
%24 = load i32, i32* @STDIN_FILENO
store i32 %24, i32* %10
store i32 -1, i32* %11
br label %25
25: ; preds = %180, %1
%26 = load i32, i32* %11
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i32, i32* %11
store i32 %29, i32* %10
store i32 -1, i32* %11
br label %30
30: ; preds = %28, %25
%31 = load i8*, i8** %4
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 1, i32* %6
store i32 1, i32* %5
br label %128
34: ; preds = %30
%35 = load i8*, i8** %4
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 0, i32* %8
store i32 1, i32* %5
br label %127
39: ; preds = %34
%40 = load i8*, i8** %4
%41 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 1, i32* %5
br label %126
44: ; preds = %39
%45 = load i8*, i8** %4
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %63
48: ; preds = %44
%49 = load i32, i32* %9
%50 = load i32, i32* @STDOUT_FILENO
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %63
52: ; preds = %48
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%54 = call i32 @pipe(i32* %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %182
58: ; preds = %52
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%60 = load i32, i32* %59
store i32 %60, i32* %9
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%62 = load i32, i32* %61
store i32 %62, i32* %11
store i32 1, i32* %5
br label %125
63: ; preds = %48, %44
%64 = load i8*, i8** %4
%65 = call i64 @strcmp(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %92
67: ; preds = %63
%68 = load i32, i32* %9
%69 = load i32, i32* @STDOUT_FILENO
%70 = icmp eq i32 %68, %69
br i1 %70, label %71, label %92
71: ; preds = %67
%72 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %72, i8** %13
%73 = load i8*, i8** %13
%74 = icmp eq i8* %73, null
br i1 %74, label %75, label %78
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = call i32 @fputs(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 %76)
br label %182
78: ; preds = %71
%79 = load i8*, i8** %13
%80 = load i32, i32* @O_CREAT
%81 = load i32, i32* @O_WRONLY
%82 = or i32 %80, %81
%83 = load i32, i32* @S_IRUSR
%84 = load i32, i32* @S_IWUSR
%85 = or i32 %83, %84
%86 = call i32 (i8*, i32, ...) @open(i8* %79, i32 %82, i32 %85)
store i32 %86, i32* %9
%87 = load i32, i32* %9
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %91
89: ; preds = %78
%90 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %182
91: ; preds = %78
br label %124
92: ; preds = %67, %63
%93 = load i8*, i8** %4
%94 = call i64 @strcmp(i8* %93, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %116
96: ; preds = %92
%97 = load i32, i32* %10
%98 = load i32, i32* @STDIN_FILENO
%99 = icmp eq i32 %97, %98
br i1 %99, label %100, label %116
100: ; preds = %96
%101 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %101, i8** %14
%102 = load i8*, i8** %14
%103 = icmp eq i8* %102, null
br i1 %103, label %104, label %107
104: ; preds = %100
%105 = load i32, i32* @stderr
%106 = call i32 @fputs(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0), i32 %105)
br label %182
107: ; preds = %100
%108 = load i8*, i8** %14
%109 = load i32, i32* @O_RDONLY
%110 = call i32 (i8*, i32, ...) @open(i8* %108, i32 %109)
store i32 %110, i32* %10
%111 = load i32, i32* %10
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %115
113: ; preds = %107
%114 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %182
115: ; preds = %107
br label %123
116: ; preds = %96, %92
%117 = load i8*, i8** %4
%118 = call i8* @strdup(i8* %117)
%119 = load i32, i32* %7
%120 = add nsw i32 %119, 1
store i32 %120, i32* %7
%121 = sext i32 %119 to i64
%122 = getelementptr inbounds [32 x i8*], [32 x i8*]* %3, i64 0, i64 %121
store i8* %118, i8** %122
br label %123
123: ; preds = %116, %115
br label %124
124: ; preds = %123, %91
br label %125
125: ; preds = %124, %58
br label %126
126: ; preds = %125, %43
br label %127
127: ; preds = %126, %38
br label %128
128: ; preds = %127, %33
%129 = load i32, i32* %5
%130 = icmp ne i32 %129, 0
br i1 %130, label %131, label %176
131: ; preds = %128
%132 = load i32, i32* %7
%133 = icmp ne i32 %132, 0
br i1 %133, label %134, label %176
134: ; preds = %131
%135 = load i32, i32* %7
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds [32 x i8*], [32 x i8*]* %3, i64 0, i64 %136
store i8* null, i8** %137
%138 = load i32, i32* %7
%139 = add nsw i32 %138, -1
store i32 %139, i32* %7
%140 = getelementptr inbounds [32 x i8*], [32 x i8*]* %3, i64 0, i64 0
%141 = load i32, i32* %7
%142 = load i32, i32* %8
%143 = load i32, i32* %10
%144 = load i32, i32* %9
%145 = call i32 @execute_command(i8** %140, i32 %141, i32 %142, i32 %143, i32 %144)
store i32 0, i32* %15
br label %146
146: ; preds = %156, %134
%147 = load i32, i32* %15
%148 = load i32, i32* %7
%149 = icmp sle i32 %147, %148
br i1 %149, label %150, label %159
150: ; preds = %146
%151 = load i32, i32* %15
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds [32 x i8*], [32 x i8*]* %3, i64 0, i64 %152
%154 = load i8*, i8** %153
%155 = call i32 @free(i8* %154)
br label %156
156: ; preds = %150
%157 = load i32, i32* %15
%158 = add nsw i32 %157, 1
store i32 %158, i32* %15
br label %146
159: ; preds = %146
store i32 0, i32* %7
store i32 0, i32* %5
store i32 1, i32* %8
%160 = load i32, i32* %9
%161 = load i32, i32* @STDOUT_FILENO
%162 = icmp ne i32 %160, %161
br i1 %162, label %163, label %167
163: ; preds = %159
%164 = load i32, i32* %9
%165 = call i32 @close(i32 %164)
%166 = load i32, i32* @STDOUT_FILENO
store i32 %166, i32* %9
br label %167
167: ; preds = %163, %159
%168 = load i32, i32* %10
%169 = load i32, i32* @STDIN_FILENO
%170 = icmp ne i32 %168, %169
br i1 %170, label %171, label %175
171: ; preds = %167
%172 = load i32, i32* %10
%173 = call i32 @close(i32 %172)
%174 = load i32, i32* @STDIN_FILENO
store i32 %174, i32* %10
br label %175
175: ; preds = %171, %167
br label %176
176: ; preds = %175, %131, %128
%177 = load i32, i32* %6
%178 = icmp ne i32 %177, 0
br i1 %178, label %179, label %180
179: ; preds = %176
br label %182
180: ; preds = %176
%181 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %181, i8** %4
br label %25
182: ; preds = %179, %113, %104, %89, %75, %56
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c" \09\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@.str.1 = [2 x i8] c"&\00"
@.str.2 = [2 x i8] c";\00"
@.str.3 = [2 x i8] c"|\00"
@.str.4 = [5 x i8] c"pipe\00"
@.str.5 = [2 x i8] c">\00"
@.str.6 = [44 x i8] c"Error: missing output redirection location\0A\00"
@stderr = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.7 = [5 x i8] c"open\00"
@.str.8 = [2 x i8] c"<\00"
@.str.9 = [43 x i8] c"Error: missing input redirection location\0A\00"
@O_RDONLY = global i32 0
define void @parse_command(i8* %0) {
%2 = alloca [32 x i8*]
%3 = alloca [2 x i32]
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp sgt i64 %4, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = bitcast [32 x i8*]* %2 to i8*
%9 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @STDOUT_FILENO
%11 = load i32, i32* @STDIN_FILENO
%12 = bitcast [2 x i32]* %3 to i8*
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%15 = getelementptr inbounds [32 x i8*], [32 x i8*]* %2, i64 0, i64 0
br label %16
16: ; preds = %138, %1
%17 = phi i32 [ 0, %1 ], [ %133, %138 ]
%18 = phi i32 [ 1, %1 ], [ %134, %138 ]
%19 = phi i32 [ %10, %1 ], [ %135, %138 ]
%20 = phi i32 [ %11, %1 ], [ %136, %138 ]
%21 = phi i32 [ -1, %1 ], [ %99, %138 ]
%22 = phi i32 [ 0, %1 ], [ %137, %138 ]
%23 = phi i8* [ %9, %1 ], [ %139, %138 ]
%24 = icmp eq i32 %21, -1
%25 = select i1 %24, i32 %20, i32 %21
%26 = icmp eq i8* %23, null
br i1 %26, label %93, label %27
27: ; preds = %16
%28 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %93, label %30
30: ; preds = %27
%31 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %93, label %33
33: ; preds = %30
%34 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
%36 = load i32, i32* @STDOUT_FILENO
%37 = icmp eq i32 %19, %36
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %39, label %47
39: ; preds = %33
%40 = call i32 @pipe(i32* %13)
%41 = icmp eq i32 %40, -1
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* %14
%44 = load i32, i32* %13
br label %93
45: ; preds = %39
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %140
47: ; preds = %33
%48 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
%50 = load i32, i32* @STDOUT_FILENO
%51 = icmp eq i32 %19, %50
%52 = select i1 %49, i1 %51, i1 false
br i1 %52, label %53, label %70
53: ; preds = %47
%54 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i32, i32* @stderr
%58 = call i32 @fputs(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 %57)
br label %140
59: ; preds = %53
%60 = load i32, i32* @O_CREAT
%61 = load i32, i32* @O_WRONLY
%62 = or i32 %61, %60
%63 = load i32, i32* @S_IRUSR
%64 = load i32, i32* @S_IWUSR
%65 = or i32 %64, %63
%66 = call i32 (i8*, i32, ...) @open(i8* %54, i32 %62, i32 %65)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %93
68: ; preds = %59
%69 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %140
70: ; preds = %47
%71 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%72 = icmp eq i64 %71, 0
%73 = load i32, i32* @STDIN_FILENO
%74 = icmp eq i32 %25, %73
%75 = select i1 %72, i1 %74, i1 false
br i1 %75, label %76, label %88
76: ; preds = %70
%77 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%78 = icmp eq i8* %77, null
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = load i32, i32* @stderr
%81 = call i32 @fputs(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0), i32 %80)
br label %140
82: ; preds = %76
%83 = load i32, i32* @O_RDONLY
%84 = call i32 (i8*, i32, ...) @open(i8* %77, i32 %83)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %93
86: ; preds = %82
%87 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %140
88: ; preds = %70
%89 = call i8* @strdup(i8* %23)
%90 = add nsw i32 %17, 1
%91 = sext i32 %17 to i64
%92 = getelementptr inbounds [32 x i8*], [32 x i8*]* %2, i64 0, i64 %91
store i8* %89, i8** %92
br label %93
93: ; preds = %82, %59, %42, %30, %27, %16, %88
%94 = phi i1 [ true, %88 ], [ false, %16 ], [ true, %27 ], [ true, %30 ], [ true, %42 ], [ true, %59 ], [ true, %82 ]
%95 = phi i32 [ %90, %88 ], [ %17, %16 ], [ %17, %27 ], [ %17, %30 ], [ %17, %42 ], [ %17, %59 ], [ %17, %82 ]
%96 = phi i32 [ %18, %88 ], [ %18, %16 ], [ 0, %27 ], [ %18, %30 ], [ %18, %42 ], [ %18, %59 ], [ %18, %82 ]
%97 = phi i32 [ %19, %88 ], [ %19, %16 ], [ %19, %27 ], [ %19, %30 ], [ %43, %42 ], [ %66, %59 ], [ %19, %82 ]
%98 = phi i32 [ %25, %88 ], [ %25, %16 ], [ %25, %27 ], [ %25, %30 ], [ %25, %42 ], [ %25, %59 ], [ %84, %82 ]
%99 = phi i32 [ -1, %88 ], [ -1, %16 ], [ -1, %27 ], [ -1, %30 ], [ %44, %42 ], [ -1, %59 ], [ -1, %82 ]
%100 = phi i32 [ %22, %88 ], [ 1, %16 ], [ 1, %27 ], [ 1, %30 ], [ 1, %42 ], [ %22, %59 ], [ %22, %82 ]
%101 = icmp ne i32 %100, 0
%102 = icmp ne i32 %95, 0
%103 = select i1 %101, i1 %102, i1 false
br i1 %103, label %104, label %132
104: ; preds = %93
%105 = sext i32 %95 to i64
%106 = getelementptr inbounds [32 x i8*], [32 x i8*]* %2, i64 0, i64 %105
store i8* null, i8** %106
%107 = add nsw i32 %95, -1
%108 = call i32 @execute_command(i8** %15, i32 %107, i32 %96, i32 %98, i32 %97)
%109 = icmp sgt i32 %95, 0
br i1 %109, label %110, label %119
110: ; preds = %104
%111 = zext i32 %95 to i64
br label %112
112: ; preds = %110, %112
%113 = phi i64 [ 0, %110 ], [ %117, %112 ]
%114 = getelementptr inbounds [32 x i8*], [32 x i8*]* %2, i64 0, i64 %113
%115 = load i8*, i8** %114
%116 = call i32 @free(i8* %115)
%117 = add nuw nsw i64 %113, 1
%118 = icmp eq i64 %117, %111
br i1 %118, label %119, label %112
119: ; preds = %112, %104
%120 = load i32, i32* @STDOUT_FILENO
%121 = icmp eq i32 %97, %120
br i1 %121, label %125, label %122
122: ; preds = %119
%123 = call i32 @close(i32 %97)
%124 = load i32, i32* @STDOUT_FILENO
br label %125
125: ; preds = %122, %119
%126 = phi i32 [ %124, %122 ], [ %97, %119 ]
%127 = load i32, i32* @STDIN_FILENO
%128 = icmp eq i32 %98, %127
br i1 %128, label %132, label %129
129: ; preds = %125
%130 = call i32 @close(i32 %98)
%131 = load i32, i32* @STDIN_FILENO
br label %132
132: ; preds = %125, %129, %93
%133 = phi i32 [ %95, %93 ], [ 0, %129 ], [ 0, %125 ]
%134 = phi i32 [ %96, %93 ], [ 1, %129 ], [ 1, %125 ]
%135 = phi i32 [ %97, %93 ], [ %126, %129 ], [ %126, %125 ]
%136 = phi i32 [ %98, %93 ], [ %131, %129 ], [ %98, %125 ]
%137 = phi i32 [ %100, %93 ], [ 0, %129 ], [ 0, %125 ]
br i1 %94, label %138, label %140
138: ; preds = %132
%139 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %16
140: ; preds = %132, %86, %79, %68, %56, %45
ret void
}