#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 */
scalar_t__ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char *, int);
size_t write(int, char *, int);
int main() {
  int fd[2];
  size_t size;
  char *string;
  pid_t pid;
  if (pipe(fd) < 0) {
    printf("Can\'t create pipe\n");
    exit(-1);
  }
  pid = fork();
  if (pid < 0)
    printf("Error in fork()\n");
  else if (pid == 0) {
    size = write(fd[1], "Hello, World!", 14);
    if (size != 14) {
      printf("Can\'t write all string\n");
      exit(-1);
    }
  } else {
    size = read(fd[0], string, 14);
    if (size < 0) {
      printf("Can\'t read string\n");
      exit(-1);
    }
    printf("%s\n", string);
  }
  if (close(fd[0]) < 0) {
    printf("Can\'t close input stream\n");
  }
  if (close(fd[1]) < 0) {
    printf("Can\'t close output stream\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    11aa <main+0x3a>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    11d3 <main+0x63>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126d <main+0xfd>
cmpq   $0x0,-0x28(%rbp)
jne    121e <main+0xae>
mov    -0x8(%rbp),%edi
lea    0xe3c(%rip),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xe,-0x18(%rbp)
je     1219 <main+0xa9>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    1268 <main+0xf8>
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0xe,%edx
call   1070 <read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jae    1256 <main+0xe6>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126d <main+0xfd>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
jge    128d <main+0x11d>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
jge    12ad <main+0x13d>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1060 <pipe@plt>
test   %rax,%rax
js     11f3 <main+0x83>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11b0 <main+0x40>
jne    1209 <main+0x99>
mov    0x4(%rsp),%edi
lea    0xe69(%rip),%rsi
mov    $0xe,%edx
call   1040 <write@plt>
cmp    $0xe,%rax
je     11bc <main+0x4c>
lea    0xe93(%rip),%rdi
jmp    11fa <main+0x8a>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%edi
call   1050 <close@plt>
test   %rax,%rax
jns    11d5 <main+0x65>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
test   %rax,%rax
jns    11ef <main+0x7f>
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    (%rsp),%edi
mov    $0xe,%edx
call   1070 <read@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Can't create pipe\0A\00"
@.str.1 = [17 x i8] c"Error in fork()\0A\00"
@.str.2 = [14 x i8] c"Hello, World!\00"
@.str.3 = [24 x i8] c"Can't write all string\0A\00"
@.str.4 = [19 x i8] c"Can't read string\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [26 x i8] c"Can't close input stream\0A\00"
@.str.7 = [27 x i8] c"Can't close output stream\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i64 @pipe(i32* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = call i64 (...) @fork()
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %45
18: ; preds = %12
%19 = load i64, i64* %5
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i64 @write(i32 %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 14)
store i64 %24, i64* %3
%25 = load i64, i64* %3
%26 = icmp ne i64 %25, 14
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %21
br label %44
31: ; preds = %18
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%33 = load i32, i32* %32
%34 = load i8*, i8** %4
%35 = call i64 @read(i32 %33, i8* %34, i32 14)
store i64 %35, i64* %3
%36 = load i64, i64* %3
%37 = icmp ult i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %31
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %31
%42 = load i8*, i8** %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %41, %30
br label %45
45: ; preds = %44, %16
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%47 = load i32, i32* %46
%48 = call i64 @close(i32 %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %52
52: ; preds = %50, %45
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%54 = load i32, i32* %53
%55 = call i64 @close(i32 %54)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %59
59: ; preds = %57, %52
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [14 x i8] c"Hello, World!\00"
@str = [26 x i8] c"Can't close output stream\00"
@str.8 = [25 x i8] c"Can't close input stream\00"
@str.9 = [23 x i8] c"Can't write all string\00"
@str.10 = [16 x i8] c"Error in fork()\00"
@str.11 = [18 x i8] c"Can't create pipe\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i64 @pipe(i32* %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
%8 = call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = call i64 (...) @fork()
%11 = icmp slt i64 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %9
%13 = icmp eq i64 %10, 0
br i1 %13, label %14, label %22
14: ; preds = %12
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i64 @write(i32 %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 14)
%18 = icmp eq i64 %17, 14
br i1 %18, label %27, label %19
19: ; preds = %14
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.9, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %12
%23 = load i32, i32* %3
%24 = call i64 @read(i32 %23, i8* undef, i32 14)
unreachable
25: ; preds = %9
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0))
br label %27
27: ; preds = %25, %14
%28 = load i32, i32* %3
%29 = call i64 @close(i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%35 = load i32, i32* %34
%36 = call i64 @close(i32 %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
ret i32 0
}