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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sleep(int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strstr(char *, char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int write(int, ...);
int main() {
  pid_t pid, pid2, pid3;
  int pip[2];
  int pip2[2];
  int pip3[2];
  int raspuns_fiu;
  char optiune[50];
  int logged;
  logged = 0;
  int nr_de_linii = 0;
  do {
    strcpy(optiune, "");
    printf("Comanda: ");
    scanf("%s", optiune);
    if (strcmp(optiune, "quit") == 0) {
      unlink("fifo");
      return 0;
    }
    if (strcmp(optiune, "login") == 0) {
      logged = 0;
      if (pipe(pip) < 0) {
        perror("pipe error");
        exit(3);
      }
      char user[50];
      char buffer[50];
      int lungime = 0;
      printf("User: ");
      scanf("%s", user);
      int l = strlen(user);
      write(pip[1], &l, 4);
      write(pip[1], user, l);
      switch (pid = fork()) {
      case -1:
        perror("fork");
        exit(2);
      case 0:
        lungime = 0;
        strcpy(buffer, "");
        read(pip[0], &lungime, 4);
        read(pip[0], buffer, lungime);
        buffer[lungime] = 0;
        FILE *fi;
        fi = fopen("/etc/passwd", "r");
        char linie[1000];
        while (fgets(linie, 1000, fi))
          if (strstr(linie, buffer) != 0)
            nr_de_linii++;
        write(pip[1], &nr_de_linii, 4);
        exit(0);
      default:
        wait(NULL);
        raspuns_fiu = 0;
        close(pip[1]);
        read(pip[0], &raspuns_fiu, 4);
        close(pip[0]);
        if (raspuns_fiu == 1)
          logged = 1;
        if (logged == 1)
          printf("V-ati logat cu succes!\n");
      }
    }
    if (strcmp(optiune, "grep") == 0) {
      if (logged == 1) {
        if (pipe(pip2) < 0) {
          perror("pipe error");
          exit(3);
        }
        int l1, l2;
        char pattern[200];
        char fisier[200];
        printf("Pattern: ");
        scanf("%s", pattern);
        l1 = strlen(pattern);
        printf("Fisier: ");
        scanf("%s", fisier);
        l2 = strlen(fisier);
        if (write(pip2[1], &l1, 4) == -1)
          printf("Eroare la scriere in pip2!\n");
        if (write(pip2[1], pattern, l1) == -1)
          printf("Eroare la scriere in pip2!\n");
        if (write(pip2[1], &l2, 4) == -1)
          printf("Eroare la scriere in pip2!\n");
        if (write(pip2[1], fisier, l2) == -1)
          printf("Eroare la scriere in pip2!\n");
        char buffer1[200];
        char buffer2[200];
        int lungime2 = 0;
        int lungime1 = 0;
        strcpy(buffer1, "");
        strcpy(buffer2, "");
        switch (pid2 = fork()) {
        case -1:
          perror("fork");
          exit(2);
        case 0:
          read(pip[0], &lungime1, 4);
          read(pip[0], buffer1, lungime1);
          buffer1[lungime1] = 0;
          read(pip[0], &lungime2, 4);
          read(pip[0], buffer2, lungime2);
          buffer2[lungime2] = 0;
          FILE *fi;
          fi = fopen(fisier, "r");
          char linie[1000];
          while (fgets(buffer2, 1000, fi)) {
            if (strstr(buffer2, buffer1) != 0) {
              nr_de_linii++;
            }
          }
          write(pip[1], &nr_de_linii, 4);
          exit(0);
        default:
          wait(NULL);
          raspuns_fiu = 0;
          close(pip2[1]);
          read(pip2[0], &raspuns_fiu, 4);
          close(pip2[0]);
          printf("Numarul de linii semnificante este: %d.\n", raspuns_fiu);
        }
      } else
        printf("Nu v-ati logat!\n");
    }
    if (strcmp(optiune, "ls") == 0) {
      if (logged == 1) {
        char linie[1000];
        char c;
        int i;
        if (pipe(pip3) < 0) {
          perror("pipe error");
          exit(3);
        }
        printf("Fac fork.\n");
        switch (pid3 = fork()) {
        case -1:
          perror("fork");
          exit(2);
        case 0:
          printf("Sunt in fiu. Execut ls.\n");
          dup2(pip3[1], 1);
          execlp("ls", "ls", NULL);
        default:
          printf("Astept ca fiul sa scrie.\n");
          wait(NULL);
          close(pip3[1]);
          sleep(1);
          printf("Fiul a terminat.\n");
          i = 0;
          while (read(pip3[0], &c, 1)) {
            if (c != '\n')
              linie[i++] = c;
            else {
              linie[i] = 0;
              printf("%s\n", linie);
              i = 0;
            }
          }
          close(pip3[0]);
        }
      } else
        printf("Nu v-ati logat!\n");
    }
  } while (strcmp(optiune, "quit") != 0);
  unlink("fifo");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xd81(%rip),%rdi
call   10e0 <scanf@plt>
lea    -0x60(%rbp),%rdi
lea    0xd74(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    12c0 <main+0x80>
lea    0xd63(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a52 <main+0x812>
lea    -0x60(%rbp),%rdi
lea    0xd4c(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1516 <main+0x2d6>
movl   $0x0,-0x64(%rbp)
lea    -0x18(%rbp),%rdi
call   10a0 <pipe@plt>
cmp    $0x0,%rax
jge    130a <main+0xca>
lea    0xd22(%rip),%rdi
call   1100 <perror@plt>
mov    $0x3,%edi
call   1110 <exit@plt>
movl   $0x0,-0xe4(%rbp)
lea    0xd0d(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x101d(%rbp)
call   1080 <printf@plt>
lea    0xcdb(%rip),%rdi
lea    -0xa0(%rbp),%rsi
mov    %rsi,-0x1028(%rbp)
call   10e0 <scanf@plt>
mov    -0x1028(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x101d(%rbp),%al
mov    %ecx,-0xe8(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xe8(%rbp),%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    -0x1028(%rbp),%rsi
mov    -0x101d(%rbp),%al
mov    -0x14(%rbp),%edi
mov    -0xe8(%rbp),%edx
call   1050 <write@plt>
mov    -0x101d(%rbp),%al
call   1150 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x101c(%rbp)
sub    $0xffffffff,%eax
je     13c2 <main+0x182>
jmp    13af <main+0x16f>
mov    -0x101c(%rbp),%eax
test   %eax,%eax
je     13d8 <main+0x198>
jmp    14b0 <main+0x270>
lea    0xc66(%rip),%rdi
call   1100 <perror@plt>
mov    $0x2,%edi
call   1110 <exit@plt>
movl   $0x0,-0xe4(%rbp)
lea    -0xe0(%rbp),%rdi
lea    0xc9b(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%edi
lea    -0xe4(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   10b0 <read@plt>
mov    -0x18(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    -0xe4(%rbp),%edx
mov    $0x0,%al
call   10b0 <read@plt>
movslq -0xe4(%rbp),%rax
movb   $0x0,-0xe0(%rbp,%rax,1)
lea    0xbfc(%rip),%rdi
lea    0xbe7(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0xf0(%rbp)
lea    -0x4e0(%rbp),%rdi
mov    -0xf0(%rbp),%rdx
mov    $0x3e8,%esi
call   10c0 <fgets@plt>
cmp    $0x0,%eax
je     1496 <main+0x256>
lea    -0x4e0(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1160 <strstr@plt>
cmp    $0x0,%eax
je     1491 <main+0x251>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    144b <main+0x20b>
mov    -0x14(%rbp),%edi
lea    -0x68(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <write@plt>
xor    %edi,%edi
call   1110 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1140 <wait@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   10b0 <read@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
cmpl   $0x1,-0x2c(%rbp)
jne    14f4 <main+0x2b4>
movl   $0x1,-0x64(%rbp)
cmpl   $0x1,-0x64(%rbp)
jne    150c <main+0x2cc>
lea    0xb3b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1511 <main+0x2d1>
jmp    1516 <main+0x2d6>
lea    -0x60(%rbp),%rdi
lea    0xb37(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    185c <main+0x61c>
cmpl   $0x1,-0x64(%rbp)
jne    1849 <main+0x609>
lea    -0x20(%rbp),%rdi
call   10a0 <pipe@plt>
cmp    $0x0,%rax
jge    1563 <main+0x323>
lea    0xac9(%rip),%rdi
call   1100 <perror@plt>
mov    $0x3,%edi
call   1110 <exit@plt>
lea    0xaf3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x5b0(%rbp),%rsi
lea    0xa8b(%rip),%rdi
call   10e0 <scanf@plt>
lea    -0x5b0(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x4e4(%rbp)
lea    0xaca(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x680(%rbp),%rsi
lea    0xa58(%rip),%rdi
call   10e0 <scanf@plt>
lea    -0x680(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x4e8(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x4e4(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    15f6 <main+0x3b6>
lea    0xa81(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x5b0(%rbp),%rsi
mov    -0x4e4(%rbp),%edx
mov    $0x0,%al
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    1624 <main+0x3e4>
lea    0xa53(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x4e8(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    1651 <main+0x411>
lea    0xa26(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x680(%rbp),%rsi
mov    -0x4e8(%rbp),%edx
mov    $0x0,%al
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    167f <main+0x43f>
lea    0x9f8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x824(%rbp)
movl   $0x0,-0x828(%rbp)
lea    0x9f1(%rip),%rsi
mov    %rsi,-0x1038(%rbp)
lea    -0x750(%rbp),%rdi
call   1040 <strcpy@plt>
mov    -0x1038(%rbp),%rsi
lea    -0x820(%rbp),%rdi
call   1040 <strcpy@plt>
xor    %eax,%eax
call   1150 <fork@plt>
mov    %eax,-0xc(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x102c(%rbp)
sub    $0xffffffff,%eax
je     16f3 <main+0x4b3>
jmp    16e0 <main+0x4a0>
mov    -0x102c(%rbp),%eax
test   %eax,%eax
je     1709 <main+0x4c9>
jmp    1800 <main+0x5c0>
lea    0x935(%rip),%rdi
call   1100 <perror@plt>
mov    $0x2,%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x828(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   10b0 <read@plt>
mov    -0x18(%rbp),%edi
lea    -0x750(%rbp),%rsi
mov    -0x828(%rbp),%edx
mov    $0x0,%al
call   10b0 <read@plt>
movslq -0x828(%rbp),%rax
movb   $0x0,-0x750(%rbp,%rax,1)
mov    -0x18(%rbp),%edi
lea    -0x824(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   10b0 <read@plt>
mov    -0x18(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x824(%rbp),%edx
mov    $0x0,%al
call   10b0 <read@plt>
movslq -0x824(%rbp),%rax
movb   $0x0,-0x820(%rbp,%rax,1)
lea    -0x680(%rbp),%rdi
lea    0x897(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x830(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x830(%rbp),%rdx
mov    $0x3e8,%esi
call   10c0 <fgets@plt>
cmp    $0x0,%eax
je     17e6 <main+0x5a6>
lea    -0x820(%rbp),%rdi
lea    -0x750(%rbp),%rsi
call   1160 <strstr@plt>
cmp    $0x0,%eax
je     17e1 <main+0x5a1>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    179b <main+0x55b>
mov    -0x14(%rbp),%edi
lea    -0x68(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <write@plt>
xor    %edi,%edi
call   1110 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1140 <wait@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x20(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   10b0 <read@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x2c(%rbp),%esi
lea    0x84f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1857 <main+0x617>
lea    0x865(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    185c <main+0x61c>
lea    -0x60(%rbp),%rdi
lea    0x85f(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1a20 <main+0x7e0>
cmpl   $0x1,-0x64(%rbp)
jne    1a0d <main+0x7cd>
lea    -0x28(%rbp),%rdi
call   10a0 <pipe@plt>
cmp    $0x0,%rax
jge    18a9 <main+0x669>
lea    0x783(%rip),%rdi
call   1100 <perror@plt>
mov    $0x3,%edi
call   1110 <exit@plt>
lea    0x819(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x103d(%rbp)
call   1080 <printf@plt>
mov    -0x103d(%rbp),%al
call   1150 <fork@plt>
mov    %eax,-0x10(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x103c(%rbp)
sub    $0xffffffff,%eax
je     18f4 <main+0x6b4>
jmp    18e1 <main+0x6a1>
mov    -0x103c(%rbp),%eax
test   %eax,%eax
je     190a <main+0x6ca>
jmp    1938 <main+0x6f8>
lea    0x734(%rip),%rdi
call   1100 <perror@plt>
mov    $0x2,%edi
call   1110 <exit@plt>
lea    0x7c3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x24(%rbp),%edi
mov    $0x1,%esi
call   1070 <dup2@plt>
lea    0x79a(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1120 <execlp@plt>
lea    0x7ae(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1140 <wait@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1130 <sleep@plt>
lea    0x79f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x1018(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x1011(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   10b0 <read@plt>
cmp    $0x0,%eax
je     1a00 <main+0x7c0>
movsbl -0x1011(%rbp),%eax
cmp    $0xa,%eax
je     19cd <main+0x78d>
mov    -0x1011(%rbp),%cl
mov    -0x1018(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1018(%rbp)
cltq
mov    %cl,-0x1010(%rbp,%rax,1)
jmp    19fb <main+0x7bb>
movslq -0x1018(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
lea    -0x1010(%rbp),%rsi
lea    0x72f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x1018(%rbp)
jmp    1979 <main+0x739>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
jmp    1a1b <main+0x7db>
lea    0x6a1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1a20 <main+0x7e0>
jmp    1a25 <main+0x7e5>
lea    -0x60(%rbp),%rdi
lea    0x5dd(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1260 <main+0x20>
lea    0x5cc(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xac8,%rsp
movl   $0x0,0x18(%rsp)
lea    0x2b0(%rsp),%r13
lea    0xd88(%rip),%r12
lea    0xd8b(%rip),%r14
lea    0xd87(%rip),%rbp
lea    0x110(%rsp),%r15
lea    0xdec(%rip),%rbx
movl   $0x0,0x1c(%rsp)
jmp    12cb <main+0x7b>
nop
mov    0x38(%rsp),%edi
call   10a0 <close@plt>
lea    0xd50(%rip),%r12
lea    0xd56(%rip),%rbp
mov    %r13,%rdi
mov    %rbp,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     172d <main+0x4dd>
mov    %r13,%rdi
lea    0xdab(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   10f0 <scanf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     172d <main+0x4dd>
mov    %r13,%rdi
lea    0xd0a(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
jne    1407 <main+0x1b7>
lea    0xc(%rsp),%rdi
call   10b0 <pipe@plt>
test   %rax,%rax
js     174d <main+0x4fd>
lea    0xcf3(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14,%rdi
lea    0x2f0(%rsp),%rbx
mov    %rbx,%rsi
call   10f0 <scanf@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %eax,0x1e0(%rsp)
mov    0x10(%rsp),%edi
lea    0x1e0(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1060 <write@plt>
mov    0x10(%rsp),%edi
mov    0x1e0(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <write@plt>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
je     1779 <main+0x529>
cmp    $0xffffffff,%eax
je     1763 <main+0x513>
xor    %edi,%edi
call   1150 <wait@plt>
movl   $0x0,0x14(%rsp)
mov    0x10(%rsp),%edi
call   10a0 <close@plt>
mov    0xc(%rsp),%edi
lea    0x14(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   10c0 <read@plt>
mov    0xc(%rsp),%edi
call   10a0 <close@plt>
cmpl   $0x1,0x14(%rsp)
sete   %bpl
jne    13f0 <main+0x1a0>
lea    0xd10(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
mov    %bpl,%al
mov    %eax,0x1c(%rsp)
lea    0xc0d(%rip),%rbp
lea    0xc7a(%rip),%rbx
mov    %r13,%rdi
lea    0xc2f(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
jne    15f1 <main+0x3a1>
cmpl   $0x1,0x1c(%rsp)
jne    15e5 <main+0x395>
lea    0x28(%rsp),%rdi
call   10b0 <pipe@plt>
test   %rax,%rax
js     174d <main+0x4fd>
lea    0xc01(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14,%rdi
lea    0x2f0(%rsp),%rbx
mov    %rbx,%rsi
call   10f0 <scanf@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %eax,0x34(%rsp)
lea    0xbde(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10f0 <scanf@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %eax,0x30(%rsp)
mov    0x2c(%rsp),%edi
lea    0x34(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1060 <write@plt>
cmp    $0xffffffff,%eax
jne    14b5 <main+0x265>
lea    0xc30(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c(%rsp),%edi
mov    0x34(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <write@plt>
cmp    $0xffffffff,%eax
jne    14d8 <main+0x288>
lea    0xc0d(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1060 <write@plt>
cmp    $0xffffffff,%eax
lea    0xb8a(%rip),%rbx
jne    1505 <main+0x2b5>
lea    0xbe0(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%r15
mov    0x2c(%rsp),%edi
mov    0x30(%rsp),%edx
lea    0x110(%rsp),%rsi
xor    %eax,%eax
call   1060 <write@plt>
cmp    $0xffffffff,%eax
jne    1530 <main+0x2e0>
lea    0xbb5(%rip),%rdi
call   1050 <puts@plt>
movl   $0x0,0x24(%rsp)
movl   $0x0,0x20(%rsp)
lea    0x40(%rsp),%rdi
lea    0xb34(%rip),%r12
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0x1e0(%rsp),%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
je     1850 <main+0x600>
cmp    $0xffffffff,%eax
je     1763 <main+0x513>
mov    %r15,%r12
xor    %edi,%edi
call   1150 <wait@plt>
movl   $0x0,0x14(%rsp)
mov    0x2c(%rsp),%edi
call   10a0 <close@plt>
mov    0x28(%rsp),%edi
lea    0x14(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   10c0 <read@plt>
mov    0x28(%rsp),%edi
call   10a0 <close@plt>
mov    0x14(%rsp),%esi
lea    0xa98(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
lea    0x110(%rsp),%r15
jne    12b7 <main+0x67>
jmp    160c <main+0x3bc>
lea    0xae4(%rip),%rdi
call   1050 <puts@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
jne    12b7 <main+0x67>
cmpl   $0x1,0x1c(%rsp)
jne    1648 <main+0x3f8>
lea    0x38(%rsp),%rdi
call   10b0 <pipe@plt>
test   %rax,%rax
js     174d <main+0x4fd>
lea    0xa5e(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
lea    0x2f0(%rsp),%rbp
je     1659 <main+0x409>
cmp    $0xffffffff,%eax
jne    1680 <main+0x430>
jmp    1763 <main+0x513>
lea    0xa81(%rip),%rdi
call   1050 <puts@plt>
jmp    12b7 <main+0x67>
lea    0xa2e(%rip),%rdi
call   1050 <puts@plt>
mov    0x3c(%rsp),%edi
mov    $0x1,%esi
call   1080 <dup2@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1130 <execlp@plt>
lea    0xa1f(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1150 <wait@plt>
mov    0x3c(%rsp),%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   1140 <sleep@plt>
lea    0xa12(%rip),%rdi
call   1050 <puts@plt>
mov    0x38(%rsp),%edi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   10c0 <read@plt>
test   %eax,%eax
je     12a0 <main+0x50>
xor    %r12d,%r12d
jmp    1711 <main+0x4c1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %r12d,%rax
movb   $0x0,0x2f0(%rsp,%rax,1)
mov    %rbp,%rdi
call   1050 <puts@plt>
xor    %r12d,%r12d
mov    0x38(%rsp),%edi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   10c0 <read@plt>
test   %eax,%eax
je     12a0 <main+0x50>
movzbl 0x110(%rsp),%eax
cmp    $0xa,%al
je     16e0 <main+0x490>
movslq %r12d,%rcx
add    $0x1,%r12d
mov    %al,0x2f0(%rsp,%rcx,1)
jmp    16f6 <main+0x4a6>
lea    0x8de(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0xac8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8c9(%rip),%rdi
call   1110 <perror@plt>
mov    $0x3,%edi
call   1120 <exit@plt>
lea    0x8c5(%rip),%rdi
call   1110 <perror@plt>
mov    $0x2,%edi
call   1120 <exit@plt>
movl   $0x0,0x40(%rsp)
lea    0x8f8(%rip),%rsi
lea    0x110(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    0xc(%rsp),%edi
xor    %ebx,%ebx
lea    0x40(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   10c0 <read@plt>
mov    0xc(%rsp),%edi
mov    0x40(%rsp),%edx
mov    %rbp,%rsi
xor    %eax,%eax
call   10c0 <read@plt>
movslq 0x40(%rsp),%rax
movb   $0x0,0x110(%rsp,%rax,1)
lea    0x85f(%rip),%rdi
lea    0x84a(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,%r15
lea    0x6e0(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   10d0 <fgets@plt>
test   %eax,%eax
je     18ec <main+0x69c>
lea    0x6e0(%rsp),%rbp
lea    0x110(%rsp),%r14
jmp    1838 <main+0x5e8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   10d0 <fgets@plt>
test   %eax,%eax
je     18ec <main+0x69c>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1170 <strstr@plt>
test   %eax,%eax
je     1820 <main+0x5d0>
add    $0x1,%ebx
mov    %ebx,0x18(%rsp)
jmp    1820 <main+0x5d0>
mov    0xc(%rsp),%edi
xor    %ebx,%ebx
lea    0x20(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   10c0 <read@plt>
mov    0xc(%rsp),%edi
mov    0x20(%rsp),%edx
lea    0x40(%rsp),%rsi
xor    %eax,%eax
call   10c0 <read@plt>
movslq 0x20(%rsp),%rax
movb   $0x0,0x40(%rsp,%rax,1)
mov    0xc(%rsp),%edi
lea    0x24(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   10c0 <read@plt>
mov    0xc(%rsp),%edi
mov    0x24(%rsp),%edx
lea    0x1e0(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   10c0 <read@plt>
movslq 0x24(%rsp),%rax
movb   $0x0,0x1e0(%rsp,%rax,1)
lea    0x75e(%rip),%rsi
lea    0x110(%rsp),%rdi
call   1100 <fopen@plt>
mov    %rax,%r15
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   10d0 <fgets@plt>
test   %eax,%eax
jne    1908 <main+0x6b8>
mov    0x10(%rsp),%edi
lea    0x18(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1060 <write@plt>
xor    %edi,%edi
call   1120 <exit@plt>
lea    0x1e0(%rsp),%rbp
lea    0x40(%rsp),%r14
jmp    1934 <main+0x6e4>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   10d0 <fgets@plt>
test   %eax,%eax
je     18ec <main+0x69c>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1170 <strstr@plt>
test   %eax,%eax
je     1920 <main+0x6d0>
add    $0x1,%ebx
mov    %ebx,0x18(%rsp)
jmp    1920 <main+0x6d0>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [10 x i8] c"Comanda: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [5 x i8] c"fifo\00"
@.str.5 = [6 x i8] c"login\00"
@.str.6 = [11 x i8] c"pipe error\00"
@.str.7 = [7 x i8] c"User: \00"
@.str.8 = [5 x i8] c"fork\00"
@.str.9 = [12 x i8] c"/etc/passwd\00"
@.str.10 = [2 x i8] c"r\00"
@.str.11 = [24 x i8] c"V-ati logat cu succes!\0A\00"
@.str.12 = [5 x i8] c"grep\00"
@.str.13 = [10 x i8] c"Pattern: \00"
@.str.14 = [9 x i8] c"Fisier: \00"
@.str.15 = [28 x i8] c"Eroare la scriere in pip2!\0A\00"
@.str.16 = [41 x i8] c"Numarul de linii semnificante este: %d.\0A\00"
@.str.17 = [17 x i8] c"Nu v-ati logat!\0A\00"
@.str.18 = [3 x i8] c"ls\00"
@.str.19 = [11 x i8] c"Fac fork.\0A\00"
@.str.20 = [25 x i8] c"Sunt in fiu. Execut ls.\0A\00"
@.str.21 = [26 x i8] c"Astept ca fiul sa scrie.\0A\00"
@.str.22 = [18 x i8] c"Fiul a terminat.\0A\00"
@.str.23 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i32]
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca i32
%9 = alloca [50 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca [50 x i8]
%13 = alloca [50 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32*
%17 = alloca [1000 x i8]
%18 = alloca i32
%19 = alloca i32
%20 = alloca [200 x i8]
%21 = alloca [200 x i8]
%22 = alloca [200 x i8]
%23 = alloca [200 x i8]
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32*
%27 = alloca [1000 x i8]
%28 = alloca [1000 x i8]
%29 = alloca i8
%30 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %10
store i32 0, i32* %11
br label %31
31: ; preds = %317, %0
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%35 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %31
%41 = call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %323
42: ; preds = %31
%43 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %126
46: ; preds = %42
store i32 0, i32* %10
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%48 = call i64 @pipe(i32* %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%52 = call i32 @exit(i32 3)
unreachable
53: ; preds = %46
store i32 0, i32* %14
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%55 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%56 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%58 = call i32 @strlen(i8* %57)
store i32 %58, i32* %15
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%60 = load i32, i32* %59
%61 = call i32 (i32, ...) @write(i32 %60, i32* %15, i32 4)
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%63 = load i32, i32* %62
%64 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%65 = load i32, i32* %15
%66 = call i32 (i32, ...) @write(i32 %63, i8* %64, i32 %65)
%67 = call i32 (...) @fork()
store i32 %67, i32* %2
switch i32 %67, label %105 [
i32 -1, label %68
i32 0, label %71
]
68: ; preds = %53
%69 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%70 = call i32 @exit(i32 2)
unreachable
71: ; preds = %53
store i32 0, i32* %14
%72 = getelementptr inbounds [50 x i8], [50 x i8]* %13, i64 0, i64 0
%73 = call i32 @strcpy(i8* %72, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%74 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%75 = load i32, i32* %74
%76 = call i32 (i32, ...) @read(i32 %75, i32* %14, i32 4)
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%78 = load i32, i32* %77
%79 = getelementptr inbounds [50 x i8], [50 x i8]* %13, i64 0, i64 0
%80 = load i32, i32* %14
%81 = call i32 (i32, ...) @read(i32 %78, i8* %79, i32 %80)
%82 = load i32, i32* %14
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [50 x i8], [50 x i8]* %13, i64 0, i64 %83
store i8 0, i8* %84
%85 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i32* %85, i32** %16
br label %86
86: ; preds = %99, %71
%87 = getelementptr inbounds [1000 x i8], [1000 x i8]* %17, i64 0, i64 0
%88 = load i32*, i32** %16
%89 = call i32 @fgets(i8* %87, i32 1000, i32* %88)
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %100
91: ; preds = %86
%92 = getelementptr inbounds [1000 x i8], [1000 x i8]* %17, i64 0, i64 0
%93 = getelementptr inbounds [50 x i8], [50 x i8]* %13, i64 0, i64 0
%94 = call i32 @strstr(i8* %92, i8* %93)
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %91
%97 = load i32, i32* %11
%98 = add nsw i32 %97, 1
store i32 %98, i32* %11
br label %99
99: ; preds = %96, %91
br label %86
100: ; preds = %86
%101 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%102 = load i32, i32* %101
%103 = call i32 (i32, ...) @write(i32 %102, i32* %11, i32 4)
%104 = call i32 @exit(i32 0)
unreachable
105: ; preds = %53
%106 = call i32 @wait(i32* null)
store i32 0, i32* %8
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%108 = load i32, i32* %107
%109 = call i32 @close(i32 %108)
%110 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%111 = load i32, i32* %110
%112 = call i32 (i32, ...) @read(i32 %111, i32* %8, i32 4)
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%114 = load i32, i32* %113
%115 = call i32 @close(i32 %114)
%116 = load i32, i32* %8
%117 = icmp eq i32 %116, 1
br i1 %117, label %118, label %119
118: ; preds = %105
store i32 1, i32* %10
br label %119
119: ; preds = %118, %105
%120 = load i32, i32* %10
%121 = icmp eq i32 %120, 1
br i1 %121, label %122, label %124
122: ; preds = %119
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
br label %124
124: ; preds = %122, %119
br label %125
125: ; preds = %124
br label %126
126: ; preds = %125, %42
%127 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%128 = call i64 @strcmp(i8* %127, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%129 = icmp eq i64 %128, 0
br i1 %129, label %130, label %252
130: ; preds = %126
%131 = load i32, i32* %10
%132 = icmp eq i32 %131, 1
br i1 %132, label %133, label %249
133: ; preds = %130
%134 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%135 = call i64 @pipe(i32* %134)
%136 = icmp slt i64 %135, 0
br i1 %136, label %137, label %140
137: ; preds = %133
%138 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%139 = call i32 @exit(i32 3)
unreachable
140: ; preds = %133
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0))
%142 = getelementptr inbounds [200 x i8], [200 x i8]* %20, i64 0, i64 0
%143 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %142)
%144 = getelementptr inbounds [200 x i8], [200 x i8]* %20, i64 0, i64 0
%145 = call i32 @strlen(i8* %144)
store i32 %145, i32* %18
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0))
%147 = getelementptr inbounds [200 x i8], [200 x i8]* %21, i64 0, i64 0
%148 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %147)
%149 = getelementptr inbounds [200 x i8], [200 x i8]* %21, i64 0, i64 0
%150 = call i32 @strlen(i8* %149)
store i32 %150, i32* %19
%151 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%152 = load i32, i32* %151
%153 = call i32 (i32, ...) @write(i32 %152, i32* %18, i32 4)
%154 = icmp eq i32 %153, -1
br i1 %154, label %155, label %157
155: ; preds = %140
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0))
br label %157
157: ; preds = %155, %140
%158 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%159 = load i32, i32* %158
%160 = getelementptr inbounds [200 x i8], [200 x i8]* %20, i64 0, i64 0
%161 = load i32, i32* %18
%162 = call i32 (i32, ...) @write(i32 %159, i8* %160, i32 %161)
%163 = icmp eq i32 %162, -1
br i1 %163, label %164, label %166
164: ; preds = %157
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0))
br label %166
166: ; preds = %164, %157
%167 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%168 = load i32, i32* %167
%169 = call i32 (i32, ...) @write(i32 %168, i32* %19, i32 4)
%170 = icmp eq i32 %169, -1
br i1 %170, label %171, label %173
171: ; preds = %166
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0))
br label %173
173: ; preds = %171, %166
%174 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%175 = load i32, i32* %174
%176 = getelementptr inbounds [200 x i8], [200 x i8]* %21, i64 0, i64 0
%177 = load i32, i32* %19
%178 = call i32 (i32, ...) @write(i32 %175, i8* %176, i32 %177)
%179 = icmp eq i32 %178, -1
br i1 %179, label %180, label %182
180: ; preds = %173
%181 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0))
br label %182
182: ; preds = %180, %173
store i32 0, i32* %24
store i32 0, i32* %25
%183 = getelementptr inbounds [200 x i8], [200 x i8]* %22, i64 0, i64 0
%184 = call i32 @strcpy(i8* %183, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%185 = getelementptr inbounds [200 x i8], [200 x i8]* %23, i64 0, i64 0
%186 = call i32 @strcpy(i8* %185, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%187 = call i32 (...) @fork()
store i32 %187, i32* %3
switch i32 %187, label %235 [
i32 -1, label %188
i32 0, label %191
]
188: ; preds = %182
%189 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%190 = call i32 @exit(i32 2)
unreachable
191: ; preds = %182
%192 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%193 = load i32, i32* %192
%194 = call i32 (i32, ...) @read(i32 %193, i32* %25, i32 4)
%195 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%196 = load i32, i32* %195
%197 = getelementptr inbounds [200 x i8], [200 x i8]* %22, i64 0, i64 0
%198 = load i32, i32* %25
%199 = call i32 (i32, ...) @read(i32 %196, i8* %197, i32 %198)
%200 = load i32, i32* %25
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds [200 x i8], [200 x i8]* %22, i64 0, i64 %201
store i8 0, i8* %202
%203 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%204 = load i32, i32* %203
%205 = call i32 (i32, ...) @read(i32 %204, i32* %24, i32 4)
%206 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%207 = load i32, i32* %206
%208 = getelementptr inbounds [200 x i8], [200 x i8]* %23, i64 0, i64 0
%209 = load i32, i32* %24
%210 = call i32 (i32, ...) @read(i32 %207, i8* %208, i32 %209)
%211 = load i32, i32* %24
%212 = sext i32 %211 to i64
%213 = getelementptr inbounds [200 x i8], [200 x i8]* %23, i64 0, i64 %212
store i8 0, i8* %213
%214 = getelementptr inbounds [200 x i8], [200 x i8]* %21, i64 0, i64 0
%215 = call i32* @fopen(i8* %214, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i32* %215, i32** %26
br label %216
216: ; preds = %229, %191
%217 = getelementptr inbounds [200 x i8], [200 x i8]* %23, i64 0, i64 0
%218 = load i32*, i32** %26
%219 = call i32 @fgets(i8* %217, i32 1000, i32* %218)
%220 = icmp ne i32 %219, 0
br i1 %220, label %221, label %230
221: ; preds = %216
%222 = getelementptr inbounds [200 x i8], [200 x i8]* %23, i64 0, i64 0
%223 = getelementptr inbounds [200 x i8], [200 x i8]* %22, i64 0, i64 0
%224 = call i32 @strstr(i8* %222, i8* %223)
%225 = icmp ne i32 %224, 0
br i1 %225, label %226, label %229
226: ; preds = %221
%227 = load i32, i32* %11
%228 = add nsw i32 %227, 1
store i32 %228, i32* %11
br label %229
229: ; preds = %226, %221
br label %216
230: ; preds = %216
%231 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%232 = load i32, i32* %231
%233 = call i32 (i32, ...) @write(i32 %232, i32* %11, i32 4)
%234 = call i32 @exit(i32 0)
unreachable
235: ; preds = %182
%236 = call i32 @wait(i32* null)
store i32 0, i32* %8
%237 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%238 = load i32, i32* %237
%239 = call i32 @close(i32 %238)
%240 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%241 = load i32, i32* %240
%242 = call i32 (i32, ...) @read(i32 %241, i32* %8, i32 4)
%243 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%244 = load i32, i32* %243
%245 = call i32 @close(i32 %244)
%246 = load i32, i32* %8
%247 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.16, i64 0, i64 0), i32 %246)
br label %248
248: ; preds = %235
br label %251
249: ; preds = %130
%250 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.17, i64 0, i64 0))
br label %251
251: ; preds = %249, %248
br label %252
252: ; preds = %251, %126
%253 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%254 = call i64 @strcmp(i8* %253, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.18, i64 0, i64 0))
%255 = icmp eq i64 %254, 0
br i1 %255, label %256, label %316
256: ; preds = %252
%257 = load i32, i32* %10
%258 = icmp eq i32 %257, 1
br i1 %258, label %259, label %313
259: ; preds = %256
%260 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%261 = call i64 @pipe(i32* %260)
%262 = icmp slt i64 %261, 0
br i1 %262, label %263, label %266
263: ; preds = %259
%264 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%265 = call i32 @exit(i32 3)
unreachable
266: ; preds = %259
%267 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.19, i64 0, i64 0))
%268 = call i32 (...) @fork()
store i32 %268, i32* %4
switch i32 %268, label %278 [
i32 -1, label %269
i32 0, label %272
]
269: ; preds = %266
%270 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%271 = call i32 @exit(i32 2)
unreachable
272: ; preds = %266
%273 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.20, i64 0, i64 0))
%274 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%275 = load i32, i32* %274
%276 = call i32 @dup2(i32 %275, i32 1)
%277 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.18, i64 0, i64 0), i32* null)
br label %278
278: ; preds = %266, %272
%279 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.21, i64 0, i64 0))
%280 = call i32 @wait(i32* null)
%281 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%282 = load i32, i32* %281
%283 = call i32 @close(i32 %282)
%284 = call i32 @sleep(i32 1)
%285 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.22, i64 0, i64 0))
store i32 0, i32* %30
br label %286
286: ; preds = %307, %278
%287 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%288 = load i32, i32* %287
%289 = call i32 (i32, ...) @read(i32 %288, i8* %29, i32 1)
%290 = icmp ne i32 %289, 0
br i1 %290, label %291, label %308
291: ; preds = %286
%292 = load i8, i8* %29
%293 = sext i8 %292 to i32
%294 = icmp ne i32 %293, 10
br i1 %294, label %295, label %301
295: ; preds = %291
%296 = load i8, i8* %29
%297 = load i32, i32* %30
%298 = add nsw i32 %297, 1
store i32 %298, i32* %30
%299 = sext i32 %297 to i64
%300 = getelementptr inbounds [1000 x i8], [1000 x i8]* %28, i64 0, i64 %299
store i8 %296, i8* %300
br label %307
301: ; preds = %291
%302 = load i32, i32* %30
%303 = sext i32 %302 to i64
%304 = getelementptr inbounds [1000 x i8], [1000 x i8]* %28, i64 0, i64 %303
store i8 0, i8* %304
%305 = getelementptr inbounds [1000 x i8], [1000 x i8]* %28, i64 0, i64 0
%306 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.23, i64 0, i64 0), i8* %305)
store i32 0, i32* %30
br label %307
307: ; preds = %301, %295
br label %286
308: ; preds = %286
%309 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%310 = load i32, i32* %309
%311 = call i32 @close(i32 %310)
br label %312
312: ; preds = %308
br label %315
313: ; preds = %256
%314 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.17, i64 0, i64 0))
br label %315
315: ; preds = %313, %312
br label %316
316: ; preds = %315, %252
br label %317
317: ; preds = %316
%318 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%319 = call i64 @strcmp(i8* %318, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%320 = icmp ne i64 %319, 0
br i1 %320, label %31, label %321
321: ; preds = %317
%322 = call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %323
323: ; preds = %321, %40
%324 = load i32, i32* %1
ret i32 %324
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [10 x i8] c"Comanda: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [5 x i8] c"fifo\00"
@.str.5 = [6 x i8] c"login\00"
@.str.6 = [11 x i8] c"pipe error\00"
@.str.7 = [7 x i8] c"User: \00"
@.str.8 = [5 x i8] c"fork\00"
@.str.9 = [12 x i8] c"/etc/passwd\00"
@.str.10 = [2 x i8] c"r\00"
@.str.12 = [5 x i8] c"grep\00"
@.str.13 = [10 x i8] c"Pattern: \00"
@.str.14 = [9 x i8] c"Fisier: \00"
@.str.16 = [41 x i8] c"Numarul de linii semnificante este: %d.\0A\00"
@.str.18 = [3 x i8] c"ls\00"
@str.24 = [10 x i8] c"Fac fork.\00"
@str.25 = [24 x i8] c"Sunt in fiu. Execut ls.\00"
@str.26 = [25 x i8] c"Astept ca fiul sa scrie.\00"
@str.27 = [17 x i8] c"Fiul a terminat.\00"
@str.28 = [16 x i8] c"Nu v-ati logat!\00"
@str.32 = [27 x i8] c"Eroare la scriere in pip2!\00"
@str.33 = [23 x i8] c"V-ati logat cu succes!\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca [50 x i8]
%6 = alloca i32
%7 = alloca [50 x i8]
%8 = alloca [50 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1000 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca [200 x i8]
%15 = alloca [200 x i8]
%16 = alloca [200 x i8]
%17 = alloca [200 x i8]
%18 = alloca i32
%19 = alloca i32
%20 = alloca [1000 x i8]
%21 = alloca i8
%22 = bitcast [2 x i32]* %1 to i8*
%23 = bitcast [2 x i32]* %2 to i8*
%24 = bitcast [2 x i32]* %3 to i8*
%25 = bitcast i32* %4 to i8*
%26 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%27 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%31 = bitcast i32* %9 to i8*
%32 = bitcast i32* %10 to i8*
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%35 = bitcast i32* %12 to i8*
%36 = bitcast i32* %13 to i8*
%37 = getelementptr inbounds [200 x i8], [200 x i8]* %14, i64 0, i64 0
%38 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%40 = getelementptr inbounds [200 x i8], [200 x i8]* %16, i64 0, i64 0
%41 = getelementptr inbounds [200 x i8], [200 x i8]* %17, i64 0, i64 0
%42 = bitcast i32* %18 to i8*
%43 = bitcast i32* %19 to i8*
%44 = getelementptr inbounds [1000 x i8], [1000 x i8]* %20, i64 0, i64 0
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br label %47
47: ; preds = %271, %0
%48 = phi i32 [ 0, %0 ], [ %119, %271 ]
%49 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%51 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%52 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %274, label %54
54: ; preds = %47
%55 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %118
57: ; preds = %54
%58 = call i64 @pipe(i32* %28)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%62 = call i32 @exit(i32 3)
unreachable
63: ; preds = %57
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%65 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%66 = call i32 @strlen(i8* %29)
store i32 %66, i32* %10
%67 = load i32, i32* %33
%68 = call i32 (i32, ...) @write(i32 %67, i32* %10, i32 4)
%69 = load i32, i32* %33
%70 = load i32, i32* %10
%71 = call i32 (i32, ...) @write(i32 %69, i8* %29, i32 %70)
%72 = call i32 (...) @fork()
switch i32 %72, label %104 [
i32 -1, label %73
i32 0, label %76
]
73: ; preds = %63
%74 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%75 = call i32 @exit(i32 2)
unreachable
76: ; preds = %63
store i32 0, i32* %9
%77 = call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%78 = load i32, i32* %28
%79 = call i32 (i32, ...) @read(i32 %78, i32* %9, i32 4)
%80 = load i32, i32* %28
%81 = load i32, i32* %9
%82 = call i32 (i32, ...) @read(i32 %80, i8* %30, i32 %81)
%83 = load i32, i32* %9
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 %84
store i8 0, i8* %85
%86 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%87 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%88 = call i32 @fgets(i8* %87, i32 1000, i32* %86)
%89 = icmp eq i32 %88, 0
br i1 %89, label %100, label %90
90: ; preds = %76, %96
%91 = phi i32 [ %97, %96 ], [ 0, %76 ]
%92 = call i32 @strstr(i8* %87, i8* %30)
%93 = icmp eq i32 %92, 0
br i1 %93, label %96, label %94
94: ; preds = %90
%95 = add nsw i32 %91, 1
store i32 %95, i32* %6
br label %96
96: ; preds = %94, %90
%97 = phi i32 [ %95, %94 ], [ %91, %90 ]
%98 = call i32 @fgets(i8* %87, i32 1000, i32* %86)
%99 = icmp eq i32 %98, 0
br i1 %99, label %100, label %90
100: ; preds = %96, %76
%101 = load i32, i32* %33
%102 = call i32 (i32, ...) @write(i32 %101, i32* %6, i32 4)
%103 = call i32 @exit(i32 0)
unreachable
104: ; preds = %63
%105 = call i32 @wait(i32* null)
store i32 0, i32* %4
%106 = load i32, i32* %33
%107 = call i32 @close(i32 %106)
%108 = load i32, i32* %28
%109 = call i32 (i32, ...) @read(i32 %108, i32* %4, i32 4)
%110 = load i32, i32* %28
%111 = call i32 @close(i32 %110)
%112 = load i32, i32* %4
%113 = icmp eq i32 %112, 1
%114 = zext i1 %113 to i32
br i1 %113, label %115, label %117
115: ; preds = %104
%116 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.33, i64 0, i64 0))
br label %117
117: ; preds = %104, %115
br label %118
118: ; preds = %117, %54
%119 = phi i32 [ %114, %117 ], [ %48, %54 ]
%120 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%121 = icmp eq i64 %120, 0
br i1 %121, label %122, label %205
122: ; preds = %118
%123 = icmp eq i32 %119, 1
br i1 %123, label %124, label %203
124: ; preds = %122
%125 = call i64 @pipe(i32* %34)
%126 = icmp slt i64 %125, 0
br i1 %126, label %127, label %130
127: ; preds = %124
%128 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%129 = call i32 @exit(i32 3)
unreachable
130: ; preds = %124
%131 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0))
%132 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%133 = call i32 @strlen(i8* %37)
store i32 %133, i32* %12
%134 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0))
%135 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%136 = call i32 @strlen(i8* %38)
store i32 %136, i32* %13
%137 = load i32, i32* %39
%138 = call i32 (i32, ...) @write(i32 %137, i32* %12, i32 4)
%139 = icmp eq i32 %138, -1
br i1 %139, label %140, label %142
140: ; preds = %130
%141 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.32, i64 0, i64 0))
br label %142
142: ; preds = %140, %130
%143 = load i32, i32* %39
%144 = load i32, i32* %12
%145 = call i32 (i32, ...) @write(i32 %143, i8* %37, i32 %144)
%146 = icmp eq i32 %145, -1
br i1 %146, label %147, label %149
147: ; preds = %142
%148 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.32, i64 0, i64 0))
br label %149
149: ; preds = %147, %142
%150 = load i32, i32* %39
%151 = call i32 (i32, ...) @write(i32 %150, i32* %13, i32 4)
%152 = icmp eq i32 %151, -1
br i1 %152, label %153, label %155
153: ; preds = %149
%154 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.32, i64 0, i64 0))
br label %155
155: ; preds = %153, %149
%156 = load i32, i32* %39
%157 = load i32, i32* %13
%158 = call i32 (i32, ...) @write(i32 %156, i8* %38, i32 %157)
%159 = icmp eq i32 %158, -1
br i1 %159, label %160, label %162
160: ; preds = %155
%161 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.32, i64 0, i64 0))
br label %162
162: ; preds = %160, %155
store i32 0, i32* %18
store i32 0, i32* %19
%163 = call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%164 = call i32 @strcpy(i8* %41, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%165 = call i32 (...) @fork()
switch i32 %165, label %208 [
i32 -1, label %166
i32 0, label %169
]
166: ; preds = %162
%167 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%168 = call i32 @exit(i32 2)
unreachable
169: ; preds = %162
%170 = load i32, i32* %28
%171 = call i32 (i32, ...) @read(i32 %170, i32* %19, i32 4)
%172 = load i32, i32* %28
%173 = load i32, i32* %19
%174 = call i32 (i32, ...) @read(i32 %172, i8* %40, i32 %173)
%175 = load i32, i32* %19
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds [200 x i8], [200 x i8]* %16, i64 0, i64 %176
store i8 0, i8* %177
%178 = load i32, i32* %28
%179 = call i32 (i32, ...) @read(i32 %178, i32* %18, i32 4)
%180 = load i32, i32* %28
%181 = load i32, i32* %18
%182 = call i32 (i32, ...) @read(i32 %180, i8* %41, i32 %181)
%183 = load i32, i32* %18
%184 = sext i32 %183 to i64
%185 = getelementptr inbounds [200 x i8], [200 x i8]* %17, i64 0, i64 %184
store i8 0, i8* %185
%186 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%187 = call i32 @fgets(i8* %41, i32 1000, i32* %186)
%188 = icmp eq i32 %187, 0
br i1 %188, label %199, label %189
189: ; preds = %169, %195
%190 = phi i32 [ %196, %195 ], [ 0, %169 ]
%191 = call i32 @strstr(i8* %41, i8* %40)
%192 = icmp eq i32 %191, 0
br i1 %192, label %195, label %193
193: ; preds = %189
%194 = add nsw i32 %190, 1
store i32 %194, i32* %6
br label %195
195: ; preds = %193, %189
%196 = phi i32 [ %194, %193 ], [ %190, %189 ]
%197 = call i32 @fgets(i8* %41, i32 1000, i32* %186)
%198 = icmp eq i32 %197, 0
br i1 %198, label %199, label %189
199: ; preds = %195, %169
%200 = load i32, i32* %33
%201 = call i32 (i32, ...) @write(i32 %200, i32* %6, i32 4)
%202 = call i32 @exit(i32 0)
unreachable
203: ; preds = %122
%204 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.28, i64 0, i64 0))
br label %205
205: ; preds = %203, %118
%206 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.18, i64 0, i64 0))
%207 = icmp eq i64 %206, 0
br i1 %207, label %220, label %271
208: ; preds = %162
%209 = call i32 @wait(i32* null)
store i32 0, i32* %4
%210 = load i32, i32* %39
%211 = call i32 @close(i32 %210)
%212 = load i32, i32* %34
%213 = call i32 (i32, ...) @read(i32 %212, i32* %4, i32 4)
%214 = load i32, i32* %34
%215 = call i32 @close(i32 %214)
%216 = load i32, i32* %4
%217 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.16, i64 0, i64 0), i32 %216)
%218 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.18, i64 0, i64 0))
%219 = icmp eq i64 %218, 0
br i1 %219, label %222, label %271
220: ; preds = %205
%221 = icmp eq i32 %119, 1
br i1 %221, label %222, label %269
222: ; preds = %208, %220
%223 = call i64 @pipe(i32* %45)
%224 = icmp slt i64 %223, 0
br i1 %224, label %225, label %228
225: ; preds = %222
%226 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%227 = call i32 @exit(i32 3)
unreachable
228: ; preds = %222
%229 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.24, i64 0, i64 0))
%230 = call i32 (...) @fork()
switch i32 %230, label %239 [
i32 -1, label %231
i32 0, label %234
]
231: ; preds = %228
%232 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%233 = call i32 @exit(i32 2)
unreachable
234: ; preds = %228
%235 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.25, i64 0, i64 0))
%236 = load i32, i32* %46
%237 = call i32 @dup2(i32 %236, i32 1)
%238 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.18, i64 0, i64 0), i32* null)
br label %239
239: ; preds = %228, %234
%240 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.26, i64 0, i64 0))
%241 = call i32 @wait(i32* null)
%242 = load i32, i32* %46
%243 = call i32 @close(i32 %242)
%244 = call i32 @sleep(i32 1)
%245 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.27, i64 0, i64 0))
%246 = load i32, i32* %45
%247 = call i32 (i32, ...) @read(i32 %246, i8* %21, i32 1)
%248 = icmp eq i32 %247, 0
br i1 %248, label %266, label %249
249: ; preds = %239, %261
%250 = phi i32 [ %262, %261 ], [ 0, %239 ]
%251 = load i8, i8* %21
%252 = icmp eq i8 %251, 10
br i1 %252, label %257, label %253
253: ; preds = %249
%254 = add nsw i32 %250, 1
%255 = sext i32 %250 to i64
%256 = getelementptr inbounds [1000 x i8], [1000 x i8]* %20, i64 0, i64 %255
store i8 %251, i8* %256
br label %261
257: ; preds = %249
%258 = sext i32 %250 to i64
%259 = getelementptr inbounds [1000 x i8], [1000 x i8]* %20, i64 0, i64 %258
store i8 0, i8* %259
%260 = call i32 @puts(i8* %44)
br label %261
261: ; preds = %257, %253
%262 = phi i32 [ %254, %253 ], [ 0, %257 ]
%263 = load i32, i32* %45
%264 = call i32 (i32, ...) @read(i32 %263, i8* %21, i32 1)
%265 = icmp eq i32 %264, 0
br i1 %265, label %266, label %249
266: ; preds = %261, %239
%267 = load i32, i32* %45
%268 = call i32 @close(i32 %267)
br label %271
269: ; preds = %220
%270 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.28, i64 0, i64 0))
br label %271
271: ; preds = %208, %205, %269, %266
%272 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%273 = icmp eq i64 %272, 0
br i1 %273, label %274, label %47
274: ; preds = %271, %47
%275 = call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}