#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ _assert(int, char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ creat(char *);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ exec(char *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int, char *, ...);
scalar_t__ fstat(int, int /*<<< orphan*/);
int /*<<< orphan*/ get_line(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ getcwd(char *);
int getpid();
int /*<<< orphan*/ gettty(char *);
int /*<<< orphan*/ logout();
scalar_t__ open(char *, int);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ printf(char *, char *, char *);
scalar_t__ stat(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strncmp(char *, char *, int);
char *strtok(char *, char *);
int /*<<< orphan*/ wait();
int prompt() {
  int cid;
  char cwd[80], tty[80], request[255], command[255];
  while (1) {
    _assert(fstat(0, 0) < 0,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/fossum/wsu_cs460/refs/heads/master/"
            "final/fsh.c",
            76);
    _assert(fstat(1, 0) < 0,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/fossum/wsu_cs460/refs/heads/master/"
            "final/fsh.c",
            77);
    _assert(fstat(2, 0) < 0,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/fossum/wsu_cs460/refs/heads/master/"
            "final/fsh.c",
            78);
    getcwd(cwd);
    gettty(tty);
    printf("%s@%s$ ", tty, cwd);
    get_line(0, request, 255);
    if (strncmp(request, "?", 2) == 0) {
      print_help();
      continue;
    } else if (strncmp(request, "logout", 7) == 0) {
      logout();
    } else if (strncmp(request, "", 1) == 0) {
      continue;
    } else {
      char *tok;
      cid = fork();
      if (!cid) {
        strcpy(command, "/bin/");
        tok = strtok(request, " ");
        while (tok != 0) {
          if (strncmp(tok, ">>", 3) == 0) {
            tok = strtok(0, " ");
            if (tok == 0) {
              fprintf(2, "NULL output filename\n");
              exit(-1);
            }
            creat(tok);
            close(1);
            if (open(tok, 01 | 02000) < 0) {
              fprintf(2, "%s: Could not open for writing\n", tok);
              exit(-1);
            }
          } else if (strncmp(tok, ">", 2) == 0) {
            tok = strtok(0, " ");
            if (tok == 0) {
              fprintf(2, "NULL output filename\n");
              exit(-1);
            }
            close(1);
            creat(tok);
            if (open(tok, 01) < 0) {
              fprintf(2, "%s: Could not open for writing\n", tok);
              exit(-1);
            }
          } else if (strncmp(tok, "<", 2) == 0) {
            tok = strtok(0, " ");
            if (tok == 0) {
              fprintf(2, "NULL output filename\n");
              exit(-1);
            }
            if (stat(tok, 0) < 0) {
              fprintf(2, "Could not open %s for reading\n", tok);
              exit(-1);
            }
            close(0);
            if (open(tok, 00) < 0) {
              fprintf(2, "Could not open %s for reading\n", tok);
              exit(-1);
            }
          } else if (strncmp(tok, "|", 2) == 0) {
            int new_pipe[2], pipe_pid;
            pipe(new_pipe);
            pipe_pid = fork();
            if (!pipe_pid) {
              strcpy(command, "/bin/");
              close(new_pipe[1]);
              close(0);
              dup2(new_pipe[0], 0);
            } else {
              tok = 0;
              close(new_pipe[0]);
              close(1);
              dup2(new_pipe[1], 1);
              continue;
            }
          } else {
            strcat(command, tok);
            strcat(command, " ");
          }
          tok = strtok(0, " ");
        }
        exec(command);
        fprintf(2, "PID:%d failed to execute\r\n", getpid());
        exit(-1);
      } else {
        wait();
      }
    }
  }
  return (-1);
}


x86 assembly (clang, -O0):
<prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2d0,%rsp
xor    %esi,%esi
mov    %esi,%edi
call   1180 <fstat@plt>
cmp    $0x0,%rax
setl   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xd59(%rip),%rsi
mov    $0x4c,%edx
call   1160 <_assert@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1180 <fstat@plt>
cmp    $0x0,%rax
setl   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xd30(%rip),%rsi
mov    $0x4d,%edx
call   1160 <_assert@plt>
mov    $0x2,%edi
xor    %esi,%esi
call   1180 <fstat@plt>
cmp    $0x0,%rax
setl   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xd07(%rip),%rsi
mov    $0x4e,%edx
call   1160 <_assert@plt>
lea    -0x60(%rbp),%rdi
call   10a0 <getcwd@plt>
lea    -0xb0(%rbp),%rdi
call   10f0 <gettty@plt>
lea    -0xb0(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    0xd5f(%rip),%rdi
call   1090 <printf@plt>
lea    -0x1b0(%rbp),%rsi
xor    %edi,%edi
mov    $0xff,%edx
call   1070 <get_line@plt>
lea    -0x1b0(%rbp),%rdi
lea    0xd41(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1370 <prompt+0xf0>
mov    $0x0,%al
call   1120 <print_help@plt>
jmp    128b <prompt+0xb>
lea    -0x1b0(%rbp),%rdi
lea    0xd15(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    139e <prompt+0x11e>
mov    $0x0,%al
call   1050 <logout@plt>
jmp    17c5 <prompt+0x545>
lea    -0x1b0(%rbp),%rdi
lea    0xd6a(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    13c5 <prompt+0x145>
jmp    128b <prompt+0xb>
mov    $0x0,%al
call   11a0 <fork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    17b4 <prompt+0x534>
lea    -0x2b0(%rbp),%rdi
lea    0xcb3(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x1b0(%rbp),%rdi
lea    0xc95(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x2b8(%rbp)
cmpq   $0x0,-0x2b8(%rbp)
je     1782 <prompt+0x502>
mov    -0x2b8(%rbp),%rdi
lea    0xc7e(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    14d2 <prompt+0x252>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc4e(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x2b8(%rbp)
cmpq   $0x0,-0x2b8(%rbp)
jne    1478 <prompt+0x1f8>
mov    $0x2,%edi
lea    0xc3c(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
mov    -0x2b8(%rbp),%rdi
call   1140 <creat@plt>
mov    $0x1,%edi
call   10b0 <close@plt>
mov    -0x2b8(%rbp),%rdi
mov    $0x401,%esi
call   1100 <open@plt>
cmp    $0x0,%rax
jge    14cd <prompt+0x24d>
mov    -0x2b8(%rbp),%rdx
mov    $0x2,%edi
lea    0xbfd(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
jmp    1766 <prompt+0x4e6>
mov    -0x2b8(%rbp),%rdi
lea    0xbc1(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1590 <prompt+0x310>
xor    %eax,%eax
mov    %eax,%edi
lea    0xb90(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x2b8(%rbp)
cmpq   $0x0,-0x2b8(%rbp)
jne    1536 <prompt+0x2b6>
mov    $0x2,%edi
lea    0xb7e(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
mov    $0x1,%edi
call   10b0 <close@plt>
mov    -0x2b8(%rbp),%rdi
call   1140 <creat@plt>
mov    -0x2b8(%rbp),%rdi
mov    $0x1,%esi
call   1100 <open@plt>
cmp    $0x0,%rax
jge    158b <prompt+0x30b>
mov    -0x2b8(%rbp),%rdx
mov    $0x2,%edi
lea    0xb3f(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
jmp    1761 <prompt+0x4e1>
mov    -0x2b8(%rbp),%rdi
lea    0xb3b(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1678 <prompt+0x3f8>
xor    %eax,%eax
mov    %eax,%edi
lea    0xad2(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x2b8(%rbp)
cmpq   $0x0,-0x2b8(%rbp)
jne    15f4 <prompt+0x374>
mov    $0x2,%edi
lea    0xac0(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
mov    -0x2b8(%rbp),%rdi
xor    %esi,%esi
call   10e0 <stat@plt>
cmp    $0x0,%rax
jge    1630 <prompt+0x3b0>
mov    -0x2b8(%rbp),%rdx
mov    $0x2,%edi
lea    0xabc(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
xor    %edi,%edi
call   10b0 <close@plt>
mov    -0x2b8(%rbp),%rdi
xor    %esi,%esi
call   1100 <open@plt>
cmp    $0x0,%rax
jge    1673 <prompt+0x3f3>
mov    -0x2b8(%rbp),%rdx
mov    $0x2,%edi
lea    0xa79(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
jmp    175c <prompt+0x4dc>
mov    -0x2b8(%rbp),%rdi
lea    0xa74(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1731 <prompt+0x4b1>
lea    -0x2c0(%rbp),%rdi
call   10c0 <pipe@plt>
mov    $0x0,%al
call   11a0 <fork@plt>
mov    %eax,-0x2c4(%rbp)
cmpl   $0x0,-0x2c4(%rbp)
jne    16f7 <prompt+0x477>
lea    -0x2b0(%rbp),%rdi
lea    0x9cc(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x2bc(%rbp),%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   10b0 <close@plt>
mov    -0x2c0(%rbp),%edi
xor    %esi,%esi
call   1080 <dup2@plt>
jmp    172c <prompt+0x4ac>
movq   $0x0,-0x2b8(%rbp)
mov    -0x2c0(%rbp),%edi
call   10b0 <close@plt>
mov    $0x1,%edi
call   10b0 <close@plt>
mov    -0x2bc(%rbp),%edi
mov    $0x1,%esi
call   1080 <dup2@plt>
jmp    1406 <prompt+0x186>
jmp    1757 <prompt+0x4d7>
lea    -0x2b0(%rbp),%rdi
mov    -0x2b8(%rbp),%rsi
call   1130 <strcat@plt>
lea    -0x2b0(%rbp),%rdi
lea    0x93d(%rip),%rsi
call   1130 <strcat@plt>
jmp    175c <prompt+0x4dc>
jmp    1761 <prompt+0x4e1>
jmp    1766 <prompt+0x4e6>
xor    %eax,%eax
mov    %eax,%edi
lea    0x91e(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x2b8(%rbp)
jmp    1406 <prompt+0x186>
lea    -0x2b0(%rbp),%rdi
call   1170 <exec@plt>
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0x959(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
mov    $0x0,%al
call   1190 <wait@plt>
jmp    17c0 <prompt+0x540>
jmp    17c5 <prompt+0x545>
jmp    17ca <prompt+0x54a>
jmp    128b <prompt+0xb>

x86 assembly (clang, -O2):
<prompt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2b8,%rsp
lea    0xd68(%rip),%rbx
lea    0x60(%rsp),%r14
lea    0x10(%rsp),%r12
lea    0xde0(%rip),%r15
lea    0x1b0(%rsp),%rbp
lea    0xdd9(%rip),%r13
jmp    12c7 <prompt+0x47>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1120 <print_help@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1180 <fstat@plt>
shr    $0x3f,%rax
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x4c,%edx
call   1160 <_assert@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1180 <fstat@plt>
shr    $0x3f,%rax
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x4d,%edx
call   1160 <_assert@plt>
mov    $0x2,%edi
xor    %esi,%esi
call   1180 <fstat@plt>
shr    $0x3f,%rax
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x4e,%edx
call   1160 <_assert@plt>
mov    %r14,%rdi
call   10a0 <getcwd@plt>
mov    %r12,%rdi
call   10f0 <gettty@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1090 <printf@plt>
xor    %edi,%edi
mov    %rbp,%rsi
mov    $0xff,%edx
call   1070 <get_line@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12c0 <prompt+0x40>
mov    %rbp,%rdi
lea    0xd22(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     13c0 <prompt+0x140>
mov    %rbp,%rdi
lea    0xd8c(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12c7 <prompt+0x47>
xor    %eax,%eax
call   11a0 <fork@plt>
test   %eax,%eax
je     13cc <prompt+0x14c>
xor    %eax,%eax
call   1190 <wait@plt>
jmp    12c7 <prompt+0x47>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <logout@plt>
jmp    12c7 <prompt+0x47>
lea    0xcc7(%rip),%rsi
lea    0xb0(%rsp),%rdi
call   1040 <strcpy@plt>
lea    0xca8(%rip),%rsi
lea    0x1b0(%rsp),%rdi
call   1110 <strtok@plt>
test   %rax,%rax
jne    142c <prompt+0x1ac>
lea    0xb0(%rsp),%rdi
call   1170 <exec@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xce8(%rip),%rsi
mov    $0x2,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
mov    %rax,%r13
lea    0xc6a(%rip),%r14
lea    0xc52(%rip),%rbx
lea    0xc5d(%rip),%r15
lea    0xb0(%rsp),%r12
jmp    1470 <prompt+0x1f0>
xchg   %ax,%ax
call   1100 <open@plt>
test   %rax,%rax
js     1617 <prompt+0x397>
xor    %edi,%edi
mov    %rbx,%rsi
call   1110 <strtok@plt>
mov    %rax,%r13
test   %rax,%rax
je     13f9 <prompt+0x179>
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1500 <prompt+0x280>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1540 <prompt+0x2c0>
mov    %r13,%rdi
lea    0xc31(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1575 <prompt+0x2f5>
mov    %r13,%rdi
lea    0xc35(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     15b6 <prompt+0x336>
mov    %r12,%rdi
mov    %r13,%rsi
call   1130 <strcat@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1130 <strcat@plt>
jmp    145e <prompt+0x1de>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
mov    %rbx,%rsi
call   1110 <strtok@plt>
test   %rax,%rax
je     15fa <prompt+0x37a>
mov    %rax,%rbp
mov    %rax,%rdi
call   1140 <creat@plt>
mov    $0x1,%edi
call   10b0 <close@plt>
mov    %rbp,%rdi
mov    $0x401,%esi
jmp    1450 <prompt+0x1d0>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
mov    %rbx,%rsi
call   1110 <strtok@plt>
test   %rax,%rax
je     15fa <prompt+0x37a>
mov    %rax,%rbp
mov    $0x1,%edi
call   10b0 <close@plt>
mov    %rbp,%rdi
call   1140 <creat@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
jmp    1450 <prompt+0x1d0>
xor    %edi,%edi
mov    %rbx,%rsi
call   1110 <strtok@plt>
test   %rax,%rax
je     15fa <prompt+0x37a>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
call   10e0 <stat@plt>
test   %rax,%rax
js     1620 <prompt+0x3a0>
xor    %edi,%edi
call   10b0 <close@plt>
mov    %rbp,%rdi
xor    %esi,%esi
call   1100 <open@plt>
test   %rax,%rax
jns    145e <prompt+0x1de>
jmp    1620 <prompt+0x3a0>
lea    0x8(%rsp),%rdi
call   10c0 <pipe@plt>
xor    %eax,%eax
call   11a0 <fork@plt>
test   %eax,%eax
jne    1640 <prompt+0x3c0>
mov    %r12,%rdi
lea    0xac5(%rip),%rsi
call   1040 <strcpy@plt>
mov    0xc(%rsp),%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   10b0 <close@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1080 <dup2@plt>
jmp    145e <prompt+0x1de>
lea    0xaa2(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
lea    0xa9b(%rip),%rsi
jmp    1627 <prompt+0x3a7>
lea    0xab4(%rip),%rsi
mov    $0x2,%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
mov    0x8(%rsp),%edi
call   10b0 <close@plt>
mov    $0x1,%edi
call   10b0 <close@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1080 <dup2@plt>
jmp    13f9 <prompt+0x179>

LLVM IR (-O0):
@.str = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fossum/wsu_cs460/refs/heads/master/final/fsh.c\00"
@.str.1 = [8 x i8] c"%s@%s$ \00"
@.str.2 = [2 x i8] c"?\00"
@.str.3 = [7 x i8] c"logout\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [6 x i8] c"/bin/\00"
@.str.6 = [2 x i8] c" \00"
@.str.7 = [3 x i8] c">>\00"
@.str.8 = [22 x i8] c"NULL output filename\0A\00"
@.str.9 = [32 x i8] c"%s: Could not open for writing\0A\00"
@.str.10 = [2 x i8] c">\00"
@.str.11 = [2 x i8] c"<\00"
@.str.12 = [31 x i8] c"Could not open %s for reading\0A\00"
@.str.13 = [2 x i8] c"|\00"
@.str.14 = [27 x i8] c"PID:%d failed to execute\0D\0A\00"
define i32 @prompt() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = alloca [255 x i8]
%5 = alloca [255 x i8]
%6 = alloca i8*
%7 = alloca [2 x i32]
%8 = alloca i32
br label %9
9: ; preds = %0, %34, %46, %185
%10 = call i64 @fstat(i32 0, i32 0)
%11 = icmp slt i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @_assert(i32 %12, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 76)
%14 = call i64 @fstat(i32 1, i32 0)
%15 = icmp slt i64 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @_assert(i32 %16, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 77)
%18 = call i64 @fstat(i32 2, i32 0)
%19 = icmp slt i64 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @_assert(i32 %20, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 78)
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%23 = call i32 @getcwd(i8* %22)
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%25 = call i32 @gettty(i8* %24)
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %27)
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%30 = call i32 @get_line(i32 0, i8* %29, i32 255)
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 2)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %9
%35 = call i32 (...) @print_help()
br label %9
36: ; preds = %9
%37 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%38 = call i64 @strncmp(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 7)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 (...) @logout()
br label %184
42: ; preds = %36
%43 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%44 = call i64 @strncmp(i8* %43, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 1)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
br label %9
47: ; preds = %42
%48 = call i32 (...) @fork()
store i32 %48, i32* %1
%49 = load i32, i32* %1
%50 = icmp ne i32 %49, 0
br i1 %50, label %180, label %51
51: ; preds = %47
%52 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%53 = call i32 @strcpy(i8* %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%54 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%55 = call i8* @strtok(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %55, i8** %6
br label %56
56: ; preds = %172, %154, %51
%57 = load i8*, i8** %6
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %174
59: ; preds = %56
%60 = load i8*, i8** %6
%61 = call i64 @strncmp(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 3)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %82
63: ; preds = %59
%64 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %64, i8** %6
%65 = load i8*, i8** %6
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%69 = call i32 @exit(i32 -1)
unreachable
70: ; preds = %63
%71 = load i8*, i8** %6
%72 = call i32 @creat(i8* %71)
%73 = call i32 @close(i32 1)
%74 = load i8*, i8** %6
%75 = call i64 @open(i8* %74, i32 1025)
%76 = icmp slt i64 %75, 0
br i1 %76, label %77, label %81
77: ; preds = %70
%78 = load i8*, i8** %6
%79 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i8* %78)
%80 = call i32 @exit(i32 -1)
unreachable
81: ; preds = %70
br label %172
82: ; preds = %59
%83 = load i8*, i8** %6
%84 = call i64 @strncmp(i8* %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32 2)
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %105
86: ; preds = %82
%87 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %87, i8** %6
%88 = load i8*, i8** %6
%89 = icmp eq i8* %88, null
br i1 %89, label %90, label %93
90: ; preds = %86
%91 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%92 = call i32 @exit(i32 -1)
unreachable
93: ; preds = %86
%94 = call i32 @close(i32 1)
%95 = load i8*, i8** %6
%96 = call i32 @creat(i8* %95)
%97 = load i8*, i8** %6
%98 = call i64 @open(i8* %97, i32 1)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %104
100: ; preds = %93
%101 = load i8*, i8** %6
%102 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i8* %101)
%103 = call i32 @exit(i32 -1)
unreachable
104: ; preds = %93
br label %171
105: ; preds = %82
%106 = load i8*, i8** %6
%107 = call i64 @strncmp(i8* %106, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32 2)
%108 = icmp eq i64 %107, 0
br i1 %108, label %109, label %134
109: ; preds = %105
%110 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %110, i8** %6
%111 = load i8*, i8** %6
%112 = icmp eq i8* %111, null
br i1 %112, label %113, label %116
113: ; preds = %109
%114 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%115 = call i32 @exit(i32 -1)
unreachable
116: ; preds = %109
%117 = load i8*, i8** %6
%118 = call i64 @stat(i8* %117, i32 0)
%119 = icmp slt i64 %118, 0
br i1 %119, label %120, label %124
120: ; preds = %116
%121 = load i8*, i8** %6
%122 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %121)
%123 = call i32 @exit(i32 -1)
unreachable
124: ; preds = %116
%125 = call i32 @close(i32 0)
%126 = load i8*, i8** %6
%127 = call i64 @open(i8* %126, i32 0)
%128 = icmp slt i64 %127, 0
br i1 %128, label %129, label %133
129: ; preds = %124
%130 = load i8*, i8** %6
%131 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %130)
%132 = call i32 @exit(i32 -1)
unreachable
133: ; preds = %124
br label %170
134: ; preds = %105
%135 = load i8*, i8** %6
%136 = call i64 @strncmp(i8* %135, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0), i32 2)
%137 = icmp eq i64 %136, 0
br i1 %137, label %138, label %163
138: ; preds = %134
%139 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%140 = call i32 @pipe(i32* %139)
%141 = call i32 (...) @fork()
store i32 %141, i32* %8
%142 = load i32, i32* %8
%143 = icmp ne i32 %142, 0
br i1 %143, label %154, label %144
144: ; preds = %138
%145 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%146 = call i32 @strcpy(i8* %145, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%147 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%148 = load i32, i32* %147
%149 = call i32 @close(i32 %148)
%150 = call i32 @close(i32 0)
%151 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%152 = load i32, i32* %151
%153 = call i32 @dup2(i32 %152, i32 0)
br label %162
154: ; preds = %138
store i8* null, i8** %6
%155 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%156 = load i32, i32* %155
%157 = call i32 @close(i32 %156)
%158 = call i32 @close(i32 1)
%159 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%160 = load i32, i32* %159
%161 = call i32 @dup2(i32 %160, i32 1)
br label %56
162: ; preds = %144
br label %169
163: ; preds = %134
%164 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%165 = load i8*, i8** %6
%166 = call i32 @strcat(i8* %164, i8* %165)
%167 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%168 = call i32 @strcat(i8* %167, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %169
169: ; preds = %163, %162
br label %170
170: ; preds = %169, %133
br label %171
171: ; preds = %170, %104
br label %172
172: ; preds = %171, %81
%173 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %173, i8** %6
br label %56
174: ; preds = %56
%175 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%176 = call i32 @exec(i8* %175)
%177 = call i32 (...) @getpid()
%178 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %177)
%179 = call i32 @exit(i32 -1)
unreachable
180: ; preds = %47
%181 = call i32 (...) @wait()
br label %182
182: ; preds = %180
br label %183
183: ; preds = %182
br label %184
184: ; preds = %183, %40
br label %185
185: ; preds = %184
br label %9
}

LLVM IR (-O2):
@.str = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fossum/wsu_cs460/refs/heads/master/final/fsh.c\00"
@.str.1 = [8 x i8] c"%s@%s$ \00"
@.str.2 = [2 x i8] c"?\00"
@.str.3 = [7 x i8] c"logout\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [6 x i8] c"/bin/\00"
@.str.6 = [2 x i8] c" \00"
@.str.7 = [3 x i8] c">>\00"
@.str.8 = [22 x i8] c"NULL output filename\0A\00"
@.str.9 = [32 x i8] c"%s: Could not open for writing\0A\00"
@.str.10 = [2 x i8] c">\00"
@.str.11 = [2 x i8] c"<\00"
@.str.12 = [31 x i8] c"Could not open %s for reading\0A\00"
@.str.13 = [2 x i8] c"|\00"
@.str.14 = [27 x i8] c"PID:%d failed to execute\0D\0A\00"
define i32 @prompt() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = alloca [255 x i8]
%4 = alloca [255 x i8]
%5 = alloca [2 x i32]
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
br label %10
10: ; preds = %140, %0
%11 = call i64 @fstat(i32 0, i32 0)
%12 = lshr i64 %11, 63
%13 = trunc i64 %12 to i32
%14 = call i32 @_assert(i32 %13, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 76)
%15 = call i64 @fstat(i32 1, i32 0)
%16 = lshr i64 %15, 63
%17 = trunc i64 %16 to i32
%18 = call i32 @_assert(i32 %17, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 77)
%19 = call i64 @fstat(i32 2, i32 0)
%20 = lshr i64 %19, 63
%21 = trunc i64 %20 to i32
%22 = call i32 @_assert(i32 %21, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 78)
%23 = call i32 @getcwd(i8* %6)
%24 = call i32 @gettty(i8* %7)
%25 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %6)
%26 = call i32 @get_line(i32 0, i8* %8, i32 255)
%27 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 2)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %10
%30 = call i32 (...) @print_help()
br label %140
31: ; preds = %10
%32 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 7)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 (...) @logout()
br label %140
36: ; preds = %31
%37 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 1)
%38 = icmp eq i64 %37, 0
br i1 %38, label %140, label %39
39: ; preds = %36
%40 = call i32 (...) @fork()
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %138
42: ; preds = %39
%43 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%44 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%45 = icmp eq i8* %44, null
br i1 %45, label %133, label %46
46: ; preds = %42
%47 = bitcast [2 x i32]* %5 to i8*
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
br label %50
50: ; preds = %46, %130
%51 = phi i8* [ %44, %46 ], [ %131, %130 ]
%52 = call i64 @strncmp(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 3)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %68
54: ; preds = %50
%55 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%56 = icmp eq i8* %55, null
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%59 = call i32 @exit(i32 -1)
unreachable
60: ; preds = %54
%61 = call i32 @creat(i8* %55)
%62 = call i32 @close(i32 1)
%63 = call i64 @open(i8* %55, i32 1025)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %130
65: ; preds = %60
%66 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i8* %55)
%67 = call i32 @exit(i32 -1)
unreachable
68: ; preds = %50
%69 = call i64 @strncmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32 2)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %85
71: ; preds = %68
%72 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%73 = icmp eq i8* %72, null
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%76 = call i32 @exit(i32 -1)
unreachable
77: ; preds = %71
%78 = call i32 @close(i32 1)
%79 = call i32 @creat(i8* %72)
%80 = call i64 @open(i8* %72, i32 1)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %130
82: ; preds = %77
%83 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i8* %72)
%84 = call i32 @exit(i32 -1)
unreachable
85: ; preds = %68
%86 = call i64 @strncmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32 2)
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %107
88: ; preds = %85
%89 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%90 = icmp eq i8* %89, null
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%93 = call i32 @exit(i32 -1)
unreachable
94: ; preds = %88
%95 = call i64 @stat(i8* %89, i32 0)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %94
%98 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %89)
%99 = call i32 @exit(i32 -1)
unreachable
100: ; preds = %94
%101 = call i32 @close(i32 0)
%102 = call i64 @open(i8* %89, i32 0)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %130
104: ; preds = %100
%105 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %89)
%106 = call i32 @exit(i32 -1)
unreachable
107: ; preds = %85
%108 = call i64 @strncmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0), i32 2)
%109 = icmp eq i64 %108, 0
br i1 %109, label %110, label %127
110: ; preds = %107
%111 = call i32 @pipe(i32* %48)
%112 = call i32 (...) @fork()
%113 = icmp eq i32 %112, 0
br i1 %113, label %114, label %121
114: ; preds = %110
%115 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%116 = load i32, i32* %49
%117 = call i32 @close(i32 %116)
%118 = call i32 @close(i32 0)
%119 = load i32, i32* %48
%120 = call i32 @dup2(i32 %119, i32 0)
br label %130
121: ; preds = %110
%122 = load i32, i32* %48
%123 = call i32 @close(i32 %122)
%124 = call i32 @close(i32 1)
%125 = load i32, i32* %49
%126 = call i32 @dup2(i32 %125, i32 1)
br label %133
127: ; preds = %107
%128 = call i32 @strcat(i8* %9, i8* %51)
%129 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %130
130: ; preds = %60, %100, %127, %77, %114
%131 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%132 = icmp eq i8* %131, null
br i1 %132, label %133, label %50
133: ; preds = %130, %121, %42
%134 = call i32 @exec(i8* %9)
%135 = call i32 (...) @getpid()
%136 = call i32 (i32, i8*, ...) @fprintf(i32 2, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %135)
%137 = call i32 @exit(i32 -1)
unreachable
138: ; preds = %39
%139 = call i32 (...) @wait()
br label %140
140: ; preds = %138, %34, %29, %36
br label %10
}