#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 */
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, int *, int);
main() {
  int p[2];
  pipe(p);
  perror("pipe");
  if (fork()) {
    int i;
    printf("enter an integer :\n");
    scanf("%d", &i);
    write(p[1], &i, sizeof(int));
    wait(0);
  } else {
    int j;
    read(p[0], &j, sizeof(int));
    printf("in child integer read is : %d\n", j);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
lea    0xe61(%rip),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
je     11f0 <main+0x70>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe4f(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1090 <wait@plt>
jmp    1212 <main+0x92>
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    -0x14(%rbp),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
lea    0xe5a(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     11f1 <main+0x61>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3b(%rip),%rdi
lea    0x4(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   10a0 <wait@plt>
jmp    1216 <main+0x86>
mov    0x8(%rsp),%edi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0x4(%rsp),%esi
lea    0xdf9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [20 x i8] c"enter an integer :\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [31 x i8] c"in child integer read is : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i32
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 %17
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 @write(i32 %14, i32* %3, i32 4)
%16 = call i32 @wait(i32 0)
br label %23
17: ; preds = %0
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%19 = load i32, i32* %18
%20 = call i32 @read(i32 %19, i32* %4, i32 4)
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %17, %10
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [31 x i8] c"in child integer read is : %d\0A\00"
@str = [19 x i8] c"enter an integer :\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = alloca i32
%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 %18, label %10
10: ; preds = %0
%11 = bitcast i32* %2 to i8*
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @write(i32 %15, i32* %2, i32 4)
%17 = call i32 @wait(i32 0)
br label %24
18: ; preds = %0
%19 = bitcast i32* %3 to i8*
%20 = load i32, i32* %5
%21 = call i32 @read(i32 %20, i32* %3, i32 4)
%22 = load i32, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %18, %10
ret i32 0
}