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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fork();
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  pid_t cpid;
  FILE *fp;
  int fifod[2];
  int sta;
  char buf[256] = "Linux C\n";
  if (pipe(fifod) < 0) {
    printf("pipe error.\n");
    exit(1);
  }
  cpid = fork();
  if (cpid < 0) {
    printf("fork error.\n");
    exit(1);
  }
  if (cpid == 0) {
    fp = fopen(argv[1], "r");
    if (fp == NULL) {
      perror("open file error");
      exit(1);
    }
    while (fgets(buf, sizeof(buf), fp) != NULL) {
      close(fifod[0]);
      write(fifod[1], buf, sizeof(buf));
    }
    fclose(fp);
    strcpy(buf, "`");
    close(fifod[0]);
    write(fifod[1], buf, sizeof(buf));
  } else {
    fp = fopen(argv[2], "w");
    if (fp == NULL) {
      perror("open write file error");
      exit(1);
    }
    close(fifod[1]);
    read(fifod[0], buf, sizeof(buf));
    while ('`' != buf[0]) {
      fputs(buf, fp);
      close(fifod[1]);
      read(fifod[0], buf, sizeof(buf));
    }
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x130(%rbp),%rdi
lea    0xdf9(%rip),%rsi
mov    $0x100,%edx
call   10c0 <memcpy@plt>
lea    -0x28(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0x0,%rax
jge    123a <main+0x5a>
lea    0xed5(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1266 <main+0x86>
lea    0xeb6(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    132c <main+0x14c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xec2(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12aa <main+0xca>
lea    0xe7f(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    12af <main+0xcf>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x100,%esi
call   10b0 <fgets@plt>
cmp    $0x0,%rax
je     12ef <main+0x10f>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   1040 <write@plt>
jmp    12af <main+0xcf>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x130(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   1040 <write@plt>
jmp    13cf <main+0x1ef>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf1(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1365 <main+0x185>
lea    0xdd8(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    -0x28(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   10a0 <read@plt>
movsbl -0x130(%rbp),%ecx
mov    $0x60,%eax
cmp    %ecx,%eax
je     13c6 <main+0x1e6>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <fputs@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    -0x28(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   10a0 <read@plt>
jmp    1381 <main+0x1a1>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
lea    0xe0c(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x100,%edx
call   10c0 <memcpy@plt>
lea    0x8(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
js     1362 <main+0x182>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
js     136b <main+0x18b>
je     12a9 <main+0xc9>
mov    0x10(%rbx),%rdi
lea    0xedb(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1381 <main+0x1a1>
mov    %rax,%r14
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   10a0 <read@plt>
cmpb   $0x60,0x10(%rsp)
je     129c <main+0xbc>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <fputs@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   10a0 <read@plt>
cmpb   $0x60,0x10(%rsp)
jne    1270 <main+0x90>
mov    %r14,%rdi
call   1060 <fclose@plt>
jmp    1355 <main+0x175>
mov    0x8(%rbx),%rdi
lea    0xe74(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     138a <main+0x1aa>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
je     131f <main+0x13f>
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
jne    12f0 <main+0x110>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xde2(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <write@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdcd(%rip),%rdi
jmp    1372 <main+0x192>
lea    0xdb8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd8c(%rip),%rdi
jmp    1391 <main+0x1b1>
lea    0xd6f(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@__const.main.buf = [256 x i8] c"Linux C\0A\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [13 x i8] c"pipe error.\0A\00"
@.str.1 = [13 x i8] c"fork error.\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [16 x i8] c"open file error\00"
@.str.4 = [2 x i8] c"`\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [22 x i8] c"open write file error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
%8 = alloca [2 x i32]
%9 = alloca i32
%10 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [256 x i8]* %10 to i8*
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%13 = call i64 @pipe(i32* %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = call i64 (...) @fork()
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = load i64, i64* %6
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %64
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %28
br label %39
39: ; preds = %44, %38
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%41 = load i32*, i32** %7
%42 = call i32* @fgets(i8* %40, i32 256, i32* %41)
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %52
44: ; preds = %39
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%46 = load i32, i32* %45
%47 = call i32 @close(i32 %46)
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%49 = load i32, i32* %48
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%51 = call i32 @write(i32 %49, i8* %50, i32 256)
br label %39
52: ; preds = %39
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%56 = call i32 @strcpy(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%58 = load i32, i32* %57
%59 = call i32 @close(i32 %58)
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%61 = load i32, i32* %60
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%63 = call i32 @write(i32 %61, i8* %62, i32 256)
br label %101
64: ; preds = %25
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 2
%67 = load i8*, i8** %66
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %68, i32** %7
%69 = load i32*, i32** %7
%70 = icmp eq i32* %69, null
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %64
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%76 = load i32, i32* %75
%77 = call i32 @close(i32 %76)
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%79 = load i32, i32* %78
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%81 = call i32 @read(i32 %79, i8* %80, i32 256)
br label %82
82: ; preds = %87, %74
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = icmp ne i32 96, %85
br i1 %86, label %87, label %98
87: ; preds = %82
%88 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%89 = load i32*, i32** %7
%90 = call i32 @fputs(i8* %88, i32* %89)
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%92 = load i32, i32* %91
%93 = call i32 @close(i32 %92)
%94 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%95 = load i32, i32* %94
%96 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%97 = call i32 @read(i32 %95, i8* %96, i32 256)
br label %82
98: ; preds = %82
%99 = load i32*, i32** %7
%100 = call i32 @fclose(i32* %99)
br label %101
101: ; preds = %98, %52
ret i32 0
}

LLVM IR (-O2):
@__const.main.buf = [256 x i8] c"Linux C\0A\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [16 x i8] c"open file error\00"
@.str.4 = [2 x i8] c"`\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [22 x i8] c"open write file error\00"
@str = [12 x i8] c"fork error.\00"
@str.7 = [12 x i8] c"pipe error.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca [256 x i8]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i64 (...) @fork()
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = icmp eq i64 %14, 0
br i1 %20, label %21, label %49
21: ; preds = %19
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = call i32* @fgets(i8* %6, i32 256, i32* %24)
%28 = icmp eq i32* %27, null
br i1 %28, label %41, label %29
29: ; preds = %26
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br label %34
31: ; preds = %21
%32 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %29, %34
%35 = load i32, i32* %7
%36 = call i32 @close(i32 %35)
%37 = load i32, i32* %30
%38 = call i32 @write(i32 %37, i8* %6, i32 256)
%39 = call i32* @fgets(i8* %6, i32 256, i32* %24)
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %34
41: ; preds = %34, %26
%42 = call i32 @fclose(i32* %24)
%43 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32, i32* %7
%45 = call i32 @close(i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @write(i32 %47, i8* %6, i32 256)
br label %75
49: ; preds = %19
%50 = getelementptr inbounds i8*, i8** %1, i64 2
%51 = load i8*, i8** %50
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %49
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%59 = load i32, i32* %58
%60 = call i32 @close(i32 %59)
%61 = load i32, i32* %7
%62 = call i32 @read(i32 %61, i8* %6, i32 256)
%63 = load i8, i8* %6
%64 = icmp eq i8 %63, 96
br i1 %64, label %73, label %65
65: ; preds = %57, %65
%66 = call i32 @fputs(i8* %6, i32* %52)
%67 = load i32, i32* %58
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* %7
%70 = call i32 @read(i32 %69, i8* %6, i32 256)
%71 = load i8, i8* %6
%72 = icmp eq i8 %71, 96
br i1 %72, label %73, label %65
73: ; preds = %65, %57
%74 = call i32 @fclose(i32* %52)
br label %75
75: ; preds = %73, %41
ret i32 0
}