#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;

/* Variables and functions */
int O_APPEND;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int dup2(int, int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int fileno(int /*<<< orphan*/);
scalar_t__ fork();
int open(char *, int, ...);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
char *strstr(char *, char *);
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  char buffer[2048];
  while (1) {
    dup2(fileno(stdout), fileno(stdout));
    dup2(fileno(stdin), fileno(stdin));
    dup2(fileno(stderr), fileno(stderr));
    printf("My Shell>");
    fgets(buffer, 2048, stdin);
    if (buffer[0] == 'e' && buffer[1] == 'x' && buffer[2] == 'i' &&
        buffer[3] == 't' && buffer[4] == '\n' && buffer[5] == 0) {
      break;
    }
    buffer[strlen(buffer) - 1] = 0;
    int cnt = 0;
    char *ptr;
    int out = -1;
    int redirect_stdin = 0;
    int redirect_stderr = 0;
    int redirect_stdout = 0;
    int pipe_out = 0;
    int fd[2];
    if (strstr(buffer, " > ")) {
      ptr = strstr(buffer, " > ");
      char *filename = ptr + 3;
      out = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
      if (out == -1) {
        printf("cannot open output file\n");
        continue;
      }
      redirect_stdout = 1;
      cnt++;
      *ptr = 0;
    }
    if (strstr(buffer, " >> ")) {
      ptr = strstr(buffer, " >> ");
      char *filename = ptr + 4;
      out = open(filename, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU);
      if (out == -1) {
        printf("cannot open output file\n");
        continue;
      }
      redirect_stdout = 1;
      cnt++;
      *ptr = 0;
    }
    if (strstr(buffer, " 2> ")) {
      ptr = strstr(buffer, " 2> ");
      char *filename = ptr + 4;
      out = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
      if (out == -1) {
        printf("cannot open output file\n");
        continue;
      }
      redirect_stderr = 1;
      cnt++;
      *ptr = 0;
    }
    if (strstr(buffer, " 2>> ")) {
      ptr = strstr(buffer, " 2>> ");
      char *filename = ptr + 5;
      out = open(filename, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU);
      if (out == -1) {
        printf("cannot open output file\n");
        continue;
      }
      redirect_stderr = 1;
      cnt++;
      *ptr = 0;
    }
    if (strstr(buffer, " < ")) {
      ptr = strstr(buffer, " < ");
      char *filename = ptr + 3;
      out = open(filename, O_RDONLY);
      if (out == -1) {
        printf("cannot open output file\n");
        continue;
      }
      redirect_stdin = 1;
      cnt++;
      *ptr = 0;
    }
    int second_process_created = 0;
    char *process2_name;
    char myargv_temp1[2048][1048];
    char *myargv1[2048];
    int myargc1 = 0;
    if (strstr(buffer, " | ")) {
      ptr = strstr(buffer, " | ");
      pipe(fd);
      process2_name = ptr + 3;
      cnt++;
      *ptr = 0;
      second_process_created = 1;
      pipe_out = 1;
      int i = 0;
      while (process2_name[i]) {
        int j = 0;
        while (process2_name[i] && process2_name[i] != ' ') {
          myargv_temp1[myargc1][j] = process2_name[i];
          j++;
          i++;
        }
        myargv_temp1[myargc1][j] = 0;
        myargv1[myargc1] = myargv_temp1[myargc1];
        myargc1++;
        if (process2_name[i])
          i++;
      }
      myargv1[myargc1] = NULL;
    }
    int run_background = 0;
    if (strstr(buffer, "&")) {
      ptr = strstr(buffer, "&");
      cnt++;
      *ptr = 0;
      run_background = 1;
    }
    if (cnt > 1) {
      printf("Combinations of several special characters are not supported, "
             "try again.\n");
      continue;
    }
    char myargv_temp[2048][1048];
    char *myargv[2048];
    int myargc = 0;
    int i = 0;
    while (buffer[i]) {
      int j = 0;
      while (buffer[i] && buffer[i] != ' ') {
        myargv_temp[myargc][j] = buffer[i];
        j++;
        i++;
      }
      myargv_temp[myargc][j] = 0;
      myargv[myargc] = myargv_temp[myargc];
      myargc++;
      if (buffer[i])
        i++;
    }
    myargv[myargc] = NULL;
    pid_t child_pid;
    int status;
    child_pid = fork();
    if (child_pid == 0) {
      if (redirect_stdin) {
        if (-1 == dup2(out, fileno(stdin))) {
          printf("cannot redirect stdin\n");
          exit(1);
        }
      }
      if (redirect_stdout) {
        if (-1 == dup2(out, fileno(stdout))) {
          printf("cannot redirect stdout\n");
          exit(1);
        }
      }
      if (redirect_stderr) {
        if (-1 == dup2(out, fileno(stderr))) {
          printf("cannot redirect stderr\n");
          exit(1);
        }
      }
      if (pipe_out) {
        if (-1 == dup2(fd[1], fileno(stdout))) {
          printf("cannot redirect pipe stdout\n");
          exit(1);
        }
      }
      execvp(myargv[0], myargv);
      if (pipe_out) {
        close(fd[1]);
      }
      exit(1);
    } else {
      if (child_pid < 0) {
        printf("fork failed.\n");
        exit(1);
      } else if (!run_background) {
        waitpid(child_pid, 0, 0);
      }
      if (pipe_out) {
        close(fd[1]);
      }
    }
    if (second_process_created) {
      child_pid = fork();
      if (child_pid == 0) {
        if (-1 == dup2(fd[0], fileno(stdin))) {
          printf("cannot redirect stdin\n");
          exit(1);
        }
        execvp(myargv1[0], myargv1);
        exit(1);
      } else {
        if (child_pid < 0) {
          printf("fork failed.\n");
          exit(1);
        } else {
          waitpid(child_pid, 0, 0);
          close(fd[0]);
        }
      }
    }
    if (out != -1) {
      close(out);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4208d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    %eax,-0x4208b8(%rbp)
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    -0x4208b8(%rbp),%edi
mov    %eax,%esi
call   1040 <dup2@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    %eax,-0x4208b4(%rbp)
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    -0x4208b4(%rbp),%edi
mov    %eax,%esi
call   1040 <dup2@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    %eax,-0x4208b0(%rbp)
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    -0x4208b0(%rbp),%edi
mov    %eax,%esi
call   1040 <dup2@plt>
lea    0xd8a(%rip),%rdi
call   1050 <printf@plt>
lea    -0x810(%rbp),%rdi
mov    0x2d3f(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1080 <fgets@plt>
movsbl -0x810(%rbp),%eax
cmp    $0x65,%eax
jne    12fa <main+0x12a>
movsbl -0x80f(%rbp),%eax
cmp    $0x78,%eax
jne    12fa <main+0x12a>
movsbl -0x80e(%rbp),%eax
cmp    $0x69,%eax
jne    12fa <main+0x12a>
movsbl -0x80d(%rbp),%eax
cmp    $0x74,%eax
jne    12fa <main+0x12a>
movsbl -0x80c(%rbp),%eax
cmp    $0xa,%eax
jne    12fa <main+0x12a>
movsbl -0x80b(%rbp),%eax
cmp    $0x0,%eax
jne    12fa <main+0x12a>
jmp    1e11 <main+0xc41>
lea    -0x810(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x810(%rbp,%rax,1)
movl   $0x0,-0x814(%rbp)
movl   $0xffffffff,-0x824(%rbp)
ff ff ff
movl   $0x0,-0x828(%rbp)
movl   $0x0,-0x82c(%rbp)
movl   $0x0,-0x830(%rbp)
movl   $0x0,-0x834(%rbp)
lea    -0x810(%rbp),%rdi
lea    0xcad(%rip),%rsi
call   10f0 <strstr@plt>
cmp    $0x0,%rax
je     1411 <main+0x241>
lea    -0x810(%rbp),%rdi
lea    0xc90(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x820(%rbp)
mov    -0x820(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x848(%rbp)
mov    -0x848(%rbp),%rdi
mov    0x2bfa(%rip),%rax
mov    (%rax),%esi
mov    0x2c49(%rip),%rax
or     (%rax),%esi
mov    0x2c38(%rip),%rax
or     (%rax),%esi
mov    0x2c17(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0xffffffff,-0x824(%rbp)
jne    13ee <main+0x21e>
lea    0xc2a(%rip),%rdi
call   1050 <printf@plt>
jmp    11e2 <main+0x12>
movl   $0x1,-0x830(%rbp)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
mov    -0x820(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x810(%rbp),%rdi
lea    0xc08(%rip),%rsi
call   10f0 <strstr@plt>
cmp    $0x0,%rax
je     14d3 <main+0x303>
lea    -0x810(%rbp),%rdi
lea    0xbeb(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x820(%rbp)
mov    -0x820(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x850(%rbp)
mov    -0x850(%rbp),%rdi
mov    0x2b38(%rip),%rax
mov    (%rax),%esi
mov    0x2b87(%rip),%rax
or     (%rax),%esi
mov    0x2b1e(%rip),%rax
or     (%rax),%esi
mov    0x2b55(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0xffffffff,-0x824(%rbp)
jne    14b0 <main+0x2e0>
lea    0xb68(%rip),%rdi
call   1050 <printf@plt>
jmp    11e2 <main+0x12>
movl   $0x1,-0x830(%rbp)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
mov    -0x820(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x810(%rbp),%rdi
lea    0xb4b(%rip),%rsi
call   10f0 <strstr@plt>
cmp    $0x0,%rax
je     1595 <main+0x3c5>
lea    -0x810(%rbp),%rdi
lea    0xb2e(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x820(%rbp)
mov    -0x820(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x858(%rbp)
mov    -0x858(%rbp),%rdi
mov    0x2a76(%rip),%rax
mov    (%rax),%esi
mov    0x2ac5(%rip),%rax
or     (%rax),%esi
mov    0x2ab4(%rip),%rax
or     (%rax),%esi
mov    0x2a93(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0xffffffff,-0x824(%rbp)
jne    1572 <main+0x3a2>
lea    0xaa6(%rip),%rdi
call   1050 <printf@plt>
jmp    11e2 <main+0x12>
movl   $0x1,-0x82c(%rbp)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
mov    -0x820(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x810(%rbp),%rdi
lea    0xa8e(%rip),%rsi
call   10f0 <strstr@plt>
cmp    $0x0,%rax
je     1657 <main+0x487>
lea    -0x810(%rbp),%rdi
lea    0xa71(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x820(%rbp)
mov    -0x820(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x860(%rbp)
mov    -0x860(%rbp),%rdi
mov    0x29b4(%rip),%rax
mov    (%rax),%esi
mov    0x2a03(%rip),%rax
or     (%rax),%esi
mov    0x299a(%rip),%rax
or     (%rax),%esi
mov    0x29d1(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0xffffffff,-0x824(%rbp)
jne    1634 <main+0x464>
lea    0x9e4(%rip),%rdi
call   1050 <printf@plt>
jmp    11e2 <main+0x12>
movl   $0x1,-0x82c(%rbp)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
mov    -0x820(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x810(%rbp),%rdi
lea    0x9d2(%rip),%rsi
call   10f0 <strstr@plt>
cmp    $0x0,%rax
je     16fe <main+0x52e>
lea    -0x810(%rbp),%rdi
lea    0x9b5(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x820(%rbp)
mov    -0x820(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x868(%rbp)
mov    -0x868(%rbp),%rdi
mov    0x2922(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0xffffffff,-0x824(%rbp)
jne    16db <main+0x50b>
lea    0x93d(%rip),%rdi
call   1050 <printf@plt>
jmp    11e2 <main+0x12>
movl   $0x1,-0x828(%rbp)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
mov    -0x820(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x86c(%rbp)
movl   $0x0,-0x210884(%rbp)
lea    -0x810(%rbp),%rdi
lea    0x91b(%rip),%rsi
call   10f0 <strstr@plt>
cmp    $0x0,%rax
je     1902 <main+0x732>
lea    -0x810(%rbp),%rdi
lea    0x8fe(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x820(%rbp)
lea    -0x83c(%rbp),%rdi
call   1070 <pipe@plt>
mov    -0x820(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x878(%rbp)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
mov    -0x820(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x86c(%rbp)
movl   $0x1,-0x834(%rbp)
movl   $0x0,-0x210888(%rbp)
mov    -0x878(%rbp),%rax
movslq -0x210888(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     18ef <main+0x71f>
movl   $0x0,-0x21088c(%rbp)
mov    -0x878(%rbp),%rax
movslq -0x210888(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x4208b9(%rbp)
je     1801 <main+0x631>
mov    -0x878(%rbp),%rax
movslq -0x210888(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x4208b9(%rbp)
mov    -0x4208b9(%rbp),%al
test   $0x1,%al
jne    1814 <main+0x644>
jmp    186a <main+0x69a>
mov    -0x878(%rbp),%rax
movslq -0x210888(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x210884(%rbp),%rcx
lea    -0x20c880(%rbp),%rax
imul   $0x418,%rcx,%rcx
add    %rcx,%rax
movslq -0x21088c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x21088c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x21088c(%rbp)
mov    -0x210888(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x210888(%rbp)
jmp    17c0 <main+0x5f0>
movslq -0x210884(%rbp),%rcx
lea    -0x20c880(%rbp),%rax
imul   $0x418,%rcx,%rcx
add    %rcx,%rax
movslq -0x21088c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movslq -0x210884(%rbp),%rax
lea    -0x20c880(%rbp),%rcx
imul   $0x418,%rax,%rax
add    %rax,%rcx
movslq -0x210884(%rbp),%rax
mov    %rcx,-0x210880(%rbp,%rax,8)
ff
mov    -0x210884(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x210884(%rbp)
mov    -0x878(%rbp),%rax
movslq -0x210888(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     18ea <main+0x71a>
mov    -0x210888(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x210888(%rbp)
jmp    179e <main+0x5ce>
movslq -0x210884(%rbp),%rax
movq   $0x0,-0x210880(%rbp,%rax,8)
movl   $0x0,-0x210890(%rbp)
lea    -0x810(%rbp),%rdi
lea    0x725(%rip),%rsi
call   10f0 <strstr@plt>
cmp    $0x0,%rax
je     1966 <main+0x796>
lea    -0x810(%rbp),%rdi
lea    0x708(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x820(%rbp)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
mov    -0x820(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x210890(%rbp)
cmpl   $0x1,-0x814(%rbp)
jle    1984 <main+0x7b4>
lea    0x6c7(%rip),%rdi
call   1050 <printf@plt>
jmp    11e2 <main+0x12>
movl   $0x0,-0x420894(%rbp)
movl   $0x0,-0x420898(%rbp)
movslq -0x420898(%rbp),%rax
cmpb   $0x0,-0x810(%rbp,%rax,1)
je     1ada <main+0x90a>
movl   $0x0,-0x42089c(%rbp)
movslq -0x420898(%rbp),%rax
movsbl -0x810(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x4208ba(%rbp)
je     19f2 <main+0x822>
movslq -0x420898(%rbp),%rax
movsbl -0x810(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
setne  %al
mov    %al,-0x4208ba(%rbp)
mov    -0x4208ba(%rbp),%al
test   $0x1,%al
jne    1a05 <main+0x835>
jmp    1a58 <main+0x888>
movslq -0x420898(%rbp),%rax
mov    -0x810(%rbp,%rax,1),%dl
movslq -0x420894(%rbp),%rcx
lea    -0x41c890(%rbp),%rax
imul   $0x418,%rcx,%rcx
add    %rcx,%rax
movslq -0x42089c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x42089c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42089c(%rbp)
mov    -0x420898(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x420898(%rbp)
jmp    19b7 <main+0x7e7>
movslq -0x420894(%rbp),%rcx
lea    -0x41c890(%rbp),%rax
imul   $0x418,%rcx,%rcx
add    %rcx,%rax
movslq -0x42089c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movslq -0x420894(%rbp),%rax
lea    -0x41c890(%rbp),%rcx
imul   $0x418,%rax,%rax
add    %rax,%rcx
movslq -0x420894(%rbp),%rax
mov    %rcx,-0x420890(%rbp,%rax,8)
ff
mov    -0x420894(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x420894(%rbp)
movslq -0x420898(%rbp),%rax
cmpb   $0x0,-0x810(%rbp,%rax,1)
je     1ad5 <main+0x905>
mov    -0x420898(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x420898(%rbp)
jmp    1998 <main+0x7c8>
movslq -0x420894(%rbp),%rax
movq   $0x0,-0x420890(%rbp,%rax,8)
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %rax,-0x4208a8(%rbp)
cmpq   $0x0,-0x4208a8(%rbp)
jne    1cb6 <main+0xae6>
cmpl   $0x0,-0x828(%rbp)
je     1b67 <main+0x997>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4208c0(%rbp)
mov    0x249f(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    -0x4208c0(%rbp),%edi
mov    %eax,%esi
call   1040 <dup2@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1b62 <main+0x992>
lea    0x538(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1b67 <main+0x997>
cmpl   $0x0,-0x830(%rbp)
je     1bc5 <main+0x9f5>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4208c4(%rbp)
mov    0x2429(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    -0x4208c4(%rbp),%edi
mov    %eax,%esi
call   1040 <dup2@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1bc0 <main+0x9f0>
lea    0x4f1(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1bc5 <main+0x9f5>
cmpl   $0x0,-0x82c(%rbp)
je     1c23 <main+0xa53>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4208c8(%rbp)
mov    0x23d3(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    -0x4208c8(%rbp),%edi
mov    %eax,%esi
call   1040 <dup2@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1c1e <main+0xa4e>
lea    0x4ab(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1c23 <main+0xa53>
cmpl   $0x0,-0x834(%rbp)
je     1c81 <main+0xab1>
mov    -0x838(%rbp),%eax
mov    %eax,-0x4208cc(%rbp)
mov    0x236d(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    -0x4208cc(%rbp),%edi
mov    %eax,%esi
call   1040 <dup2@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1c7c <main+0xaac>
lea    0x465(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1c81 <main+0xab1>
mov    -0x420890(%rbp),%rdi
lea    -0x420890(%rbp),%rsi
call   10c0 <execvp@plt>
cmpl   $0x0,-0x834(%rbp)
je     1cac <main+0xadc>
mov    -0x838(%rbp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpq   $0x0,-0x4208a8(%rbp)
jge    1cda <main+0xb0a>
lea    0x424(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x210890(%rbp)
jne    1cf7 <main+0xb27>
mov    -0x4208a8(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10a0 <waitpid@plt>
jmp    1cfc <main+0xb2c>
cmpl   $0x0,-0x834(%rbp)
je     1d14 <main+0xb44>
mov    -0x838(%rbp),%edi
call   1060 <close@plt>
jmp    1d19 <main+0xb49>
cmpl   $0x0,-0x86c(%rbp)
je     1df4 <main+0xc24>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %rax,-0x4208a8(%rbp)
cmpq   $0x0,-0x4208a8(%rbp)
jne    1dab <main+0xbdb>
mov    -0x83c(%rbp),%eax
mov    %eax,-0x4208d0(%rbp)
mov    0x2273(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    -0x4208d0(%rbp),%edi
mov    %eax,%esi
call   1040 <dup2@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1d8e <main+0xbbe>
lea    0x30c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x210880(%rbp),%rdi
lea    -0x210880(%rbp),%rsi
call   10c0 <execvp@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpq   $0x0,-0x4208a8(%rbp)
jge    1dcf <main+0xbff>
lea    0x32f(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x4208a8(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10a0 <waitpid@plt>
mov    -0x83c(%rbp),%edi
call   1060 <close@plt>
jmp    1def <main+0xc1f>
jmp    1df4 <main+0xc24>
cmpl   $0xffffffff,-0x824(%rbp)
je     1e0c <main+0xc3c>
mov    -0x824(%rbp),%edi
call   1060 <close@plt>
jmp    11e2 <main+0x12>
xor    %eax,%eax
add    $0x4208d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x420828,%rsp
mov    0x2da8(%rip),%r15
mov    0x2db9(%rip),%rbx
mov    0x2da2(%rip),%r12
jmp    122c <main+0x3c>
nopl   0x0(%rax,%rax,1)
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%edi
call   10b0 <fileno@plt>
mov    %eax,%ebp
mov    (%r15),%edi
call   10b0 <fileno@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <dup2@plt>
mov    (%rbx),%edi
call   10b0 <fileno@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
call   10b0 <fileno@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <dup2@plt>
mov    (%r12),%edi
call   10b0 <fileno@plt>
mov    %eax,%ebp
mov    (%r12),%edi
call   10b0 <fileno@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <dup2@plt>
lea    0xd7c(%rip),%rdi
call   1070 <printf@plt>
mov    (%rbx),%edx
lea    0x20(%rsp),%rdi
mov    $0x800,%esi
call   10a0 <fgets@plt>
movdqa 0x20(%rsp),%xmm0
movd   %xmm0,%eax
cmp    $0x74697865,%eax
jne    12bd <main+0xcd>
cmpb   $0xa,0x24(%rsp)
jne    12bd <main+0xcd>
cmpb   $0x0,0x25(%rsp)
je     16fa <main+0x50a>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
mov    %rbp,%rdi
lea    0xd2f(%rip),%rsi
call   1110 <strstr@plt>
test   %rax,%rax
je     1330 <main+0x140>
mov    %rax,%rbp
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
mov    0x2ca8(%rip),%rax
or     (%rax),%esi
lea    0x3(%rbp),%rdi
mov    0x2ceb(%rip),%rax
or     (%rax),%esi
mov    0x2cca(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1220 <main+0x30>
mov    %eax,%r13d
movb   $0x0,0x0(%rbp)
mov    $0x1,%r14d
jmp    1339 <main+0x149>
nop
xor    %r14d,%r14d
mov    $0xffffffff,%r13d
lea    0x20(%rsp),%rdi
lea    0xcc9(%rip),%rsi
call   1110 <strstr@plt>
test   %rax,%rax
je     13a0 <main+0x1b0>
mov    %rax,%rbp
mov    0x2c9f(%rip),%rax
mov    (%rax),%esi
mov    0x2c3e(%rip),%rax
or     (%rax),%esi
lea    0x4(%rbp),%rdi
mov    0x2c29(%rip),%rax
or     (%rax),%esi
mov    0x2c60(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1220 <main+0x30>
mov    %eax,%r13d
add    $0x1,%r14d
movb   $0x0,0x0(%rbp)
movl   $0x1,0xc(%rsp)
jmp    13a5 <main+0x1b5>
nop
mov    %r14d,0xc(%rsp)
lea    0x20(%rsp),%rdi
lea    0xc62(%rip),%rsi
call   1110 <strstr@plt>
test   %rax,%rax
je     1410 <main+0x220>
mov    %rax,%rbp
mov    0x2c33(%rip),%rax
mov    (%rax),%esi
mov    0x2bd2(%rip),%rax
or     (%rax),%esi
lea    0x4(%rbp),%rdi
mov    0x2c15(%rip),%rax
or     (%rax),%esi
mov    0x2bf4(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1220 <main+0x30>
mov    %eax,%r13d
add    $0x1,%r14d
movb   $0x0,0x0(%rbp)
movl   $0x1,0x8(%rsp)
jmp    1418 <main+0x228>
nopl   0x0(%rax,%rax,1)
movl   $0x0,0x8(%rsp)
lea    0x20(%rsp),%rdi
lea    0xbf4(%rip),%rsi
call   1110 <strstr@plt>
test   %rax,%rax
je     147c <main+0x28c>
mov    %rax,%rbp
mov    0x2bc0(%rip),%rax
mov    (%rax),%esi
mov    0x2b5f(%rip),%rax
or     (%rax),%esi
lea    0x5(%rbp),%rdi
mov    0x2b4a(%rip),%rax
or     (%rax),%esi
mov    0x2b81(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1220 <main+0x30>
mov    %eax,%r13d
add    $0x1,%r14d
movb   $0x0,0x0(%rbp)
movl   $0x1,0x8(%rsp)
lea    0x20(%rsp),%rdi
lea    0xb96(%rip),%rsi
call   1110 <strstr@plt>
test   %rax,%rax
je     14c4 <main+0x2d4>
lea    0x3(%rax),%rdi
mov    %rax,%rbp
mov    0x2b30(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1220 <main+0x30>
mov    %eax,%r13d
add    $0x1,%r14d
mov    %rbp,0x18(%rsp)
movb   $0x0,0x0(%rbp)
jmp    14c9 <main+0x2d9>
mov    %rax,0x18(%rsp)
lea    0x20(%rsp),%rdi
lea    0xb4d(%rip),%rsi
call   1110 <strstr@plt>
mov    %rax,%r12
test   %rax,%rax
je     1596 <main+0x3a6>
lea    0x10(%rsp),%rdi
call   1090 <pipe@plt>
movb   $0x0,(%r12)
cmpb   $0x0,0x3(%r12)
je     1582 <main+0x392>
lea    0x3(%r12),%r8
xor    %eax,%eax
lea    0x214820(%rsp),%rdx
xor    %esi,%esi
jmp    1562 <main+0x372>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%ecx
imul   $0x418,%rax,%rbp
add    %rsp,%rbp
add    $0x214820,%rbp
movb   $0x0,(%rcx,%rbp,1)
mov    %rbp,0x4820(%rsp,%rax,8)
add    $0x1,%rax
cmpb   $0x1,(%rbx,%rdi,1)
mov    %esi,%esi
sbb    $0xffffffffffffffff,%rsi
add    %rbx,%rsi
movslq %esi,%rcx
add    $0x418,%rdx
cmpb   $0x0,0x3(%r12,%rcx,1)
je     1584 <main+0x394>
movslq %esi,%rdi
add    %r8,%rdi
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%rdi,%rbx,1),%ecx
test   $0xdf,%cl
je     1520 <main+0x330>
mov    %cl,(%rdx,%rbx,1)
add    $0x1,%rbx
jmp    1570 <main+0x380>
xor    %eax,%eax
add    $0x1,%r14d
mov    %eax,%eax
movq   $0x0,0x4820(%rsp,%rax,8)
lea    0x20(%rsp),%rdi
mov    $0x26,%esi
call   1060 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
je     15b5 <main+0x3c5>
add    $0x1,%r14d
movb   $0x0,(%r15)
cmp    $0x2,%r14d
jl     15e1 <main+0x3f1>
lea    0xad1(%rip),%rdi
call   1030 <puts@plt>
mov    0x29e2(%rip),%r15
mov    0x29e3(%rip),%r12
mov    0x29ec(%rip),%rbx
jmp    122c <main+0x3c>
cmpb   $0x0,0x20(%rsp)
je     1662 <main+0x472>
xor    %eax,%eax
lea    0x8820(%rsp),%rcx
xor    %edx,%edx
jmp    1640 <main+0x450>
cs nopw 0x0(%rax,%rax,1)
mov    %esi,%edi
imul   $0x418,%rax,%rbp
add    %rsp,%rbp
add    $0x8820,%rbp
movb   $0x0,(%rdi,%rbp,1)
mov    %rbp,0x820(%rsp,%rax,8)
add    $0x1,%rax
mov    %edx,%edx
cmp    $0x1,%bl
sbb    $0xffffffffffffffff,%rdx
add    %rsi,%rdx
movslq %edx,%rsi
add    $0x418,%rcx
cmpb   $0x0,0x20(%rsp,%rsi,1)
je     1664 <main+0x474>
movslq %edx,%rsi
lea    (%rsp,%rsi,1),%rdi
add    $0x20,%rdi
xor    %esi,%esi
nopl   (%rax)
movzbl (%rdi,%rsi,1),%ebx
test   $0xdf,%bl
je     1600 <main+0x410>
mov    %bl,(%rcx,%rsi,1)
add    $0x1,%rsi
jmp    1650 <main+0x460>
xor    %eax,%eax
mov    %eax,%eax
movq   $0x0,0x820(%rsp,%rax,8)
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
je     1717 <main+0x527>
js     170e <main+0x51e>
test   %r15,%r15
jne    1699 <main+0x4a9>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <waitpid@plt>
test   %r12,%r12
mov    0x290d(%rip),%r15
mov    0x290e(%rip),%r12
mov    0x2917(%rip),%rbx
je     16e3 <main+0x4f3>
mov    0x14(%rsp),%edi
call   1080 <close@plt>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
je     1769 <main+0x579>
js     170e <main+0x51e>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <waitpid@plt>
mov    0x10(%rsp),%edi
call   1080 <close@plt>
cmp    $0xffffffff,%r13d
je     122c <main+0x3c>
mov    %r13d,%edi
call   1080 <close@plt>
jmp    122c <main+0x3c>
xor    %eax,%eax
add    $0x420828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x911(%rip),%rdi
jmp    1789 <main+0x599>
cmpq   $0x0,0x18(%rsp)
je     173c <main+0x54c>
mov    0x28a2(%rip),%rax
mov    (%rax),%edi
call   10b0 <fileno@plt>
mov    %r13d,%edi
mov    %eax,%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
je     1782 <main+0x592>
cmpl   $0x0,0xc(%rsp)
je     1798 <main+0x5a8>
mov    0x2866(%rip),%rax
mov    (%rax),%edi
call   10b0 <fileno@plt>
mov    %r13d,%edi
mov    %eax,%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1798 <main+0x5a8>
lea    0x8ff(%rip),%rdi
jmp    1789 <main+0x599>
mov    0x10(%rsp),%ebp
mov    (%rbx),%edi
call   10b0 <fileno@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
jne    17dc <main+0x5ec>
lea    0x8f4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
cmpl   $0x0,0x8(%rsp)
je     17c5 <main+0x5d5>
mov    0x2812(%rip),%rax
mov    (%rax),%edi
call   10b0 <fileno@plt>
mov    %r13d,%edi
mov    %eax,%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
jne    17c5 <main+0x5d5>
lea    0x88c(%rip),%rdi
jmp    1789 <main+0x599>
test   %r12,%r12
jne    17fb <main+0x60b>
mov    0x820(%rsp),%rdi
lea    0x820(%rsp),%rsi
jmp    17ec <main+0x5fc>
mov    0x4820(%rsp),%rdi
lea    0x4820(%rsp),%rsi
call   10e0 <execvp@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x14(%rsp),%ebx
mov    0x27aa(%rip),%rax
mov    (%rax),%edi
call   10b0 <fileno@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1827 <main+0x637>
lea    0x811(%rip),%rdi
jmp    1789 <main+0x599>
mov    0x820(%rsp),%rdi
lea    0x820(%rsp),%rsi
call   10e0 <execvp@plt>
mov    0x14(%rsp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str = [10 x i8] c"My Shell>\00"
@.str.1 = [4 x i8] c" > \00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@.str.2 = [25 x i8] c"cannot open output file\0A\00"
@.str.3 = [5 x i8] c" >> \00"
@O_APPEND = global i32 0
@.str.4 = [5 x i8] c" 2> \00"
@.str.5 = [6 x i8] c" 2>> \00"
@.str.6 = [4 x i8] c" < \00"
@O_RDONLY = global i32 0
@.str.7 = [4 x i8] c" | \00"
@.str.8 = [2 x i8] c"&\00"
@.str.9 = [74 x i8] c"Combinations of several special characters are not supported, try again.\0A\00"
@.str.10 = [23 x i8] c"cannot redirect stdin\0A\00"
@.str.11 = [24 x i8] c"cannot redirect stdout\0A\00"
@.str.12 = [24 x i8] c"cannot redirect stderr\0A\00"
@.str.13 = [29 x i8] c"cannot redirect pipe stdout\0A\00"
@.str.14 = [14 x i8] c"fork failed.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2048 x i8]
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [2 x i32]
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i8*
%18 = alloca [2048 x [1048 x i8]]
%19 = alloca [2048 x i8*]
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca [2048 x [1048 x i8]]
%25 = alloca [2048 x i8*]
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i64
%30 = alloca i32
store i32 0, i32* %1
br label %31
31: ; preds = %0, %105, %130, %155, %180, %200, %305, %508
%32 = load i32, i32* @stdout
%33 = call i32 @fileno(i32 %32)
%34 = load i32, i32* @stdout
%35 = call i32 @fileno(i32 %34)
%36 = call i32 @dup2(i32 %33, i32 %35)
%37 = load i32, i32* @stdin
%38 = call i32 @fileno(i32 %37)
%39 = load i32, i32* @stdin
%40 = call i32 @fileno(i32 %39)
%41 = call i32 @dup2(i32 %38, i32 %40)
%42 = load i32, i32* @stderr
%43 = call i32 @fileno(i32 %42)
%44 = load i32, i32* @stderr
%45 = call i32 @fileno(i32 %44)
%46 = call i32 @dup2(i32 %43, i32 %45)
%47 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%48 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%49 = load i32, i32* @stdin
%50 = call i32 @fgets(i8* %48, i32 2048, i32 %49)
%51 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 101
br i1 %54, label %55, label %81
55: ; preds = %31
%56 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 1
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 120
br i1 %59, label %60, label %81
60: ; preds = %55
%61 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 2
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 105
br i1 %64, label %65, label %81
65: ; preds = %60
%66 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 3
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 116
br i1 %69, label %70, label %81
70: ; preds = %65
%71 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 4
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 10
br i1 %74, label %75, label %81
75: ; preds = %70
%76 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 5
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %75
br label %509
81: ; preds = %75, %70, %65, %60, %55, %31
%82 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%83 = call i32 @strlen(i8* %82)
%84 = sub nsw i32 %83, 1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %85
store i8 0, i8* %86
store i32 0, i32* %3
store i32 -1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%87 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%88 = call i8* @strstr(i8* %87, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%89 = icmp ne i8* %88, null
br i1 %89, label %90, label %111
90: ; preds = %81
%91 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%92 = call i8* @strstr(i8* %91, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %92, i8** %4
%93 = load i8*, i8** %4
%94 = getelementptr inbounds i8, i8* %93, i64 3
store i8* %94, i8** %11
%95 = load i8*, i8** %11
%96 = load i32, i32* @O_WRONLY
%97 = load i32, i32* @O_CREAT
%98 = or i32 %96, %97
%99 = load i32, i32* @O_TRUNC
%100 = or i32 %98, %99
%101 = load i32, i32* @S_IRWXU
%102 = call i32 (i8*, i32, ...) @open(i8* %95, i32 %100, i32 %101)
store i32 %102, i32* %5
%103 = load i32, i32* %5
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %107
105: ; preds = %90
%106 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %31
107: ; preds = %90
store i32 1, i32* %8
%108 = load i32, i32* %3
%109 = add nsw i32 %108, 1
store i32 %109, i32* %3
%110 = load i8*, i8** %4
store i8 0, i8* %110
br label %111
111: ; preds = %107, %81
%112 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%113 = call i8* @strstr(i8* %112, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%114 = icmp ne i8* %113, null
br i1 %114, label %115, label %136
115: ; preds = %111
%116 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%117 = call i8* @strstr(i8* %116, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %117, i8** %4
%118 = load i8*, i8** %4
%119 = getelementptr inbounds i8, i8* %118, i64 4
store i8* %119, i8** %12
%120 = load i8*, i8** %12
%121 = load i32, i32* @O_WRONLY
%122 = load i32, i32* @O_CREAT
%123 = or i32 %121, %122
%124 = load i32, i32* @O_APPEND
%125 = or i32 %123, %124
%126 = load i32, i32* @S_IRWXU
%127 = call i32 (i8*, i32, ...) @open(i8* %120, i32 %125, i32 %126)
store i32 %127, i32* %5
%128 = load i32, i32* %5
%129 = icmp eq i32 %128, -1
br i1 %129, label %130, label %132
130: ; preds = %115
%131 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %31
132: ; preds = %115
store i32 1, i32* %8
%133 = load i32, i32* %3
%134 = add nsw i32 %133, 1
store i32 %134, i32* %3
%135 = load i8*, i8** %4
store i8 0, i8* %135
br label %136
136: ; preds = %132, %111
%137 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%138 = call i8* @strstr(i8* %137, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%139 = icmp ne i8* %138, null
br i1 %139, label %140, label %161
140: ; preds = %136
%141 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%142 = call i8* @strstr(i8* %141, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i8* %142, i8** %4
%143 = load i8*, i8** %4
%144 = getelementptr inbounds i8, i8* %143, i64 4
store i8* %144, i8** %13
%145 = load i8*, i8** %13
%146 = load i32, i32* @O_WRONLY
%147 = load i32, i32* @O_CREAT
%148 = or i32 %146, %147
%149 = load i32, i32* @O_TRUNC
%150 = or i32 %148, %149
%151 = load i32, i32* @S_IRWXU
%152 = call i32 (i8*, i32, ...) @open(i8* %145, i32 %150, i32 %151)
store i32 %152, i32* %5
%153 = load i32, i32* %5
%154 = icmp eq i32 %153, -1
br i1 %154, label %155, label %157
155: ; preds = %140
%156 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %31
157: ; preds = %140
store i32 1, i32* %7
%158 = load i32, i32* %3
%159 = add nsw i32 %158, 1
store i32 %159, i32* %3
%160 = load i8*, i8** %4
store i8 0, i8* %160
br label %161
161: ; preds = %157, %136
%162 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%163 = call i8* @strstr(i8* %162, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%164 = icmp ne i8* %163, null
br i1 %164, label %165, label %186
165: ; preds = %161
%166 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%167 = call i8* @strstr(i8* %166, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i8* %167, i8** %4
%168 = load i8*, i8** %4
%169 = getelementptr inbounds i8, i8* %168, i64 5
store i8* %169, i8** %14
%170 = load i8*, i8** %14
%171 = load i32, i32* @O_WRONLY
%172 = load i32, i32* @O_CREAT
%173 = or i32 %171, %172
%174 = load i32, i32* @O_APPEND
%175 = or i32 %173, %174
%176 = load i32, i32* @S_IRWXU
%177 = call i32 (i8*, i32, ...) @open(i8* %170, i32 %175, i32 %176)
store i32 %177, i32* %5
%178 = load i32, i32* %5
%179 = icmp eq i32 %178, -1
br i1 %179, label %180, label %182
180: ; preds = %165
%181 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %31
182: ; preds = %165
store i32 1, i32* %7
%183 = load i32, i32* %3
%184 = add nsw i32 %183, 1
store i32 %184, i32* %3
%185 = load i8*, i8** %4
store i8 0, i8* %185
br label %186
186: ; preds = %182, %161
%187 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%188 = call i8* @strstr(i8* %187, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%189 = icmp ne i8* %188, null
br i1 %189, label %190, label %206
190: ; preds = %186
%191 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%192 = call i8* @strstr(i8* %191, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
store i8* %192, i8** %4
%193 = load i8*, i8** %4
%194 = getelementptr inbounds i8, i8* %193, i64 3
store i8* %194, i8** %15
%195 = load i8*, i8** %15
%196 = load i32, i32* @O_RDONLY
%197 = call i32 (i8*, i32, ...) @open(i8* %195, i32 %196)
store i32 %197, i32* %5
%198 = load i32, i32* %5
%199 = icmp eq i32 %198, -1
br i1 %199, label %200, label %202
200: ; preds = %190
%201 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %31
202: ; preds = %190
store i32 1, i32* %6
%203 = load i32, i32* %3
%204 = add nsw i32 %203, 1
store i32 %204, i32* %3
%205 = load i8*, i8** %4
store i8 0, i8* %205
br label %206
206: ; preds = %202, %186
store i32 0, i32* %16
store i32 0, i32* %20
%207 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%208 = call i8* @strstr(i8* %207, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%209 = icmp ne i8* %208, null
br i1 %209, label %210, label %292
210: ; preds = %206
%211 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%212 = call i8* @strstr(i8* %211, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
store i8* %212, i8** %4
%213 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%214 = call i32 @pipe(i32* %213)
%215 = load i8*, i8** %4
%216 = getelementptr inbounds i8, i8* %215, i64 3
store i8* %216, i8** %17
%217 = load i32, i32* %3
%218 = add nsw i32 %217, 1
store i32 %218, i32* %3
%219 = load i8*, i8** %4
store i8 0, i8* %219
store i32 1, i32* %16
store i32 1, i32* %9
store i32 0, i32* %21
br label %220
220: ; preds = %287, %210
%221 = load i8*, i8** %17
%222 = load i32, i32* %21
%223 = sext i32 %222 to i64
%224 = getelementptr inbounds i8, i8* %221, i64 %223
%225 = load i8, i8* %224
%226 = icmp ne i8 %225, 0
br i1 %226, label %227, label %288
227: ; preds = %220
store i32 0, i32* %22
br label %228
228: ; preds = %246, %227
%229 = load i8*, i8** %17
%230 = load i32, i32* %21
%231 = sext i32 %230 to i64
%232 = getelementptr inbounds i8, i8* %229, i64 %231
%233 = load i8, i8* %232
%234 = sext i8 %233 to i32
%235 = icmp ne i32 %234, 0
br i1 %235, label %236, label %244
236: ; preds = %228
%237 = load i8*, i8** %17
%238 = load i32, i32* %21
%239 = sext i32 %238 to i64
%240 = getelementptr inbounds i8, i8* %237, i64 %239
%241 = load i8, i8* %240
%242 = sext i8 %241 to i32
%243 = icmp ne i32 %242, 32
br label %244
244: ; preds = %236, %228
%245 = phi i1 [ false, %228 ], [ %243, %236 ]
br i1 %245, label %246, label %262
246: ; preds = %244
%247 = load i8*, i8** %17
%248 = load i32, i32* %21
%249 = sext i32 %248 to i64
%250 = getelementptr inbounds i8, i8* %247, i64 %249
%251 = load i8, i8* %250
%252 = load i32, i32* %20
%253 = sext i32 %252 to i64
%254 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %18, i64 0, i64 %253
%255 = load i32, i32* %22
%256 = sext i32 %255 to i64
%257 = getelementptr inbounds [1048 x i8], [1048 x i8]* %254, i64 0, i64 %256
store i8 %251, i8* %257
%258 = load i32, i32* %22
%259 = add nsw i32 %258, 1
store i32 %259, i32* %22
%260 = load i32, i32* %21
%261 = add nsw i32 %260, 1
store i32 %261, i32* %21
br label %228
262: ; preds = %244
%263 = load i32, i32* %20
%264 = sext i32 %263 to i64
%265 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %18, i64 0, i64 %264
%266 = load i32, i32* %22
%267 = sext i32 %266 to i64
%268 = getelementptr inbounds [1048 x i8], [1048 x i8]* %265, i64 0, i64 %267
store i8 0, i8* %268
%269 = load i32, i32* %20
%270 = sext i32 %269 to i64
%271 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %18, i64 0, i64 %270
%272 = getelementptr inbounds [1048 x i8], [1048 x i8]* %271, i64 0, i64 0
%273 = load i32, i32* %20
%274 = sext i32 %273 to i64
%275 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %19, i64 0, i64 %274
store i8* %272, i8** %275
%276 = load i32, i32* %20
%277 = add nsw i32 %276, 1
store i32 %277, i32* %20
%278 = load i8*, i8** %17
%279 = load i32, i32* %21
%280 = sext i32 %279 to i64
%281 = getelementptr inbounds i8, i8* %278, i64 %280
%282 = load i8, i8* %281
%283 = icmp ne i8 %282, 0
br i1 %283, label %284, label %287
284: ; preds = %262
%285 = load i32, i32* %21
%286 = add nsw i32 %285, 1
store i32 %286, i32* %21
br label %287
287: ; preds = %284, %262
br label %220
288: ; preds = %220
%289 = load i32, i32* %20
%290 = sext i32 %289 to i64
%291 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %19, i64 0, i64 %290
store i8* null, i8** %291
br label %292
292: ; preds = %288, %206
store i32 0, i32* %23
%293 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%294 = call i8* @strstr(i8* %293, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%295 = icmp ne i8* %294, null
br i1 %295, label %296, label %302
296: ; preds = %292
%297 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%298 = call i8* @strstr(i8* %297, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i8* %298, i8** %4
%299 = load i32, i32* %3
%300 = add nsw i32 %299, 1
store i32 %300, i32* %3
%301 = load i8*, i8** %4
store i8 0, i8* %301
store i32 1, i32* %23
br label %302
302: ; preds = %296, %292
%303 = load i32, i32* %3
%304 = icmp sgt i32 %303, 1
br i1 %304, label %305, label %307
305: ; preds = %302
%306 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.9, i64 0, i64 0))
br label %31
307: ; preds = %302
store i32 0, i32* %26
store i32 0, i32* %27
br label %308
308: ; preds = %370, %307
%309 = load i32, i32* %27
%310 = sext i32 %309 to i64
%311 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %310
%312 = load i8, i8* %311
%313 = icmp ne i8 %312, 0
br i1 %313, label %314, label %371
314: ; preds = %308
store i32 0, i32* %28
br label %315
315: ; preds = %331, %314
%316 = load i32, i32* %27
%317 = sext i32 %316 to i64
%318 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %317
%319 = load i8, i8* %318
%320 = sext i8 %319 to i32
%321 = icmp ne i32 %320, 0
br i1 %321, label %322, label %329
322: ; preds = %315
%323 = load i32, i32* %27
%324 = sext i32 %323 to i64
%325 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %324
%326 = load i8, i8* %325
%327 = sext i8 %326 to i32
%328 = icmp ne i32 %327, 32
br label %329
329: ; preds = %322, %315
%330 = phi i1 [ false, %315 ], [ %328, %322 ]
br i1 %330, label %331, label %346
331: ; preds = %329
%332 = load i32, i32* %27
%333 = sext i32 %332 to i64
%334 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %333
%335 = load i8, i8* %334
%336 = load i32, i32* %26
%337 = sext i32 %336 to i64
%338 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %24, i64 0, i64 %337
%339 = load i32, i32* %28
%340 = sext i32 %339 to i64
%341 = getelementptr inbounds [1048 x i8], [1048 x i8]* %338, i64 0, i64 %340
store i8 %335, i8* %341
%342 = load i32, i32* %28
%343 = add nsw i32 %342, 1
store i32 %343, i32* %28
%344 = load i32, i32* %27
%345 = add nsw i32 %344, 1
store i32 %345, i32* %27
br label %315
346: ; preds = %329
%347 = load i32, i32* %26
%348 = sext i32 %347 to i64
%349 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %24, i64 0, i64 %348
%350 = load i32, i32* %28
%351 = sext i32 %350 to i64
%352 = getelementptr inbounds [1048 x i8], [1048 x i8]* %349, i64 0, i64 %351
store i8 0, i8* %352
%353 = load i32, i32* %26
%354 = sext i32 %353 to i64
%355 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %24, i64 0, i64 %354
%356 = getelementptr inbounds [1048 x i8], [1048 x i8]* %355, i64 0, i64 0
%357 = load i32, i32* %26
%358 = sext i32 %357 to i64
%359 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %25, i64 0, i64 %358
store i8* %356, i8** %359
%360 = load i32, i32* %26
%361 = add nsw i32 %360, 1
store i32 %361, i32* %26
%362 = load i32, i32* %27
%363 = sext i32 %362 to i64
%364 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %363
%365 = load i8, i8* %364
%366 = icmp ne i8 %365, 0
br i1 %366, label %367, label %370
367: ; preds = %346
%368 = load i32, i32* %27
%369 = add nsw i32 %368, 1
store i32 %369, i32* %27
br label %370
370: ; preds = %367, %346
br label %308
371: ; preds = %308
%372 = load i32, i32* %26
%373 = sext i32 %372 to i64
%374 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %25, i64 0, i64 %373
store i8* null, i8** %374
%375 = call i64 (...) @fork()
store i64 %375, i64* %29
%376 = load i64, i64* %29
%377 = icmp eq i64 %376, 0
br i1 %377, label %378, label %444
378: ; preds = %371
%379 = load i32, i32* %6
%380 = icmp ne i32 %379, 0
br i1 %380, label %381, label %391
381: ; preds = %378
%382 = load i32, i32* %5
%383 = load i32, i32* @stdin
%384 = call i32 @fileno(i32 %383)
%385 = call i32 @dup2(i32 %382, i32 %384)
%386 = icmp eq i32 -1, %385
br i1 %386, label %387, label %390
387: ; preds = %381
%388 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%389 = call i32 @exit(i32 1)
unreachable
390: ; preds = %381
br label %391
391: ; preds = %390, %378
%392 = load i32, i32* %8
%393 = icmp ne i32 %392, 0
br i1 %393, label %394, label %404
394: ; preds = %391
%395 = load i32, i32* %5
%396 = load i32, i32* @stdout
%397 = call i32 @fileno(i32 %396)
%398 = call i32 @dup2(i32 %395, i32 %397)
%399 = icmp eq i32 -1, %398
br i1 %399, label %400, label %403
400: ; preds = %394
%401 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
%402 = call i32 @exit(i32 1)
unreachable
403: ; preds = %394
br label %404
404: ; preds = %403, %391
%405 = load i32, i32* %7
%406 = icmp ne i32 %405, 0
br i1 %406, label %407, label %417
407: ; preds = %404
%408 = load i32, i32* %5
%409 = load i32, i32* @stderr
%410 = call i32 @fileno(i32 %409)
%411 = call i32 @dup2(i32 %408, i32 %410)
%412 = icmp eq i32 -1, %411
br i1 %412, label %413, label %416
413: ; preds = %407
%414 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
%415 = call i32 @exit(i32 1)
unreachable
416: ; preds = %407
br label %417
417: ; preds = %416, %404
%418 = load i32, i32* %9
%419 = icmp ne i32 %418, 0
br i1 %419, label %420, label %431
420: ; preds = %417
%421 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%422 = load i32, i32* %421
%423 = load i32, i32* @stdout
%424 = call i32 @fileno(i32 %423)
%425 = call i32 @dup2(i32 %422, i32 %424)
%426 = icmp eq i32 -1, %425
br i1 %426, label %427, label %430
427: ; preds = %420
%428 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
%429 = call i32 @exit(i32 1)
unreachable
430: ; preds = %420
br label %431
431: ; preds = %430, %417
%432 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %25, i64 0, i64 0
%433 = load i8*, i8** %432
%434 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %25, i64 0, i64 0
%435 = call i32 @execvp(i8* %433, i8** %434)
%436 = load i32, i32* %9
%437 = icmp ne i32 %436, 0
br i1 %437, label %438, label %442
438: ; preds = %431
%439 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%440 = load i32, i32* %439
%441 = call i32 @close(i32 %440)
br label %442
442: ; preds = %438, %431
%443 = call i32 @exit(i32 1)
unreachable
444: ; preds = %371
%445 = load i64, i64* %29
%446 = icmp slt i64 %445, 0
br i1 %446, label %447, label %450
447: ; preds = %444
%448 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0))
%449 = call i32 @exit(i32 1)
unreachable
450: ; preds = %444
%451 = load i32, i32* %23
%452 = icmp ne i32 %451, 0
br i1 %452, label %456, label %453
453: ; preds = %450
%454 = load i64, i64* %29
%455 = call i32 @waitpid(i64 %454, i32 0, i32 0)
br label %456
456: ; preds = %453, %450
br label %457
457: ; preds = %456
%458 = load i32, i32* %9
%459 = icmp ne i32 %458, 0
br i1 %459, label %460, label %464
460: ; preds = %457
%461 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%462 = load i32, i32* %461
%463 = call i32 @close(i32 %462)
br label %464
464: ; preds = %460, %457
br label %465
465: ; preds = %464
%466 = load i32, i32* %16
%467 = icmp ne i32 %466, 0
br i1 %467, label %468, label %502
468: ; preds = %465
%469 = call i64 (...) @fork()
store i64 %469, i64* %29
%470 = load i64, i64* %29
%471 = icmp eq i64 %470, 0
br i1 %471, label %472, label %488
472: ; preds = %468
%473 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%474 = load i32, i32* %473
%475 = load i32, i32* @stdin
%476 = call i32 @fileno(i32 %475)
%477 = call i32 @dup2(i32 %474, i32 %476)
%478 = icmp eq i32 -1, %477
br i1 %478, label %479, label %482
479: ; preds = %472
%480 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%481 = call i32 @exit(i32 1)
unreachable
482: ; preds = %472
%483 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %19, i64 0, i64 0
%484 = load i8*, i8** %483
%485 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %19, i64 0, i64 0
%486 = call i32 @execvp(i8* %484, i8** %485)
%487 = call i32 @exit(i32 1)
unreachable
488: ; preds = %468
%489 = load i64, i64* %29
%490 = icmp slt i64 %489, 0
br i1 %490, label %491, label %494
491: ; preds = %488
%492 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0))
%493 = call i32 @exit(i32 1)
unreachable
494: ; preds = %488
%495 = load i64, i64* %29
%496 = call i32 @waitpid(i64 %495, i32 0, i32 0)
%497 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%498 = load i32, i32* %497
%499 = call i32 @close(i32 %498)
br label %500
500: ; preds = %494
br label %501
501: ; preds = %500
br label %502
502: ; preds = %501, %465
%503 = load i32, i32* %5
%504 = icmp ne i32 %503, -1
br i1 %504, label %505, label %508
505: ; preds = %502
%506 = load i32, i32* %5
%507 = call i32 @close(i32 %506)
br label %508
508: ; preds = %505, %502
br label %31
509: ; preds = %80
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str = [10 x i8] c"My Shell>\00"
@.str.1 = [4 x i8] c" > \00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@.str.3 = [5 x i8] c" >> \00"
@O_APPEND = global i32 0
@.str.4 = [5 x i8] c" 2> \00"
@.str.5 = [6 x i8] c" 2>> \00"
@.str.6 = [4 x i8] c" < \00"
@O_RDONLY = global i32 0
@.str.7 = [4 x i8] c" | \00"
@str.16 = [13 x i8] c"fork failed.\00"
@str.17 = [28 x i8] c"cannot redirect pipe stdout\00"
@str.18 = [23 x i8] c"cannot redirect stderr\00"
@str.19 = [23 x i8] c"cannot redirect stdout\00"
@str.20 = [22 x i8] c"cannot redirect stdin\00"
@str.21 = [73 x i8] c"Combinations of several special characters are not supported, try again.\00"
@str.26 = [24 x i8] c"cannot open output file\00"
define i32 @main() {
%1 = alloca [2048 x i8]
%2 = alloca [2 x i32]
%3 = alloca [2048 x [1048 x i8]]
%4 = alloca [2048 x i8*]
%5 = alloca [2048 x [1048 x i8]]
%6 = alloca [2048 x i8*]
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 4
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 5
%10 = bitcast [2 x i32]* %2 to i8*
%11 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %3, i64 0, i64 0, i64 0
%12 = bitcast [2048 x i8*]* %4 to i8*
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%14 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %5, i64 0, i64 0, i64 0
%15 = bitcast [2048 x i8*]* %6 to i8*
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%17 = bitcast [2048 x i8]* %1 to <4 x i8>*
br label %18
18: ; preds = %326, %0
%19 = load i32, i32* @stdout
%20 = call i32 @fileno(i32 %19)
%21 = load i32, i32* @stdout
%22 = call i32 @fileno(i32 %21)
%23 = call i32 @dup2(i32 %20, i32 %22)
%24 = load i32, i32* @stdin
%25 = call i32 @fileno(i32 %24)
%26 = load i32, i32* @stdin
%27 = call i32 @fileno(i32 %26)
%28 = call i32 @dup2(i32 %25, i32 %27)
%29 = load i32, i32* @stderr
%30 = call i32 @fileno(i32 %29)
%31 = load i32, i32* @stderr
%32 = call i32 @fileno(i32 %31)
%33 = call i32 @dup2(i32 %30, i32 %32)
%34 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%35 = load i32, i32* @stdin
%36 = call i32 @fgets(i8* %7, i32 2048, i32 %35)
%37 = load <4 x i8>, <4 x i8>* %17
%38 = freeze <4 x i8> %37
%39 = bitcast <4 x i8> %38 to i32
%40 = icmp eq i32 %39, 1953069157
%41 = load i8, i8* %8
%42 = icmp eq i8 %41, 10
%43 = select i1 %40, i1 %42, i1 false
%44 = load i8, i8* %9
%45 = icmp eq i8 %44, 0
%46 = select i1 %43, i1 %45, i1 false
br i1 %46, label %327, label %47
47: ; preds = %18
%48 = call i32 @strlen(i8* %7)
%49 = add nsw i32 %48, -1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %50
store i8 0, i8* %51
%52 = call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%53 = icmp eq i8* %52, null
br i1 %53, label %67, label %54
54: ; preds = %47
%55 = getelementptr inbounds i8, i8* %52, i64 3
%56 = load i32, i32* @O_WRONLY
%57 = load i32, i32* @O_CREAT
%58 = or i32 %57, %56
%59 = load i32, i32* @O_TRUNC
%60 = or i32 %58, %59
%61 = load i32, i32* @S_IRWXU
%62 = call i32 (i8*, i32, ...) @open(i8* %55, i32 %60, i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %54
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.26, i64 0, i64 0))
br label %326
66: ; preds = %54
store i8 0, i8* %52
br label %67
67: ; preds = %66, %47
%68 = phi i32 [ %62, %66 ], [ -1, %47 ]
%69 = phi i32 [ 1, %66 ], [ 0, %47 ]
%70 = call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%71 = icmp eq i8* %70, null
br i1 %71, label %86, label %72
72: ; preds = %67
%73 = getelementptr inbounds i8, i8* %70, i64 4
%74 = load i32, i32* @O_WRONLY
%75 = load i32, i32* @O_CREAT
%76 = or i32 %75, %74
%77 = load i32, i32* @O_APPEND
%78 = or i32 %76, %77
%79 = load i32, i32* @S_IRWXU
%80 = call i32 (i8*, i32, ...) @open(i8* %73, i32 %78, i32 %79)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %84
82: ; preds = %72
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.26, i64 0, i64 0))
br label %326
84: ; preds = %72
%85 = add nuw nsw i32 %69, 1
store i8 0, i8* %70
br label %86
86: ; preds = %84, %67
%87 = phi i32 [ 1, %84 ], [ %69, %67 ]
%88 = phi i32 [ %80, %84 ], [ %68, %67 ]
%89 = phi i32 [ %85, %84 ], [ %69, %67 ]
%90 = call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%91 = icmp eq i8* %90, null
br i1 %91, label %106, label %92
92: ; preds = %86
%93 = getelementptr inbounds i8, i8* %90, i64 4
%94 = load i32, i32* @O_WRONLY
%95 = load i32, i32* @O_CREAT
%96 = or i32 %95, %94
%97 = load i32, i32* @O_TRUNC
%98 = or i32 %96, %97
%99 = load i32, i32* @S_IRWXU
%100 = call i32 (i8*, i32, ...) @open(i8* %93, i32 %98, i32 %99)
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %104
102: ; preds = %92
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.26, i64 0, i64 0))
br label %326
104: ; preds = %92
%105 = add nuw nsw i32 %89, 1
store i8 0, i8* %90
br label %106
106: ; preds = %104, %86
%107 = phi i32 [ 1, %104 ], [ 0, %86 ]
%108 = phi i32 [ %100, %104 ], [ %88, %86 ]
%109 = phi i32 [ %105, %104 ], [ %89, %86 ]
%110 = call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%111 = icmp eq i8* %110, null
br i1 %111, label %126, label %112
112: ; preds = %106
%113 = getelementptr inbounds i8, i8* %110, i64 5
%114 = load i32, i32* @O_WRONLY
%115 = load i32, i32* @O_CREAT
%116 = or i32 %115, %114
%117 = load i32, i32* @O_APPEND
%118 = or i32 %116, %117
%119 = load i32, i32* @S_IRWXU
%120 = call i32 (i8*, i32, ...) @open(i8* %113, i32 %118, i32 %119)
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %124
122: ; preds = %112
%123 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.26, i64 0, i64 0))
br label %326
124: ; preds = %112
%125 = add nuw nsw i32 %109, 1
store i8 0, i8* %110
br label %126
126: ; preds = %124, %106
%127 = phi i32 [ 1, %124 ], [ %107, %106 ]
%128 = phi i32 [ %120, %124 ], [ %108, %106 ]
%129 = phi i32 [ %125, %124 ], [ %109, %106 ]
%130 = call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%131 = icmp eq i8* %130, null
br i1 %131, label %141, label %132
132: ; preds = %126
%133 = getelementptr inbounds i8, i8* %130, i64 3
%134 = load i32, i32* @O_RDONLY
%135 = call i32 (i8*, i32, ...) @open(i8* %133, i32 %134)
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %139
137: ; preds = %132
%138 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.26, i64 0, i64 0))
br label %326
139: ; preds = %132
%140 = add nuw nsw i32 %129, 1
store i8 0, i8* %130
br label %141
141: ; preds = %139, %126
%142 = phi i32 [ %135, %139 ], [ %128, %126 ]
%143 = phi i32 [ %140, %139 ], [ %129, %126 ]
%144 = call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%145 = icmp eq i8* %144, null
br i1 %145, label %185, label %146
146: ; preds = %141
%147 = call i32 @pipe(i32* %13)
%148 = getelementptr inbounds i8, i8* %144, i64 3
%149 = add nuw nsw i32 %143, 1
store i8 0, i8* %144
%150 = load i8, i8* %148
%151 = icmp eq i8 %150, 0
br i1 %151, label %181, label %152
152: ; preds = %146, %165
%153 = phi i64 [ %172, %165 ], [ 0, %146 ]
%154 = phi i32 [ %176, %165 ], [ 0, %146 ]
%155 = sext i32 %154 to i64
br label %156
156: ; preds = %152, %161
%157 = phi i64 [ 0, %152 ], [ %163, %161 ]
%158 = phi i64 [ %155, %152 ], [ %164, %161 ]
%159 = getelementptr inbounds i8, i8* %148, i64 %158
%160 = load i8, i8* %159
switch i8 %160, label %161 [
i8 0, label %165
i8 32, label %165
]
161: ; preds = %156
%162 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %3, i64 0, i64 %153, i64 %157
store i8 %160, i8* %162
%163 = add nuw i64 %157, 1
%164 = add i64 %158, 1
br label %156
165: ; preds = %156, %156
%166 = getelementptr inbounds i8, i8* %148, i64 %158
%167 = trunc i64 %158 to i32
%168 = and i64 %157, 4294967295
%169 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %3, i64 0, i64 %153, i64 %168
store i8 0, i8* %169
%170 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %3, i64 0, i64 %153, i64 0
%171 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %4, i64 0, i64 %153
store i8* %170, i8** %171
%172 = add nuw i64 %153, 1
%173 = load i8, i8* %166
%174 = icmp ne i8 %173, 0
%175 = zext i1 %174 to i32
%176 = add nsw i32 %167, %175
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds i8, i8* %148, i64 %177
%179 = load i8, i8* %178
%180 = icmp eq i8 %179, 0
br i1 %180, label %181, label %152
181: ; preds = %165, %146
%182 = phi i64 [ 0, %146 ], [ %172, %165 ]
%183 = and i64 %182, 4294967295
%184 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %4, i64 0, i64 %183
store i8* null, i8** %184
br label %185
185: ; preds = %181, %141
%186 = phi i32 [ %149, %181 ], [ %143, %141 ]
%187 = call i8* @strchr(i8* %7, i32 38)
%188 = icmp eq i8* %187, null
br i1 %188, label %191, label %189
189: ; preds = %185
%190 = add nsw i32 %186, 1
store i8 0, i8* %187
br label %191
191: ; preds = %189, %185
%192 = phi i32 [ %190, %189 ], [ %186, %185 ]
%193 = icmp sgt i32 %192, 1
br i1 %193, label %194, label %196
194: ; preds = %191
%195 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.21, i64 0, i64 0))
br label %325
196: ; preds = %191
%197 = load i8, i8* %7
%198 = icmp eq i8 %197, 0
br i1 %198, label %226, label %199
199: ; preds = %196, %212
%200 = phi i64 [ %218, %212 ], [ 0, %196 ]
%201 = phi i32 [ %221, %212 ], [ 0, %196 ]
%202 = sext i32 %201 to i64
br label %203
203: ; preds = %199, %208
%204 = phi i64 [ 0, %199 ], [ %210, %208 ]
%205 = phi i64 [ %202, %199 ], [ %211, %208 ]
%206 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %205
%207 = load i8, i8* %206
switch i8 %207, label %208 [
i8 0, label %212
i8 32, label %212
]
208: ; preds = %203
%209 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %5, i64 0, i64 %200, i64 %204
store i8 %207, i8* %209
%210 = add nuw i64 %204, 1
%211 = add i64 %205, 1
br label %203
212: ; preds = %203, %203
%213 = trunc i64 %205 to i32
%214 = and i64 %204, 4294967295
%215 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %5, i64 0, i64 %200, i64 %214
store i8 0, i8* %215
%216 = getelementptr inbounds [2048 x [1048 x i8]], [2048 x [1048 x i8]]* %5, i64 0, i64 %200, i64 0
%217 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %6, i64 0, i64 %200
store i8* %216, i8** %217
%218 = add nuw i64 %200, 1
%219 = icmp ne i8 %207, 0
%220 = zext i1 %219 to i32
%221 = add nsw i32 %213, %220
%222 = sext i32 %221 to i64
%223 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %222
%224 = load i8, i8* %223
%225 = icmp eq i8 %224, 0
br i1 %225, label %226, label %199
226: ; preds = %212, %196
%227 = phi i64 [ 0, %196 ], [ %218, %212 ]
%228 = and i64 %227, 4294967295
%229 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %6, i64 0, i64 %228
store i8* null, i8** %229
%230 = call i64 (...) @fork()
%231 = icmp eq i64 %230, 0
br i1 %231, label %232, label %283
232: ; preds = %226
br i1 %131, label %241, label %233
233: ; preds = %232
%234 = load i32, i32* @stdin
%235 = call i32 @fileno(i32 %234)
%236 = call i32 @dup2(i32 %142, i32 %235)
%237 = icmp eq i32 %236, -1
br i1 %237, label %238, label %241
238: ; preds = %233
%239 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.20, i64 0, i64 0))
%240 = call i32 @exit(i32 1)
unreachable
241: ; preds = %233, %232
%242 = icmp eq i32 %87, 0
br i1 %242, label %251, label %243
243: ; preds = %241
%244 = load i32, i32* @stdout
%245 = call i32 @fileno(i32 %244)
%246 = call i32 @dup2(i32 %142, i32 %245)
%247 = icmp eq i32 %246, -1
br i1 %247, label %248, label %251
248: ; preds = %243
%249 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.19, i64 0, i64 0))
%250 = call i32 @exit(i32 1)
unreachable
251: ; preds = %243, %241
%252 = icmp eq i32 %127, 0
br i1 %252, label %261, label %253
253: ; preds = %251
%254 = load i32, i32* @stderr
%255 = call i32 @fileno(i32 %254)
%256 = call i32 @dup2(i32 %142, i32 %255)
%257 = icmp eq i32 %256, -1
br i1 %257, label %258, label %261
258: ; preds = %253
%259 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.18, i64 0, i64 0))
%260 = call i32 @exit(i32 1)
unreachable
261: ; preds = %253, %251
br i1 %145, label %277, label %262
262: ; preds = %261
%263 = load i32, i32* %16
%264 = load i32, i32* @stdout
%265 = call i32 @fileno(i32 %264)
%266 = call i32 @dup2(i32 %263, i32 %265)
%267 = icmp eq i32 %266, -1
br i1 %267, label %268, label %271
268: ; preds = %262
%269 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.17, i64 0, i64 0))
%270 = call i32 @exit(i32 1)
unreachable
271: ; preds = %262
%272 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %6, i64 0, i64 0
%273 = load i8*, i8** %272
%274 = call i32 @execvp(i8* %273, i8** %272)
%275 = load i32, i32* %16
%276 = call i32 @close(i32 %275)
br label %281
277: ; preds = %261
%278 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %6, i64 0, i64 0
%279 = load i8*, i8** %278
%280 = call i32 @execvp(i8* %279, i8** %278)
br label %281
281: ; preds = %277, %271
%282 = call i32 @exit(i32 1)
unreachable
283: ; preds = %226
%284 = icmp slt i64 %230, 0
br i1 %284, label %285, label %288
285: ; preds = %283
%286 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.16, i64 0, i64 0))
%287 = call i32 @exit(i32 1)
unreachable
288: ; preds = %283
br i1 %188, label %289, label %291
289: ; preds = %288
%290 = call i32 @waitpid(i64 %230, i32 0, i32 0)
br label %291
291: ; preds = %288, %289
br i1 %145, label %320, label %292
292: ; preds = %291
%293 = load i32, i32* %16
%294 = call i32 @close(i32 %293)
%295 = call i64 (...) @fork()
%296 = icmp eq i64 %295, 0
br i1 %296, label %297, label %311
297: ; preds = %292
%298 = load i32, i32* %13
%299 = load i32, i32* @stdin
%300 = call i32 @fileno(i32 %299)
%301 = call i32 @dup2(i32 %298, i32 %300)
%302 = icmp eq i32 %301, -1
br i1 %302, label %303, label %306
303: ; preds = %297
%304 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.20, i64 0, i64 0))
%305 = call i32 @exit(i32 1)
unreachable
306: ; preds = %297
%307 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %4, i64 0, i64 0
%308 = load i8*, i8** %307
%309 = call i32 @execvp(i8* %308, i8** %307)
%310 = call i32 @exit(i32 1)
unreachable
311: ; preds = %292
%312 = icmp slt i64 %295, 0
br i1 %312, label %313, label %316
313: ; preds = %311
%314 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.16, i64 0, i64 0))
%315 = call i32 @exit(i32 1)
unreachable
316: ; preds = %311
%317 = call i32 @waitpid(i64 %295, i32 0, i32 0)
%318 = load i32, i32* %13
%319 = call i32 @close(i32 %318)
br label %320
320: ; preds = %291, %316
%321 = icmp eq i32 %142, -1
br i1 %321, label %324, label %322
322: ; preds = %320
%323 = call i32 @close(i32 %142)
br label %324
324: ; preds = %322, %320
br label %325
325: ; preds = %324, %194
br label %326
326: ; preds = %137, %122, %102, %82, %64, %325
br label %18
327: ; preds = %18
ret i32 0
}