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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fileread(char *, int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ wait(unsigned int *);
int execgrepmore(char *filepath, char *pattern) {
  pid_t pidgrep, cpidgrep, pidmore, cpidmore;
  unsigned status;
  int fdsi[2], fdsfile[2];
  char *commandg[3], *commandm[2];
  commandg[0] = "grep";
  commandg[1] = pattern;
  commandg[2] = NULL;
  commandm[0] = "more";
  commandm[1] = NULL;
  if (pipe(fdsfile) < 0) {
    perror("Cannot create pipe");
    return 1;
  }
  if (pipe(fdsi) < 0) {
    perror("Cannot create pipe");
    return 1;
  }
  switch (pidgrep = fork()) {
  case -1:
    perror("Fork failed");
    exit(1);
    break;
  case 0:
    if (close(fdsfile[1]) < 0)
      perror("Pipe closing  error");
    if (close(fdsi[0]) < 0)
      perror("Pipe closing  error");
    printf("grepping %s for pattern %s\n", filepath, commandg[1]);
    dup2(fdsfile[0], 0);
    dup2(fdsi[1], 1);
    if (execvp(commandg[0], commandg) < 0) {
      perror("Execution error");
      return 1;
    }
    if (close(fdsfile[0]) < 0)
      perror("Pipe closing  error");
    if (close(fdsi[1]) < 0)
      perror("Pipe closing  error");
    break;
  default:
    switch (pidmore = fork()) {
    case -1:
      perror("Fork failed");
      exit(1);
      break;
    case 0:
      if (close(fdsfile[1]) < 0)
        perror("Pipe closing  error");
      if (close(fdsfile[0]) < 0)
        perror("Pipe closing  error");
      if (close(fdsi[1]) < 0)
        perror("Pipe closing  error");
      dup2(fdsi[0], 0);
      if (execvp(commandm[0], commandm) < 0) {
        perror("Execution error");
        return 1;
      }
      if (close(fdsi[0] < 0))
        perror("Pipe closing error");
      break;
    default:
      if (close(fdsfile[0]) < 0)
        perror("Pipe closing  error");
      if (close(fdsi[1]) < 0)
        perror("Pipe closing  error");
      if (close(fdsi[0]) < 0)
        perror("Pipe closing error");
      if ((fileread(filepath, fdsfile[1])) == 1)
        return 1;
      if (close(fdsfile[1]) < 0)
        perror("Pipe closing  error");
      while ((cpidgrep = wait(&status)) != pidgrep) {
        if (cpidgrep < 0) {
          perror("Wait failed");
          break;
        }
      }
      while ((cpidmore = wait(&status)) != pidmore) {
        if (cpidmore < 0) {
          perror("Wait failed");
          break;
        }
      }
    }
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<execgrepmore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe46(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
movq   $0x0,-0x50(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x70(%rbp)
movq   $0x0,-0x68(%rbp)
lea    -0x3c(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    120c <execgrepmore+0x6c>
lea    0xe0f(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1563 <execgrepmore+0x3c3>
lea    -0x34(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    1237 <execgrepmore+0x97>
lea    0xde4(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1563 <execgrepmore+0x3c3>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,-0x1c(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x74(%rbp)
sub    $0xffffffff,%eax
je     1264 <execgrepmore+0xc4>
jmp    1254 <execgrepmore+0xb4>
mov    -0x74(%rbp),%eax
test   %eax,%eax
je     127a <execgrepmore+0xda>
jmp    134c <execgrepmore+0x1ac>
lea    0xdb2(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    1297 <execgrepmore+0xf7>
lea    0xd97(%rip),%rdi
call   1080 <perror@plt>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    12b4 <execgrepmore+0x114>
lea    0xd7a(%rip),%rdi
call   1080 <perror@plt>
mov    -0x10(%rbp),%rsi
mov    -0x58(%rbp),%rdx
lea    0xd7a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x3c(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x30(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x60(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1090 <execvp@plt>
cmp    $0x0,%eax
jge    130d <execgrepmore+0x16d>
lea    0xd5d(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1563 <execgrepmore+0x3c3>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    132a <execgrepmore+0x18a>
lea    0xd04(%rip),%rdi
call   1080 <perror@plt>
mov    -0x30(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    1347 <execgrepmore+0x1a7>
lea    0xce7(%rip),%rdi
call   1080 <perror@plt>
jmp    155c <execgrepmore+0x3bc>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,-0x24(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x78(%rbp)
sub    $0xffffffff,%eax
je     1379 <execgrepmore+0x1d9>
jmp    1369 <execgrepmore+0x1c9>
mov    -0x78(%rbp),%eax
test   %eax,%eax
je     138f <execgrepmore+0x1ef>
jmp    1449 <execgrepmore+0x2a9>
lea    0xc9d(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    13ac <execgrepmore+0x20c>
lea    0xc82(%rip),%rdi
call   1080 <perror@plt>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    13c9 <execgrepmore+0x229>
lea    0xc65(%rip),%rdi
call   1080 <perror@plt>
mov    -0x30(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    13e6 <execgrepmore+0x246>
lea    0xc48(%rip),%rdi
call   1080 <perror@plt>
mov    -0x34(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x70(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1090 <execvp@plt>
cmp    $0x0,%eax
jge    141e <execgrepmore+0x27e>
lea    0xc4c(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1563 <execgrepmore+0x3c3>
cmpl   $0x0,-0x34(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <close@plt>
cmp    $0x0,%eax
je     1444 <execgrepmore+0x2a4>
lea    0xc2a(%rip),%rdi
call   1080 <perror@plt>
jmp    1557 <execgrepmore+0x3b7>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    1466 <execgrepmore+0x2c6>
lea    0xbc8(%rip),%rdi
call   1080 <perror@plt>
mov    -0x30(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    1483 <execgrepmore+0x2e3>
lea    0xbab(%rip),%rdi
call   1080 <perror@plt>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    14a0 <execgrepmore+0x300>
lea    0xbce(%rip),%rdi
call   1080 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1070 <fileread@plt>
cmp    $0x1,%eax
jne    14c1 <execgrepmore+0x321>
movl   $0x1,-0x4(%rbp)
jmp    1563 <execgrepmore+0x3c3>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%eax
jge    14de <execgrepmore+0x33e>
lea    0xb50(%rip),%rdi
call   1080 <perror@plt>
jmp    14e3 <execgrepmore+0x343>
lea    -0x2c(%rbp),%rdi
call   10b0 <wait@plt>
mov    %eax,-0x20(%rbp)
cmp    -0x1c(%rbp),%eax
je     1518 <execgrepmore+0x378>
cmpl   $0x0,-0x20(%rbp)
jge    1513 <execgrepmore+0x373>
lea    0xb73(%rip),%rdi
call   1080 <perror@plt>
jmp    1518 <execgrepmore+0x378>
jmp    14e3 <execgrepmore+0x343>
jmp    151d <execgrepmore+0x37d>
lea    -0x2c(%rbp),%rdi
call   10b0 <wait@plt>
mov    %eax,-0x28(%rbp)
cmp    -0x24(%rbp),%eax
je     1552 <execgrepmore+0x3b2>
cmpl   $0x0,-0x28(%rbp)
jge    154d <execgrepmore+0x3ad>
lea    0xb39(%rip),%rdi
call   1080 <perror@plt>
jmp    1552 <execgrepmore+0x3b2>
jmp    151d <execgrepmore+0x37d>
jmp    1557 <execgrepmore+0x3b7>
jmp    155c <execgrepmore+0x3bc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execgrepmore>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe47(%rip),%rax
mov    %rax,0x30(%rsp)
mov    %rsi,0x38(%rsp)
movq   $0x0,0x40(%rsp)
lea    0xe32(%rip),%rax
mov    %rax,0x20(%rsp)
movq   $0x0,0x28(%rsp)
lea    0xc(%rsp),%rdi
call   1060 <pipe@plt>
mov    $0x1,%r15d
lea    0xe12(%rip),%rbx
test   %rax,%rax
js     14b5 <execgrepmore+0x315>
lea    0x14(%rsp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
js     14b5 <execgrepmore+0x315>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     12fa <execgrepmore+0x15a>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     14de <execgrepmore+0x33e>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     1397 <execgrepmore+0x1f7>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
je     14de <execgrepmore+0x33e>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
test   %eax,%eax
js     1445 <execgrepmore+0x2a5>
mov    0x18(%rsp),%edi
call   1050 <close@plt>
test   %eax,%eax
js     1456 <execgrepmore+0x2b6>
mov    0x14(%rsp),%edi
call   1050 <close@plt>
test   %eax,%eax
js     1467 <execgrepmore+0x2c7>
mov    0x10(%rsp),%esi
mov    %r14,%rdi
call   1070 <fileread@plt>
mov    $0x1,%r15d
cmp    $0x1,%eax
je     14bd <execgrepmore+0x31d>
mov    0x10(%rsp),%edi
call   1050 <close@plt>
test   %eax,%eax
js     14cd <execgrepmore+0x32d>
lea    0x1c(%rsp),%rbp
nopl   (%rax)
mov    %rbp,%rdi
call   10b0 <wait@plt>
cmp    %ebx,%eax
je     12cc <execgrepmore+0x12c>
test   %eax,%eax
jns    12b0 <execgrepmore+0x110>
lea    0xdb5(%rip),%rdi
call   1080 <perror@plt>
lea    0x1c(%rsp),%rbp
lea    0xda4(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10b0 <wait@plt>
cmp    %r12d,%eax
je     13fe <execgrepmore+0x25e>
test   %eax,%eax
jns    12e0 <execgrepmore+0x140>
jmp    14b2 <execgrepmore+0x312>
mov    0x10(%rsp),%edi
call   1050 <close@plt>
test   %eax,%eax
js     1412 <execgrepmore+0x272>
mov    0x14(%rsp),%edi
call   1050 <close@plt>
test   %eax,%eax
js     1423 <execgrepmore+0x283>
lea    0xd1a(%rip),%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0x18(%rsp),%edi
mov    $0x1,%r15d
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xcac(%rip),%rdi
lea    0x30(%rsp),%rsi
call   1090 <execvp@plt>
test   %eax,%eax
js     1406 <execgrepmore+0x266>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
test   %eax,%eax
js     1434 <execgrepmore+0x294>
mov    0x18(%rsp),%edi
call   1050 <close@plt>
xor    %r15d,%r15d
test   %eax,%eax
jns    14bd <execgrepmore+0x31d>
lea    0xc97(%rip),%rbx
jmp    14b5 <execgrepmore+0x315>
mov    0x10(%rsp),%edi
call   1050 <close@plt>
test   %eax,%eax
js     1478 <execgrepmore+0x2d8>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
test   %eax,%eax
js     1489 <execgrepmore+0x2e9>
mov    0x18(%rsp),%edi
call   1050 <close@plt>
test   %eax,%eax
js     149a <execgrepmore+0x2fa>
mov    0x14(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
lea    0xc29(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1090 <execvp@plt>
test   %eax,%eax
js     1406 <execgrepmore+0x266>
mov    0x14(%rsp),%edi
shr    $0x1f,%edi
call   1050 <close@plt>
test   %eax,%eax
jne    14ab <execgrepmore+0x30b>
xor    %r15d,%r15d
jmp    14bd <execgrepmore+0x31d>
lea    0xc4c(%rip),%rbx
jmp    14b5 <execgrepmore+0x315>
lea    0xc10(%rip),%rdi
call   1080 <perror@plt>
jmp    130b <execgrepmore+0x16b>
lea    0xbff(%rip),%rdi
call   1080 <perror@plt>
jmp    131c <execgrepmore+0x17c>
lea    0xbee(%rip),%rdi
call   1080 <perror@plt>
jmp    1377 <execgrepmore+0x1d7>
lea    0xbdd(%rip),%rdi
call   1080 <perror@plt>
jmp    125a <execgrepmore+0xba>
lea    0xbcc(%rip),%rdi
call   1080 <perror@plt>
jmp    126b <execgrepmore+0xcb>
lea    0xbfb(%rip),%rdi
call   1080 <perror@plt>
jmp    127c <execgrepmore+0xdc>
lea    0xbaa(%rip),%rdi
call   1080 <perror@plt>
jmp    13a8 <execgrepmore+0x208>
lea    0xb99(%rip),%rdi
call   1080 <perror@plt>
jmp    13b9 <execgrepmore+0x219>
lea    0xb88(%rip),%rdi
call   1080 <perror@plt>
jmp    13ca <execgrepmore+0x22a>
lea    0xbb7(%rip),%rbx
xor    %r15d,%r15d
mov    %rbx,%rdi
call   1080 <perror@plt>
mov    %r15d,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb55(%rip),%rdi
call   1080 <perror@plt>
jmp    12a8 <execgrepmore+0x108>
lea    0xb38(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"grep\00"
@.str.1 = [5 x i8] c"more\00"
@.str.2 = [19 x i8] c"Cannot create pipe\00"
@.str.3 = [12 x i8] c"Fork failed\00"
@.str.4 = [20 x i8] c"Pipe closing error\00"
@.str.5 = [28 x i8] c"grepping %s for pattern %s\0A\00"
@.str.6 = [16 x i8] c"Execution error\00"
@.str.7 = [19 x i8] c"Pipe closing error\00"
@.str.8 = [12 x i8] c"Wait failed\00"
define i32 @execgrepmore(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca [2 x i32]
%6 = alloca [3 x i8*]
%7 = alloca [2 x i8*]
%8 = bitcast i32* %3 to i8*
%9 = bitcast [2 x i32]* %4 to i8*
%10 = bitcast [2 x i32]* %5 to i8*
%11 = bitcast [3 x i8*]* %6 to i8*
%12 = bitcast [2 x i8*]* %7 to i8*
%13 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 1
store i8* %1, i8** %14
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 2
store i8* null, i8** %15
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
store i8* null, i8** %17
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%19 = call i64 @pipe(i32* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %141, label %21
21: ; preds = %2
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%23 = call i64 @pipe(i32* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %141, label %25
25: ; preds = %21
%26 = call i32 (...) @fork()
switch i32 %26, label %62 [
i32 -1, label %27
i32 0, label %30
]
27: ; preds = %25
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %25
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
%38 = load i32, i32* %22
%39 = call i32 @close(i32 %38)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
%44 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %1)
%45 = load i32, i32* %18
%46 = call i32 @dup2(i32 %45, i32 0)
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%48 = load i32, i32* %47
%49 = call i32 @dup2(i32 %48, i32 1)
%50 = call i32 @execvp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %13)
%51 = icmp slt i32 %50, 0
br i1 %51, label %141, label %52
52: ; preds = %43
%53 = load i32, i32* %18
%54 = call i32 @close(i32 %53)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %58
58: ; preds = %56, %52
%59 = load i32, i32* %47
%60 = call i32 @close(i32 %59)
%61 = icmp slt i32 %60, 0
br i1 %61, label %141, label %145
62: ; preds = %25
%63 = call i32 (...) @fork()
switch i32 %63, label %97 [
i32 -1, label %64
i32 0, label %67
]
64: ; preds = %62
%65 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %62
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%69 = load i32, i32* %68
%70 = call i32 @close(i32 %69)
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %67
%73 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %74
74: ; preds = %72, %67
%75 = load i32, i32* %18
%76 = call i32 @close(i32 %75)
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %74
%79 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %80
80: ; preds = %78, %74
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%82 = load i32, i32* %81
%83 = call i32 @close(i32 %82)
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %80
%86 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %87
87: ; preds = %85, %80
%88 = load i32, i32* %22
%89 = call i32 @dup2(i32 %88, i32 0)
%90 = call i32 @execvp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %16)
%91 = icmp slt i32 %90, 0
br i1 %91, label %141, label %92
92: ; preds = %87
%93 = load i32, i32* %22
%94 = lshr i32 %93, 31
%95 = call i32 @close(i32 %94)
%96 = icmp eq i32 %95, 0
br i1 %96, label %145, label %141
97: ; preds = %62
%98 = load i32, i32* %18
%99 = call i32 @close(i32 %98)
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %97
%102 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %103
103: ; preds = %101, %97
%104 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%105 = load i32, i32* %104
%106 = call i32 @close(i32 %105)
%107 = icmp slt i32 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %103
%109 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %110
110: ; preds = %108, %103
%111 = load i32, i32* %22
%112 = call i32 @close(i32 %111)
%113 = icmp slt i32 %112, 0
br i1 %113, label %114, label %116
114: ; preds = %110
%115 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %116
116: ; preds = %114, %110
%117 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%118 = load i32, i32* %117
%119 = call i32 @fileread(i8* %0, i32 %118)
%120 = icmp eq i32 %119, 1
br i1 %120, label %145, label %121
121: ; preds = %116
%122 = load i32, i32* %117
%123 = call i32 @close(i32 %122)
%124 = icmp slt i32 %123, 0
br i1 %124, label %125, label %127
125: ; preds = %121
%126 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %127
127: ; preds = %125, %121
br label %128
128: ; preds = %127, %131
%129 = call i32 @wait(i32* %3)
%130 = icmp eq i32 %129, %26
br i1 %130, label %135, label %131
131: ; preds = %128
%132 = icmp slt i32 %129, 0
br i1 %132, label %133, label %128
133: ; preds = %131
%134 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
br label %135
135: ; preds = %128, %133
br label %136
136: ; preds = %135, %139
%137 = call i32 @wait(i32* %3)
%138 = icmp eq i32 %137, %63
br i1 %138, label %145, label %139
139: ; preds = %136
%140 = icmp slt i32 %137, 0
br i1 %140, label %141, label %136
141: ; preds = %139, %92, %87, %58, %43, %21, %2
%142 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %2 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %21 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), %43 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), %58 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), %87 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), %92 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), %139 ]
%143 = phi i32 [ 1, %2 ], [ 1, %21 ], [ 1, %43 ], [ 0, %58 ], [ 1, %87 ], [ 0, %92 ], [ 0, %139 ]
%144 = call i32 @perror(i8* %142)
br label %145
145: ; preds = %136, %141, %58, %92, %116
%146 = phi i32 [ 1, %116 ], [ 0, %92 ], [ 0, %58 ], [ %143, %141 ], [ 0, %136 ]
ret i32 %146
}