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

/* Variables and functions */
int BUFSIZ;
int EXIT_SUCCESS;
int O_APPEND;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int S_IRGRP;
int S_IRUSR;
int S_IWUSR;
int WEXITSTATUS(int);
scalar_t__ chdir(char *);
int /*<<< orphan*/ close(int);
int dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeArgs(int, char **);
int getcmd(char ***, int, int *, char **, char **, char **, int *);
int /*<<< orphan*/ getcwd(char *, int);
char *getenv(char *);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ processChildren(int);
int /*<<< orphan*/ setenv(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(void) {
  char **argv, *fileIn = NULL, *fileOut = NULL, *fileErr = NULL, cwd[BUFSIZ];
  int argc, son_status, retVal = 0, redir = 0, out = 1, in = 0, err = 2,
                        wait = 0, tube[2];
  pid_t pid;
  printf("Welcome on DATShell! (Damn, Another Tiny Shell !).\n");
  while (1) {
    processChildren(0);
    argc = getcmd(&argv, retVal, &redir, &fileOut, &fileIn, &fileErr, &wait);
    if (strcmp(argv[0], "exit") == 0) {
      printf("Exiting DatShell!\n");
      freeArgs(argc, argv);
      processChildren(1);
      return EXIT_SUCCESS;
    } else if (strcmp(argv[0], "cd") == 0) {
      if (argc == 1)
        chdir(getenv("HOME"));
      else if (chdir(argv[1])) {
        perror("Unable to cd ");
      }
      setenv("PWD", getcwd(cwd, BUFSIZ), 1);
    } else {
      pid = fork();
      switch (pid) {
      case -1:
        perror("Unable to fork.");
        freeArgs(argc, argv);
        return 1;
        break;
      case 0:
        switch (redir) {
        case 1:
          out = open(fileOut, O_WRONLY | O_CREAT | O_TRUNC,
                     S_IRUSR | S_IWUSR | S_IRGRP);
          if (out == -1) {
            perror("Unable to open file ");
            exit(2);
          }
          if (dup2(out, STDOUT_FILENO) == -1) {
            perror("Unable to redirect ");
            exit(3);
          }
          break;
        case 2:
          out = open(fileOut, O_WRONLY | O_CREAT | O_APPEND,
                     S_IRUSR | S_IWUSR | S_IRGRP);
          if (out == -1) {
            perror("Unable to open file ");
            exit(2);
          }
          if (dup2(out, STDOUT_FILENO) == -1) {
            perror("Unable to redirect ");
            exit(3);
          }
          break;
        case 4:
          in = open(fileIn, O_RDONLY);
          if (in == -1) {
            perror("Unable to open file ");
            exit(2);
          }
          if (dup2(in, STDIN_FILENO) == -1) {
            perror("Unable to redirect ");
            exit(3);
          }
          break;
        case 8:
          err = open(fileErr, O_WRONLY | O_CREAT | O_APPEND,
                     S_IRUSR | S_IWUSR | S_IRGRP);
          if (err == -1) {
            perror("Unable to open file ");
            exit(2);
          }
          if (dup2(err, STDERR_FILENO) == -1) {
            perror("Unable to redirect ");
            exit(3);
          }
          break;
        case 16:
          if (pipe(tube) == -1) {
            perror("Unable to create pipe ");
            exit(4);
          }
          switch (fork()) {
          case -1:
            perror("Unable to fork !");
            return 1;
            break;
          case 0:
            close(tube[0]);
            if (dup2(tube[1], STDOUT_FILENO) == -1) {
              perror("Unable to redirect ");
              exit(3);
            }
            execvp(argv[0], argv);
            fprintf(stderr, "ttsh : command not found : %s\n", argv[0]);
            freeArgs(argc, argv);
            return -1;
            break;
          default:
            argc = getcmd(&argv, retVal, &redir, &fileOut, &fileIn, &fileErr,
                          &wait);
            close(tube[1]);
            if (dup2(tube[0], STDIN_FILENO) == -1) {
              perror("Unable to redirect ");
              exit(3);
            }
            execvp(argv[0], argv);
            fprintf(stderr, "ttsh : command not found : %s\n", argv[0]);
            freeArgs(argc, argv);
          }
          break;
        }
        execvp(argv[0], argv);
        fprintf(stderr, "ttsh : command not found : %s\n", argv[0]);
        freeArgs(argc, argv);
        return -1;
        break;
      default:
        if (redir == 16) {
          argc =
              getcmd(&argv, retVal, &redir, &fileOut, &fileIn, &fileErr, &wait);
        }
        redir = 0;
        if (wait == 0) {
          waitpid(pid, &son_status, 0);
          retVal = WEXITSTATUS(son_status);
        } else {
          processChildren(pid);
        }
      }
    }
    freeArgs(argc, argv);
    free(fileIn);
    free(fileOut);
    free(fileErr);
    fileIn = NULL;
    fileOut = NULL;
    fileErr = NULL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x2,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
lea    0xd69(%rip),%rdi
call   1090 <printf@plt>
jmp    12e1 <main+0x91>
xor    %edi,%edi
call   1170 <processChildren@plt>
mov    -0x44(%rbp),%esi
lea    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x18(%rbp),%r8
lea    -0x28(%rbp),%r9
lea    -0x58(%rbp),%rax
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1060 <getcmd@plt>
add    $0x10,%rsp
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd4f(%rip),%rsi
call   10e0 <strcmp@plt>
cmp    $0x0,%rax
jne    136e <main+0x11e>
lea    0xd3e(%rip),%rdi
call   1090 <printf@plt>
mov    -0x3c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <freeArgs@plt>
mov    $0x1,%edi
call   1170 <processChildren@plt>
mov    0x2c33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    1965 <main+0x715>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd10(%rip),%rsi
call   10e0 <strcmp@plt>
cmp    $0x0,%rax
jne    1400 <main+0x1b0>
cmpl   $0x1,-0x3c(%rbp)
jne    13ae <main+0x15e>
lea    0xcf3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1070 <chdir@plt>
jmp    13d6 <main+0x186>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <chdir@plt>
cmp    $0x0,%rax
je     13d1 <main+0x181>
lea    0xcc8(%rip),%rdi
call   1130 <perror@plt>
jmp    13d6 <main+0x186>
mov    -0x70(%rbp),%rdi
mov    0x2bcf(%rip),%rax
mov    (%rax),%esi
call   10a0 <getcwd@plt>
mov    %eax,%esi
lea    0xcb1(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
jmp    191c <main+0x6cc>
xor    %eax,%eax
call   1160 <fork@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x74(%rbp)
sub    $0xffffffff,%eax
je     142e <main+0x1de>
jmp    141e <main+0x1ce>
mov    -0x74(%rbp),%eax
test   %eax,%eax
je     1459 <main+0x209>
jmp    18a2 <main+0x652>
lea    0xc71(%rip),%rdi
call   1130 <perror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <freeArgs@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    1965 <main+0x715>
mov    -0x48(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x80(%rbp)
sub    $0xf,%eax
ja     1857 <main+0x607>
mov    -0x80(%rbp),%rax
lea    0xb87(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rdi
mov    0x2aeb(%rip),%rax
mov    (%rax),%esi
mov    0x2b62(%rip),%rax
or     (%rax),%esi
mov    0x2b51(%rip),%rax
or     (%rax),%esi
mov    0x2af0(%rip),%rax
mov    (%rax),%edx
mov    0x2b17(%rip),%rax
or     (%rax),%edx
mov    0x2ae6(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1120 <open@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    14e6 <main+0x296>
lea    0xbdf(%rip),%rdi
call   1130 <perror@plt>
mov    $0x2,%edi
call   1150 <exit@plt>
mov    -0x4c(%rbp),%edi
mov    0x2af0(%rip),%rax
mov    (%rax),%esi
call   1080 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1516 <main+0x2c6>
lea    0xbc4(%rip),%rdi
call   1130 <perror@plt>
mov    $0x3,%edi
call   1150 <exit@plt>
jmp    1857 <main+0x607>
mov    -0x20(%rbp),%rdi
mov    0x2a52(%rip),%rax
mov    (%rax),%esi
mov    0x2ac9(%rip),%rax
or     (%rax),%esi
mov    0x2a38(%rip),%rax
or     (%rax),%esi
mov    0x2a57(%rip),%rax
mov    (%rax),%edx
mov    0x2a7e(%rip),%rax
or     (%rax),%edx
mov    0x2a4d(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1120 <open@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    157f <main+0x32f>
lea    0xb46(%rip),%rdi
call   1130 <perror@plt>
mov    $0x2,%edi
call   1150 <exit@plt>
mov    -0x4c(%rbp),%edi
mov    0x2a57(%rip),%rax
mov    (%rax),%esi
call   1080 <dup2@plt>
cmp    $0xffffffff,%eax
jne    15af <main+0x35f>
lea    0xb2b(%rip),%rdi
call   1130 <perror@plt>
mov    $0x3,%edi
call   1150 <exit@plt>
jmp    1857 <main+0x607>
mov    -0x18(%rbp),%rdi
mov    0x2a11(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1120 <open@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x50(%rbp)
jne    15eb <main+0x39b>
lea    0xada(%rip),%rdi
call   1130 <perror@plt>
mov    $0x2,%edi
call   1150 <exit@plt>
mov    -0x50(%rbp),%edi
mov    0x2993(%rip),%rax
mov    (%rax),%esi
call   1080 <dup2@plt>
cmp    $0xffffffff,%eax
jne    161b <main+0x3cb>
lea    0xabf(%rip),%rdi
call   1130 <perror@plt>
mov    $0x3,%edi
call   1150 <exit@plt>
jmp    1857 <main+0x607>
mov    -0x28(%rbp),%rdi
mov    0x294d(%rip),%rax
mov    (%rax),%esi
mov    0x29c4(%rip),%rax
or     (%rax),%esi
mov    0x2933(%rip),%rax
or     (%rax),%esi
mov    0x2952(%rip),%rax
mov    (%rax),%edx
mov    0x2979(%rip),%rax
or     (%rax),%edx
mov    0x2948(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1120 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    1684 <main+0x434>
lea    0xa41(%rip),%rdi
call   1130 <perror@plt>
mov    $0x2,%edi
call   1150 <exit@plt>
mov    -0x54(%rbp),%edi
mov    0x291a(%rip),%rax
mov    (%rax),%esi
call   1080 <dup2@plt>
cmp    $0xffffffff,%eax
jne    16b4 <main+0x464>
lea    0xa26(%rip),%rdi
call   1130 <perror@plt>
mov    $0x3,%edi
call   1150 <exit@plt>
jmp    1857 <main+0x607>
lea    -0x60(%rbp),%rdi
call   10c0 <pipe@plt>
cmp    $0xffffffff,%eax
jne    16e1 <main+0x491>
lea    0xa0d(%rip),%rdi
call   1130 <perror@plt>
mov    $0x4,%edi
call   1150 <exit@plt>
xor    %eax,%eax
call   1160 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x84(%rbp)
sub    $0xffffffff,%eax
je     1711 <main+0x4c1>
jmp    16fe <main+0x4ae>
mov    -0x84(%rbp),%eax
test   %eax,%eax
je     1730 <main+0x4e0>
jmp    17b3 <main+0x563>
lea    0x9de(%rip),%rdi
call   1130 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    1965 <main+0x715>
mov    -0x60(%rbp),%edi
call   10b0 <close@plt>
mov    -0x5c(%rbp),%edi
mov    0x289e(%rip),%rax
mov    (%rax),%esi
call   1080 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1768 <main+0x518>
lea    0x972(%rip),%rdi
call   1130 <perror@plt>
mov    $0x3,%edi
call   1150 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1140 <execvp@plt>
mov    0x2839(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x978(%rip),%rsi
call   10f0 <fprintf@plt>
mov    -0x3c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <freeArgs@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    1965 <main+0x715>
mov    -0x44(%rbp),%esi
lea    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x18(%rbp),%r8
lea    -0x28(%rbp),%r9
lea    -0x58(%rbp),%rax
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1060 <getcmd@plt>
add    $0x10,%rsp
mov    %eax,-0x3c(%rbp)
mov    -0x5c(%rbp),%edi
call   10b0 <close@plt>
mov    -0x60(%rbp),%edi
mov    0x2794(%rip),%rax
mov    (%rax),%esi
call   1080 <dup2@plt>
cmp    $0xffffffff,%eax
jne    181a <main+0x5ca>
lea    0x8c0(%rip),%rdi
call   1130 <perror@plt>
mov    $0x3,%edi
call   1150 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1140 <execvp@plt>
mov    0x2787(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x8c6(%rip),%rsi
call   10f0 <fprintf@plt>
mov    -0x3c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <freeArgs@plt>
jmp    1857 <main+0x607>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1140 <execvp@plt>
mov    0x274a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x889(%rip),%rsi
call   10f0 <fprintf@plt>
mov    -0x3c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <freeArgs@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    1965 <main+0x715>
cmpl   $0x10,-0x48(%rbp)
jne    18db <main+0x68b>
mov    -0x44(%rbp),%esi
lea    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x18(%rbp),%r8
lea    -0x28(%rbp),%r9
lea    -0x58(%rbp),%rax
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1060 <getcmd@plt>
add    $0x10,%rsp
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x48(%rbp)
cmpl   $0x0,-0x58(%rbp)
jne    190a <main+0x6ba>
mov    -0x64(%rbp),%edi
lea    -0x40(%rbp),%rsi
xor    %edx,%edx
call   1110 <waitpid@plt>
mov    -0x40(%rbp),%edi
call   1100 <WEXITSTATUS@plt>
mov    %eax,-0x44(%rbp)
jmp    1912 <main+0x6c2>
mov    -0x64(%rbp),%edi
call   1170 <processChildren@plt>
jmp    1917 <main+0x6c7>
jmp    191c <main+0x6cc>
jmp    1921 <main+0x6d1>
mov    -0x3c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <freeArgs@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
jmp    12dc <main+0x8c>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsp,-0x68(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    0x2d2c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
lea    0xe2f(%rip),%rdi
call   1050 <puts@plt>
lea    -0x50(%rbp),%r12
lea    -0x48(%rbp),%r13
xor    %r14d,%r14d
jmp    1327 <main+0xd7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0x0,-0x34(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1400 <main+0x1b0>
mov    %r15d,%edi
call   1170 <processChildren@plt>
mov    -0x30(%rbp),%rsi
mov    %ebx,%edi
call   10d0 <freeArgs@plt>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
xor    %edi,%edi
call   1170 <processChildren@plt>
sub    $0x8,%rsp
lea    -0x30(%rbp),%rdi
mov    %r14d,%esi
lea    -0x34(%rbp),%rdx
lea    -0x40(%rbp),%rcx
mov    %r12,%r8
mov    %r13,%r9
lea    -0x38(%rbp),%rax
push   %rax
call   1070 <getcmd@plt>
add    $0x10,%rsp
mov    %eax,%ebx
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
lea    0xcdb(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     1468 <main+0x218>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
lea    0xcc4(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     13e0 <main+0x190>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
je     1497 <main+0x247>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     16c0 <main+0x470>
cmpl   $0x10,-0x34(%rbp)
jne    12d0 <main+0x80>
sub    $0x8,%rsp
lea    -0x30(%rbp),%rdi
mov    %r14d,%esi
lea    -0x34(%rbp),%rdx
lea    -0x40(%rbp),%rcx
mov    %r12,%r8
mov    %r13,%r9
lea    -0x38(%rbp),%rax
push   %rax
call   1070 <getcmd@plt>
add    $0x10,%rsp
mov    %eax,%ebx
jmp    12d0 <main+0x80>
xchg   %ax,%ax
cmp    $0x1,%ebx
jne    141e <main+0x1ce>
lea    0xc5c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1080 <chdir@plt>
jmp    1430 <main+0x1e0>
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
lea    -0x5c(%rbp),%rsi
xor    %edx,%edx
call   1110 <waitpid@plt>
mov    -0x5c(%rbp),%edi
call   1100 <WEXITSTATUS@plt>
mov    %eax,%r14d
jmp    12e9 <main+0x99>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <chdir@plt>
test   %rax,%rax
jne    145a <main+0x20a>
mov    0x2b79(%rip),%rax
mov    (%rax),%esi
mov    -0x70(%rbp),%rdi
call   10a0 <getcwd@plt>
lea    0xc12(%rip),%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1060 <setenv@plt>
jmp    12e9 <main+0x99>
lea    0xbec(%rip),%rdi
call   1130 <perror@plt>
jmp    1430 <main+0x1e0>
lea    0xca3(%rip),%rdi
call   1050 <puts@plt>
mov    -0x30(%rbp),%rsi
mov    %ebx,%edi
call   10d0 <freeArgs@plt>
mov    $0x1,%edi
call   1170 <processChildren@plt>
mov    0x2b00(%rip),%rax
mov    (%rax),%eax
jmp    15e5 <main+0x395>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
cmp    $0xf,%eax
ja     15ad <main+0x35d>
lea    0xb53(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2abb(%rip),%rax
mov    0x2b34(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2b21(%rip),%rax
jmp    14ea <main+0x29a>
mov    0x2aa0(%rip),%rax
mov    0x2b19(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2a86(%rip),%rax
or     (%rax),%esi
mov    0x2aa5(%rip),%rax
mov    0x2ace(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    -0x40(%rbp),%rdi
mov    0x2a97(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   1120 <open@plt>
cmp    $0xffffffff,%eax
je     170d <main+0x4bd>
mov    0x2abe(%rip),%rcx
jmp    159b <main+0x34b>
mov    -0x50(%rbp),%rdi
mov    0x2aa1(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1120 <open@plt>
cmp    $0xffffffff,%eax
je     170d <main+0x4bd>
mov    0x2a40(%rip),%rcx
jmp    159b <main+0x34b>
mov    0x2a27(%rip),%rax
mov    0x2aa0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2a0d(%rip),%rax
or     (%rax),%esi
mov    0x2a2c(%rip),%rax
mov    0x2a55(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    -0x48(%rbp),%rdi
mov    0x2a1e(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   1120 <open@plt>
cmp    $0xffffffff,%eax
je     170d <main+0x4bd>
mov    0x2a0d(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1090 <dup2@plt>
cmp    $0xffffffff,%eax
je     16f7 <main+0x4a7>
mov    -0x30(%rbp),%rsi
mov    (%rsi),%rdi
call   1140 <execvp@plt>
mov    0x29f8(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
lea    0xaf0(%rip),%rsi
call   10f0 <fprintf@plt>
mov    -0x30(%rbp),%rsi
mov    %ebx,%edi
call   10d0 <freeArgs@plt>
mov    $0xffffffff,%eax
mov    -0x68(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    -0x58(%rbp),%rdi
call   10c0 <pipe@plt>
cmp    $0xffffffff,%eax
je     1723 <main+0x4d3>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
je     16a7 <main+0x457>
cmp    $0xffffffff,%eax
je     16e1 <main+0x491>
sub    $0x8,%rsp
lea    -0x30(%rbp),%rdi
lea    -0x34(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x50(%rbp),%r8
lea    -0x48(%rbp),%r9
mov    %r14d,%esi
lea    -0x38(%rbp),%rax
push   %rax
call   1070 <getcmd@plt>
add    $0x10,%rsp
mov    %eax,%ebx
mov    -0x54(%rbp),%edi
call   10b0 <close@plt>
mov    -0x58(%rbp),%edi
mov    0x2929(%rip),%rax
mov    (%rax),%esi
call   1090 <dup2@plt>
cmp    $0xffffffff,%eax
je     16f7 <main+0x4a7>
mov    -0x30(%rbp),%rsi
mov    (%rsi),%rdi
call   1140 <execvp@plt>
mov    0x2936(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
lea    0xa2e(%rip),%rsi
call   10f0 <fprintf@plt>
mov    -0x30(%rbp),%rsi
mov    %ebx,%edi
call   10d0 <freeArgs@plt>
jmp    15ad <main+0x35d>
mov    -0x58(%rbp),%edi
call   10b0 <close@plt>
mov    -0x54(%rbp),%edi
mov    0x2927(%rip),%rax
mov    (%rax),%esi
jmp    159f <main+0x34f>
lea    0x998(%rip),%rdi
call   1130 <perror@plt>
mov    -0x30(%rbp),%rsi
mov    %ebx,%edi
call   10d0 <freeArgs@plt>
mov    $0x1,%eax
jmp    15e5 <main+0x395>
lea    0x9c7(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%eax
jmp    15e5 <main+0x395>
lea    0x986(%rip),%rdi
call   1130 <perror@plt>
mov    $0x3,%edi
call   1150 <exit@plt>
lea    0x95b(%rip),%rdi
call   1130 <perror@plt>
mov    $0x2,%edi
call   1150 <exit@plt>
lea    0x96e(%rip),%rdi
call   1130 <perror@plt>
mov    $0x4,%edi
call   1150 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [52 x i8] c"Welcome on DATShell! (Damn, Another Tiny Shell !).\0A\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [19 x i8] c"Exiting DatShell!\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.3 = [3 x i8] c"cd\00"
@.str.4 = [5 x i8] c"HOME\00"
@.str.5 = [14 x i8] c"Unable to cd \00"
@.str.6 = [4 x i8] c"PWD\00"
@.str.7 = [16 x i8] c"Unable to fork.\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@.str.8 = [21 x i8] c"Unable to open file \00"
@STDOUT_FILENO = global i32 0
@.str.9 = [20 x i8] c"Unable to redirect \00"
@O_APPEND = global i32 0
@O_RDONLY = global i32 0
@STDIN_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.10 = [23 x i8] c"Unable to create pipe \00"
@.str.11 = [17 x i8] c"Unable to fork !\00"
@stderr = global i32 0
@.str.12 = [31 x i8] c"ttsh : command not found : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [2 x i32]
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %3
store i8* null, i8** %4
store i8* null, i8** %5
%19 = load i32, i32* @BUFSIZ
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %6
%22 = alloca i8, i64 %20
store i64 %20, i64* %7
store i32 0, i32* %10
store i32 0, i32* %11
store i32 1, i32* %12
store i32 0, i32* %13
store i32 2, i32* %14
store i32 0, i32* %15
%23 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %275, %0
br label %25
25: ; preds = %24
%26 = call i32 @processChildren(i32 0)
%27 = load i32, i32* %10
%28 = call i32 @getcmd(i8*** %2, i32 %27, i32* %11, i8** %4, i8** %3, i8** %5, i32* %15)
store i32 %28, i32* %8
%29 = load i8**, i8*** %2
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %25
%35 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* %8
%37 = load i8**, i8*** %2
%38 = call i32 @freeArgs(i32 %36, i8** %37)
%39 = call i32 @processChildren(i32 1)
%40 = load i32, i32* @EXIT_SUCCESS
store i32 %40, i32* %1
store i32 1, i32* %18
br label %285
41: ; preds = %25
%42 = load i8**, i8*** %2
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %66
47: ; preds = %41
%48 = load i32, i32* %8
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%52 = call i64 @chdir(i8* %51)
br label %62
53: ; preds = %47
%54 = load i8**, i8*** %2
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i64 @chdir(i8* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %59, %53
br label %62
62: ; preds = %61, %50
%63 = load i32, i32* @BUFSIZ
%64 = call i32 @getcwd(i8* %22, i32 %63)
%65 = call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %64, i32 1)
br label %274
66: ; preds = %41
%67 = call i32 (...) @fork()
store i32 %67, i32* %17
%68 = load i32, i32* %17
switch i32 %68, label %255 [
i32 -1, label %69
i32 0, label %74
]
69: ; preds = %66
%70 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%71 = load i32, i32* %8
%72 = load i8**, i8*** %2
%73 = call i32 @freeArgs(i32 %71, i8** %72)
store i32 1, i32* %1
store i32 1, i32* %18
br label %285
74: ; preds = %66
%75 = load i32, i32* %11
switch i32 %75, label %241 [
i32 1, label %76
i32 2, label %103
i32 4, label %130
i32 8, label %148
i32 16, label %175
]
76: ; preds = %74
%77 = load i8*, i8** %4
%78 = load i32, i32* @O_WRONLY
%79 = load i32, i32* @O_CREAT
%80 = or i32 %78, %79
%81 = load i32, i32* @O_TRUNC
%82 = or i32 %80, %81
%83 = load i32, i32* @S_IRUSR
%84 = load i32, i32* @S_IWUSR
%85 = or i32 %83, %84
%86 = load i32, i32* @S_IRGRP
%87 = or i32 %85, %86
%88 = call i32 (i8*, i32, ...) @open(i8* %77, i32 %82, i32 %87)
store i32 %88, i32* %12
%89 = load i32, i32* %12
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %94
91: ; preds = %76
%92 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%93 = call i32 @exit(i32 2)
unreachable
94: ; preds = %76
%95 = load i32, i32* %12
%96 = load i32, i32* @STDOUT_FILENO
%97 = call i32 @dup2(i32 %95, i32 %96)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %102
99: ; preds = %94
%100 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%101 = call i32 @exit(i32 3)
unreachable
102: ; preds = %94
br label %241
103: ; preds = %74
%104 = load i8*, i8** %4
%105 = load i32, i32* @O_WRONLY
%106 = load i32, i32* @O_CREAT
%107 = or i32 %105, %106
%108 = load i32, i32* @O_APPEND
%109 = or i32 %107, %108
%110 = load i32, i32* @S_IRUSR
%111 = load i32, i32* @S_IWUSR
%112 = or i32 %110, %111
%113 = load i32, i32* @S_IRGRP
%114 = or i32 %112, %113
%115 = call i32 (i8*, i32, ...) @open(i8* %104, i32 %109, i32 %114)
store i32 %115, i32* %12
%116 = load i32, i32* %12
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %121
118: ; preds = %103
%119 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%120 = call i32 @exit(i32 2)
unreachable
121: ; preds = %103
%122 = load i32, i32* %12
%123 = load i32, i32* @STDOUT_FILENO
%124 = call i32 @dup2(i32 %122, i32 %123)
%125 = icmp eq i32 %124, -1
br i1 %125, label %126, label %129
126: ; preds = %121
%127 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%128 = call i32 @exit(i32 3)
unreachable
129: ; preds = %121
br label %241
130: ; preds = %74
%131 = load i8*, i8** %3
%132 = load i32, i32* @O_RDONLY
%133 = call i32 (i8*, i32, ...) @open(i8* %131, i32 %132)
store i32 %133, i32* %13
%134 = load i32, i32* %13
%135 = icmp eq i32 %134, -1
br i1 %135, label %136, label %139
136: ; preds = %130
%137 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%138 = call i32 @exit(i32 2)
unreachable
139: ; preds = %130
%140 = load i32, i32* %13
%141 = load i32, i32* @STDIN_FILENO
%142 = call i32 @dup2(i32 %140, i32 %141)
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %147
144: ; preds = %139
%145 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%146 = call i32 @exit(i32 3)
unreachable
147: ; preds = %139
br label %241
148: ; preds = %74
%149 = load i8*, i8** %5
%150 = load i32, i32* @O_WRONLY
%151 = load i32, i32* @O_CREAT
%152 = or i32 %150, %151
%153 = load i32, i32* @O_APPEND
%154 = or i32 %152, %153
%155 = load i32, i32* @S_IRUSR
%156 = load i32, i32* @S_IWUSR
%157 = or i32 %155, %156
%158 = load i32, i32* @S_IRGRP
%159 = or i32 %157, %158
%160 = call i32 (i8*, i32, ...) @open(i8* %149, i32 %154, i32 %159)
store i32 %160, i32* %14
%161 = load i32, i32* %14
%162 = icmp eq i32 %161, -1
br i1 %162, label %163, label %166
163: ; preds = %148
%164 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%165 = call i32 @exit(i32 2)
unreachable
166: ; preds = %148
%167 = load i32, i32* %14
%168 = load i32, i32* @STDERR_FILENO
%169 = call i32 @dup2(i32 %167, i32 %168)
%170 = icmp eq i32 %169, -1
br i1 %170, label %171, label %174
171: ; preds = %166
%172 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%173 = call i32 @exit(i32 3)
unreachable
174: ; preds = %166
br label %241
175: ; preds = %74
%176 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 0
%177 = call i32 @pipe(i32* %176)
%178 = icmp eq i32 %177, -1
br i1 %178, label %179, label %182
179: ; preds = %175
%180 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%181 = call i32 @exit(i32 4)
unreachable
182: ; preds = %175
%183 = call i32 (...) @fork()
switch i32 %183, label %212 [
i32 -1, label %184
i32 0, label %186
]
184: ; preds = %182
%185 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %1
store i32 1, i32* %18
br label %285
186: ; preds = %182
%187 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 0
%188 = load i32, i32* %187
%189 = call i32 @close(i32 %188)
%190 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 1
%191 = load i32, i32* %190
%192 = load i32, i32* @STDOUT_FILENO
%193 = call i32 @dup2(i32 %191, i32 %192)
%194 = icmp eq i32 %193, -1
br i1 %194, label %195, label %198
195: ; preds = %186
%196 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%197 = call i32 @exit(i32 3)
unreachable
198: ; preds = %186
%199 = load i8**, i8*** %2
%200 = getelementptr inbounds i8*, i8** %199, i64 0
%201 = load i8*, i8** %200
%202 = load i8**, i8*** %2
%203 = call i32 @execvp(i8* %201, i8** %202)
%204 = load i32, i32* @stderr
%205 = load i8**, i8*** %2
%206 = getelementptr inbounds i8*, i8** %205, i64 0
%207 = load i8*, i8** %206
%208 = call i32 @fprintf(i32 %204, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %207)
%209 = load i32, i32* %8
%210 = load i8**, i8*** %2
%211 = call i32 @freeArgs(i32 %209, i8** %210)
store i32 -1, i32* %1
store i32 1, i32* %18
br label %285
212: ; preds = %182
%213 = load i32, i32* %10
%214 = call i32 @getcmd(i8*** %2, i32 %213, i32* %11, i8** %4, i8** %3, i8** %5, i32* %15)
store i32 %214, i32* %8
%215 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 1
%216 = load i32, i32* %215
%217 = call i32 @close(i32 %216)
%218 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 0
%219 = load i32, i32* %218
%220 = load i32, i32* @STDIN_FILENO
%221 = call i32 @dup2(i32 %219, i32 %220)
%222 = icmp eq i32 %221, -1
br i1 %222, label %223, label %226
223: ; preds = %212
%224 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%225 = call i32 @exit(i32 3)
unreachable
226: ; preds = %212
%227 = load i8**, i8*** %2
%228 = getelementptr inbounds i8*, i8** %227, i64 0
%229 = load i8*, i8** %228
%230 = load i8**, i8*** %2
%231 = call i32 @execvp(i8* %229, i8** %230)
%232 = load i32, i32* @stderr
%233 = load i8**, i8*** %2
%234 = getelementptr inbounds i8*, i8** %233, i64 0
%235 = load i8*, i8** %234
%236 = call i32 @fprintf(i32 %232, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %235)
%237 = load i32, i32* %8
%238 = load i8**, i8*** %2
%239 = call i32 @freeArgs(i32 %237, i8** %238)
br label %240
240: ; preds = %226
br label %241
241: ; preds = %74, %240, %174, %147, %129, %102
%242 = load i8**, i8*** %2
%243 = getelementptr inbounds i8*, i8** %242, i64 0
%244 = load i8*, i8** %243
%245 = load i8**, i8*** %2
%246 = call i32 @execvp(i8* %244, i8** %245)
%247 = load i32, i32* @stderr
%248 = load i8**, i8*** %2
%249 = getelementptr inbounds i8*, i8** %248, i64 0
%250 = load i8*, i8** %249
%251 = call i32 @fprintf(i32 %247, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %250)
%252 = load i32, i32* %8
%253 = load i8**, i8*** %2
%254 = call i32 @freeArgs(i32 %252, i8** %253)
store i32 -1, i32* %1
store i32 1, i32* %18
br label %285
255: ; preds = %66
%256 = load i32, i32* %11
%257 = icmp eq i32 %256, 16
br i1 %257, label %258, label %261
258: ; preds = %255
%259 = load i32, i32* %10
%260 = call i32 @getcmd(i8*** %2, i32 %259, i32* %11, i8** %4, i8** %3, i8** %5, i32* %15)
store i32 %260, i32* %8
br label %261
261: ; preds = %258, %255
store i32 0, i32* %11
%262 = load i32, i32* %15
%263 = icmp eq i32 %262, 0
br i1 %263, label %264, label %269
264: ; preds = %261
%265 = load i32, i32* %17
%266 = call i32 @waitpid(i32 %265, i32* %9, i32 0)
%267 = load i32, i32* %9
%268 = call i32 @WEXITSTATUS(i32 %267)
store i32 %268, i32* %10
br label %272
269: ; preds = %261
%270 = load i32, i32* %17
%271 = call i32 @processChildren(i32 %270)
br label %272
272: ; preds = %269, %264
br label %273
273: ; preds = %272
br label %274
274: ; preds = %273, %62
br label %275
275: ; preds = %274
%276 = load i32, i32* %8
%277 = load i8**, i8*** %2
%278 = call i32 @freeArgs(i32 %276, i8** %277)
%279 = load i8*, i8** %3
%280 = call i32 @free(i8* %279)
%281 = load i8*, i8** %4
%282 = call i32 @free(i8* %281)
%283 = load i8*, i8** %5
%284 = call i32 @free(i8* %283)
store i8* null, i8** %3
store i8* null, i8** %4
store i8* null, i8** %5
br label %24
285: ; preds = %241, %198, %184, %69, %34
%286 = load i8*, i8** %6
%287 = load i32, i32* %1
ret i32 %287
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str.1 = [5 x i8] c"exit\00"
@EXIT_SUCCESS = global i32 0
@.str.3 = [3 x i8] c"cd\00"
@.str.4 = [5 x i8] c"HOME\00"
@.str.5 = [14 x i8] c"Unable to cd \00"
@.str.6 = [4 x i8] c"PWD\00"
@.str.7 = [16 x i8] c"Unable to fork.\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@.str.8 = [21 x i8] c"Unable to open file \00"
@STDOUT_FILENO = global i32 0
@.str.9 = [20 x i8] c"Unable to redirect \00"
@O_APPEND = global i32 0
@O_RDONLY = global i32 0
@STDIN_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.10 = [23 x i8] c"Unable to create pipe \00"
@.str.11 = [17 x i8] c"Unable to fork !\00"
@stderr = global i32 0
@.str.12 = [31 x i8] c"ttsh : command not found : %s\0A\00"
@str = [51 x i8] c"Welcome on DATShell! (Damn, Another Tiny Shell !).\00"
@str.13 = [18 x i8] c"Exiting DatShell!\00"
define i32 @main() {
%1 = alloca i8**
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2 x i32]
%9 = bitcast i8*** %1 to i8*
%10 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%11 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%12 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%13 = load i32, i32* @BUFSIZ
%14 = zext i32 %13 to i64
%15 = tail call i8* @llvm.stacksave()
%16 = alloca i8, i64 %14
%17 = bitcast i32* %5 to i8*
%18 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%19 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%20 = bitcast [2 x i32]* %8 to i8*
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %233, %0
%23 = phi i32 [ 0, %0 ], [ %235, %233 ]
%24 = call i32 @processChildren(i32 0)
%25 = call i32 @getcmd(i8*** %1, i32 %23, i32* %6, i8** %3, i8** %2, i8** %4, i32* %7)
%26 = load i8**, i8*** %1
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %22
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.13, i64 0, i64 0))
%32 = load i8**, i8*** %1
%33 = call i32 @freeArgs(i32 %25, i8** %32)
%34 = call i32 @processChildren(i32 1)
%35 = load i32, i32* @EXIT_SUCCESS
br label %244
36: ; preds = %22
%37 = load i8**, i8*** %1
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %58
41: ; preds = %36
%42 = icmp eq i32 %25, 1
br i1 %42, label %43, label %46
43: ; preds = %41
%44 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%45 = call i64 @chdir(i8* %44)
br label %54
46: ; preds = %41
%47 = load i8**, i8*** %1
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i64 @chdir(i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %46
%53 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %46, %52, %43
%55 = load i32, i32* @BUFSIZ
%56 = call i32 @getcwd(i8* %16, i32 %55)
%57 = call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %56, i32 1)
br label %233
58: ; preds = %36
%59 = call i32 (...) @fork()
switch i32 %59, label %218 [
i32 -1, label %60
i32 0, label %64
]
60: ; preds = %58
%61 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%62 = load i8**, i8*** %1
%63 = call i32 @freeArgs(i32 %25, i8** %62)
br label %244
64: ; preds = %58
%65 = load i32, i32* %6
switch i32 %65, label %207 [
i32 1, label %66
i32 2, label %90
i32 4, label %114
i32 8, label %129
i32 16, label %153
]
66: ; preds = %64
%67 = load i8*, i8** %3
%68 = load i32, i32* @O_WRONLY
%69 = load i32, i32* @O_CREAT
%70 = or i32 %69, %68
%71 = load i32, i32* @O_TRUNC
%72 = or i32 %70, %71
%73 = load i32, i32* @S_IRUSR
%74 = load i32, i32* @S_IWUSR
%75 = or i32 %74, %73
%76 = load i32, i32* @S_IRGRP
%77 = or i32 %75, %76
%78 = call i32 (i8*, i32, ...) @open(i8* %67, i32 %72, i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %83
80: ; preds = %66
%81 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%82 = call i32 @exit(i32 2)
unreachable
83: ; preds = %66
%84 = load i32, i32* @STDOUT_FILENO
%85 = call i32 @dup2(i32 %78, i32 %84)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %207
87: ; preds = %83
%88 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%89 = call i32 @exit(i32 3)
unreachable
90: ; preds = %64
%91 = load i8*, i8** %3
%92 = load i32, i32* @O_WRONLY
%93 = load i32, i32* @O_CREAT
%94 = or i32 %93, %92
%95 = load i32, i32* @O_APPEND
%96 = or i32 %94, %95
%97 = load i32, i32* @S_IRUSR
%98 = load i32, i32* @S_IWUSR
%99 = or i32 %98, %97
%100 = load i32, i32* @S_IRGRP
%101 = or i32 %99, %100
%102 = call i32 (i8*, i32, ...) @open(i8* %91, i32 %96, i32 %101)
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %107
104: ; preds = %90
%105 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%106 = call i32 @exit(i32 2)
unreachable
107: ; preds = %90
%108 = load i32, i32* @STDOUT_FILENO
%109 = call i32 @dup2(i32 %102, i32 %108)
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %207
111: ; preds = %107
%112 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%113 = call i32 @exit(i32 3)
unreachable
114: ; preds = %64
%115 = load i8*, i8** %2
%116 = load i32, i32* @O_RDONLY
%117 = call i32 (i8*, i32, ...) @open(i8* %115, i32 %116)
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %122
119: ; preds = %114
%120 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%121 = call i32 @exit(i32 2)
unreachable
122: ; preds = %114
%123 = load i32, i32* @STDIN_FILENO
%124 = call i32 @dup2(i32 %117, i32 %123)
%125 = icmp eq i32 %124, -1
br i1 %125, label %126, label %207
126: ; preds = %122
%127 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%128 = call i32 @exit(i32 3)
unreachable
129: ; preds = %64
%130 = load i8*, i8** %4
%131 = load i32, i32* @O_WRONLY
%132 = load i32, i32* @O_CREAT
%133 = or i32 %132, %131
%134 = load i32, i32* @O_APPEND
%135 = or i32 %133, %134
%136 = load i32, i32* @S_IRUSR
%137 = load i32, i32* @S_IWUSR
%138 = or i32 %137, %136
%139 = load i32, i32* @S_IRGRP
%140 = or i32 %138, %139
%141 = call i32 (i8*, i32, ...) @open(i8* %130, i32 %135, i32 %140)
%142 = icmp eq i32 %141, -1
br i1 %142, label %143, label %146
143: ; preds = %129
%144 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%145 = call i32 @exit(i32 2)
unreachable
146: ; preds = %129
%147 = load i32, i32* @STDERR_FILENO
%148 = call i32 @dup2(i32 %141, i32 %147)
%149 = icmp eq i32 %148, -1
br i1 %149, label %150, label %207
150: ; preds = %146
%151 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%152 = call i32 @exit(i32 3)
unreachable
153: ; preds = %64
%154 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%155 = call i32 @pipe(i32* %154)
%156 = icmp eq i32 %155, -1
br i1 %156, label %157, label %160
157: ; preds = %153
%158 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%159 = call i32 @exit(i32 4)
unreachable
160: ; preds = %153
%161 = call i32 (...) @fork()
switch i32 %161, label %185 [
i32 -1, label %162
i32 0, label %164
]
162: ; preds = %160
%163 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %244
164: ; preds = %160
%165 = load i32, i32* %154
%166 = call i32 @close(i32 %165)
%167 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%168 = load i32, i32* %167
%169 = load i32, i32* @STDOUT_FILENO
%170 = call i32 @dup2(i32 %168, i32 %169)
%171 = icmp eq i32 %170, -1
br i1 %171, label %172, label %175
172: ; preds = %164
%173 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%174 = call i32 @exit(i32 3)
unreachable
175: ; preds = %164
%176 = load i8**, i8*** %1
%177 = load i8*, i8** %176
%178 = call i32 @execvp(i8* %177, i8** %176)
%179 = load i32, i32* @stderr
%180 = load i8**, i8*** %1
%181 = load i8*, i8** %180
%182 = call i32 @fprintf(i32 %179, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %181)
%183 = load i8**, i8*** %1
%184 = call i32 @freeArgs(i32 %25, i8** %183)
br label %244
185: ; preds = %160
%186 = call i32 @getcmd(i8*** %1, i32 %23, i32* %6, i8** %3, i8** %2, i8** %4, i32* %7)
%187 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%188 = load i32, i32* %187
%189 = call i32 @close(i32 %188)
%190 = load i32, i32* %154
%191 = load i32, i32* @STDIN_FILENO
%192 = call i32 @dup2(i32 %190, i32 %191)
%193 = icmp eq i32 %192, -1
br i1 %193, label %194, label %197
194: ; preds = %185
%195 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%196 = call i32 @exit(i32 3)
unreachable
197: ; preds = %185
%198 = load i8**, i8*** %1
%199 = load i8*, i8** %198
%200 = call i32 @execvp(i8* %199, i8** %198)
%201 = load i32, i32* @stderr
%202 = load i8**, i8*** %1
%203 = load i8*, i8** %202
%204 = call i32 @fprintf(i32 %201, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %203)
%205 = load i8**, i8*** %1
%206 = call i32 @freeArgs(i32 %186, i8** %205)
br label %207
207: ; preds = %146, %122, %107, %83, %64, %197
%208 = phi i32 [ %25, %64 ], [ %186, %197 ], [ %25, %146 ], [ %25, %122 ], [ %25, %107 ], [ %25, %83 ]
%209 = load i8**, i8*** %1
%210 = load i8*, i8** %209
%211 = call i32 @execvp(i8* %210, i8** %209)
%212 = load i32, i32* @stderr
%213 = load i8**, i8*** %1
%214 = load i8*, i8** %213
%215 = call i32 @fprintf(i32 %212, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %214)
%216 = load i8**, i8*** %1
%217 = call i32 @freeArgs(i32 %208, i8** %216)
br label %244
218: ; preds = %58
%219 = load i32, i32* %6
%220 = icmp eq i32 %219, 16
br i1 %220, label %221, label %223
221: ; preds = %218
%222 = call i32 @getcmd(i8*** %1, i32 %23, i32* %6, i8** %3, i8** %2, i8** %4, i32* %7)
br label %223
223: ; preds = %221, %218
%224 = phi i32 [ %222, %221 ], [ %25, %218 ]
store i32 0, i32* %6
%225 = load i32, i32* %7
%226 = icmp eq i32 %225, 0
br i1 %226, label %227, label %231
227: ; preds = %223
%228 = call i32 @waitpid(i32 %59, i32* %5, i32 0)
%229 = load i32, i32* %5
%230 = call i32 @WEXITSTATUS(i32 %229)
br label %233
231: ; preds = %223
%232 = call i32 @processChildren(i32 %59)
br label %233
233: ; preds = %54, %227, %231
%234 = phi i32 [ %25, %54 ], [ %224, %227 ], [ %224, %231 ]
%235 = phi i32 [ %23, %54 ], [ %230, %227 ], [ %23, %231 ]
%236 = load i8**, i8*** %1
%237 = call i32 @freeArgs(i32 %234, i8** %236)
%238 = load i8*, i8** %2
%239 = call i32 @free(i8* %238)
%240 = load i8*, i8** %3
%241 = call i32 @free(i8* %240)
%242 = load i8*, i8** %4
%243 = call i32 @free(i8* %242)
store i8* null, i8** %2
store i8* null, i8** %3
store i8* null, i8** %4
br label %22
244: ; preds = %207, %175, %162, %60, %30
%245 = phi i32 [ %35, %30 ], [ -1, %207 ], [ -1, %175 ], [ 1, %162 ], [ 1, %60 ]
ret i32 %245
}