#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*/ readbuffer;
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  int fd[2], nbytes;
  pid_t pid;
  char readbuffer[14];
  char string[] = "Hello World! \n";
  if (pipe(fd) < 0) {
    perror("pipe error");
    exit(1);
  }
  if ((pid = fork()) < 0) {
    perror("fork error");
    exit(1);
  }
  if (pid) {
    close(fd[0]);
    write(fd[1], string, strlen(string));
    write(fd[1], string, strlen(string));
    write(fd[1], string, strlen(string));
    write(fd[1], string, strlen(string));
    close(fd[1]);
    wait(NULL);
  } else {
    close(fd[1]);
    int i = 0;
    for (i = 0; i < 4; i++) {
      nbytes = read(fd[0], readbuffer, sizeof(readbuffer));
      printf("read %s \n ", readbuffer);
    }
    close(fd[0]);
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe47(%rip),%rax
mov    %rax,-0x35(%rbp)
mov    0xe45(%rip),%eax
mov    %eax,-0x2d(%rbp)
mov    0xe3f(%rip),%ax
mov    %ax,-0x29(%rbp)
mov    0xe37(%rip),%al
mov    %al,-0x27(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
jge    1203 <main+0x63>
lea    0xe1b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    122e <main+0x8e>
lea    0xdfb(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
je     12eb <main+0x14b>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x7c(%rbp)
lea    -0x35(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x35(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x6c(%rbp)
lea    -0x35(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x35(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x35(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x35(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x35(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x35(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <wait@plt>
jmp    134c <main+0x1ac>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x4,-0x3c(%rbp)
jge    133d <main+0x19d>
mov    -0xc(%rbp),%edi
lea    -0x26(%rbp),%rsi
mov    $0xe,%edx
call   1080 <read@plt>
mov    %eax,-0x10(%rbp)
lea    -0x26(%rbp),%rsi
lea    0xcfb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1301 <main+0x161>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
movabs $0xa2021646c726f,%rax
mov    %rax,0x17(%rsp)
movabs $0x6f57206f6c6c6548,%rax
20 57 6f
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
js     1278 <main+0xd8>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
js     1281 <main+0xe1>
je     1297 <main+0xf7>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0xc(%rsp),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0xc(%rsp),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0xc(%rsp),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd90(%rip),%rdi
jmp    1288 <main+0xe8>
lea    0xd92(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
lea    0x22(%rsp),%rbx
mov    %rbx,%rsi
mov    $0xe,%edx
call   1080 <read@plt>
lea    0xd68(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0xe,%edx
call   1080 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0xe,%edx
call   1080 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0xe,%edx
call   1080 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.string = [15 x i8] c"Hello World! \0A\00"
@.str = [11 x i8] c"pipe error\00"
@.str.1 = [11 x i8] c"fork error\00"
@.str.2 = [11 x i8] c"read %s \0A \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i64
%5 = alloca [14 x i8]
%6 = alloca [15 x i8]
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [15 x i8]* %6 to i8*
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%10 = call i64 @pipe(i32* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i64 (...) @fork()
store i64 %16, i64* %4
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = load i64, i64* %4
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %56
24: ; preds = %21
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%29 = load i32, i32* %28
%30 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%31 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @write(i32 %29, i8* %30, i32 %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%37 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @write(i32 %35, i8* %36, i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%43 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
%45 = call i32 @write(i32 %41, i8* %42, i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%47 = load i32, i32* %46
%48 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%49 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @write(i32 %47, i8* %48, i32 %50)
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%53 = load i32, i32* %52
%54 = call i32 @close(i32 %53)
%55 = call i32 @wait(i32* null)
br label %78
56: ; preds = %21
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%58 = load i32, i32* %57
%59 = call i32 @close(i32 %58)
store i32 0, i32* %7
store i32 0, i32* %7
br label %60
60: ; preds = %70, %56
%61 = load i32, i32* %7
%62 = icmp slt i32 %61, 4
br i1 %62, label %63, label %73
63: ; preds = %60
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%65 = load i32, i32* %64
%66 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%67 = call i32 @read(i32 %65, i8* %66, i32 14)
store i32 %67, i32* %3
%68 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%69 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %63
%71 = load i32, i32* %7
%72 = add nsw i32 %71, 1
store i32 %72, i32* %7
br label %60
73: ; preds = %60
%74 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%75 = load i32, i32* %74
%76 = call i32 @close(i32 %75)
%77 = call i32 @exit(i32 0)
unreachable
78: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@__const.main.string = [15 x i8] c"Hello World! \0A\00"
@.str = [11 x i8] c"pipe error\00"
@.str.1 = [11 x i8] c"fork error\00"
@.str.2 = [11 x i8] c"read %s \0A \00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [14 x i8]
%3 = alloca [15 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, 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 = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i64 (...) @fork()
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = icmp eq i64 %14, 0
br i1 %20, label %40, label %21
21: ; preds = %19
%22 = load i32, i32* %7
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @strlen(i8* %6)
%27 = call i32 @write(i32 %25, i8* %6, i32 %26)
%28 = load i32, i32* %24
%29 = call i32 @strlen(i8* %6)
%30 = call i32 @write(i32 %28, i8* %6, i32 %29)
%31 = load i32, i32* %24
%32 = call i32 @strlen(i8* %6)
%33 = call i32 @write(i32 %31, i8* %6, i32 %32)
%34 = load i32, i32* %24
%35 = call i32 @strlen(i8* %6)
%36 = call i32 @write(i32 %34, i8* %6, i32 %35)
%37 = load i32, i32* %24
%38 = call i32 @close(i32 %37)
%39 = call i32 @wait(i32* null)
ret i32 0
40: ; preds = %19
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %7
%45 = call i32 @read(i32 %44, i8* %5, i32 14)
%46 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%47 = load i32, i32* %7
%48 = call i32 @read(i32 %47, i8* %5, i32 14)
%49 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%50 = load i32, i32* %7
%51 = call i32 @read(i32 %50, i8* %5, i32 14)
%52 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%53 = load i32, i32* %7
%54 = call i32 @read(i32 %53, i8* %5, i32 14)
%55 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%56 = load i32, i32* %7
%57 = call i32 @close(i32 %56)
%58 = call i32 @exit(i32 0)
unreachable
}