#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 pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char buffer[20];
  int pfd[2];
  if (pipe(pfd) == -1) {
    printf("Pipe Creation Failed");
    exit(0);
  } else
    printf("Pipe Created Successfully\n");
  printf("Writing to pipe\n");
  write(pfd[1], "Hello World", 11);
  printf("Reading from pipe to buffer\n");
  read(pfd[0], buffer, 11);
  printf("Buffer : %s\n", buffer);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1186 <main+0x36>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
lea    0xe95(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xb,%edx
call   1060 <read@plt>
lea    -0x20(%rbp),%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     11df <main+0x7f>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
lea    0xe7e(%rip),%rsi
mov    $0xb,%edx
call   1040 <write@plt>
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0xb,%edx
call   1070 <read@plt>
lea    0xe57(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xe1a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Pipe Creation Failed\00"
@.str.1 = [27 x i8] c"Pipe Created Successfully\0A\00"
@.str.2 = [17 x i8] c"Writing to pipe\0A\00"
@.str.3 = [12 x i8] c"Hello World\00"
@.str.4 = [29 x i8] c"Reading from pipe to buffer\0A\00"
@.str.5 = [13 x i8] c"Buffer : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [2 x i32]
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 0)
unreachable
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 11)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 11)
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %22)
ret i32 1
}

LLVM IR (-O2):
@.str = [21 x i8] c"Pipe Creation Failed\00"
@.str.3 = [12 x i8] c"Hello World\00"
@.str.5 = [13 x i8] c"Buffer : %s\0A\00"
@str = [26 x i8] c"Pipe Created Successfully\00"
@str.6 = [16 x i8] c"Writing to pipe\00"
@str.7 = [28 x i8] c"Reading from pipe to buffer\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [2 x i32]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = bitcast [2 x i32]* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 11)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0))
%18 = load i32, i32* %5
%19 = call i32 @read(i32 %18, i8* %3, i32 11)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %3)
ret i32 1
}