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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int getpid();
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int ipc[2], proc;
  int leido, success;
  char buff[80] = {0};
  if (pipe(ipc) == -1)
    exit(-1);
  switch (fork()) {
  case 0:
    close(ipc[1]);
    strncpy(buff, "INFORMACION IMPORTANTE", sizeof("INFORMACION IMPORTANTE"));
    write(ipc[1], buff, sizeof("INFORMACION IMPORTANTE"));
    exit(0);
  default:
    printf("Leyendo tuberia... \n");
    leido = read(ipc[0], buff, sizeof(buff));
    if (leido < 1) {
      write(0, "\nError al leer tuberia", sizeof("\nError al leer tuberia"));
    } else {
      write(0, "Leido de la tuberia ", sizeof("\nLeido de la tuberia"));
      write(0, buff, leido - 1);
      printf(", por el proceso padre, pid %d \n", getpid());
    }
    wait(NULL);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1070 <memset@plt>
lea    -0xc(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11eb <main+0x3b>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
jne    1234 <main+0x84>
jmp    11ff <main+0x4f>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
lea    -0x70(%rbp),%rdi
lea    0xdee(%rip),%rsi
mov    $0x17,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x17,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x50,%edx
call   10a0 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1278 <main+0xc8>
xor    %edi,%edi
lea    0xdc3(%rip),%rsi
mov    $0x17,%edx
call   1040 <write@plt>
jmp    12b3 <main+0x103>
xor    %edi,%edi
lea    0xdc2(%rip),%rsi
mov    $0x15,%edx
call   1040 <write@plt>
lea    -0x70(%rbp),%rsi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %edi,%edi
call   1040 <write@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <wait@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1090 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11ea <main+0x3a>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
jne    122f <main+0x7f>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
lea    0xdfb(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x17,%edx
call   1030 <strncpy@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x17,%edx
call   1050 <write@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xe2e(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x50,%edx
call   10a0 <read@plt>
test   %eax,%eax
jg     1267 <main+0xb7>
lea    0xdbe(%rip),%rsi
xor    %edi,%edi
mov    $0x17,%edx
call   1050 <write@plt>
jmp    12a4 <main+0xf4>
mov    %eax,%ebx
lea    0xdbe(%rip),%rsi
xor    %edi,%edi
mov    $0x15,%edx
call   1050 <write@plt>
add    $0xffffffff,%ebx
lea    0x10(%rsp),%rsi
xor    %edi,%edi
mov    %ebx,%edx
call   1050 <write@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xda8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10c0 <wait@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"INFORMACION IMPORTANTE\00"
@.str.1 = [21 x i8] c"Leyendo tuberia... \0A\00"
@.str.2 = [23 x i8] c"\0AError al leer tuberia\00"
@.str.3 = [21 x i8] c"Leido de la tuberia \00"
@.str.4 = [33 x i8] c", por el proceso padre, pid %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [80 x i8]
store i32 0, i32* %1
%7 = bitcast [80 x i8]* %6 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = call i32 (...) @fork()
switch i32 %14, label %26 [
i32 0, label %15
]
15: ; preds = %13
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%20 = call i32 @strncpy(i8* %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 23)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%24 = call i32 @write(i32 %22, i8* %23, i32 23)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%29 = load i32, i32* %28
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 80)
store i32 %31, i32* %4
%32 = load i32, i32* %4
%33 = icmp slt i32 %32, 1
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = call i32 @write(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 23)
br label %44
36: ; preds = %26
%37 = call i32 @write(i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 21)
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%39 = load i32, i32* %4
%40 = sub nsw i32 %39, 1
%41 = call i32 @write(i32 0, i8* %38, i32 %40)
%42 = call i32 (...) @getpid()
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %36, %34
%45 = call i32 @wait(i32* null)
%46 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [23 x i8] c"INFORMACION IMPORTANTE\00"
@.str.2 = [23 x i8] c"\0AError al leer tuberia\00"
@.str.3 = [21 x i8] c"Leido de la tuberia \00"
@.str.4 = [33 x i8] c", por el proceso padre, pid %d \0A\00"
@str = [20 x i8] c"Leyendo tuberia... \00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [80 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [80 x i8], [80 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 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = call i32 (...) @fork()
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @close(i32 %15)
%17 = call i32 @strncpy(i8* %4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 23)
%18 = load i32, i32* %14
%19 = call i32 @write(i32 %18, i8* %4, i32 23)
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %10
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%23 = load i32, i32* %5
%24 = call i32 @read(i32 %23, i8* %4, i32 80)
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @write(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 23)
br label %34
28: ; preds = %21
%29 = call i32 @write(i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 21)
%30 = add nsw i32 %24, -1
%31 = call i32 @write(i32 0, i8* %4, i32 %30)
%32 = call i32 (...) @getpid()
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %28, %26
%35 = call i32 @wait(i32* null)
%36 = call i32 @exit(i32 0)
unreachable
}