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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Less number of arguments\n");
    exit(-1);
  }
  int pipe_fd[2];
  if (pipe(pipe_fd) == -1) {
    fprintf(stderr, "Pipe creation failed\n");
    exit(-2);
  }
  pid_t pid = fork();
  if (pid == -1) {
    fprintf(stderr, "Child process creation failed\n");
    exit(-3);
  }
  if (pid > 0) {
    FILE *fin;
    fin = fopen(argv[1], "rb");
    close(pipe_fd[0]);
    char buffer[10];
    while (fread(buffer, sizeof(char), 9, fin) != 0) {
      write(pipe_fd[1], buffer, 9);
    }
  } else if (pid == 0) {
    FILE *fout;
    char buffer[10];
    close(pipe_fd[1]);
    while (read(pipe_fd[0], buffer, 9))
      printf("%s", buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11df <main+0x3f>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    -0x18(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1210 <main+0x70>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xfffffffe,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1243 <main+0xa3>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xfffffffd,%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    12a9 <main+0x109>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf3(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
lea    -0x32(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x9,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     12a4 <main+0x104>
mov    -0x14(%rbp),%edi
lea    -0x32(%rbp),%rsi
mov    $0x9,%edx
call   1040 <write@plt>
jmp    126d <main+0xcd>
jmp    12f5 <main+0x155>
cmpl   $0x0,-0x1c(%rbp)
jne    12f0 <main+0x150>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x4a(%rbp),%rsi
mov    $0x9,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
je     12eb <main+0x14b>
lea    -0x4a(%rbp),%rsi
lea    0xd71(%rip),%rdi
call   1050 <printf@plt>
jmp    12bb <main+0x11b>
jmp    12f0 <main+0x150>
jmp    12f5 <main+0x155>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jle    12ab <main+0x10b>
mov    %rsi,%rbx
lea    0x4(%rsp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
je     12ca <main+0x12a>
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     12e9 <main+0x149>
test   %eax,%eax
jle    124d <main+0xad>
mov    0x8(%rbx),%rdi
lea    0xe6a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
call   1060 <close@plt>
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x9,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     12a1 <main+0x101>
lea    0xe(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x9,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x9,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    1220 <main+0x80>
jmp    12a1 <main+0x101>
jne    12a1 <main+0x101>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0x4(%rsp),%edi
lea    0xe(%rsp),%rsi
mov    $0x9,%edx
call   1080 <read@plt>
test   %rax,%rax
je     12a1 <main+0x101>
lea    0xddb(%rip),%r14
lea    0xe(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
mov    $0x9,%edx
call   1080 <read@plt>
test   %rax,%rax
jne    1280 <main+0xe0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd45(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xfffffffe,%edi
call   10b0 <exit@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xfffffffd,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Less number of arguments\0A\00"
@.str.1 = [22 x i8] c"Pipe creation failed\0A\00"
@.str.2 = [31 x i8] c"Child process creation failed\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [10 x i8]
%10 = alloca i32*
%11 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%20 = call i32 @pipe(i32* %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 -2)
unreachable
26: ; preds = %18
%27 = call i32 (...) @fork()
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 -3)
unreachable
34: ; preds = %26
%35 = load i32, i32* %7
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %56
37: ; preds = %34
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %41, i32** %8
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%43 = load i32, i32* %42
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %50, %37
%46 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%47 = load i32*, i32** %8
%48 = call i64 @fread(i8* %46, i32 1, i32 9, i32* %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %45
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%52 = load i32, i32* %51
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%54 = call i32 @write(i32 %52, i8* %53, i32 9)
br label %45
55: ; preds = %45
br label %74
56: ; preds = %34
%57 = load i32, i32* %7
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %73
59: ; preds = %56
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%61 = load i32, i32* %60
%62 = call i32 @close(i32 %61)
br label %63
63: ; preds = %69, %59
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%65 = load i32, i32* %64
%66 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%67 = call i64 @read(i32 %65, i8* %66, i32 9)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %63
%70 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%71 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %70)
br label %63
72: ; preds = %63
br label %73
73: ; preds = %72, %56
br label %74
74: ; preds = %73, %55
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Less number of arguments\0A\00"
@.str.1 = [22 x i8] c"Pipe creation failed\0A\00"
@.str.2 = [31 x i8] c"Child process creation failed\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca [10 x i8]
%5 = alloca [10 x i8]
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = bitcast [2 x i32]* %3 to i8*
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 -2)
unreachable
20: ; preds = %11
%21 = call i32 (...) @fork()
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 -3)
unreachable
27: ; preds = %20
%28 = icmp sgt i32 %21, 0
br i1 %28, label %29, label %46
29: ; preds = %27
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* %13
%34 = call i32 @close(i32 %33)
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%36 = call i64 @fread(i8* %35, i32 1, i32 9, i32* %32)
%37 = icmp eq i64 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %29
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br label %40
40: ; preds = %38, %40
%41 = load i32, i32* %39
%42 = call i32 @write(i32 %41, i8* %35, i32 9)
%43 = call i64 @fread(i8* %35, i32 1, i32 9, i32* %32)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %40
45: ; preds = %40, %29
br label %62
46: ; preds = %27
%47 = icmp eq i32 %21, 0
br i1 %47, label %48, label %62
48: ; preds = %46
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 @close(i32 %51)
%53 = load i32, i32* %13
%54 = call i64 @read(i32 %53, i8* %49, i32 9)
%55 = icmp eq i64 %54, 0
br i1 %55, label %61, label %56
56: ; preds = %48, %56
%57 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%58 = load i32, i32* %13
%59 = call i64 @read(i32 %58, i8* %49, i32 9)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %56
61: ; preds = %56, %48
br label %62
62: ; preds = %46, %61, %45
ret i32 0
}