#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *grep_env(char *);
int /*<<< orphan*/ inc_ras_pipe();
int /*<<< orphan*/ insert_ras_pipe(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ pop_ras_pipe(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
char *strtok(char *, char *);
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ write(int, char *, int);
int exec_com(char *input, char *output, int pipe_num, int nfd) {
  FILE *fptr = NULL;
  char *tok, *ftok, *file_name, input_tmp[10000];
  char pipe_input_buffer[10000];
  pop_ras_pipe(pipe_input_buffer);
  int to_file = 0;
  strcpy(input_tmp, input);
  input_tmp[strlen(input_tmp) - 1] = 0;
  ftok = strstr(input_tmp, " > ");
  if (ftok != NULL) {
    to_file = 1;
    file_name = &ftok[3];
    fptr = fopen(file_name, "w");
  }
  int pipe_fd[2];
  int pipe2_fd[2];
  if (pipe(pipe_fd) == -1) {
    perror("Error: Unable to create pipe.");
    exit(EXIT_FAILURE);
  }
  if (pipe(pipe2_fd) == -1) {
    perror("Error: Unable to create pipe.");
    exit(EXIT_FAILURE);
  }
  pid_t pid;
  if ((pid = fork()) < 0) {
    perror("Error: Unable to create child process.");
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    close(pipe2_fd[1]);
    if (to_file) {
      dup2(fileno(fptr), STDOUT_FILENO);
    } else
      dup2(pipe_fd[1], STDOUT_FILENO);
    dup2(nfd, STDERR_FILENO);
    dup2(pipe2_fd[0], STDIN_FILENO);
    close(pipe_fd[1]);
    close(pipe2_fd[0]);
    int i = 0;
    char *tok;
    char *args[256];
    char command[256] = "";
    tok = strtok(input, " ");
    strcat(command, tok);
    while (tok != NULL) {
      args[i] = tok;
      tok = strtok(NULL, " ");
      i++;
      if (tok != NULL && !strcmp(tok, ">"))
        break;
    }
    args[i] = 0;
    if (!strcmp(args[0], "printenv")) {
      printf("%s\n", grep_env(args[1]));
      exit(EXIT_SUCCESS);
    }
    execvp(command, args);
    fprintf(stderr, "Unknown command: [%s].\n", args[0]);
    exit(EXIT_FAILURE);
  } else {
    close(pipe2_fd[0]);
    close(pipe_fd[1]);
    write(pipe2_fd[1], pipe_input_buffer, 10000);
    close(pipe2_fd[1]);
    int status = 0;
    wait(&status);
    read(pipe_fd[0], output, 10000);
    close(pipe_fd[0]);
    if (to_file)
      fclose(fptr);
    if (status > 0) {
      insert_ras_pipe(pipe_input_buffer, 0);
      inc_ras_pipe();
      return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<exec_com>:
push   %rbp
mov    %rsp,%rbp
sub    $0x57a0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x4e60(%rbp),%rdi
call   1080 <pop_ras_pipe@plt>
movl   $0x0,-0x4e64(%rbp)
lea    -0x2750(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x2750(%rbp),%rdi
call   1070 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x2750(%rbp,%rax,1)
lea    -0x2750(%rbp),%rdi
lea    0xcf2(%rip),%rsi
call   11c0 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     134c <exec_com+0xac>
movl   $0x1,-0x4e64(%rbp)
mov    -0x38(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xcc1(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    -0x4e6c(%rbp),%rdi
call   10d0 <pipe@plt>
cmp    $0xffffffff,%eax
jne    137b <exec_com+0xdb>
lea    0xc9e(%rip),%rdi
call   1150 <perror@plt>
mov    0x2c54(%rip),%rax
mov    (%rax),%edi
call   1190 <exit@plt>
lea    -0x4e74(%rbp),%rdi
call   10d0 <pipe@plt>
cmp    $0xffffffff,%eax
jne    13aa <exec_com+0x10a>
lea    0xc6f(%rip),%rdi
call   1150 <perror@plt>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
call   1190 <exit@plt>
mov    $0x0,%al
call   11b0 <fork@plt>
mov    %rax,-0x4e80(%rbp)
cmp    $0x0,%rax
jge    13dc <exec_com+0x13c>
lea    0xc5b(%rip),%rdi
call   1150 <perror@plt>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
call   1190 <exit@plt>
cmpq   $0x0,-0x4e80(%rbp)
jne    15c9 <exec_com+0x329>
mov    -0x4e70(%rbp),%edi
call   10c0 <close@plt>
cmpl   $0x0,-0x4e64(%rbp)
je     1420 <exec_com+0x180>
mov    -0x28(%rbp),%rdi
call   1120 <fileno@plt>
mov    %eax,%edi
mov    0x2bdc(%rip),%rax
mov    (%rax),%esi
call   1090 <dup2@plt>
jmp    1434 <exec_com+0x194>
mov    -0x4e68(%rbp),%edi
mov    0x2bc3(%rip),%rax
mov    (%rax),%esi
call   1090 <dup2@plt>
mov    -0x20(%rbp),%edi
mov    0x2b92(%rip),%rax
mov    (%rax),%esi
call   1090 <dup2@plt>
mov    -0x4e74(%rbp),%edi
mov    0x2b66(%rip),%rax
mov    (%rax),%esi
call   1090 <dup2@plt>
mov    -0x4e68(%rbp),%edi
call   10c0 <close@plt>
mov    -0x4e74(%rbp),%edi
call   10c0 <close@plt>
movl   $0x0,-0x4e84(%rbp)
lea    -0x5790(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   10b0 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xb6b(%rip),%rsi
call   1160 <strtok@plt>
mov    %rax,-0x4e90(%rbp)
lea    -0x5790(%rbp),%rdi
mov    -0x4e90(%rbp),%rsi
call   1180 <strcat@plt>
cmpq   $0x0,-0x4e90(%rbp)
je     1534 <exec_com+0x294>
mov    -0x4e90(%rbp),%rcx
movslq -0x4e84(%rbp),%rax
mov    %rcx,-0x5690(%rbp,%rax,8)
ff
xor    %eax,%eax
mov    %eax,%edi
lea    0xb1d(%rip),%rsi
call   1160 <strtok@plt>
mov    %rax,-0x4e90(%rbp)
mov    -0x4e84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e84(%rbp)
cmpq   $0x0,-0x4e90(%rbp)
je     152f <exec_com+0x28f>
mov    -0x4e90(%rbp),%rdi
lea    0xb2f(%rip),%rsi
call   1100 <strcmp@plt>
cmp    $0x0,%eax
jne    152f <exec_com+0x28f>
jmp    1534 <exec_com+0x294>
jmp    14b6 <exec_com+0x216>
movslq -0x4e84(%rbp),%rax
movq   $0x0,-0x5690(%rbp,%rax,8)
mov    -0x5690(%rbp),%rdi
lea    0xaf8(%rip),%rsi
call   1100 <strcmp@plt>
cmp    $0x0,%eax
jne    158c <exec_com+0x2ec>
mov    -0x5688(%rbp),%rdi
call   1130 <grep_env@plt>
mov    %rax,%rsi
lea    0xadd(%rip),%rdi
call   10a0 <printf@plt>
mov    0x2a3b(%rip),%rax
mov    (%rax),%edi
call   1190 <exit@plt>
lea    -0x5790(%rbp),%rdi
lea    -0x5690(%rbp),%rsi
call   1170 <execvp@plt>
mov    0x2a32(%rip),%rax
mov    (%rax),%edi
mov    -0x5690(%rbp),%rdx
lea    0xaa4(%rip),%rsi
call   1110 <fprintf@plt>
mov    0x2a06(%rip),%rax
mov    (%rax),%edi
call   1190 <exit@plt>
mov    -0x4e74(%rbp),%edi
call   10c0 <close@plt>
mov    -0x4e68(%rbp),%edi
call   10c0 <close@plt>
mov    -0x4e70(%rbp),%edi
lea    -0x4e60(%rbp),%rsi
mov    $0x2710,%edx
call   1040 <write@plt>
mov    -0x4e70(%rbp),%edi
call   10c0 <close@plt>
movl   $0x0,-0x5794(%rbp)
lea    -0x5794(%rbp),%rdi
call   11a0 <wait@plt>
mov    -0x4e6c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x2710,%edx
call   10e0 <read@plt>
mov    -0x4e6c(%rbp),%edi
call   10c0 <close@plt>
cmpl   $0x0,-0x4e64(%rbp)
je     164c <exec_com+0x3ac>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x0,-0x5794(%rbp)
jle    167f <exec_com+0x3df>
lea    -0x4e60(%rbp),%rdi
xor    %esi,%esi
call   10f0 <insert_ras_pipe@plt>
mov    $0x0,%al
call   1050 <inc_ras_pipe@plt>
mov    0x2953(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1695 <exec_com+0x3f5>
jmp    1684 <exec_com+0x3e4>
jmp    1689 <exec_com+0x3e9>
mov    0x2930(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x57a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_com>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5738,%rsp
mov    %ecx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x910(%rsp),%rdi
call   1080 <pop_ras_pipe@plt>
lea    0x3020(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
lea    0xd20(%rip),%rsi
mov    %rbp,%rdi
call   11b0 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1305 <exec_com+0x75>
lea    0x3(%rbp),%rdi
lea    0xd09(%rip),%rsi
call   1130 <fopen@plt>
mov    %rax,%r12
jmp    1308 <exec_com+0x78>
xor    %r12d,%r12d
lea    0x8(%rsp),%rdi
call   10c0 <pipe@plt>
cmp    $0xffffffff,%eax
je     1400 <exec_com+0x170>
mov    %rsp,%rdi
call   10c0 <pipe@plt>
cmp    $0xffffffff,%eax
je     1400 <exec_com+0x170>
xor    %eax,%eax
call   11a0 <fork@plt>
test   %rax,%rax
js     1409 <exec_com+0x179>
je     1423 <exec_com+0x193>
mov    (%rsp),%edi
call   10b0 <close@plt>
mov    0xc(%rsp),%edi
call   10b0 <close@plt>
mov    0x4(%rsp),%edi
lea    0x910(%rsp),%rsi
mov    $0x2710,%edx
call   1040 <write@plt>
mov    0x4(%rsp),%edi
call   10b0 <close@plt>
movl   $0x0,0x110(%rsp)
lea    0x110(%rsp),%rdi
call   1190 <wait@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x2710,%edx
call   10d0 <read@plt>
mov    0x8(%rsp),%edi
call   10b0 <close@plt>
test   %rbp,%rbp
je     13b1 <exec_com+0x121>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    0x110(%rsp),%ebx
test   %ebx,%ebx
jle    13fa <exec_com+0x16a>
lea    0x910(%rsp),%rdi
xor    %esi,%esi
call   10e0 <insert_ras_pipe@plt>
xor    %eax,%eax
call   1050 <inc_ras_pipe@plt>
mov    0x2bef(%rip),%rax
mov    (%rax),%eax
test   %ebx,%ebx
jg     13e8 <exec_com+0x158>
mov    0x2bda(%rip),%rax
mov    (%rax),%eax
add    $0x5738,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebx,%ebx
jle    13df <exec_com+0x14f>
jmp    13e8 <exec_com+0x158>
lea    0xbff(%rip),%rdi
jmp    1410 <exec_com+0x180>
lea    0xc14(%rip),%rdi
call   1140 <perror@plt>
mov    0x2bac(%rip),%rax
mov    (%rax),%edi
call   1180 <exit@plt>
mov    0x4(%rsp),%edi
call   10b0 <close@plt>
test   %rbp,%rbp
jne    1437 <exec_com+0x1a7>
mov    0xc(%rsp),%edi
jmp    1441 <exec_com+0x1b1>
mov    %r12,%rdi
call   1110 <fileno@plt>
mov    %eax,%edi
mov    0x2ba8(%rip),%rax
mov    (%rax),%esi
call   1090 <dup2@plt>
mov    0x2b7a(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1090 <dup2@plt>
mov    (%rsp),%edi
mov    0x2b4e(%rip),%rax
mov    (%rax),%esi
call   1090 <dup2@plt>
mov    0xc(%rsp),%edi
call   10b0 <close@plt>
mov    (%rsp),%edi
call   10b0 <close@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0xb0b(%rip),%rsi
mov    %r14,%rdi
call   1150 <strtok@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    %rax,%rsi
call   1170 <strcat@plt>
test   %rbx,%rbx
jne    1519 <exec_com+0x289>
xor    %r13d,%r13d
jmp    1574 <exec_com+0x2e4>
lea    0x110(%rsp),%rbp
movabs $0x100000000,%r12
lea    0xad0(%rip),%r14
lea    0xb12(%rip),%r15
mov    %r12,%rcx
nopl   0x0(%rax)
mov    %rcx,%r13
mov    %rbx,0x0(%rbp)
xor    %edi,%edi
mov    %r14,%rsi
call   1150 <strtok@plt>
test   %rax,%rax
je     1570 <exec_com+0x2e0>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   10f0 <strcmp@plt>
add    $0x8,%rbp
lea    (%r12,%r13,1),%rcx
test   %eax,%eax
jne    1540 <exec_com+0x2b0>
sar    $0x20,%r13
movq   $0x0,0x110(%rsp,%r13,8)
mov    0x110(%rsp),%rdi
lea    0xabe(%rip),%rsi
call   10f0 <strcmp@plt>
test   %eax,%eax
jne    15c2 <exec_com+0x332>
mov    0x118(%rsp),%rdi
call   1120 <grep_env@plt>
lea    0xaaa(%rip),%rdi
mov    %rax,%rsi
call   10a0 <printf@plt>
mov    0x2a05(%rip),%rax
mov    (%rax),%edi
call   1180 <exit@plt>
lea    0x10(%rsp),%rdi
lea    0x110(%rsp),%rsi
call   1160 <execvp@plt>
mov    0x29fd(%rip),%rax
mov    (%rax),%edi
mov    0x110(%rsp),%rdx
lea    0xa6e(%rip),%rsi
call   1100 <fprintf@plt>
jmp    1415 <exec_com+0x185>

LLVM IR (-O0):
@.str = [4 x i8] c" > \00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [30 x i8] c"Error: Unable to create pipe.\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [39 x i8] c"Error: Unable to create child process.\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@.str.4 = [2 x i8] c" \00"
@.str.5 = [2 x i8] c">\00"
@.str.6 = [9 x i8] c"printenv\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.8 = [24 x i8] c"Unknown command: [%s].\0A\00"
define i32 @exec_com(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca [10000 x i8]
%15 = alloca [10000 x i8]
%16 = alloca i32
%17 = alloca [2 x i32]
%18 = alloca [2 x i32]
%19 = alloca i64
%20 = alloca i32
%21 = alloca i8*
%22 = alloca [256 x i8*]
%23 = alloca [256 x i8]
%24 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32* null, i32** %10
%25 = getelementptr inbounds [10000 x i8], [10000 x i8]* %15, i64 0, i64 0
%26 = call i32 @pop_ras_pipe(i8* %25)
store i32 0, i32* %16
%27 = getelementptr inbounds [10000 x i8], [10000 x i8]* %14, i64 0, i64 0
%28 = load i8*, i8** %6
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = getelementptr inbounds [10000 x i8], [10000 x i8]* %14, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10000 x i8], [10000 x i8]* %14, i64 0, i64 %33
store i8 0, i8* %34
%35 = getelementptr inbounds [10000 x i8], [10000 x i8]* %14, i64 0, i64 0
%36 = call i8* @strstr(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %36, i8** %12
%37 = load i8*, i8** %12
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %44
39: ; preds = %4
store i32 1, i32* %16
%40 = load i8*, i8** %12
%41 = getelementptr inbounds i8, i8* %40, i64 3
store i8* %41, i8** %13
%42 = load i8*, i8** %13
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %43, i32** %10
br label %44
44: ; preds = %39, %4
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 0
%46 = call i32 @pipe(i32* %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %44
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 0
%54 = call i32 @pipe(i32* %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %52
%61 = call i64 (...) @fork()
store i64 %61, i64* %19
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %60
%68 = load i64, i64* %19
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %150
70: ; preds = %67
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 1
%72 = load i32, i32* %71
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* %16
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %81
76: ; preds = %70
%77 = load i32*, i32** %10
%78 = call i32 @fileno(i32* %77)
%79 = load i32, i32* @STDOUT_FILENO
%80 = call i32 @dup2(i32 %78, i32 %79)
br label %86
81: ; preds = %70
%82 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 1
%83 = load i32, i32* %82
%84 = load i32, i32* @STDOUT_FILENO
%85 = call i32 @dup2(i32 %83, i32 %84)
br label %86
86: ; preds = %81, %76
%87 = load i32, i32* %9
%88 = load i32, i32* @STDERR_FILENO
%89 = call i32 @dup2(i32 %87, i32 %88)
%90 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 0
%91 = load i32, i32* %90
%92 = load i32, i32* @STDIN_FILENO
%93 = call i32 @dup2(i32 %91, i32 %92)
%94 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 1
%95 = load i32, i32* %94
%96 = call i32 @close(i32 %95)
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 0
%98 = load i32, i32* %97
%99 = call i32 @close(i32 %98)
store i32 0, i32* %20
%100 = bitcast [256 x i8]* %23 to i8*
%101 = load i8*, i8** %6
%102 = call i8* @strtok(i8* %101, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %102, i8** %21
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %23, i64 0, i64 0
%104 = load i8*, i8** %21
%105 = call i32 @strcat(i8* %103, i8* %104)
br label %106
106: ; preds = %124, %86
%107 = load i8*, i8** %21
%108 = icmp ne i8* %107, null
br i1 %108, label %109, label %125
109: ; preds = %106
%110 = load i8*, i8** %21
%111 = load i32, i32* %20
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [256 x i8*], [256 x i8*]* %22, i64 0, i64 %112
store i8* %110, i8** %113
%114 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %114, i8** %21
%115 = load i32, i32* %20
%116 = add nsw i32 %115, 1
store i32 %116, i32* %20
%117 = load i8*, i8** %21
%118 = icmp ne i8* %117, null
br i1 %118, label %119, label %124
119: ; preds = %109
%120 = load i8*, i8** %21
%121 = call i32 @strcmp(i8* %120, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%122 = icmp ne i32 %121, 0
br i1 %122, label %124, label %123
123: ; preds = %119
br label %125
124: ; preds = %119, %109
br label %106
125: ; preds = %123, %106
%126 = load i32, i32* %20
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds [256 x i8*], [256 x i8*]* %22, i64 0, i64 %127
store i8* null, i8** %128
%129 = getelementptr inbounds [256 x i8*], [256 x i8*]* %22, i64 0, i64 0
%130 = load i8*, i8** %129
%131 = call i32 @strcmp(i8* %130, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%132 = icmp ne i32 %131, 0
br i1 %132, label %140, label %133
133: ; preds = %125
%134 = getelementptr inbounds [256 x i8*], [256 x i8*]* %22, i64 0, i64 1
%135 = load i8*, i8** %134
%136 = call i8* @grep_env(i8* %135)
%137 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %136)
%138 = load i32, i32* @EXIT_SUCCESS
%139 = call i32 @exit(i32 %138)
unreachable
140: ; preds = %125
%141 = getelementptr inbounds [256 x i8], [256 x i8]* %23, i64 0, i64 0
%142 = getelementptr inbounds [256 x i8*], [256 x i8*]* %22, i64 0, i64 0
%143 = call i32 @execvp(i8* %141, i8** %142)
%144 = load i32, i32* @stderr
%145 = getelementptr inbounds [256 x i8*], [256 x i8*]* %22, i64 0, i64 0
%146 = load i8*, i8** %145
%147 = call i32 @fprintf(i32 %144, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %146)
%148 = load i32, i32* @EXIT_FAILURE
%149 = call i32 @exit(i32 %148)
unreachable
150: ; preds = %67
%151 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 0
%152 = load i32, i32* %151
%153 = call i32 @close(i32 %152)
%154 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 1
%155 = load i32, i32* %154
%156 = call i32 @close(i32 %155)
%157 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 1
%158 = load i32, i32* %157
%159 = getelementptr inbounds [10000 x i8], [10000 x i8]* %15, i64 0, i64 0
%160 = call i32 @write(i32 %158, i8* %159, i32 10000)
%161 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 1
%162 = load i32, i32* %161
%163 = call i32 @close(i32 %162)
store i32 0, i32* %24
%164 = call i32 @wait(i32* %24)
%165 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 0
%166 = load i32, i32* %165
%167 = load i8*, i8** %7
%168 = call i32 @read(i32 %166, i8* %167, i32 10000)
%169 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 0
%170 = load i32, i32* %169
%171 = call i32 @close(i32 %170)
%172 = load i32, i32* %16
%173 = icmp ne i32 %172, 0
br i1 %173, label %174, label %177
174: ; preds = %150
%175 = load i32*, i32** %10
%176 = call i32 @fclose(i32* %175)
br label %177
177: ; preds = %174, %150
%178 = load i32, i32* %24
%179 = icmp sgt i32 %178, 0
br i1 %179, label %180, label %185
180: ; preds = %177
%181 = getelementptr inbounds [10000 x i8], [10000 x i8]* %15, i64 0, i64 0
%182 = call i32 @insert_ras_pipe(i8* %181, i32 0)
%183 = call i32 (...) @inc_ras_pipe()
%184 = load i32, i32* @EXIT_FAILURE
store i32 %184, i32* %5
br label %189
185: ; preds = %177
br label %186
186: ; preds = %185
br label %187
187: ; preds = %186
%188 = load i32, i32* @EXIT_SUCCESS
store i32 %188, i32* %5
br label %189
189: ; preds = %187, %180
%190 = load i32, i32* %5
ret i32 %190
}

LLVM IR (-O2):
@.str = [4 x i8] c" > \00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [30 x i8] c"Error: Unable to create pipe.\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [39 x i8] c"Error: Unable to create child process.\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@.str.4 = [2 x i8] c" \00"
@.str.5 = [2 x i8] c">\00"
@.str.6 = [9 x i8] c"printenv\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.8 = [24 x i8] c"Unknown command: [%s].\0A\00"
define i32 @exec_com(i8* %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = alloca [10000 x i8]
%6 = alloca [10000 x i8]
%7 = alloca [2 x i32]
%8 = alloca [2 x i32]
%9 = alloca [256 x i8*]
%10 = alloca [256 x i8]
%11 = alloca i32
%12 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%14 = call i32 @pop_ras_pipe(i8* %13)
%15 = call i32 @strcpy(i8* %12, i8* %0)
%16 = call i32 @strlen(i8* %12)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i8* @strstr(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %4
%23 = getelementptr inbounds i8, i8* %20, i64 3
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %22, %4
%26 = phi i32* [ %24, %22 ], [ null, %4 ]
%27 = bitcast [2 x i32]* %7 to i8*
%28 = bitcast [2 x i32]* %8 to i8*
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%30 = call i32 @pipe(i32* %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %25
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%38 = call i32 @pipe(i32* %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %36
%45 = call i64 (...) @fork()
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %44
%52 = icmp eq i64 %45, 0
br i1 %52, label %53, label %115
53: ; preds = %51
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%55 = load i32, i32* %54
%56 = call i32 @close(i32 %55)
br i1 %21, label %59, label %57
57: ; preds = %53
%58 = call i32 @fileno(i32* %26)
br label %62
59: ; preds = %53
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%61 = load i32, i32* %60
br label %62
62: ; preds = %59, %57
%63 = phi i32 [ %61, %59 ], [ %58, %57 ]
%64 = load i32, i32* @STDOUT_FILENO
%65 = call i32 @dup2(i32 %63, i32 %64)
%66 = load i32, i32* @STDERR_FILENO
%67 = call i32 @dup2(i32 %3, i32 %66)
%68 = load i32, i32* %37
%69 = load i32, i32* @STDIN_FILENO
%70 = call i32 @dup2(i32 %68, i32 %69)
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%72 = load i32, i32* %71
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* %37
%75 = call i32 @close(i32 %74)
%76 = bitcast [256 x i8*]* %9 to i8*
%77 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%78 = call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%79 = call i32 @strcat(i8* %77, i8* %78)
%80 = icmp eq i8* %78, null
br i1 %80, label %94, label %81
81: ; preds = %62, %88
%82 = phi i64 [ %86, %88 ], [ 0, %62 ]
%83 = phi i8* [ %85, %88 ], [ %78, %62 ]
%84 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 %82
store i8* %83, i8** %84
%85 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%86 = add nuw i64 %82, 1
%87 = icmp eq i8* %85, null
br i1 %87, label %91, label %88
88: ; preds = %81
%89 = call i32 @strcmp(i8* %85, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %81
91: ; preds = %88, %81
%92 = shl i64 %86, 32
%93 = ashr exact i64 %92, 32
br label %94
94: ; preds = %91, %62
%95 = phi i64 [ 0, %62 ], [ %93, %91 ]
%96 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 %95
store i8* null, i8** %96
%97 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 0
%98 = load i8*, i8** %97
%99 = call i32 @strcmp(i8* dereferenceable(1) %98, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%100 = icmp eq i32 %99, 0
br i1 %100, label %101, label %108
101: ; preds = %94
%102 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 1
%103 = load i8*, i8** %102
%104 = call i8* @grep_env(i8* %103)
%105 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %104)
%106 = load i32, i32* @EXIT_SUCCESS
%107 = call i32 @exit(i32 %106)
unreachable
108: ; preds = %94
%109 = call i32 @execvp(i8* %77, i8** %97)
%110 = load i32, i32* @stderr
%111 = load i8*, i8** %97
%112 = call i32 @fprintf(i32 %110, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %111)
%113 = load i32, i32* @EXIT_FAILURE
%114 = call i32 @exit(i32 %113)
unreachable
115: ; preds = %51
%116 = load i32, i32* %37
%117 = call i32 @close(i32 %116)
%118 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%119 = load i32, i32* %118
%120 = call i32 @close(i32 %119)
%121 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%122 = load i32, i32* %121
%123 = call i32 @write(i32 %122, i8* %13, i32 10000)
%124 = load i32, i32* %121
%125 = call i32 @close(i32 %124)
%126 = bitcast i32* %11 to i8*
store i32 0, i32* %11
%127 = call i32 @wait(i32* %11)
%128 = load i32, i32* %29
%129 = call i32 @read(i32 %128, i8* %1, i32 10000)
%130 = load i32, i32* %29
%131 = call i32 @close(i32 %130)
br i1 %21, label %134, label %132
132: ; preds = %115
%133 = call i32 @fclose(i32* %26)
br label %134
134: ; preds = %132, %115
%135 = load i32, i32* %11
%136 = icmp sgt i32 %135, 0
br i1 %136, label %137, label %141
137: ; preds = %134
%138 = call i32 @insert_ras_pipe(i8* %13, i32 0)
%139 = call i32 (...) @inc_ras_pipe()
%140 = load i32, i32* @EXIT_FAILURE
br label %141
141: ; preds = %134, %137
%142 = phi i32 [ %140, %137 ], [ undef, %134 ]
%143 = load i32, i32* @EXIT_SUCCESS
%144 = select i1 %136, i32 %142, i32 %143
ret i32 %144
}