#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd[2];
  char buffer[30];
  pipe(fd);
  if (!fork()) {
    printf("HIJO: escribiendo en el PIPE\n");
    buffer[0] = 'h';
    buffer[1] = 'o';
    buffer[2] = 'l';
    buffer[3] = 'a';
    buffer[4] = '.';
    write(fd[1], buffer, 5);
    printf("HIJO.... adios\n");
    exit(0);
  } else {
    sleep(2);
    printf("PADRE: leyendo desde pipe \n");
    read(fd[0], buffer, 5);
    printf("PADRE: he leido \%s \n", buffer);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x8(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%eax
jne    11d9 <main+0x69>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x68,-0x30(%rbp)
movb   $0x6f,-0x2f(%rbp)
movb   $0x6c,-0x2e(%rbp)
movb   $0x61,-0x2d(%rbp)
movb   $0x2e,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    $0x2,%edi
call   1080 <sleep@plt>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x5,%edx
call   1060 <read@plt>
lea    -0x30(%rbp),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%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   10a0 <fork@plt>
test   %eax,%eax
je     11df <main+0x5f>
mov    $0x2,%edi
call   1090 <sleep@plt>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x5,%edx
call   1070 <read@plt>
lea    0xe33(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
movl   $0x616c6f68,0x10(%rsp)
61
movb   $0x2e,0x14(%rsp)
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"HIJO: escribiendo en el PIPE\0A\00"
@.str.1 = [16 x i8] c"HIJO.... adios\0A\00"
@.str.2 = [28 x i8] c"PADRE: leyendo desde pipe \0A\00"
@.str.3 = [21 x i8] c"PADRE: he leido %s \0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [30 x i8]
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i32 @pipe(i32* %3)
%5 = call i32 (...) @fork()
%6 = icmp ne i32 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
store i8 104, i8* %9
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 1
store i8 111, i8* %10
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 2
store i8 108, i8* %11
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 3
store i8 97, i8* %12
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 4
store i8 46, i8* %13
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%17 = call i32 @write(i32 %15, i8* %16, i32 5)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %0
%21 = call i32 @sleep(i32 2)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 5)
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [21 x i8] c"PADRE: he leido %s \0A\00"
@str = [29 x i8] c"HIJO: escribiendo en el PIPE\00"
@str.4 = [15 x i8] c"HIJO.... adios\00"
@str.5 = [27 x i8] c"PADRE: leyendo desde pipe \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 %20
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
store i8 104, i8* %4
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 1
store i8 111, i8* %11
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 2
store i8 108, i8* %12
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 3
store i8 97, i8* %13
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 4
store i8 46, i8* %14
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @write(i32 %16, i8* %4, i32 5)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %0
%21 = call i32 @sleep(i32 2)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
%23 = load i32, i32* %5
%24 = call i32 @read(i32 %23, i8* %4, i32 5)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %4)
ret i32 0
}