#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*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int x;
  int fd[2];
  char buf[30];
  char s[30];
  pipe(fd);
  while ((x = fork()) == -1)
    ;
  if (x == 0) {
    sprintf(buf, "This is an example of pipe!/n");
    write(fd[1], buf, 30);
    exit(0);
  } else {
    wait(0);
    read(fd[0], s, 30);
    printf("%s", s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11b0 <main+0x30>
jmp    1198 <main+0x18>
cmpl   $0x0,-0x8(%rbp)
jne    11e2 <main+0x62>
lea    -0x30(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x1e,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1090 <wait@plt>
mov    -0x10(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x1e,%edx
call   1060 <read@plt>
lea    -0x50(%rbp),%rsi
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
nop
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     1180 <main+0x10>
test   %eax,%eax
je     11c4 <main+0x54>
xor    %edi,%edi
call   1080 <wait@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x1e,%edx
call   1060 <read@plt>
lea    0xe6a(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret
movups 0xe43(%rip),%xmm0
movups %xmm0,0x1e(%rsp)
movups 0xe29(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x1e,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"This is an example of pipe!/n\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca [30 x i8]
%5 = alloca [30 x i8]
store i32 0, i32* %1
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
br label %8
8: ; preds = %11, %0
%9 = call i32 (...) @fork()
store i32 %9, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %8
br label %8
12: ; preds = %8
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%17 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%21 = call i32 @write(i32 %19, i8* %20, i32 30)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %12
%24 = call i32 @wait(i32 0)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 30)
%29 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"This is an example of pipe!/n\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [30 x i8]
%3 = alloca [30 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
br label %9
9: ; preds = %9, %0
%10 = call i32 (...) @fork()
switch i32 %10, label %16 [
i32 -1, label %9
i32 0, label %11
]
11: ; preds = %9
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @write(i32 %13, i8* %5, i32 30)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %9
%17 = call i32 @wait(i32 0)
%18 = load i32, i32* %7
%19 = call i32 @read(i32 %18, i8* %6, i32 30)
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
ret i32 0
}