#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 /*<<< orphan*/ open(int);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main() {
  int fd[2];
  char input[30] = "Santosh Hello";
  char output[30];
  if (!pipe(fd)) {
    printf("Inside the Pipe\n");
    open(fd[1]);
    write(fd[1], input, strlen(input) + 1);
    open(fd[0]);
    close(fd[1]);
    read(fd[0], output, 30);
    printf("\nRead: %s\n", output);
    close(fd[0]);
  } else {
    printf("Error\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe74(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe72(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xe6c(%rip),%ax
mov    %ax,-0x14(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%eax
jne    1246 <main+0xd6>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <open@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1090 <open@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x1e,%edx
call   1080 <read@plt>
lea    -0x50(%rbp),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
jmp    1254 <main+0xe4>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
movups 0xe80(%rip),%xmm0
movups %xmm0,0x1e(%rsp)
movaps 0xe66(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
test   %eax,%eax
je     11bb <main+0x3b>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
jmp    1231 <main+0xb1>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
call   10a0 <open@plt>
mov    0xc(%rsp),%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <write@plt>
mov    0x8(%rsp),%edi
call   10a0 <open@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x1e,%edx
call   1090 <read@plt>
lea    0xe00(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.input = [30 x i8] c"Santosh Hello\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [17 x i8] c"Inside the Pipe\0A\00"
@.str.1 = [11 x i8] c"\0ARead: %s\0A\00"
@.str.2 = [7 x i8] c"Error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [30 x i8]
%4 = alloca [30 x i8]
store i32 0, i32* %1
%5 = bitcast [30 x i8]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %36, label %9
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @open(i32 %12)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
%20 = call i32 @write(i32 %15, i8* %16, i64 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%22 = load i32, i32* %21
%23 = call i32 @open(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 30)
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%34 = load i32, i32* %33
%35 = call i32 @close(i32 %34)
br label %38
36: ; preds = %0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %9
ret i32 0
}

LLVM IR (-O2):
@__const.main.input = [30 x i8] c"Santosh Hello\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.1 = [11 x i8] c"\0ARead: %s\0A\00"
@str = [16 x i8] c"Inside the Pipe\00"
@str.3 = [6 x i8] c"Error\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)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %28
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @open(i32 %13)
%15 = load i32, i32* %12
%16 = call i64 @strlen(i8* %5)
%17 = add nsw i64 %16, 1
%18 = call i32 @write(i32 %15, i8* %5, i64 %17)
%19 = load i32, i32* %7
%20 = call i32 @open(i32 %19)
%21 = load i32, i32* %12
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %7
%24 = call i32 @read(i32 %23, i8* %6, i32 30)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%26 = load i32, i32* %7
%27 = call i32 @close(i32 %26)
br label %30
28: ; preds = %0
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %10
ret i32 0
}