#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(int argc, char *argv[]) {
  int fd[2], numBytes;
  pid_t PID;
  char mensaje[] = "\nEl primer mensaje transmitido por un cauce!!\n";
  char buffer[80];
  pipe(fd);
  if ((PID = fork()) < 0) {
    perror("fork");
    exit(1);
  }
  if (PID == 0) {
    close(fd[0]);
    write(fd[1], mensaje, strlen(mensaje) + 1);
    exit(0);
  } else {
    close(fd[1]);
    numBytes = read(fd[0], buffer, sizeof(buffer));
    printf("\nEl numero de bytes recibidos es: %d", numBytes);
    printf("\nLa cadena enviada a traves del cauce es: %s", buffer);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe3c(%rip),%rsi
mov    $0x2f,%edx
call   1090 <memcpy@plt>
lea    -0x18(%rbp),%rdi
call   1070 <pipe@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    1202 <main+0x62>
lea    0xe3c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1252 <main+0xb2>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x50,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xb0(%rbp),%rsi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x98,%rsp
movups 0xe7e(%rip),%xmm0
movups %xmm0,0x2f(%rsp)
movaps 0xe63(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe47(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
js     1223 <main+0x93>
je     1239 <main+0xa9>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
lea    0x40(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x50,%edx
call   1080 <read@plt>
lea    0xe38(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe05(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <write@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.mensaje = [47 x i8] c"\0AEl primer mensaje transmitido por un cauce!!\0A\00"
@.str = [5 x i8] c"fork\00"
@.str.1 = [37 x i8] c"\0AEl numero de bytes recibidos es: %d\00"
@.str.2 = [45 x i8] c"\0ALa cadena enviada a traves del cauce es: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i64
%9 = alloca [47 x i8]
%10 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [47 x i8]* %9 to i8*
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%13 = call i32 @pipe(i32* %12)
%14 = call i64 (...) @fork()
store i64 %14, i64* %8
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i64, i64* %8
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds [47 x i8], [47 x i8]* %9, i64 0, i64 0
%29 = getelementptr inbounds [47 x i8], [47 x i8]* %9, i64 0, i64 0
%30 = call i64 @strlen(i8* %29)
%31 = add nsw i64 %30, 1
%32 = call i32 @write(i32 %27, i8* %28, i64 %31)
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %19
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 80)
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %34
ret i32 0
}

LLVM IR (-O2):
@__const.main.mensaje = [47 x i8] c"\0AEl primer mensaje transmitido por un cauce!!\0A\00"
@.str = [5 x i8] c"fork\00"
@.str.1 = [37 x i8] c"\0AEl numero de bytes recibidos es: %d\00"
@.str.2 = [45 x i8] c"\0ALa cadena enviada a traves del cauce es: %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [47 x i8]
%5 = alloca [80 x i8]
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [47 x i8], [47 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [80 x i8], [80 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 slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = icmp eq i64 %11, 0
br i1 %17, label %18, label %27
18: ; preds = %16
%19 = load i32, i32* %9
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i64 @strlen(i8* %7)
%24 = add nsw i64 %23, 1
%25 = call i32 @write(i32 %22, i8* %7, i64 %24)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %16
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = load i32, i32* %9
%32 = call i32 @read(i32 %31, i8* %8, i32 80)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %8)
ret i32 0
}