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

/* Forward declarations */

/* Type definitions */
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int, ...);
int pipe(int *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd[2];
  pid_t pid;
  const char *inname = argv[1];
  const char *outname = argv[2];
  if (argc != 3) {
    printf("usage: pipe_example input_file output_file\n");
    exit(EXIT_FAILURE);
  }
  if (pipe(fd) == -1) {
    fprintf(stderr, "Pipe failed");
    exit(EXIT_FAILURE);
  }
  if ((pid = fork()) < 0) {
    fprintf(stderr, "Fork error");
    exit(EXIT_FAILURE);
  }
  if (pid > 0) {
    char buffer[100];
    int fdr;
    int num;
    close(fd[0]);
    if ((fdr = open(inname, O_RDONLY)) < 0) {
      fprintf(stderr, "Parent: Error opening file %s for reading.\n", inname);
      exit(EXIT_FAILURE);
    }
    while ((num = read(fdr, buffer, 100)) > 0) {
      if (write(fd[1], buffer, num) < 0) {
        fprintf(stderr, "Parent: Error writing to pipe.\n");
        exit(EXIT_FAILURE);
      }
    }
    if (num < 0) {
      fprintf(stderr, "Parent: Error reading from %s\n", inname);
      exit(EXIT_FAILURE);
    }
    close(fdr);
    close(fd[1]);
  } else {
    char inbuf[100];
    int fdw;
    int num;
    close(fd[1]);
    fdw = open(outname, O_CREAT | O_WRONLY | O_TRUNC, 0644);
    if (fdw < 0) {
      fprintf(stderr, "Child: Can't open file %s for writing\n", outname);
      exit(EXIT_FAILURE);
    }
    while ((num = read(fd[0], inbuf, 100)) > 0) {
      if (write(fdw, inbuf, num) < 0) {
        fprintf(stderr, "Child: Error writing to %s\n", outname);
        exit(EXIT_FAILURE);
      }
    }
    if (num < 0) {
      fprintf(stderr, "Child: Error reading from pipe.\n");
      exit(EXIT_FAILURE);
    }
    close(fdw);
    close(fd[0]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11e5 <main+0x55>
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    121c <main+0x8c>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1256 <main+0xc6>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jle    1377 <main+0x1e7>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0xa4(%rbp)
cmp    $0x0,%eax
jge    12b5 <main+0x125>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    12ba <main+0x12a>
mov    -0xa4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %eax,-0xa8(%rbp)
cmp    $0x0,%eax
jle    1329 <main+0x199>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0xa8(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1324 <main+0x194>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xd60(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    12ba <main+0x12a>
cmpl   $0x0,-0xa8(%rbp)
jge    135f <main+0x1cf>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0xa4(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    14a3 <main+0x313>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%rdi
mov    0x2c6e(%rip),%rax
mov    (%rax),%esi
mov    0x2c1d(%rip),%rax
or     (%rax),%esi
mov    0x2c54(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    13e6 <main+0x256>
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xcdd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2be1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    13eb <main+0x25b>
mov    -0x18(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %eax,-0x118(%rbp)
cmp    $0x0,%eax
jle    145e <main+0x2ce>
mov    -0x114(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x118(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1459 <main+0x2c9>
mov    0x2b91(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xc91(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b6e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    13eb <main+0x25b>
cmpl   $0x0,-0x118(%rbp)
jge    1490 <main+0x300>
mov    0x2b56(%rip),%rax
mov    (%rax),%edi
lea    0xc76(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b37(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x114(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
cmp    $0x3,%edi
jne    1311 <main+0x181>
mov    0x8(%rsi),%r15
mov    0x10(%rsi),%r14
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     131f <main+0x18f>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
js     1334 <main+0x1a4>
je     1258 <main+0xc8>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
js     1349 <main+0x1b9>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1242 <main+0xb2>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    1200 <main+0x70>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12e0 <main+0x150>
js     135b <main+0x1cb>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
jmp    12ff <main+0x16f>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x2d90(%rip),%rax
mov    0x2d41(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d76(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
js     1373 <main+0x1e3>
mov    %eax,%ebx
lea    0x10(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%edi
mov    %rbp,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    12ee <main+0x15e>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    12a0 <main+0x110>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
js     1388 <main+0x1f8>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdce(%rip),%rdi
call   1030 <puts@plt>
jmp    12e0 <main+0x150>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xcd1(%rip),%rsi
jmp    1236 <main+0xa6>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
lea    0xcc8(%rip),%rsi
jmp    1236 <main+0xa6>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
lea    0xcbe(%rip),%rsi
jmp    136b <main+0x1db>
mov    0x2c66(%rip),%rax
mov    (%rax),%edi
lea    0xcf8(%rip),%rsi
mov    %r15,%rdx
jmp    12d9 <main+0x149>
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
lea    0xcff(%rip),%rsi
jmp    12d6 <main+0x146>
mov    0x2c39(%rip),%rax
mov    (%rax),%edi
lea    0xd2d(%rip),%rsi
jmp    1236 <main+0xa6>

LLVM IR (-O0):
@.str = [44 x i8] c"usage: pipe_example input_file output_file\0A\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"Pipe failed\00"
@.str.2 = [11 x i8] c"Fork error\00"
@O_RDONLY = global i32 0
@.str.3 = [44 x i8] c"Parent: Error opening file %s for reading.\0A\00"
@.str.4 = [32 x i8] c"Parent: Error writing to pipe.\0A\00"
@.str.5 = [31 x i8] c"Parent: Error reading from %s\0A\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.6 = [39 x i8] c"Child: Can't open file %s for writing\0A\00"
@.str.7 = [28 x i8] c"Child: Error writing to %s\0A\00"
@.str.8 = [33 x i8] c"Child: Error reading from pipe.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [100 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca [100 x i8]
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %8
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
store i8* %21, i8** %9
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 3
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %2
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%30 = call i32 @pipe(i32* %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28
%38 = call i64 (...) @fork()
store i64 %38, i64* %7
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %37
%46 = load i64, i64* %7
%47 = icmp sgt i64 %46, 0
br i1 %47, label %48, label %96
48: ; preds = %45
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
%52 = load i8*, i8** %8
%53 = load i32, i32* @O_RDONLY
%54 = call i32 (i8*, i32, ...) @open(i8* %52, i32 %53)
store i32 %54, i32* %11
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %48
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %8
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %48
br label %63
63: ; preds = %80, %62
%64 = load i32, i32* %11
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%66 = call i32 @read(i32 %64, i8* %65, i32 100)
store i32 %66, i32* %12
%67 = icmp sgt i32 %66, 0
br i1 %67, label %68, label %81
68: ; preds = %63
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%70 = load i32, i32* %69
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%72 = load i32, i32* %12
%73 = call i64 @write(i32 %70, i8* %71, i32 %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %80
75: ; preds = %68
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; preds = %68
br label %63
81: ; preds = %63
%82 = load i32, i32* %12
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %90
84: ; preds = %81
%85 = load i32, i32* @stderr
%86 = load i8*, i8** %8
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %86)
%88 = load i32, i32* @EXIT_FAILURE
%89 = call i32 @exit(i32 %88)
unreachable
90: ; preds = %81
%91 = load i32, i32* %11
%92 = call i32 @close(i32 %91)
%93 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%94 = load i32, i32* %93
%95 = call i32 @close(i32 %94)
br label %149
96: ; preds = %45
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%98 = load i32, i32* %97
%99 = call i32 @close(i32 %98)
%100 = load i8*, i8** %9
%101 = load i32, i32* @O_CREAT
%102 = load i32, i32* @O_WRONLY
%103 = or i32 %101, %102
%104 = load i32, i32* @O_TRUNC
%105 = or i32 %103, %104
%106 = call i32 (i8*, i32, ...) @open(i8* %100, i32 %105, i32 420)
store i32 %106, i32* %14
%107 = load i32, i32* %14
%108 = icmp slt i32 %107, 0
br i1 %108, label %109, label %115
109: ; preds = %96
%110 = load i32, i32* @stderr
%111 = load i8*, i8** %9
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* %111)
%113 = load i32, i32* @EXIT_FAILURE
%114 = call i32 @exit(i32 %113)
unreachable
115: ; preds = %96
br label %116
116: ; preds = %134, %115
%117 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%118 = load i32, i32* %117
%119 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%120 = call i32 @read(i32 %118, i8* %119, i32 100)
store i32 %120, i32* %15
%121 = icmp sgt i32 %120, 0
br i1 %121, label %122, label %135
122: ; preds = %116
%123 = load i32, i32* %14
%124 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%125 = load i32, i32* %15
%126 = call i64 @write(i32 %123, i8* %124, i32 %125)
%127 = icmp slt i64 %126, 0
br i1 %127, label %128, label %134
128: ; preds = %122
%129 = load i32, i32* @stderr
%130 = load i8*, i8** %9
%131 = call i32 (i32, i8*, ...) @fprintf(i32 %129, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %130)
%132 = load i32, i32* @EXIT_FAILURE
%133 = call i32 @exit(i32 %132)
unreachable
134: ; preds = %122
br label %116
135: ; preds = %116
%136 = load i32, i32* %15
%137 = icmp slt i32 %136, 0
br i1 %137, label %138, label %143
138: ; preds = %135
%139 = load i32, i32* @stderr
%140 = call i32 (i32, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%141 = load i32, i32* @EXIT_FAILURE
%142 = call i32 @exit(i32 %141)
unreachable
143: ; preds = %135
%144 = load i32, i32* %14
%145 = call i32 @close(i32 %144)
%146 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%147 = load i32, i32* %146
%148 = call i32 @close(i32 %147)
br label %149
149: ; preds = %143, %90
ret i32 0
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"Pipe failed\00"
@.str.2 = [11 x i8] c"Fork error\00"
@O_RDONLY = global i32 0
@.str.3 = [44 x i8] c"Parent: Error opening file %s for reading.\0A\00"
@.str.4 = [32 x i8] c"Parent: Error writing to pipe.\0A\00"
@.str.5 = [31 x i8] c"Parent: Error reading from %s\0A\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.6 = [39 x i8] c"Child: Can't open file %s for writing\0A\00"
@.str.7 = [28 x i8] c"Child: Error writing to %s\0A\00"
@.str.8 = [33 x i8] c"Child: Error reading from pipe.\0A\00"
@str = [43 x i8] c"usage: pipe_example input_file output_file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = icmp eq i32 %0, 3
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%18 = call i32 @pipe(i32* %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
%26 = call i64 (...) @fork()
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %25
%34 = icmp eq i64 %26, 0
br i1 %34, label %72, label %35
35: ; preds = %33
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%37 = load i32, i32* %17
%38 = call i32 @close(i32 %37)
%39 = load i32, i32* @O_RDONLY
%40 = call i32 (i8*, i32, ...) @open(i8* %8, i32 %39)
%41 = icmp slt i32 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %35
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br label %49
44: ; preds = %35
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %42, %52
%50 = call i32 @read(i32 %40, i8* %36, i32 100)
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %61
52: ; preds = %49
%53 = load i32, i32* %43
%54 = call i64 @write(i32 %53, i8* %36, i32 %50)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %49
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %49
%62 = icmp slt i32 %50, 0
br i1 %62, label %63, label %68
63: ; preds = %61
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %61
%69 = call i32 @close(i32 %40)
%70 = load i32, i32* %43
%71 = call i32 @close(i32 %70)
br label %112
72: ; preds = %33
%73 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%74 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%75 = load i32, i32* %74
%76 = call i32 @close(i32 %75)
%77 = load i32, i32* @O_CREAT
%78 = load i32, i32* @O_WRONLY
%79 = or i32 %78, %77
%80 = load i32, i32* @O_TRUNC
%81 = or i32 %79, %80
%82 = call i32 (i8*, i32, ...) @open(i8* %10, i32 %81, i32 420)
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %89
84: ; preds = %72
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* %10)
%87 = load i32, i32* @EXIT_FAILURE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %72, %93
%90 = load i32, i32* %17
%91 = call i32 @read(i32 %90, i8* %73, i32 100)
%92 = icmp sgt i32 %91, 0
br i1 %92, label %93, label %101
93: ; preds = %89
%94 = call i64 @write(i32 %82, i8* %73, i32 %91)
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %89
96: ; preds = %93
%97 = load i32, i32* @stderr
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %10)
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %89
%102 = icmp slt i32 %91, 0
br i1 %102, label %103, label %108
103: ; preds = %101
%104 = load i32, i32* @stderr
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%106 = load i32, i32* @EXIT_FAILURE
%107 = call i32 @exit(i32 %106)
unreachable
108: ; preds = %101
%109 = call i32 @close(i32 %82)
%110 = load i32, i32* %17
%111 = call i32 @close(i32 %110)
br label %112
112: ; preds = %108, %68
ret i32 0
}