#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 int /*<<< orphan*/ b;

/* Variables and functions */
scalar_t__ fork();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, scalar_t__);
main() {
  int p[2];
  pipe(p);
  perror("pipe");
  if (fork()) {
    char a[50] = {};
    printf("enter a string :\n");
    gets(a);
    write(p[1], a, strlen(a) + 1);
    wait(0);
  } else {
    char b[50] = {};
    read(p[0], b, sizeof(b));
    printf("in child string read is : %s\n", b);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
lea    0xe3e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
je     1241 <main+0xa1>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1090 <gets@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
jmp    1274 <main+0xd4>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x32,%edx
call   1080 <read@plt>
lea    -0x80(%rbp),%rsi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
lea    0xe49(%rip),%rdi
call   10a0 <perror@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
xorps  %xmm0,%xmm0
test   %rax,%rax
je     121d <main+0x7d>
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <gets@plt>
mov    0xc(%rsp),%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
jmp    125a <main+0xba>
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x32,%edx
call   1080 <read@plt>
lea    0xdb5(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [18 x i8] c"enter a string :\0A\00"
@.str.2 = [30 x i8] c"in child string read is : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [50 x i8]
%4 = alloca [50 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i64 (...) @fork()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %0
%11 = bitcast [50 x i8]* %3 to i8*
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%14 = call i32 @gets(i8* %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %19, 1
%21 = call i32 @write(i32 %16, i8* %17, i64 %20)
%22 = call i32 @wait(i32 0)
br label %31
23: ; preds = %0
%24 = bitcast [50 x i8]* %4 to i8*
%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]* %4, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 50)
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %23, %10
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.2 = [30 x i8] c"in child string read is : %s\0A\00"
@str = [17 x i8] c"enter a string :\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %0
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%13 = call i32 @gets(i8* %11)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i64 @strlen(i8* %11)
%17 = add nsw i64 %16, 1
%18 = call i32 @write(i32 %15, i8* %11, i64 %17)
%19 = call i32 @wait(i32 0)
br label %25
20: ; preds = %0
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%22 = load i32, i32* %5
%23 = call i32 @read(i32 %22, i8* %21, i32 50)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %25
25: ; preds = %20, %10
ret i32 0
}