#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*/ str;
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fds[2];
  char str[] = "Who are u?";
  char buf[40];
  pid_t pid;
  pipe(fds);
  pid = fork();
  if (pid == 0) {
    write(fds[1], str, sizeof(str));
  } else {
    read(fds[0], buf, 40);
    puts(buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x23(%rbp)
mov    0xe90(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xe88(%rip),%al
mov    %al,-0x19(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    11ba <main+0x6a>
mov    -0x14(%rbp),%edi
lea    -0x23(%rbp),%rsi
mov    $0xb,%edx
call   1040 <write@plt>
jmp    11d4 <main+0x84>
mov    -0x18(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x28,%edx
call   1060 <read@plt>
lea    -0x50(%rbp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
movabs $0x20657261206f6857,%rax
72 65 20
mov    %rax,0x10(%rsp)
movl   $0x3f7520,0x17(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11a2 <main+0x52>
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x28,%edx
call   1060 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    11b5 <main+0x65>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0xb,%edx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.str = [11 x i8] c"Who are u?\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca [11 x i8]
%8 = alloca [40 x i8]
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [11 x i8]* %7 to i8*
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = call i64 (...) @fork()
store i64 %13, i64* %9
%14 = load i64, i64* %9
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%20 = call i32 @write(i32 %18, i8* %19, i32 11)
br label %28
21: ; preds = %2
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds [40 x i8], [40 x i8]* %8, i64 0, i64 0
%25 = call i32 @read(i32 %23, i8* %24, i32 40)
%26 = getelementptr inbounds [40 x i8], [40 x i8]* %8, i64 0, i64 0
%27 = call i32 @puts(i8* %26)
br label %28
28: ; preds = %21, %16
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [11 x i8] c"Who are u?\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [11 x i8]
%5 = alloca [40 x i8]
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%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* %7, i32 11)
br label %21
17: ; preds = %2
%18 = load i32, i32* %9
%19 = call i32 @read(i32 %18, i8* %8, i32 40)
%20 = call i32 @puts(i8* %8)
br label %21
21: ; preds = %17, %13
ret i32 0
}