#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*/ msg;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int pfds[2];
  char buf[30];
  pipe(pfds);
  int MAX_BUF;
  if (!fork()) {
    char *msg = "Swagatam ...";
    printf(" CHILD: I will be sending the following\n\t\"%s\"\n", msg);
    printf(" CHILD: Writing to the pipe\n");
    write(pfds[1], msg, sizeof(msg));
    printf(" CHILD: Existing\n");
    exit(0);
  } else {
    printf("PARENT: Reading from pipe\n");
    read(pfds[0], buf, MAX_BUF);
    printf("PARENT: read \"%s\"\n", buf);
    printf("Is something missing ...?\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%eax
jne    11d9 <main+0x79>
lea    0xe71(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1060 <read@plt>
lea    -0x30(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11cc <main+0x5c>
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <read@plt>
lea    0xe8e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xe3a(%rip),%rdi
lea    0xe26(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Swagatam ...\00"
@.str.1 = [47 x i8] c" CHILD: I will be sending the following\0A\09\22%s\22\0A\00"
@.str.2 = [29 x i8] c" CHILD: Writing to the pipe\0A\00"
@.str.3 = [18 x i8] c" CHILD: Existing\0A\00"
@.str.4 = [27 x i8] c"PARENT: Reading from pipe\0A\00"
@.str.5 = [19 x i8] c"PARENT: read \22%s\22\0A\00"
@.str.6 = [27 x i8] c"Is something missing ...?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [30 x i8]
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = call i32 (...) @fork()
%9 = icmp ne i32 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %0
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %5
%11 = load i8*, i8** %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%15 = load i32, i32* %14
%16 = load i8*, i8** %5
%17 = call i32 @write(i32 %15, i8* %16, i32 8)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%25 = load i32, i32* %4
%26 = call i32 @read(i32 %23, i8* %24, i32 %25)
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %30
30: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Swagatam ...\00"
@.str.1 = [47 x i8] c" CHILD: I will be sending the following\0A\09\22%s\22\0A\00"
@.str.5 = [19 x i8] c"PARENT: read \22%s\22\0A\00"
@str = [28 x i8] c" CHILD: Writing to the pipe\00"
@str.7 = [17 x i8] c" CHILD: Existing\00"
@str.8 = [26 x i8] c"PARENT: Reading from pipe\00"
@str.9 = [26 x i8] c"Is something missing ...?\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [30 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 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 @write(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 8)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0))
%19 = load i32, i32* %5
%20 = call i32 @read(i32 %19, i8* %4, i32 undef)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.9, i64 0, i64 0))
ret i32 0
}