#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int 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[] = "Hello, world!";
  char st[50];
  int sz = 14;
  printf("Ok\n");
  if (pipe(fd) == 0) {
    printf("Piped\n");
    int id = fork();
    if (id > 0)
      size = write(fd[1], string, sz);
    else {
      size = read(fd[0], st, sz);
      printf("|%s|\n", st);
    }
  }
  close(fd[0]);
  close(fd[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x26(%rbp)
mov    0xe88(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xe82(%rip),%ax
mov    %ax,-0x1a(%rbp)
movl   $0xe,-0x64(%rbp)
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jne    121a <main+0xba>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jle    11f0 <main+0x90>
mov    -0x8(%rbp),%edi
lea    -0x26(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1030 <write@plt>
mov    %rax,-0x18(%rbp)
jmp    1215 <main+0xb5>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1070 <read@plt>
mov    %rax,-0x18(%rbp)
lea    -0x60(%rbp),%rsi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121a <main+0xba>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
movabs $0x21646c726f7720,%rax
mov    %rax,0x16(%rsp)
movabs $0x77202c6f6c6c6548,%rax
2c 20 77
mov    %rax,0x10(%rsp)
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
jne    1201 <main+0x91>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
jle    11da <main+0x6a>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0xe,%edx
call   1040 <write@plt>
jmp    1201 <main+0x91>
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
mov    $0xe,%edx
call   1080 <read@plt>
lea    0xe17(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.string = [14 x i8] c"Hello, world!\00"
@.str = [4 x i8] c"Ok\0A\00"
@.str.1 = [7 x i8] c"Piped\0A\00"
@.str.2 = [6 x i8] c"|%s|\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i64
%4 = alloca [14 x i8]
%5 = alloca [50 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [14 x i8]* %4 to i8*
store i32 14, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = call i64 @pipe(i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (...) @fork()
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%22 = load i32, i32* %6
%23 = call i64 @write(i32 %20, i8* %21, i32 %22)
store i64 %23, i64* %3
br label %32
24: ; preds = %13
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%28 = load i32, i32* %6
%29 = call i64 @read(i32 %26, i8* %27, i32 %28)
store i64 %29, i64* %3
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %24, %18
br label %33
33: ; preds = %32, %0
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%35 = load i32, i32* %34
%36 = call i32 @close(i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
ret i32 0
}

LLVM IR (-O2):
@__const.main.string = [14 x i8] c"Hello, world!\00"
@.str.2 = [6 x i8] c"|%s|\0A\00"
@str = [3 x i8] c"Ok\00"
@str.3 = [6 x i8] c"Piped\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [14 x i8]
%3 = alloca [50 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 [50 x i8], [50 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%9 = call i64 @pipe(i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.3, i64 0, i64 0))
%13 = call i32 (...) @fork()
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i64 @write(i32 %17, i8* %5, i32 14)
br label %23
19: ; preds = %11
%20 = load i32, i32* %8
%21 = call i64 @read(i32 %20, i8* %6, i32 14)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %23
23: ; preds = %15, %19, %0
%24 = load i32, i32* %8
%25 = call i32 @close(i32 %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
ret i32 0
}